The Gaudi Framework  v33r0 (d5ea422b)
ChronoEntity.h
Go to the documentation of this file.
1 /***********************************************************************************\
2 * (c) Copyright 1998-2019 CERN for the benefit of the LHCb and ATLAS collaborations *
3 * *
4 * This software is distributed under the terms of the Apache version 2 licence, *
5 * copied verbatim in the file "LICENSE". *
6 * *
7 * In applying this licence, CERN does not waive the privileges and immunities *
8 * granted to it by virtue of its status as an Intergovernmental Organization *
9 * or submit itself to any jurisdiction. *
10 \***********************************************************************************/
11 #ifndef GAUDIKERNEL_CHRONOENTITY_H
12 #define GAUDIKERNEL_CHRONOENTITY_H 1
13 // ============================================================================
14 // Include files
15 // ============================================================================
16 // GaudiKernel
17 // ============================================================================
18 #include "GaudiKernel/IChronoSvc.h"
19 #include "GaudiKernel/StatEntity.h"
20 #include "GaudiKernel/Timing.h"
21 // ============================================================================
32 public:
34  ChronoEntity() = default;
35 
36 public:
37  // ==========================================================================
38  // The basic Chrono Operations
39  // ==========================================================================
44  // ==========================================================================
48  inline IChronoSvc::ChronoStatus status() const;
49  // ==========================================================================
50 public:
51  // ==========================================================
52  // Access to Chrono Statistics
53  // ==========================================================
55  inline unsigned long nOfMeasurements() const;
56  // ==========================================================
58  inline double uMinimalTime() const;
60  inline double kMinimalTime() const;
62  inline double eMinimalTime() const;
64  inline double uMaximalTime() const;
66  inline double kMaximalTime() const;
68  inline double eMaximalTime() const;
70  inline double uTotalTime() const;
72  inline double kTotalTime() const;
74  inline double eTotalTime() const;
76  inline double totalTime() const;
78  inline double kMeanTime() const;
80  inline double uMeanTime() const;
82  inline double eMeanTime() const;
84  inline double kRMSTime() const;
86  inline double uRMSTime() const;
88  inline double eRMSTime() const;
90  inline double kMeanErrorTime() const;
92  inline double uMeanErrorTime() const;
94  inline double eMeanErrorTime() const;
95  // ==========================================================================
96 public:
97  // ==========================================================================
99  friend bool operator<( ChronoEntity const& lhs, ChronoEntity const& rhs ) {
100  return std::make_tuple( lhs.totalTime(), lhs.m_user, lhs.m_kernel, lhs.m_elapsed ) <
101  std::make_tuple( rhs.totalTime(), rhs.m_user, rhs.m_kernel, rhs.m_elapsed );
102  }
103  // ==========================================================================
105  ChronoEntity& operator+=( const ChronoEntity& entity );
106  // ==========================================================================
107 public:
108  // ==========================================================================
110  std::string outputUserTime() const;
112  std::string outputSystemTime() const;
114  std::string outputElapsedTime() const;
115  // ==========================================================================
116 public:
117  // ==========================================================================
124  inline std::string outputUserTime( const std::string& fmt, System::TimeType unit ) const;
131  inline std::string outputSystemTime( const std::string& fmt, System::TimeType unit ) const;
138  inline std::string outputElapsedTime( const std::string& fmt, System::TimeType unit ) const;
139  // ==========================================================================
158  std::string outputTime( IChronoSvc::ChronoType typ, const std::string& fmt, System::TimeType unit ) const;
159  // ==========================================================================
160 protected:
161  // ==========================================================================
163  std::string format( const double total, const double minimal, const double mean, const double rms,
164  const double maximal, const unsigned long number ) const;
165  // ==========================================================================
166 private:
167  // ==========================================================================
175  StatEntity m_user; // the actual storage of "user" time
177  StatEntity m_kernel; // the actual storage of "kernel" time
179  StatEntity m_elapsed; // the actual storage of "elapsed" time
181  static const System::TimeType TimeUnit = System::microSec;
182  // ==========================================================================
183 };
184 // ============================================================================
185 // return the status of chrono
186 // ============================================================================
188 // ============================================================================
189 // number of chrono measurements
190 // ============================================================================
191 inline unsigned long ChronoEntity::nOfMeasurements() const { return m_user.nEntries(); }
192 // ============================================================================
193 // minimal measurement for user time
194 // ============================================================================
195 inline double ChronoEntity::uMinimalTime() const { return m_user.flagMin(); }
196 // ============================================================================
197 // minimal measurement for kernel time
198 // ============================================================================
199 inline double ChronoEntity::kMinimalTime() const { return m_kernel.flagMin(); }
200 // ============================================================================
201 // minimal measurement for elapsed time
202 // ============================================================================
203 inline double ChronoEntity::eMinimalTime() const { return m_elapsed.flagMin(); }
204 // ============================================================================
205 // maximal measurement for user time
206 // ============================================================================
207 inline double ChronoEntity::uMaximalTime() const { return m_user.flagMax(); }
208 // ============================================================================
209 // maximal measurement for kernel time
210 // ============================================================================
211 inline double ChronoEntity::kMaximalTime() const { return m_kernel.flagMax(); }
212 // ============================================================================
213 // maximal measurement for ellapsed time
214 // ============================================================================
215 inline double ChronoEntity::eMaximalTime() const { return m_elapsed.flagMax(); }
216 // ============================================================================
217 // total user time
218 // ============================================================================
219 inline double ChronoEntity::uTotalTime() const { return m_user.flag(); }
220 // ============================================================================
221 // total Kernel time
222 // ============================================================================
223 inline double ChronoEntity::kTotalTime() const { return m_kernel.flag(); }
224 // ============================================================================
225 // total Elapsed time
226 // ============================================================================
227 inline double ChronoEntity::eTotalTime() const { return m_elapsed.flag(); }
228 // ============================================================================
229 // total time
230 // ============================================================================
231 inline double ChronoEntity::totalTime() const { return uTotalTime() + kTotalTime(); }
232 // ============================================================================
233 // average Kernel Time
234 // ============================================================================
235 inline double ChronoEntity::kMeanTime() const { return m_kernel.flagMean(); }
236 // ============================================================================
237 // average User Time
238 // ============================================================================
239 inline double ChronoEntity::uMeanTime() const { return m_user.flagMean(); }
240 // ============================================================================
241 // average Elapsed Time
242 // ============================================================================
243 inline double ChronoEntity::eMeanTime() const { return m_elapsed.flagMean(); }
244 // ============================================================================
245 // r.m.s Kernel Time
246 // ============================================================================
247 inline double ChronoEntity::kRMSTime() const { return m_kernel.flagRMS(); }
248 // ============================================================================
249 // r.m.s User Time
250 // ============================================================================
251 inline double ChronoEntity::uRMSTime() const { return m_user.flagRMS(); }
252 // ============================================================================
253 // r.m.s Elapsed Time
254 // ============================================================================
255 inline double ChronoEntity::eRMSTime() const { return m_elapsed.flagRMS(); }
256 // ============================================================================
257 // error in mean Kernel time
258 // ============================================================================
259 inline double ChronoEntity::kMeanErrorTime() const { return m_kernel.flagMeanErr(); }
260 // ============================================================================
261 // error in mean User time
262 // ============================================================================
263 inline double ChronoEntity::uMeanErrorTime() const { return m_user.flagMeanErr(); }
264 // ============================================================================
265 // error in mean Elapsed time
266 // ============================================================================
267 inline double ChronoEntity::eMeanErrorTime() const { return m_elapsed.flagMeanErr(); }
268 // ============================================================================
269 // return the last delta-time of type "type"
270 // ============================================================================
272  const IChronoSvc::ChronoTime result = -1;
273  switch ( type ) {
274  case IChronoSvc::USER:
275  return m_delta.userTime<TimeUnit>();
276  case IChronoSvc::KERNEL:
277  return m_delta.kernelTime<TimeUnit>();
278  case IChronoSvc::ELAPSED:
279  return m_delta.elapsedTime<TimeUnit>();
280  default:
281  return result;
282  }
283  // cannot reach this point
284 }
285 // ============================================================================
286 /* print the chrono according the format and units
287  * @param fmt the format string
288  * @param unit the unit
289  * @return the string representations
290  * @see boost::format
291  */
292 // ============================================================================
294  return outputTime( IChronoSvc::USER, fmt, unit );
295 }
296 // ============================================================================
297 /* print the chrono according the format and units
298  * @param fmt the format string
299  * @param unit the unit
300  * @return the string representations
301  * @see boost::format
302  */
303 // ============================================================================
305  return outputTime( IChronoSvc::KERNEL, fmt, unit );
306 }
307 // ============================================================================
308 /* print the chrono according the format and units
309  * @param fmt the format string
310  * @param unit the unit
311  * @return the string representations
312  * @see boost::format
313  */
314 // ============================================================================
316  return outputTime( IChronoSvc::ELAPSED, fmt, unit );
317 }
318 // ============================================================================
319 // The END
320 // ============================================================================
321 #endif // GAUDIKERNEL_CHRONOENTITY_H
std::string outputTime(IChronoSvc::ChronoType typ, const std::string &fmt, System::TimeType unit) const
print the chrono according the format and units
TimeValueType userTime() const
Retrieve the user time in the requested unit.
Definition: Timing.h:174
double eRMSTime() const
r.m.s Elapsed Time
Definition: ChronoEntity.h:255
GAUDI_API std::string format(const char *,...)
MsgStream format utility "a la sprintf(...)".
Definition: MsgStream.cpp:119
double uMeanErrorTime() const
error in mean User time
Definition: ChronoEntity.h:263
IChronoSvc::ChronoStatus m_status
current status of this chrono object;
Definition: ChronoEntity.h:169
StatEntity m_elapsed
the actual storage of "elapsed" time
Definition: ChronoEntity.h:179
a small helper class for implementation of ChronoStatSvc service, It also could be used as some local...
Definition: ChronoEntity.h:31
double flagMean() const
Definition: StatEntity.h:99
IChronoSvc::ChronoTime delta(IChronoSvc::ChronoType type) const
return the last delta-time of type "type"
Definition: ChronoEntity.h:271
double kMeanErrorTime() const
error in mean Kernel time
Definition: ChronoEntity.h:259
TimeValueType elapsedTime() const
Retrieve the elapsed time in the requested unit.
Definition: Timing.h:180
StatEntity m_user
the actual storage of "user" time
Definition: ChronoEntity.h:175
T make_tuple(T... args)
double uMinimalTime() const
minimal measurement for user time
Definition: ChronoEntity.h:195
double eMeanErrorTime() const
error in mean Elapsed time
Definition: ChronoEntity.h:267
def start
Definition: IOTest.py:108
TimeValueType kernelTime() const
Retrieve the kernel time in the requested unit.
Definition: Timing.h:168
STL class.
System::ProcessTime m_start
start stamp for current measurement of process times
Definition: ChronoEntity.h:173
System::ProcessTime m_delta
delta process times
Definition: ChronoEntity.h:171
double kRMSTime() const
r.m.s Kernel Time
Definition: ChronoEntity.h:247
double eMaximalTime() const
maximal measurement for elapsed time
Definition: ChronoEntity.h:215
double uTotalTime() const
total user time
Definition: ChronoEntity.h:219
unsigned long nOfMeasurements() const
number of chrono measurements
Definition: ChronoEntity.h:191
TimeType
Time type for conversion.
Definition: Timing.h:67
double eMinimalTime() const
minimal measurement for elapsed time
Definition: ChronoEntity.h:203
StatEntity m_kernel
the actual storage of "kernel" time
Definition: ChronoEntity.h:177
double flagMeanErr() const
Definition: StatEntity.h:101
double uMeanTime() const
average User Time
Definition: ChronoEntity.h:239
double kMeanTime() const
average Kernel Time
Definition: ChronoEntity.h:235
Simple class to hold the time information of a process.
Definition: Timing.h:156
double flagRMS() const
Definition: StatEntity.h:100
double eTotalTime() const
total Elapsed time
Definition: ChronoEntity.h:227
double flagMin() const
Definition: StatEntity.h:102
double ChronoTime
Type of the delta-time.
Definition: IChronoSvc.h:49
double kTotalTime() const
total Kernel time
Definition: ChronoEntity.h:223
double uMaximalTime() const
maximal measurement for user time
Definition: ChronoEntity.h:207
double kMinimalTime() const
minimal measurement for kernel time
Definition: ChronoEntity.h:199
double totalTime() const
total time
Definition: ChronoEntity.h:231
double flagMax() const
Definition: StatEntity.h:103
static const System::TimeType TimeUnit
internal unit used for the system time conversion (microseconds)
Definition: ChronoEntity.h:181
double flag() const
Definition: StatEntity.h:97
friend bool operator<(ChronoEntity const &lhs, ChronoEntity const &rhs)
comparison operator
Definition: ChronoEntity.h:99
double eMeanTime() const
average Elapsed Time
Definition: ChronoEntity.h:243
backward compatible StatEntity class.
Definition: StatEntity.h:18
#define GAUDI_API
Definition: Kernel.h:81
double kMaximalTime() const
maximal measurement for kernel time
Definition: ChronoEntity.h:211
IChronoSvc::ChronoStatus status() const
return the status of chrono
Definition: ChronoEntity.h:187
std::string outputElapsedTime() const
print the chrono ;
double uRMSTime() const
r.m.s User Time
Definition: ChronoEntity.h:251
std::string outputUserTime() const
print the chrono ;
std::string outputSystemTime() const
print the chrono ;