The Gaudi Framework  v40r0 (475e45c1)
ChronoEntity Class Reference

#include <GaudiKernel/ChronoEntity.h>

Collaboration diagram for ChronoEntity:

Public Member Functions

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

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 More...
 

Protected Attributes

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

Static Protected Attributes

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

Friends

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

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>();
189  case IChronoSvc::KERNEL:
190  return m_delta.kernelTime<TimeUnit>();
191  case IChronoSvc::ELAPSED:
192  return m_delta.elapsedTime<TimeUnit>();
193  default:
194  return result;
195  }
196  // cannot reach this point
197 }

◆ eMaximalTime()

double ChronoEntity::eMaximalTime ( ) const
inline

maximal measurement for elapsed time

Definition at line 170 of file ChronoEntity.h.

170 { return m_elapsed.flagMax(); }

◆ 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 }

◆ kMaximalTime()

double ChronoEntity::kMaximalTime ( ) const
inline

maximal measurement for kernel time

Definition at line 169 of file ChronoEntity.h.

169 { return m_kernel.flagMax(); }

◆ 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(); }

◆ 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 }

◆ 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 }

◆ 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 }

◆ 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;
177  case IChronoSvc::KERNEL:
178  stat = &m_kernel;
179  break;
180  case IChronoSvc::ELAPSED:
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 }

◆ 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 }

◆ 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 }

