The Gaudi Framework  master (ff829712)
Loading...
Searching...
No Matches
ChronoEntity Class Reference

a small helper class for implementation of ChronoStatSvc service, It also could be used as some local timer More...

#include <GaudiKernel/ChronoEntity.h>

Collaboration diagram for ChronoEntity:

Public Member Functions

 ChronoEntity ()=default
 default constructor
 
IChronoSvc::ChronoStatus start ()
 start the current chrono
 
IChronoSvc::ChronoStatus stop ()
 stop the chrono
 
IChronoSvc::ChronoTime delta (IChronoSvc::ChronoType type) const
 return the last delta-time of type "type"
 
IChronoSvc::ChronoStatus status () const
 return the status of chrono
 
unsigned long nOfMeasurements () const
 number of chrono measurements
 
double uMinimalTime () const
 minimal measurement for user time
 
double kMinimalTime () const
 minimal measurement for kernel time
 
double eMinimalTime () const
 minimal measurement for elapsed time
 
double uMaximalTime () const
 maximal measurement for user time
 
double kMaximalTime () const
 maximal measurement for kernel time
 
double eMaximalTime () const
 maximal measurement for elapsed time
 
double uTotalTime () const
 total user time
 
double kTotalTime () const
 total Kernel time
 
double eTotalTime () const
 total Elapsed time
 
double totalTime () const
 total time
 
double kMeanTime () const
 average Kernel Time
 
double uMeanTime () const
 average User Time
 
double eMeanTime () const
 average Elapsed Time
 
double kRMSTime () const
 r.m.s Kernel Time
 
double uRMSTime () const
 r.m.s User Time
 
double eRMSTime () const
 r.m.s Elapsed Time
 
double kMeanErrorTime () const
 error in mean Kernel time
 
double uMeanErrorTime () const
 error in mean User time
 
double eMeanErrorTime () const
 error in mean Elapsed time
 
ChronoEntityoperator+= (const ChronoEntity &entity)
 Compound assignment operator.
 
std::string outputUserTime () const
 print the chrono ;
 
std::string outputSystemTime () const
 print the chrono ;
 
std::string outputElapsedTime () const
 print the chrono ;
 
std::string outputUserTime (std::string_view fmt, System::TimeType unit) const
 print the chrono according the format and units
 
std::string outputSystemTime (std::string_view fmt, System::TimeType unit) const
 print the chrono according the format and units
 
std::string outputElapsedTime (std::string_view fmt, System::TimeType unit) const
 print the chrono according the format and units
 
std::string outputTime (IChronoSvc::ChronoType typ, std::string_view fmt, System::TimeType unit) const
 print the chrono according the format and units
 

Protected Member Functions

std::string format (const double total, const double minimal, const double mean, const double rms, const double maximal, const unsigned long number) const
 format
 

Protected Attributes

IChronoSvc::ChronoStatus m_status = IChronoSvc::UNKNOWN
 current status of this chrono object;
 
System::ProcessTime m_delta
 delta process times
 
System::ProcessTime m_start
 start stamp for current measurement of process times
 
StatEntity m_user
 the actual storage of "user" time
 
StatEntity m_kernel
 the actual storage of "kernel" time
 
StatEntity m_elapsed
 the actual storage of "elapsed" time
 

Static Protected Attributes

static const System::TimeType TimeUnit = System::microSec
 internal unit used for the system time conversion (microseconds)
 

Friends

bool operator< (ChronoEntity const &lhs, ChronoEntity const &rhs)
 comparison operator
 

Detailed Description

a small helper class for implementation of ChronoStatSvc service, It also could be used as some local timer

Author
Vanya BELYAEV Ivan..nosp@m.Bely.nosp@m.aev@i.nosp@m.tep..nosp@m.ru
Date
December 1, 1999

Definition at line 26 of file ChronoEntity.h.

Constructor & Destructor Documentation

◆ ChronoEntity()

ChronoEntity::ChronoEntity ( )
default

default constructor

Member Function Documentation

◆ delta()

IChronoSvc::ChronoTime ChronoEntity::delta ( IChronoSvc::ChronoType type) const
inline

return the last delta-time of type "type"

Definition at line 184 of file ChronoEntity.h.

