The Gaudi Framework  master (b9786168)
Loading...
Searching...
No Matches
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
15#include <GaudiKernel/Timing.h>
16
27public:
29 ChronoEntity() = default;
30
31 // ==========================================================================
32 // The basic Chrono Operations
33 // ==========================================================================
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 }
92
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
143protected:
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
161};
162
164inline unsigned long ChronoEntity::nOfMeasurements() const { return m_user.nEntries(); }
165inline double ChronoEntity::uMinimalTime() const { return m_user.flagMin(); }
166inline double ChronoEntity::kMinimalTime() const { return m_kernel.flagMin(); }
167inline double ChronoEntity::eMinimalTime() const { return m_elapsed.flagMin(); }
168inline double ChronoEntity::uMaximalTime() const { return m_user.flagMax(); }
169inline double ChronoEntity::kMaximalTime() const { return m_kernel.flagMax(); }
170inline double ChronoEntity::eMaximalTime() const { return m_elapsed.flagMax(); }
171inline double ChronoEntity::uTotalTime() const { return m_user.flag(); }
172inline double ChronoEntity::kTotalTime() const { return m_kernel.flag(); }
173inline double ChronoEntity::eTotalTime() const { return m_elapsed.flag(); }
174inline double ChronoEntity::totalTime() const { return uTotalTime() + kTotalTime(); }
175inline double ChronoEntity::kMeanTime() const { return m_kernel.flagMean(); }
176inline double ChronoEntity::uMeanTime() const { return m_user.flagMean(); }
177inline double ChronoEntity::eMeanTime() const { return m_elapsed.flagMean(); }
178inline double ChronoEntity::kRMSTime() const { return m_kernel.flagRMS(); }
179inline double ChronoEntity::uRMSTime() const { return m_user.flagRMS(); }
180inline double ChronoEntity::eRMSTime() const { return m_elapsed.flagRMS(); }
181inline double ChronoEntity::kMeanErrorTime() const { return m_kernel.flagMeanErr(); }
182inline double ChronoEntity::uMeanErrorTime() const { return m_user.flagMeanErr(); }
183inline 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>();
190 return m_delta.kernelTime<TimeUnit>();
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 */
205inline 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 */
215inline 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 */
225inline std::string ChronoEntity::outputElapsedTime( std::string_view fmt, System::TimeType unit ) const {
226 return outputTime( IChronoSvc::ELAPSED, fmt, unit );
227}
#define GAUDI_API
Definition Kernel.h:49
GAUDI_API std::string format(const char *,...)
MsgStream format utility "a la sprintf(...)".
Definition MsgStream.cpp:93
a small helper class for implementation of ChronoStatSvc service, It also could be used as some local...
std::string outputSystemTime() const
print the chrono ;
double kMaximalTime() const
maximal measurement for kernel time
std::string outputTime(IChronoSvc::ChronoType typ, std::string_view fmt, System::TimeType unit) const
print the chrono according the format and units
double uMeanErrorTime() const
error in mean User time
double kTotalTime() const
total Kernel time
System::ProcessTime m_start
start stamp for current measurement of process times
double eMinimalTime() const
minimal measurement for elapsed time
IChronoSvc::ChronoTime delta(IChronoSvc::ChronoType type) const
return the last delta-time of type "type"
IChronoSvc::ChronoStatus start()
start the current chrono
ChronoEntity()=default
default constructor
IChronoSvc::ChronoStatus stop()
stop the chrono
double eMeanTime() const
average Elapsed Time
IChronoSvc::ChronoStatus status() const
return the status of chrono
double kMeanErrorTime() const
error in mean Kernel time
double uMeanTime() const
average User Time
double uMaximalTime() const
maximal measurement for user time
unsigned long nOfMeasurements() const
number of chrono measurements
double uTotalTime() const
total user time
StatEntity m_elapsed
the actual storage of "elapsed" time
double uRMSTime() const
r.m.s User Time
static const System::TimeType TimeUnit
internal unit used for the system time conversion (microseconds)
StatEntity m_kernel
the actual storage of "kernel" time
double eMaximalTime() const
maximal measurement for elapsed time
System::ProcessTime m_delta
delta process times
double kMinimalTime() const
minimal measurement for kernel time
double totalTime() const
total time
std::string outputElapsedTime() const
print the chrono ;
friend bool operator<(ChronoEntity const &lhs, ChronoEntity const &rhs)
comparison operator
StatEntity m_user
the actual storage of "user" time
double kMeanTime() const
average Kernel Time
double uMinimalTime() const
minimal measurement for user time
double eTotalTime() const
total Elapsed time
double eRMSTime() const
r.m.s Elapsed Time
std::string outputUserTime() const
print the chrono ;
double eMeanErrorTime() const
error in mean Elapsed time
IChronoSvc::ChronoStatus m_status
current status of this chrono object;
double kRMSTime() const
r.m.s Kernel Time
double ChronoTime
Type of the delta-time.
Definition IChronoSvc.h:38
backward compatible StatEntity class.
Definition StatEntity.h:23
Simple class to hold the time information of a process.
Definition Timing.h:134
TimeType
Time type for conversion.
Definition Timing.h:45
@ microSec
Definition Timing.h:45