◆ 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 
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 Function 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:
System::milliSec
@ milliSec
Definition: Timing.h:54
ChronoEntity::m_user
StatEntity m_user
the actual storage of "user" time
Definition: ChronoEntity.h:154
ChronoEntity::m_elapsed
StatEntity m_elapsed
the actual storage of "elapsed" time
Definition: ChronoEntity.h:158
ChronoEntity::eMinimalTime
double eMinimalTime() const
minimal measurement for elapsed time
Definition: ChronoEntity.h:167
System::Hour
@ Hour
Definition: Timing.h:54
IChronoSvc::ChronoTime
double ChronoTime
Type of the delta-time.
Definition: IChronoSvc.h:38
ChronoEntity::uMinimalTime
double uMinimalTime() const
minimal measurement for user time
Definition: ChronoEntity.h:165
ChronoEntity::eRMSTime
double eRMSTime() const
r.m.s Elapsed Time
Definition: ChronoEntity.h:180
ChronoEntity::format
std::string format(const double total, const double minimal, const double mean, const double rms, const double maximal, const unsigned long number) const
format
Definition: ChronoEntity.cpp:80
System::Year
@ Year
Definition: Timing.h:54
IChronoSvc::ELAPSED
@ ELAPSED
Definition: IChronoSvc.h:44
StatEntity
backward compatible StatEntity class.
Definition: StatEntity.h:23
System::microSec
@ microSec
Definition: Timing.h:54
ChronoEntity::eMeanTime
double eMeanTime() const
average Elapsed Time
Definition: ChronoEntity.h:177
System::ProcessTime::kernelTime
TimeValueType kernelTime() const
Retrieve the kernel time in the requested unit.
Definition: Timing.h:155
Gaudi::Units::second
constexpr double second
Definition: SystemOfUnits.h:138
ChronoEntity::eTotalTime
double eTotalTime() const
total Elapsed time
Definition: ChronoEntity.h:173
ChronoEntity::kMinimalTime
double kMinimalTime() const
minimal measurement for kernel time
Definition: ChronoEntity.h:166
StatEntity::flagRMS
double flagRMS() const
Definition: StatEntity.h:99
ChronoEntity::m_delta
System::ProcessTime m_delta
delta process times
Definition: ChronoEntity.h:150
StatEntity::flag
double flag() const
Definition: StatEntity.h:96
System::nanoSec
@ nanoSec
Definition: Timing.h:54
ChronoEntity::nOfMeasurements
unsigned long nOfMeasurements() const
number of chrono measurements
Definition: ChronoEntity.h:164
System::Month
@ Month
Definition: Timing.h:54
ChronoEntity::m_status
IChronoSvc::ChronoStatus m_status
current status of this chrono object;
Definition: ChronoEntity.h:148
StatEntity::flagMax
double flagMax() const
Definition: StatEntity.h:102
ChronoEntity::uMeanTime
double uMeanTime() const
average User Time
Definition: ChronoEntity.h:176
Gaudi::Units::microsecond
constexpr double microsecond
Definition: SystemOfUnits.h:140
StatEntity::flagMeanErr
double flagMeanErr() const
Definition: StatEntity.h:100
System::ProcessTime::elapsedTime
TimeValueType elapsedTime() const
Retrieve the elapsed time in the requested unit.
Definition: Timing.h:167
Gaudi::Utils::begin
AttribStringParser::Iterator begin(const AttribStringParser &parser)
Definition: AttribStringParser.h:135
IChronoSvc::RUNNING
@ RUNNING
Definition: IChronoSvc.h:42
StatEntity::flagMean
double flagMean() const
Definition: StatEntity.h:98
ChronoEntity::kRMSTime
double kRMSTime() const
r.m.s Kernel Time
Definition: ChronoEntity.h:178
ChronoEntity::kTotalTime
double kTotalTime() const
total Kernel time
Definition: ChronoEntity.h:172
ChronoEntity::m_start
System::ProcessTime m_start
start stamp for current measurement of process times
Definition: ChronoEntity.h:152
ChronoEntity::m_kernel
StatEntity m_kernel
the actual storage of "kernel" time
Definition: ChronoEntity.h:156
format
GAUDI_API std::string format(const char *,...)
MsgStream format utility "a la sprintf(...)".
Definition: MsgStream.cpp:99
ChronoEntity::kMaximalTime
double kMaximalTime() const
maximal measurement for kernel time
Definition: ChronoEntity.h:169
ChronoEntity::uRMSTime
double uRMSTime() const
r.m.s User Time
Definition: ChronoEntity.h:179
gaudirun.type
type
Definition: gaudirun.py:160
System::Sec
@ Sec
Definition: Timing.h:54
System::Day
@ Day
Definition: Timing.h:54
System::Min
@ Min
Definition: Timing.h:54
IChronoSvc::KERNEL
@ KERNEL
Definition: IChronoSvc.h:44
fmt
StatEntity::flagMin
double flagMin() const
Definition: StatEntity.h:101
Gaudi::Units::nanosecond
constexpr double nanosecond
Definition: SystemOfUnits.h:137
ChronoEntity::kMeanTime
double kMeanTime() const
average Kernel Time
Definition: ChronoEntity.h:175
IChronoSvc::STOPPED
@ STOPPED
Definition: IChronoSvc.h:42
Gaudi::Units::millisecond
constexpr double millisecond
Definition: SystemOfUnits.h:139
IOTest.end
end
Definition: IOTest.py:125
ChronoEntity::TimeUnit
static const System::TimeType TimeUnit
internal unit used for the system time conversion (microseconds)
Definition: ChronoEntity.h:160
ChronoEntity::uMaximalTime
double uMaximalTime() const
maximal measurement for user time
Definition: ChronoEntity.h:168
System::ProcessTime::userTime
TimeValueType userTime() const
Retrieve the user time in the requested unit.
Definition: Timing.h:161
System::getProcessTime
GAUDI_API ProcessTime getProcessTime(long pid=-1)
Retrieve the process time data for a process.
Definition: Timing.cpp:207
ChronoEntity::outputTime
std::string outputTime(IChronoSvc::ChronoType typ, std::string_view fmt, System::TimeType unit) const
print the chrono according the format and units
Definition: ChronoEntity.cpp:134
IChronoSvc::USER
@ USER
Definition: IChronoSvc.h:44
ChronoEntity::eMaximalTime
double eMaximalTime() const
maximal measurement for elapsed time
Definition: ChronoEntity.h:170
ChronoEntity::uTotalTime
double uTotalTime() const
total user time
Definition: ChronoEntity.h:171