184 {
185 const IChronoSvc::ChronoTime result = -1;
186 switch ( type ) {
187 case IChronoSvc::USER:
188 return m_delta.userTime<TimeUnit>();
190 return m_delta.kernelTime<TimeUnit>();
192 return m_delta.elapsedTime<TimeUnit>();
193 default:
194 return result;
195 }
196 // cannot reach this point
197}
static const System::TimeType TimeUnit
internal unit used for the system time conversion (microseconds)
System::ProcessTime m_delta
delta process times
double ChronoTime
Type of the delta-time.
Definition IChronoSvc.h:38

◆ eMaximalTime()

double ChronoEntity::eMaximalTime ( ) const
inline

maximal measurement for elapsed time

Definition at line 170 of file ChronoEntity.h.

170{ return m_elapsed.flagMax(); }
StatEntity m_elapsed
the actual storage of "elapsed" time

◆ eMeanErrorTime()

double ChronoEntity::eMeanErrorTime ( ) const
inline

error in mean Elapsed time

Definition at line 183 of file ChronoEntity.h.

183{ return m_elapsed.flagMeanErr(); }

◆ eMeanTime()

double ChronoEntity::eMeanTime ( ) const
inline

average Elapsed Time

Definition at line 177 of file ChronoEntity.h.

177{ return m_elapsed.flagMean(); }

◆ eMinimalTime()

double ChronoEntity::eMinimalTime ( ) const
inline

minimal measurement for elapsed time

Definition at line 167 of file ChronoEntity.h.

167{ return m_elapsed.flagMin(); }

◆ eRMSTime()

double ChronoEntity::eRMSTime ( ) const
inline

r.m.s Elapsed Time

Definition at line 180 of file ChronoEntity.h.

180{ return m_elapsed.flagRMS(); }

◆ eTotalTime()

double ChronoEntity::eTotalTime ( ) const
inline

total Elapsed time

Definition at line 173 of file ChronoEntity.h.

173{ return m_elapsed.flag(); }

◆ format()

std::string ChronoEntity::format ( const double total,
const double minimal,
const double mean,
const double rms,
const double maximal,
const unsigned long number ) const
protected

format

Todo
: cache the format

Definition at line 80 of file ChronoEntity.cpp.

81 {
82
84 constexpr auto fmt = "Tot={1:5.3g}{0:5} {3} #={2:3}";
85 constexpr auto stat_fmt = "Ave/Min/Max={1:8.3g}(+-{2:8.3g})/{3:8.3g}/{4:8.3g}{0:5}";
86
87 static const std::array<std::tuple<int, double, std::string_view>, 9> tbl{ { { 500, microsecond, " [us]" },
88 { 500, millisecond, " [ms]" },
89 { 500, second, " [s]" },
90 { 500, minute, "[min]" },
91 { 500, hour, " [h]" },
92 { 10, day, "[day]" },
93 { 5, week, " [w]" },
94 { 20, month, "[mon]" },
95 { -1, year, " [y]" } } };
96
97 auto i = find_if( begin( tbl ), prev( end( tbl ) ),
98 [&]( const auto& i ) { return total < std::get<0>( i ) * std::get<1>( i ); } );
99 long double unit = std::get<1>( *i );
100 std::string_view unit_name = std::get<2>( *i );
101
102 auto stats = [&]() -> std::string {
103 if ( number > 1 ) {
104 auto i = find_if( begin( tbl ), prev( end( tbl ) ),
105 [&]( const auto& i ) { return total < std::get<0>( i ) * std::get<1>( i ); } );
106 auto unit = std::get<1>( *i );
107 std::string_view unit_name = std::get<2>( *i );
108 return fmt::format( stat_fmt, unit_name, (double)( mean / unit ), (double)( rms / unit ),
109 (double)( minimal / unit ), (double)( maximal / unit ) );
110 } else {
111 return {};
112 }
113 };
114
115 return fmt::format( fmt, unit_name, (double)( total / unit ), number, stats() );
116}
constexpr double millisecond
constexpr double second
constexpr double microsecond
AttribStringParser::Iterator begin(const AttribStringParser &parser)

◆ kMaximalTime()

double ChronoEntity::kMaximalTime ( ) const
inline

maximal measurement for kernel time

Definition at line 169 of file ChronoEntity.h.

169{ return m_kernel.flagMax(); }
StatEntity m_kernel
the actual storage of "kernel" time

