The Gaudi Framework  master (37c0b60a)
ChronoEntity.h
Go to the documentation of this file.
1 /***********************************************************************************\
2 * (c) Copyright 1998-2024 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  IChronoSvc::ChronoStatus status() const;
49  // ==========================================================================
50 public:
51  // ==========================================================
52  // Access to Chrono Statistics
53  // ==========================================================
55  unsigned long nOfMeasurements() const;
56  // ==========================================================
58  double uMinimalTime() const;
60  double kMinimalTime() const;
62  double eMinimalTime() const;
64  double uMaximalTime() const;
66  double kMaximalTime() const;
68  double eMaximalTime() const;
70  double uTotalTime() const;
72  double kTotalTime() const;
74  double eTotalTime() const;
76  double totalTime() const;
78  double kMeanTime() const;
80  double uMeanTime() const;
82  double eMeanTime() const;
84  double kRMSTime() const;
86  double uRMSTime() const;
88  double eRMSTime() const;
90  double kMeanErrorTime() const;
92  double uMeanErrorTime() const;
94  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  std::string outputUserTime( std::string_view fmt, System::TimeType unit ) const;
131  std::string outputSystemTime( std::string_view fmt, System::TimeType unit ) const;
138  std::string outputElapsedTime( std::string_view fmt, System::TimeType unit ) const;
139  // ==========================================================================
158  std::string outputTime( IChronoSvc::ChronoType typ, std::string_view 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 // ============================================================================
293 inline std::string ChronoEntity::outputUserTime( std::string_view fmt, System::TimeType unit ) const {
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 // ============================================================================
304 inline std::string ChronoEntity::outputSystemTime( std::string_view fmt, System::TimeType unit ) const {
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 // ============================================================================
315 inline std::string ChronoEntity::outputElapsedTime( std::string_view fmt, System::TimeType unit ) const {
316  return outputTime( IChronoSvc::ELAPSED, fmt, unit );
317 }
318 // ============================================================================
319 // The END
320 // ============================================================================
321 #endif // GAUDIKERNEL_CHRONOENTITY_H
ChronoEntity::m_user
StatEntity m_user
the actual storage of "user" time
Definition: ChronoEntity.h:175
std::make_tuple
T make_tuple(T... args)
ChronoEntity::m_elapsed
StatEntity m_elapsed
the actual storage of "elapsed" time
Definition: ChronoEntity.h:179
std::string
STL class.
ChronoEntity::eMinimalTime
double eMinimalTime() const
minimal measurement for elapsed time
Definition: ChronoEntity.h:203
ChronoEntity
Definition: ChronoEntity.h:31
IChronoSvc::ChronoTime
double ChronoTime
Type of the delta-time.
Definition: IChronoSvc.h:49
ChronoEntity::uMinimalTime
double uMinimalTime() const
minimal measurement for user time
Definition: ChronoEntity.h:195
ChronoEntity::eRMSTime
double eRMSTime() const
r.m.s Elapsed Time
Definition: ChronoEntity.h:255
IChronoSvc::UNKNOWN
@ UNKNOWN
Definition: IChronoSvc.h:54
ChronoEntity::totalTime
double totalTime() const
total time
Definition: ChronoEntity.h:231
ChronoEntity::eMeanErrorTime
double eMeanErrorTime() const
error in mean Elapsed time
Definition: ChronoEntity.h:267
IChronoSvc::ELAPSED
@ ELAPSED
Definition: IChronoSvc.h:56
StatEntity
backward compatible StatEntity class.
Definition: StatEntity.h:23
StatEntity.h
System::microSec
@ microSec
Definition: Timing.h:67
ChronoEntity::eMeanTime
double eMeanTime() const
average Elapsed Time
Definition: ChronoEntity.h:243
System::ProcessTime::kernelTime
TimeValueType kernelTime() const
Retrieve the kernel time in the requested unit.
Definition: Timing.h:168
ChronoEntity::delta
IChronoSvc::ChronoTime delta(IChronoSvc::ChronoType type) const
return the last delta-time of type "type"
Definition: ChronoEntity.h:271
ChronoEntity::eTotalTime
double eTotalTime() const
total Elapsed time
Definition: ChronoEntity.h:227
ChronoEntity::kMinimalTime
double kMinimalTime() const
minimal measurement for kernel time
Definition: ChronoEntity.h:199
IOTest.start
start
Definition: IOTest.py:110
StatEntity::flagRMS
double flagRMS() const
Definition: StatEntity.h:99
IChronoSvc::ChronoType
ChronoType
Definition: IChronoSvc.h:56
System::TimeType
TimeType
Time type for conversion.
Definition: Timing.h:67
ChronoEntity::m_delta
System::ProcessTime m_delta
delta process times
Definition: ChronoEntity.h:171
StatEntity::flag
double flag() const
Definition: StatEntity.h:96
ChronoEntity::nOfMeasurements
unsigned long nOfMeasurements() const
number of chrono measurements
Definition: ChronoEntity.h:191
ChronoEntity::m_status
IChronoSvc::ChronoStatus m_status
current status of this chrono object;
Definition: ChronoEntity.h:169
StatEntity::flagMax
double flagMax() const
Definition: StatEntity.h:102
ChronoEntity::uMeanTime
double uMeanTime() const
average User Time
Definition: ChronoEntity.h:239
ChronoEntity::outputSystemTime
std::string outputSystemTime() const
print the chrono ;
Definition: ChronoEntity.cpp:89
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:180
StatEntity::flagMean
double flagMean() const
Definition: StatEntity.h:98
ChronoEntity::kRMSTime
double kRMSTime() const
r.m.s Kernel Time
Definition: ChronoEntity.h:247
ChronoEntity::kTotalTime
double kTotalTime() const
total Kernel time
Definition: ChronoEntity.h:223
ChronoEntity::outputElapsedTime
std::string outputElapsedTime() const
print the chrono ;
Definition: ChronoEntity.cpp:95
ChronoEntity::kMeanErrorTime
double kMeanErrorTime() const
error in mean Kernel time
Definition: ChronoEntity.h:259
ChronoEntity::outputUserTime
std::string outputUserTime() const
print the chrono ;
Definition: ChronoEntity.cpp:82
ChronoEntity::m_start
System::ProcessTime m_start
start stamp for current measurement of process times
Definition: ChronoEntity.h:173
System::ProcessTime
Simple class to hold the time information of a process.
Definition: Timing.h:156
ChronoEntity::m_kernel
StatEntity m_kernel
the actual storage of "kernel" time
Definition: ChronoEntity.h:177
format
GAUDI_API std::string format(const char *,...)
MsgStream format utility "a la sprintf(...)".
Definition: MsgStream.cpp:119
ChronoEntity::status
IChronoSvc::ChronoStatus status() const
return the status of chrono
Definition: ChronoEntity.h:187
ChronoEntity::operator<
friend bool operator<(ChronoEntity const &lhs, ChronoEntity const &rhs)
comparison operator
Definition: ChronoEntity.h:99
ChronoEntity::kMaximalTime
double kMaximalTime() const
maximal measurement for kernel time
Definition: ChronoEntity.h:211
ChronoEntity::uRMSTime
double uRMSTime() const
r.m.s User Time
Definition: ChronoEntity.h:251
Timing.h
gaudirun.type
type
Definition: gaudirun.py:160
IChronoSvc::KERNEL
@ KERNEL
Definition: IChronoSvc.h:56
fmt
IChronoSvc::ChronoStatus
ChronoStatus
Definition: IChronoSvc.h:54
StatEntity::flagMin
double flagMin() const
Definition: StatEntity.h:101
ChronoEntity::kMeanTime
double kMeanTime() const
average Kernel Time
Definition: ChronoEntity.h:235
ChronoEntity::ChronoEntity
ChronoEntity()=default
default constructor
ChronoEntity::TimeUnit
static const System::TimeType TimeUnit
internal unit used for the system time conversion (microseconds)
Definition: ChronoEntity.h:181
ChronoEntity::uMaximalTime
double uMaximalTime() const
maximal measurement for user time
Definition: ChronoEntity.h:207
ChronoEntity::uMeanErrorTime
double uMeanErrorTime() const
error in mean User time
Definition: ChronoEntity.h:263
System::ProcessTime::userTime
TimeValueType userTime() const
Retrieve the user time in the requested unit.
Definition: Timing.h:174
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:168
IChronoSvc::USER
@ USER
Definition: IChronoSvc.h:56
ChronoEntity::eMaximalTime
double eMaximalTime() const
maximal measurement for elapsed time
Definition: ChronoEntity.h:215
IChronoSvc.h
GAUDI_API
#define GAUDI_API
Definition: Kernel.h:81
ChronoEntity::uTotalTime
double uTotalTime() const
total user time
Definition: ChronoEntity.h:219