Loading [MathJax]/extensions/tex2jax.js
The Gaudi Framework  master (d98a2936)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
ChronoEntity.h
Go to the documentation of this file.
1 /***********************************************************************************\
2 * (c) Copyright 1998-2025 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 #pragma once
12 
13 #include <GaudiKernel/IChronoSvc.h>
14 #include <GaudiKernel/StatEntity.h>
15 #include <GaudiKernel/Timing.h>
16 
27 public:
29  ChronoEntity() = default;
30 
31  // ==========================================================================
32  // The basic Chrono Operations
33  // ==========================================================================
41  IChronoSvc::ChronoStatus status() const;
42 
43  // ==========================================================
44  // Access to Chrono Statistics
45  // ==========================================================
47  unsigned long nOfMeasurements() const;
49  double uMinimalTime() const;
51  double kMinimalTime() const;
53  double eMinimalTime() const;
55  double uMaximalTime() const;
57  double kMaximalTime() const;
59  double eMaximalTime() const;
61  double uTotalTime() const;
63  double kTotalTime() const;
65  double eTotalTime() const;
67  double totalTime() const;
69  double kMeanTime() const;
71  double uMeanTime() const;
73  double eMeanTime() const;
75  double kRMSTime() const;
77  double uRMSTime() const;
79  double eRMSTime() const;
81  double kMeanErrorTime() const;
83  double uMeanErrorTime() const;
85  double eMeanErrorTime() const;
86 
88  friend bool operator<( ChronoEntity const& lhs, ChronoEntity const& rhs ) {
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  }
93  ChronoEntity& operator+=( const ChronoEntity& entity );
94 
96  std::string outputUserTime() const;
98  std::string outputSystemTime() const;
100  std::string outputElapsedTime() const;
101 
108  std::string outputUserTime( std::string_view fmt, System::TimeType unit ) const;
115  std::string outputSystemTime( std::string_view fmt, System::TimeType unit ) const;
122  std::string outputElapsedTime( std::string_view fmt, System::TimeType unit ) const;
141  std::string outputTime( IChronoSvc::ChronoType typ, std::string_view fmt, System::TimeType unit ) const;
142 
143 protected:
145  std::string format( const double total, const double minimal, const double mean, const double rms,
146  const double maximal, const unsigned long number ) const;
154  StatEntity m_user; // the actual storage of "user" time
156  StatEntity m_kernel; // the actual storage of "kernel" time
158  StatEntity m_elapsed; // the actual storage of "elapsed" time
160  static const System::TimeType TimeUnit = System::microSec;
161 };
162 
164 inline unsigned long ChronoEntity::nOfMeasurements() const { return m_user.nEntries(); }
165 inline double ChronoEntity::uMinimalTime() const { return m_user.flagMin(); }
166 inline double ChronoEntity::kMinimalTime() const { return m_kernel.flagMin(); }
167 inline double ChronoEntity::eMinimalTime() const { return m_elapsed.flagMin(); }
168 inline double ChronoEntity::uMaximalTime() const { return m_user.flagMax(); }
169 inline double ChronoEntity::kMaximalTime() const { return m_kernel.flagMax(); }
170 inline double ChronoEntity::eMaximalTime() const { return m_elapsed.flagMax(); }
171 inline double ChronoEntity::uTotalTime() const { return m_user.flag(); }
172 inline double ChronoEntity::kTotalTime() const { return m_kernel.flag(); }
173 inline double ChronoEntity::eTotalTime() const { return m_elapsed.flag(); }
174 inline double ChronoEntity::totalTime() const { return uTotalTime() + kTotalTime(); }
175 inline double ChronoEntity::kMeanTime() const { return m_kernel.flagMean(); }
176 inline double ChronoEntity::uMeanTime() const { return m_user.flagMean(); }
177 inline double ChronoEntity::eMeanTime() const { return m_elapsed.flagMean(); }
178 inline double ChronoEntity::kRMSTime() const { return m_kernel.flagRMS(); }
179 inline double ChronoEntity::uRMSTime() const { return m_user.flagRMS(); }
180 inline double ChronoEntity::eRMSTime() const { return m_elapsed.flagRMS(); }
181 inline double ChronoEntity::kMeanErrorTime() const { return m_kernel.flagMeanErr(); }
182 inline double ChronoEntity::uMeanErrorTime() const { return m_user.flagMeanErr(); }
183 inline double ChronoEntity::eMeanErrorTime() const { return m_elapsed.flagMeanErr(); }
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 }
198 
199 /* print the chrono according the format and units
200  * @param fmt the format string
201  * @param unit the unit
202  * @return the string representations
203  * @see boost::format
204  */
205 inline std::string ChronoEntity::outputUserTime( std::string_view fmt, System::TimeType unit ) const {
206  return outputTime( IChronoSvc::USER, fmt, unit );
207 }
208 
209 /* print the chrono according the format and units
210  * @param fmt the format string
211  * @param unit the unit
212  * @return the string representations
213  * @see boost::format
214  */
215 inline std::string ChronoEntity::outputSystemTime( std::string_view fmt, System::TimeType unit ) const {
216  return outputTime( IChronoSvc::KERNEL, fmt, unit );
217 }
218 
219 /* print the chrono according the format and units
220  * @param fmt the format string
221  * @param unit the unit
222  * @return the string representations
223  * @see boost::format
224  */
225 inline std::string ChronoEntity::outputElapsedTime( std::string_view fmt, System::TimeType unit ) const {
226  return outputTime( IChronoSvc::ELAPSED, fmt, unit );
227 }
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
ChronoEntity
Definition: ChronoEntity.h:26
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
IChronoSvc::UNKNOWN
@ UNKNOWN
Definition: IChronoSvc.h:42
ChronoEntity::totalTime
double totalTime() const
total time
Definition: ChronoEntity.h:174
ChronoEntity::eMeanErrorTime
double eMeanErrorTime() const
error in mean Elapsed time
Definition: ChronoEntity.h:183
IChronoSvc::ELAPSED
@ ELAPSED
Definition: IChronoSvc.h:44
StatEntity
backward compatible StatEntity class.
Definition: StatEntity.h:23
StatEntity.h
System::microSec
@ microSec
Definition: Timing.h:45
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:146
ChronoEntity::delta
IChronoSvc::ChronoTime delta(IChronoSvc::ChronoType type) const
return the last delta-time of type "type"
Definition: ChronoEntity.h:184
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
IOTest.start
start
Definition: IOTest.py:110
StatEntity::flagRMS
double flagRMS() const
Definition: StatEntity.h:99
IChronoSvc::ChronoType
ChronoType
Definition: IChronoSvc.h:44
System::TimeType
TimeType
Time type for conversion.
Definition: Timing.h:45
ChronoEntity::m_delta
System::ProcessTime m_delta
delta process times
Definition: ChronoEntity.h:150
StatEntity::flag
double flag() const
Definition: StatEntity.h:96
ChronoEntity::nOfMeasurements
unsigned long nOfMeasurements() const
number of chrono measurements
Definition: ChronoEntity.h:164
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
ChronoEntity::outputSystemTime
std::string outputSystemTime() const
print the chrono ;
Definition: ChronoEntity.cpp:72
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:158
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::outputElapsedTime
std::string outputElapsedTime() const
print the chrono ;
Definition: ChronoEntity.cpp:76
ChronoEntity::kMeanErrorTime
double kMeanErrorTime() const
error in mean Kernel time
Definition: ChronoEntity.h:181
ChronoEntity::outputUserTime
std::string outputUserTime() const
print the chrono ;
Definition: ChronoEntity.cpp:68
ChronoEntity::m_start
System::ProcessTime m_start
start stamp for current measurement of process times
Definition: ChronoEntity.h:152
System::ProcessTime
Simple class to hold the time information of a process.
Definition: Timing.h:134
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:93
ChronoEntity::status
IChronoSvc::ChronoStatus status() const
return the status of chrono
Definition: ChronoEntity.h:163
ChronoEntity::operator<
friend bool operator<(ChronoEntity const &lhs, ChronoEntity const &rhs)
comparison operator
Definition: ChronoEntity.h:88
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
Timing.h
gaudirun.type
type
Definition: gaudirun.py:160
IChronoSvc::KERNEL
@ KERNEL
Definition: IChronoSvc.h:44
fmt
IChronoSvc::ChronoStatus
ChronoStatus
Definition: IChronoSvc.h:42
StatEntity::flagMin
double flagMin() const
Definition: StatEntity.h:101
ChronoEntity::kMeanTime
double kMeanTime() const
average Kernel Time
Definition: ChronoEntity.h:175
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:160
ChronoEntity::uMaximalTime
double uMaximalTime() const
maximal measurement for user time
Definition: ChronoEntity.h:168
ChronoEntity::uMeanErrorTime
double uMeanErrorTime() const
error in mean User time
Definition: ChronoEntity.h:182
System::ProcessTime::userTime
TimeValueType userTime() const
Retrieve the user time in the requested unit.
Definition: Timing.h:152
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
IChronoSvc.h
GAUDI_API
#define GAUDI_API
Definition: Kernel.h:49
ChronoEntity::uTotalTime
double uTotalTime() const
total user time
Definition: ChronoEntity.h:171