◆ kMeanErrorTime()

double ChronoEntity::kMeanErrorTime ( ) const
inline

error in mean Kernel time

Definition at line 181 of file ChronoEntity.h.

181{ return m_kernel.flagMeanErr(); }

◆ kMeanTime()

double ChronoEntity::kMeanTime ( ) const
inline

average Kernel Time

Definition at line 175 of file ChronoEntity.h.

175{ return m_kernel.flagMean(); }

◆ kMinimalTime()

double ChronoEntity::kMinimalTime ( ) const
inline

minimal measurement for kernel time

Definition at line 166 of file ChronoEntity.h.

166{ return m_kernel.flagMin(); }

◆ kRMSTime()

double ChronoEntity::kRMSTime ( ) const
inline

r.m.s Kernel Time

Definition at line 178 of file ChronoEntity.h.

178{ return m_kernel.flagRMS(); }

◆ kTotalTime()

double ChronoEntity::kTotalTime ( ) const
inline

total Kernel time

Definition at line 172 of file ChronoEntity.h.

172{ return m_kernel.flag(); }

◆ nOfMeasurements()

unsigned long ChronoEntity::nOfMeasurements ( ) const
inline

number of chrono measurements

Definition at line 164 of file ChronoEntity.h.

164{ return m_user.nEntries(); }
StatEntity m_user
the actual storage of "user" time

◆ operator+=()

ChronoEntity & ChronoEntity::operator+= ( const ChronoEntity & entity)

Compound assignment operator.

Definition at line 117 of file ChronoEntity.cpp.

117 {
118 // System::ProcessTime type
119 m_delta += e.m_delta;
120
121 // Summing, massaging here does not make too much sense.
122 // This is done only for final reductions
123 // Keep by convention the original one.
124 // m_start += e.m_start;
125
126 // Tymevaluetypes type
127 m_user += e.m_user;
128 m_kernel += e.m_kernel;
129 m_elapsed += e.m_elapsed;
130
131 return *this;
132}

◆ outputElapsedTime() [1/2]

std::string ChronoEntity::outputElapsedTime ( ) const

print the chrono ;

Definition at line 76 of file ChronoEntity.cpp.

76 {
77 return "TimeElapsed: " +
79}
double eMinimalTime() const
minimal measurement for elapsed time
std::string format(const double total, const double minimal, const double mean, const double rms, const double maximal, const unsigned long number) const
format
double eMeanTime() const
average Elapsed Time
unsigned long nOfMeasurements() const
number of chrono measurements
double eMaximalTime() const
maximal measurement for elapsed time
double eTotalTime() const
total Elapsed time
double eRMSTime() const
r.m.s Elapsed Time

◆ outputElapsedTime() [2/2]

std::string ChronoEntity::outputElapsedTime ( std::string_view fmt,
System::TimeType unit ) const
inline

print the chrono according the format and units

Parameters
fmtthe format string
unitthe unit
Returns
the string representations
See also
boost::format

Definition at line 225 of file ChronoEntity.h.

225 {
226 return outputTime( IChronoSvc::ELAPSED, fmt, unit );
227}
std::string outputTime(IChronoSvc::ChronoType typ, std::string_view fmt, System::TimeType unit) const
print the chrono according the format and units

◆ outputSystemTime() [1/2]

std::string ChronoEntity::outputSystemTime ( ) const

print the chrono ;

Definition at line 72 of file ChronoEntity.cpp.

72 {
73 return "Time System : " +
75}
double kMaximalTime() const
maximal measurement for kernel time
double kTotalTime() const
total Kernel time
double kMinimalTime() const
minimal measurement for kernel time
double kMeanTime() const
average Kernel Time
double kRMSTime() const
r.m.s Kernel Time

◆ outputSystemTime() [2/2]

std::string ChronoEntity::outputSystemTime ( std::string_view fmt,
System::TimeType unit ) const
inline

print the chrono according the format and units

Parameters
fmtthe format string
unitthe unit
Returns
the string representations
See also
boost::format

Definition at line 215 of file ChronoEntity.h.

215 {
216 return outputTime( IChronoSvc::KERNEL, fmt, unit );
217}

◆ outputTime()

std::string ChronoEntity::outputTime ( IChronoSvc::ChronoType typ,
std::string_view fmt,
System::TimeType unit ) const

