libzypp
11.13.5
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
libzypp
Welcome to libzypp
Code Pitfalls - Frequently made mistakes
Code Snippets
Environment Variables
Testing for provided features.
Notes on revisions
Extending ZYpp: Plugins and Hooks
Services
Solver - Vendor protection
Writing and tunning testcases
Libzypp and threads
Todo List
Deprecated List
Modules
Namespaces
Classes
Files
File List
zypp
base
Algorithm.h
Collector.h
Counter.h
Debug.h
DefaultIntegral.h
DtorReset.h
Easy.h
Errno.h
Exception.cc
Exception.h
ExternalDataSource.cc
ExternalDataSource.h
Fd.cc
Fd.h
Flags.h
Function.h
Functional.h
Gettext.cc
Gettext.h
GzStream.cc
GzStream.h
InputStream.cc
InputStream.h
InterProcessMutex.cc
InterProcessMutex.h
IOStream.cc
IOStream.h
Iterator.h
LogControl.cc
LogControl.h
Logger.h
LogTools.h
Measure.cc
Measure.h
NonCopyable.h
ProfilingFormater.cc
ProfilingFormater.h
ProvideNumericId.h
PtrTypes.h
Random.cc
Random.h
ReferenceCounted.cc
ReferenceCounted.h
Regex.cc
Regex.h
SafeBool.h
SerialNumber.cc
SerialNumber.h
Signal.h
String.cc
String.h
StrMatcher.cc
StrMatcher.h
Sysconfig.cc
Sysconfig.h
Tr1hash.h
Unit.cc
Unit.h
UserRequestException.cc
UserRequestException.h
WatchFile.h
media
misc
parser
pool
repo
sat
solver
target
thread
ui
url
ws
zypp_detail
APIConfig.h
Arch.cc
Arch.h
AutoDispose.h
Bit.h
ByteCount.cc
ByteCount.h
Callback.h
Capabilities.cc
Capabilities.h
Capability.cc
Capability.h
CapMatch.cc
CapMatch.h
Changelog.cc
Changelog.h
CheckSum.cc
CheckSum.h
CountryCode.cc
CountryCode.h
Date.cc
Date.h
Dep.cc
Dep.h
Digest.cc
Digest.h
DiskUsage.cc
DiskUsage.h
DiskUsageCounter.cc
DiskUsageCounter.h
DownloadMode.cc
DownloadMode.h
Edition.cc
Edition.h
ExternalProgram.cc
ExternalProgram.h
Fetcher.cc
Fetcher.h
FileChecker.cc
FileChecker.h
Filter.h
Glob.cc
Glob.h
HistoryLog.cc
HistoryLog.h
HistoryLogData.cc
HistoryLogData.h
IdString.cc
IdString.h
IdStringType.h
InstanceId.cc
InstanceId.h
KeyContext.h
KeyRing.cc
KeyRing.h
KVMap.h
LanguageCode.cc
LanguageCode.h
Locale.cc
Locale.h
Locks.cc
Locks.h
ManagedFile.h
MediaProducts.cc
MediaProducts.h
MediaSetAccess.cc
MediaSetAccess.h
Misc.h
OnMediaLocation.cc
OnMediaLocation.h
Package.cc
Package.h
PackageKeyword.h
Patch.cc
Patch.h
PathInfo.cc
PathInfo.h
Pathname.cc
Pathname.h
Pattern.cc
Pattern.h
PluginFrame.cc
PluginFrame.h
PluginFrameException.cc
PluginFrameException.h
PluginScript.cc
PluginScript.h
PluginScriptException.cc
PluginScriptException.h
PoolItem.cc
PoolItem.h
PoolItemBest.cc
PoolItemBest.h
PoolQuery.cc
PoolQuery.h
PoolQueryResult.cc
PoolQueryResult.h
PoolQueryUtil.tcc
ProblemSolution.cc
ProblemSolution.h
ProblemTypes.h
Product.cc
Product.h
ProgressData.cc
ProgressData.h
ProvideFilePolicy.cc
ProvideFilePolicy.h
PublicKey.cc
PublicKey.h
Range.cc
Range.h
Rel.cc
Rel.h
RelCompare.h
RepoInfo.cc
RepoInfo.h
RepoManager.cc
RepoManager.h
Repository.cc
Repository.h
RepoStatus.cc
RepoStatus.h
ResFilters.h
ResKind.cc
ResKind.h
ResObject.cc
ResObject.h
ResObjects.h
Resolvable.cc
Resolvable.h
Resolver.cc
Resolver.h
ResolverProblem.cc
ResolverProblem.h
ResPool.cc
ResPool.h
ResPoolProxy.cc
ResPoolProxy.h
ResStatus.cc
ResStatus.h
ResTraits.h
ServiceInfo.cc
ServiceInfo.h
Signature.cc
Signature.h
SrcPackage.cc
SrcPackage.h
SysContent.cc
SysContent.h
Target.cc
Target.h
TmpPath.cc
TmpPath.h
TriBool.h
Url.cc
Url.h
Vendor.h
VendorAttr.cc
VendorAttr.h
VendorSupportOptions.cc
VendorSupportOptions.h
ZConfig.cc
ZConfig.h
ZYpp.cc
ZYpp.h
ZYppCallbacks.h
ZYppCommit.h
ZYppCommitPolicy.cc
ZYppCommitPolicy.h
ZYppCommitResult.cc
ZYppCommitResult.h
ZYppFactory.cc
ZYppFactory.h
File Members
Measure.cc
Go to the documentation of this file.
1
/*---------------------------------------------------------------------\
2
| ____ _ __ __ ___ |
3
| |__ / \ / / . \ . \ |
4
| / / \ V /| _/ _/ |
5
| / /__ | | | | | | |
6
| /_____||_| |_| |_| |
7
| |
8
\---------------------------------------------------------------------*/
12
extern
"C"
13
{
14
#include <sys/times.h>
15
#include <unistd.h>
16
}
17
#include <iostream>
18
19
#include "
zypp/base/Logger.h
"
20
#include "
zypp/base/Measure.h
"
21
#include "
zypp/base/String.h
"
22
23
using
std::endl;
24
25
#undef ZYPP_BASE_LOGGER_LOGGROUP
26
#define ZYPP_BASE_LOGGER_LOGGROUP "Measure"
27
29
namespace
zypp
30
{
31
32
namespace
debug
33
{
34
36
struct
Tm
37
{
38
Tm
()
39
:
_real
( 0 )
40
,
_proc
(
tmsEmpty
)
41
{}
42
43
void
get
()
44
{
45
_real
= ::time(NULL);
46
::times( &
_proc
);
47
}
48
49
Tm
operator-
(
const
Tm
& rhs )
const
50
{
51
Tm
ret( *
this
);
52
ret.
_real
-= rhs.
_real
;
53
ret.
_proc
.tms_utime -= rhs.
_proc
.tms_utime;
54
ret.
_proc
.tms_stime -= rhs.
_proc
.tms_stime;
55
ret.
_proc
.tms_cutime -= rhs.
_proc
.tms_cutime;
56
ret.
_proc
.tms_cstime -= rhs.
_proc
.tms_cstime;
57
return
ret;
58
}
59
60
std::string
asString
()
const
61
{
62
std::string ret(
timeStr
(
_real
) );
63
ret +=
" (u "
;
64
ret +=
timeStr
(
asSec
(
_proc
.tms_utime ) );
65
ret +=
" s "
;
66
ret +=
timeStr
(
asSec
(
_proc
.tms_stime ) );
67
ret +=
" c "
;
68
ret +=
timeStr
(
asSec
(
_proc
.tms_cutime +
_proc
.tms_cstime ) );
69
ret +=
")"
;
70
return
ret;
71
}
72
73
std::string
stringIf
( clock_t ticks_r,
const
std::string & tag_r )
const
74
{
75
std::string ret;
76
if
( ticks_r )
77
{
78
ret += tag_r;
79
ret +=
timeStr
(
asSec
( ticks_r ) );
80
}
81
return
ret;
82
}
83
84
double
asSec
( clock_t ticks_r )
const
85
{
return
double(ticks_r) /
ticks
; }
86
87
std::string
timeStr
( time_t sec_r )
const
88
{
89
time_t h = sec_r/3600;
90
sec_r -= h*3600;
91
time_t m = sec_r/60;
92
sec_r -= m*60;
93
if
( h )
94
return
str::form
(
"%lu:%02lu:%02lu"
, h, m, sec_r );
95
if
( m )
96
return
str::form
(
"%lu:%02lu"
, m, sec_r );
97
return
str::form
(
"%lu"
, sec_r );
98
}
99
100
std::string
timeStr
(
double
sec_r )
const
101
{
102
time_t h = time_t(sec_r)/3600;
103
sec_r -= h*3600;
104
time_t m = time_t(sec_r)/60;
105
sec_r -= m*60;
106
if
( h )
107
return
str::form
(
"%lu:%02lu:%05.2lf"
, h, m, sec_r );
108
if
( m )
109
return
str::form
(
"%lu:%05.2lf"
, m, sec_r );
110
return
str::form
(
"%.2lf"
, sec_r );
111
}
112
114
static
const
long
ticks
;
116
static
const
struct
tms
tmsEmpty
;
118
time_t
_real
;
120
struct
tms
_proc
;
121
};
122
123
const
struct
tms
Tm
::
tmsEmpty
= { 0, 0, 0, 0 };
124
const
long
Tm::ticks
= sysconf(_SC_CLK_TCK);
125
127
std::ostream &
operator<<
( std::ostream & str,
const
Tm
& obj )
128
{
129
return
str << obj.
asString
();
130
}
131
132
134
//
135
// CLASS NAME : Measure::Impl
136
//
138
class
Measure::Impl
139
{
140
public
:
141
Impl
(
const
std::string & ident_r )
142
:
_ident
( ident_r )
143
,
_seq
( 0 )
144
{
145
INT
<<
"START MEASURE("
<<
_ident
<<
")"
<< endl;
146
_start
.
get
();
147
}
148
149
~Impl
()
150
{
151
_stop
.
get
();
152
++
_seq
;
153
std::ostream & str(
INT
<<
"MEASURE("
<<
_ident
<<
") "
);
154
dumpMeasure
( str );
155
}
156
157
void
restart
()
158
{
159
INT
<<
"RESTART MEASURE("
<<
_ident
<<
")"
<< endl;
160
_start
=
_stop
;
161
}
162
163
void
elapsed
()
const
164
{
165
_stop
.
get
();
166
++
_seq
;
167
std::ostream & str(
INT
<<
"ELAPSED("
<<
_ident
<<
") "
);
168
dumpMeasure
( str );
169
_elapsed
=
_stop
;
170
}
171
172
private
:
173
std::ostream &
dumpMeasure
( std::ostream & str_r )
const
174
{
175
str_r << (
_stop
-
_start
);
176
if
(
_seq
> 1 )
// diff to previous _elapsed
177
{
178
str_r <<
" ["
<< (
_stop
-
_elapsed
) <<
"]"
;
179
}
180
return
str_r << endl;
181
}
182
183
private
:
184
std::string
_ident
;
185
Tm
_start
;
186
mutable
unsigned
_seq
;
187
mutable
Tm
_elapsed
;
188
mutable
Tm
_stop
;
189
};
191
193
//
194
// CLASS NAME : Measure
195
//
197
199
//
200
// METHOD NAME : Measure::Measure
201
// METHOD TYPE : Ctor
202
//
203
Measure::Measure
()
204
{}
205
207
//
208
// METHOD NAME : Measure::Measure
209
// METHOD TYPE : Ctor
210
//
211
Measure::Measure
(
const
std::string & ident_r )
212
: _pimpl( new
Impl
( ident_r ) )
213
{}
214
216
//
217
// METHOD NAME : Measure::~Measure
218
// METHOD TYPE : Dtor
219
//
220
Measure::~Measure
()
221
{}
222
224
//
225
// METHOD NAME : Measure::start
226
// METHOD TYPE : void
227
//
228
void
Measure::start
(
const
std::string & ident_r )
229
{
230
stop
();
231
_pimpl
.
reset
(
new
Impl
( ident_r ) );
232
}
233
235
//
236
// METHOD NAME : Measure::start
237
// METHOD TYPE : void
238
//
239
void
Measure::restart
()
240
{
241
_pimpl
->
restart
();
242
}
243
245
//
246
// METHOD NAME : Measure::
247
// METHOD TYPE : void
248
//
249
void
Measure::elapsed
()
const
250
{
251
if
(
_pimpl
)
252
_pimpl
->
elapsed
();
253
}
254
256
//
257
// METHOD NAME : Measure::
258
// METHOD TYPE : void
259
//
260
void
Measure::stop
()
261
{
262
_pimpl
.
reset
();
263
}
264
266
}
// namespace debug
269
}
// namespace zypp
zypp
base
Measure.cc
Generated by
1.8.1