14 #include <sys/times.h> 25 #undef ZYPP_BASE_LOGGER_LOGGROUP 26 #define ZYPP_BASE_LOGGER_LOGGROUP "Measure" 73 std::string
stringIf( clock_t ticks_r,
const std::string & tag_r )
const 84 double asSec( clock_t ticks_r )
const 85 {
return double(ticks_r) /
ticks; }
89 time_t h = sec_r/3600;
94 return str::form(
"%lu:%02lu:%02lu", h, m, sec_r );
96 return str::form(
"%lu:%02lu", m, sec_r );
102 time_t h = time_t(sec_r)/3600;
104 time_t m = time_t(sec_r)/60;
107 return str::form(
"%lu:%02lu:%05.2lf", h, m, sec_r );
109 return str::form(
"%lu:%05.2lf", m, sec_r );
123 const struct tms
Tm::
tmsEmpty = { 0, 0, 0, 0 };
124 const long Tm::ticks = sysconf(_SC_CLK_TCK);
141 Impl(
const std::string & ident_r )
147 log() << _level <<
"START MEASURE(" << _ident <<
")" << endl;
155 std::ostream &
str( log() << _level <<
"MEASURE(" << _ident <<
") " );
157 _glevel.erase( 0, 2 );
162 log() << _level <<
"RESTART MEASURE(" << _ident <<
")" << endl;
166 void elapsed(
const std::string & tag_r = std::string() )
const 170 std::ostream &
str( log() << _level <<
"ELAPSED(" << _ident <<
") " );
171 dumpMeasure( str, tag_r );
177 std::ostream &
log()
const 180 std::ostream &
dumpMeasure( std::ostream & str_r,
const std::string & tag_r = std::string() )
const 182 str_r << ( _stop - _start );
185 str_r <<
" [" << ( _stop - _elapsed ) <<
"]";
187 if ( ! tag_r.empty() )
188 str_r <<
" - " << tag_r;
189 return str_r << endl;
217 : _pimpl( new
Impl( ident_r ) )
void elapsed() const
Print elapsed time for a running timer.
double asSec(clock_t ticks_r) const
time_t _real
Real time via ::time.
void elapsed(const std::string &tag_r=std::string()) const
std::string asString(const DefaultIntegral< Tp, TInitial > &obj)
Tm operator-(const Tm &rhs) const
void stop()
Stop a running timer.
RW_pointer< Impl > _pimpl
Pointer to implementation.
String related utilities and Regular expression matching.
std::string form(const char *format,...) __attribute__((format(printf
Printf style construction of std::string.
void restart()
re start the timer without reset-ing it.
std::string timeStr(double sec_r) const
std::ostream & dumpMeasure(std::ostream &str_r, const std::string &tag_r=std::string()) const
void start(const std::string &ident_r=std::string())
Start timer for ident_r string.
struct tms _proc
Process times via ::times.
std::string asString() const
Measure()
Default Ctor does nothing.
Impl(const std::string &ident_r)
std::ostream & operator<<(std::ostream &str, const Tm &obj)
Tm Stream output.
Times measured by Measure.
static std::string _glevel
std::string stringIf(clock_t ticks_r, const std::string &tag_r) const
static const long ticks
Systems ticks per second.
std::string timeStr(time_t sec_r) const
std::ostream & log() const
Return the log stream.
Easy-to use interface to the ZYPP dependency resolver.