print the chrono according the format and units

The format fields are:

  1. number of entries
  2. total time (in the specified units)
  3. mean time (in the specified units)
  4. r.m.s. time (in the specified units)
  5. error in mean time (in the specified units)
  6. minimal time (in the specified units)
  7. maximal time (in the specified units)
Parameters
typthe chrono type
fmtthe format string
unitthe unit
Returns
the string representations
See also
boost::format

Definition at line 134 of file ChronoEntity.cpp.

134 {
135 boost::format _fmt( std::string{ fmt } );
136 // allow various number of arguments
137 using namespace boost::io;
138 _fmt.exceptions( all_error_bits ^ ( too_many_args_bit | too_few_args_bit ) );
139 double _unit = microsecond;
140 switch ( unit ) {
141 case System::Year:
142 _unit = year;
143 break;
144 case System::Month:
145 _unit = month;
146 break;
147 case System::Day:
148 _unit = day;
149 break;
150 case System::Hour:
151 _unit = hour;
152 break;
153 case System::Min:
154 _unit = minute;
155 break;
156 case System::Sec:
157 _unit = second;
158 break;
159 case System::milliSec:
160 _unit = millisecond;
161 break;
162 case System::microSec:
163 _unit = microsecond;
164 break;
165 case System::nanoSec:
166 _unit = nanosecond;
167 break;
168 default:
169 _unit = microsecond;
170 break;
171 }
172 const StatEntity* stat = &m_user;
173 switch ( typ ) {
174 case IChronoSvc::USER:
175 stat = &m_user;
176 break;
178 stat = &m_kernel;
179 break;
181 stat = &m_elapsed;
182 break;
183 default:
184 stat = &m_user;
185 break;
186 }
187 _fmt % ( stat->nEntries() ) // %1 : #entries
188 % ( stat->flag() / _unit ) // %2 : total time
189 % ( stat->flagMean() / _unit ) // %3 : mean time
190 % ( stat->flagRMS() / _unit ) // %4 : RMS time
191 % ( stat->flagMeanErr() / _unit ) // %5 : error in mean time
192 % ( stat->flagMin() / _unit ) // %6 : minimal time
193 % ( stat->flagMax() / _unit ); // %7 : maximal time
194 return _fmt.str();
195}
double flag() const
Definition StatEntity.h:96
double flagRMS() const
Definition StatEntity.h:99
double flagMax() const
Definition StatEntity.h:102
double flagMin() const
Definition StatEntity.h:101
double flagMeanErr() const
Definition StatEntity.h:100
double flagMean() const
Definition StatEntity.h:98
constexpr double nanosecond
@ milliSec
Definition Timing.h:45
@ Min
Definition Timing.h:45
@ Year
Definition Timing.h:45
@ Sec
Definition Timing.h:45
@ nanoSec
Definition Timing.h:45
@ Hour
Definition Timing.h:45
@ Month
Definition Timing.h:45
@ microSec
Definition Timing.h:45
@ Day
Definition Timing.h:45

◆ outputUserTime() [1/2]

std::string ChronoEntity::outputUserTime ( ) const

print the chrono ;

Definition at line 68 of file ChronoEntity.cpp.

68 {
69 return "Time User : " +
71}
double uMeanTime() const
average User Time
double uMaximalTime() const
maximal measurement for user time
double uTotalTime() const
total user time
double uRMSTime() const
r.m.s User Time
double uMinimalTime() const
minimal measurement for user time

◆ outputUserTime() [2/2]

std::string ChronoEntity::outputUserTime ( std::string_view fmt,
System::TimeType unit ) const
inline

print the chrono according the format and units

Parameters
fmtthe format string
unitthe unit
Returns
the string representations
See also
boost::format

Definition at line 205 of file ChronoEntity.h.

205 {
206 return outputTime( IChronoSvc::USER, fmt, unit );
207}

◆ start()

IChronoSvc::ChronoStatus ChronoEntity::start ( )

start the current chrono

Definition at line 35 of file ChronoEntity.cpp.

35 {
36 if ( IChronoSvc::RUNNING == m_status ) { return m_status; }
37 //
38 // following lines could be platform dependent!
39 //
40 // Store in object the measured times
42
44
45 return m_status;
46}
System::ProcessTime m_start
start stamp for current measurement of process times
IChronoSvc::ChronoStatus m_status
current status of this chrono object;
GAUDI_API ProcessTime getProcessTime(long pid=-1)
Retrieve the process time data for a process.
Definition Timing.cpp:192

◆ status()

IChronoSvc::ChronoStatus ChronoEntity::status ( ) const
inline

return the status of chrono

Definition at line 163 of file ChronoEntity.h.

163{ return m_status; }

◆ stop()

IChronoSvc::ChronoStatus ChronoEntity::stop ( )

stop the chrono

Definition at line 50 of file ChronoEntity.cpp.

50 {
51 if ( IChronoSvc::RUNNING != m_status ) { return m_status; }
52
53 // following lines could be platform dependent!
55
56 // update the counters:
57
58 m_user += m_delta.userTime<TimeUnit>();
59 m_kernel += m_delta.kernelTime<TimeUnit>();
60 m_elapsed += m_delta.elapsedTime<TimeUnit>();
61
62 // set new status
63
65
66 return m_status;
67}

◆ totalTime()

double ChronoEntity::totalTime ( ) const
inline

total time

Definition at line 174 of file ChronoEntity.h.

174{ return uTotalTime() + kTotalTime(); }

◆ uMaximalTime()

double ChronoEntity::uMaximalTime ( ) const
inline

maximal measurement for user time

Definition at line 168 of file ChronoEntity.h.

168{ return m_user.flagMax(); }

◆ uMeanErrorTime()

double ChronoEntity::uMeanErrorTime ( ) const
inline

error in mean User time

Definition at line 182 of file ChronoEntity.h.

182{ return m_user.flagMeanErr(); }

◆ uMeanTime()

double ChronoEntity::uMeanTime ( ) const
inline

average User Time

Definition at line 176 of file ChronoEntity.h.

176{ return m_user.flagMean(); }

◆ uMinimalTime()

double ChronoEntity::uMinimalTime ( ) const
inline

minimal measurement for user time

Definition at line 165 of file ChronoEntity.h.

165{ return m_user.flagMin(); }

◆ uRMSTime()

double ChronoEntity::uRMSTime ( ) const
inline

r.m.s User Time

Definition at line 179 of file ChronoEntity.h.

179{ return m_user.flagRMS(); }

◆ uTotalTime()

double ChronoEntity::uTotalTime ( ) const
inline

total user time

Definition at line 171 of file ChronoEntity.h.

171{ return m_user.flag(); }

Friends And Related Symbol Documentation

◆ operator<

bool operator< ( ChronoEntity const & lhs,
ChronoEntity const & rhs )
friend

comparison operator

Definition at line 88 of file ChronoEntity.h.

88 {
89 return std::make_tuple( lhs.totalTime(), lhs.m_user, lhs.m_kernel, lhs.m_elapsed ) <
90 std::make_tuple( rhs.totalTime(), rhs.m_user, rhs.m_kernel, rhs.m_elapsed );
91 }

Member Data Documentation

◆ m_delta

System::ProcessTime ChronoEntity::m_delta
protected

delta process times

Definition at line 150 of file ChronoEntity.h.

◆ m_elapsed

StatEntity ChronoEntity::m_elapsed
protected

the actual storage of "elapsed" time

Definition at line 158 of file ChronoEntity.h.

◆ m_kernel

StatEntity ChronoEntity::m_kernel
protected

the actual storage of "kernel" time

Definition at line 156 of file ChronoEntity.h.

◆ m_start

System::ProcessTime ChronoEntity::m_start
protected

start stamp for current measurement of process times

Definition at line 152 of file ChronoEntity.h.

◆ m_status

IChronoSvc::ChronoStatus ChronoEntity::m_status = IChronoSvc::UNKNOWN
protected

current status of this chrono object;

Definition at line 148 of file ChronoEntity.h.

◆ m_user

StatEntity ChronoEntity::m_user
protected

the actual storage of "user" time

Definition at line 154 of file ChronoEntity.h.

◆ TimeUnit

const System::TimeType ChronoEntity::TimeUnit = System::microSec
staticprotected

internal unit used for the system time conversion (microseconds)

Definition at line 160 of file ChronoEntity.h.


The documentation for this class was generated from the following files: