The Gaudi Framework  master (ff829712)
Loading...
Searching...
No Matches
ChronoStatSvc Class Reference

The Chrono & Stat Sservice: service implements the IChronoStatSvc interface and provides the basic chronometry and some statistical counts needed by all applications. More...

#include </builds/gaudi/Gaudi/GaudiCommonSvc/src/ChronoStatSvc.h>

Inheritance diagram for ChronoStatSvc:
Collaboration diagram for ChronoStatSvc:

Public Types

using ChronoMap = std::map<IChronoStatSvc::ChronoTag, ChronoEntity>
 some useful typedefs
 
using StatMap = std::map<IChronoStatSvc::StatTag, StatEntity>
 
- Public Types inherited from extends< Service, IChronoStatSvc, IIncidentListener >
using base_class
 Typedef to this class.
 
using extend_interfaces_base
 Typedef to the base of this class.
 
- Public Types inherited from Service
using Factory = Gaudi::PluginService::Factory<IService*( const std::string&, ISvcLocator* )>
 
- Public Types inherited from PropertyHolder< CommonMessaging< implements< IService, IProperty, IStateful > > >
using PropertyHolderImpl
 Typedef used to refer to this class from derived classes, as in.
 
- Public Types inherited from CommonMessaging< implements< IService, IProperty, IStateful > >
using base_class
 
- Public Types inherited from extend_interfaces< Interfaces... >
using ext_iids
 take union of the ext_iids of all Interfaces...
 

Public Member Functions

StatusCode initialize () override
 Implementation of IService::initialize()
 
StatusCode finalize () override
 Implementation of IService::finalize()
 
ChronoEntitychronoStart (const IChronoStatSvc::ChronoTag &chronoTag) override
 Implementation of IChronoStatSvc::chronoStart.
 
const ChronoEntitychronoStop (const IChronoStatSvc::ChronoTag &chronoTag) override
 Implementation of IChronoStatSvc::chronoStop.
 
IChronoStatSvc::ChronoTime chronoDelta (const IChronoStatSvc::ChronoTag &chronoTag, IChronoStatSvc::ChronoType theType) override
 Implementation of IchronoStatSvc::chronoDelta.
 
void chronoPrint (const IChronoStatSvc::ChronoTag &chronoTag) override
 Implementation of IChronoStatSvc::chronoPrint.
 
ChronoStatus chronoStatus (const IChronoStatSvc::ChronoTag &chronoTag) override
 Implementation of IChronoStatSvc::chronoStatus.
 
void stat (const IChronoStatSvc::StatTag &statTag, const IChronoStatSvc::StatFlag &statFlag) override
 Implementation of IChronoStatSvc::stat add statistical information to the entity , tagged by its name.
 
void statPrint (const IChronoStatSvc::ChronoTag &statTag) override
 prints (using message service) info about statistical entity, tagged by its name
 
const ChronoEntitychrono (const IChronoStatSvc::ChronoTag &t) const override
 extract the chrono entity for the given tag (name)
 
StatEntitystat (const IChronoStatSvc::StatTag &t) override
 extract the stat entity for the given tag (name)
 
 ChronoStatSvc (const std::string &name, ISvcLocator *svcloc)
 Default constructor.
 
void merge (const ChronoStatSvc &css)
 Compound assignment operator.
 
void handle (const Incident &incident) override
 
 ~ChronoStatSvc () override=default
 
- Public Member Functions inherited from extends< Service, IChronoStatSvc, IIncidentListener >
void const * i_cast (const InterfaceID &tid) const override
 Implementation of IInterface::i_cast.
 
StatusCode queryInterface (const InterfaceID &ti, void **pp) override
 Implementation of IInterface::queryInterface.
 
std::vector< std::string > getInterfaceNames () const override
 Implementation of IInterface::getInterfaceNames.
 
- Public Member Functions inherited from Service
const std::string & name () const override
 Retrieve name of the service.
 
StatusCode configure () override
 
StatusCode initialize () override
 
StatusCode start () override
 
StatusCode stop () override
 
StatusCode finalize () override
 
StatusCode terminate () override
 
Gaudi::StateMachine::State FSMState () const override
 
Gaudi::StateMachine::State targetFSMState () const override
 
StatusCode reinitialize () override
 
StatusCode restart () override
 
StatusCode sysInitialize () override
 Initialize Service.
 
StatusCode sysStart () override
 Initialize Service.
 
StatusCode sysStop () override
 Initialize Service.
 
StatusCode sysFinalize () override
 Finalize Service.
 
StatusCode sysReinitialize () override
 Re-initialize the Service.
 
StatusCode sysRestart () override
 Re-initialize the Service.
 
 Service (std::string name, ISvcLocator *svcloc)
 Standard Constructor.
 
SmartIF< ISvcLocator > & serviceLocator () const override
 Retrieve pointer to service locator.
 
template<typename IFace = IService>
SmartIF< IFace > service (const std::string &name, bool createIf=true) const
 
template<class T>
Gaudi::Details::PropertyBasedeclareProperty (const std::string &name, ToolHandle< T > &hndl, const std::string &doc="none")
 
template<class T>
StatusCode declareTool (ToolHandle< T > &handle, bool createIf=true)
 
template<class T>
StatusCode declareTool (ToolHandle< T > &handle, const std::string &toolTypeAndName, bool createIf=true)
 Declare used tool.
 
template<class T>
Gaudi::Details::PropertyBasedeclareProperty (const std::string &name, ToolHandleArray< T > &hndlArr, const std::string &doc="none")
 
template<class T>
void addToolsArray (ToolHandleArray< T > &hndlArr)
 
const std::vector< IAlgTool * > & tools () const
 
SmartIF< IAuditorSvc > & auditorSvc () const
 The standard auditor service.May not be invoked before sysInitialize() has been invoked.
 
- Public Member Functions inherited from PropertyHolder< CommonMessaging< implements< IService, IProperty, IStateful > > >
StatusCode setProperty (const Gaudi::Details::PropertyBase &p)
 Set the property from a property.
 
StatusCode setProperty (const std::string &name, const char *v)
 Special case for string literals.
 
StatusCode setProperty (const std::string &name, const std::string &v)
 Special case for std::string.
 
StatusCode setProperty (const std::string &name, const TYPE &value)
 set the property form the value
 
 PropertyHolder ()=default
 
Gaudi::Details::PropertyBasedeclareProperty (Gaudi::Details::PropertyBase &prop)
 Declare a property.
 
Gaudi::Details::PropertyBasedeclareProperty (const std::string &name, TYPE &value, const std::string &doc="none")
 Helper to wrap a regular data member and use it as a regular property.
 
Gaudi::Details::PropertyBasedeclareProperty (const std::string &name, Gaudi::Property< TYPE, VERIFIER, HANDLERS > &prop, const std::string &doc="none")
 Declare a PropertyBase instance setting name and documentation.
 
Gaudi::Details::PropertyBasedeclareRemoteProperty (const std::string &name, IProperty *rsvc, const std::string &rname="")
 Declare a remote property.
 
StatusCode setProperty (const std::string &name, const Gaudi::Details::PropertyBase &p) override
 set the property from another property with a different name
 
StatusCode setProperty (const std::string &s) override
 set the property from the formatted string
 
StatusCode setProperty (const Gaudi::Details::PropertyBase &p)
 Set the property from a property.
 
StatusCode setProperty (const std::string &name, const char *v)
 Special case for string literals.
 
StatusCode setProperty (const std::string &name, const std::string &v)
 Special case for std::string.
 
StatusCode setProperty (const std::string &name, const TYPE &value)
 set the property form the value
 
StatusCode setPropertyRepr (const std::string &n, const std::string &r) override
 set the property from name and value string representation
 
StatusCode getProperty (Gaudi::Details::PropertyBase *p) const override
 get the property
 
const Gaudi::Details::PropertyBasegetProperty (std::string_view name) const override
 get the property by name
 
StatusCode getProperty (std::string_view n, std::string &v) const override
 convert the property to the string
 
const std::vector< Gaudi::Details::PropertyBase * > & getProperties () const override
 get all properties
 
bool hasProperty (std::string_view name) const override
 Return true if we have a property with the given name.
 
Gaudi::Details::PropertyBaseproperty (std::string_view name) const
 \fixme property and bindPropertiesTo should be protected
 
void bindPropertiesTo (Gaudi::Interfaces::IOptionsSvc &optsSvc)
 
 PropertyHolder (const PropertyHolder &)=delete
 
PropertyHolderoperator= (const PropertyHolder &)=delete
 
- Public Member Functions inherited from CommonMessaging< implements< IService, IProperty, IStateful > >
MSG::Level msgLevel () const
 get the cached level (originally extracted from the embedded MsgStream)
 
bool msgLevel (MSG::Level lvl) const
 get the output level from the embedded MsgStream
 
- Public Member Functions inherited from CommonMessagingBase
virtual ~CommonMessagingBase ()=default
 Virtual destructor.
 
const SmartIF< IMessageSvc > & msgSvc () const
 The standard message service.
 
MsgStreammsgStream () const
 Return an uninitialized MsgStream.
 
MsgStreammsgStream (const MSG::Level level) const
 Predefined configurable message stream for the efficient printouts.
 
MsgStreamalways () const
 shortcut for the method msgStream(MSG::ALWAYS)
 
MsgStreamfatal () const
 shortcut for the method msgStream(MSG::FATAL)
 
MsgStreamerr () const
 shortcut for the method msgStream(MSG::ERROR)
 
MsgStreamerror () const
 shortcut for the method msgStream(MSG::ERROR)
 
MsgStreamwarning () const
 shortcut for the method msgStream(MSG::WARNING)
 
MsgStreaminfo () const
 shortcut for the method msgStream(MSG::INFO)
 
MsgStreamdebug () const
 shortcut for the method msgStream(MSG::DEBUG)
 
MsgStreamverbose () const
 shortcut for the method msgStream(MSG::VERBOSE)
 
MsgStreammsg () const
 shortcut for the method msgStream(MSG::INFO)
 

Protected Member Functions

void printStats ()
 
- Protected Member Functions inherited from Service
std::vector< IAlgTool * > & tools ()
 
 ~Service () override
 
int outputLevel () const
 get the Service's output level
 
- Protected Member Functions inherited from CommonMessaging< implements< IService, IProperty, IStateful > >
MSG::Level setUpMessaging () const
 Set up local caches.
 
MSG::Level resetMessaging ()
 Reinitialize internal states.
 
void updateMsgStreamOutputLevel (int level)
 Update the output level of the cached MsgStream.
 

Private Types

using TimeMap = std::map<ChronoTag, std::vector<IChronoSvc::ChronoTime>>
 

Private Member Functions

 ChronoStatSvc ()=delete
 
 ChronoStatSvc (const ChronoStatSvc &)=delete
 
ChronoStatSvcoperator= (const ChronoStatSvc &)=delete
 
void saveStats ()
 dump the statistics into an ASCII file for offline processing
 
bool isMT () const
 
ChronoEntitygetEntity (const ChronoTag &chronoTag)
 

Static Private Member Functions

static MSG::Level int2level (int l)
 

Private Attributes

ChronoMap m_chronoEntities
 chrono part
 
std::mutex m_mutex
 Mutex protecting m_chronoEntities.
 
MSG::Level m_chronoPrintLevel = MSG::INFO
 level of info printing
 
StatMap m_statEntities
 stat part
 
MSG::Level m_statPrintLevel = MSG::INFO
 level of info printing
 
Gaudi::Property< bool > m_chronoTableFlag
 
Gaudi::Property< bool > m_chronoCoutFlag
 
Gaudi::Property< int > m_intChronoPrintLevel
 
Gaudi::Property< bool > m_chronoOrderFlag { this, "ChronoTableToBeOrdered", true, "should the printout be ordered" }
 
Gaudi::Property< bool > m_printUserTime { this, "PrintUserTime", true }
 
Gaudi::Property< bool > m_printSystemTime { this, "PrintSystemTime", false }
 
Gaudi::Property< bool > m_printEllapsedTime { this, "PrintEllapsedTime", false }
 
Gaudi::Property< bool > m_statTableFlag
 
Gaudi::Property< bool > m_statCoutFlag
 
Gaudi::Property< int > m_intStatPrintLevel
 
Gaudi::Property< bool > m_statOrderFlag { this, "StatTableToBeOrdered", true, "should the printout be ordered" }
 
Gaudi::Property< std::string > m_statsOutFileName
 
Gaudi::Property< std::string > m_header
 
Gaudi::Property< bool > m_useEffFormat
 
Gaudi::Property< std::string > m_perEventFile { this, "PerEventFile", "", "File name for per-event deltas" }
 
ServiceHandle< IInterfacem_hiveWhiteBoardSvc { this, "HiveWhiteBoardSvc", "EventDataSvc" }
 
TimeMap m_perEvtTime
 
std::ofstream m_ofd
 

Additional Inherited Members

- Protected Attributes inherited from Service
Gaudi::StateMachine::State m_state = Gaudi::StateMachine::OFFLINE
 Service state.
 
Gaudi::StateMachine::State m_targetState = Gaudi::StateMachine::OFFLINE
 Service state.
 
Gaudi::Property< int > m_outputLevel { this, "OutputLevel", MSG::NIL, "output level" }
 flag indicating whether ToolHandle tools have been added to m_tools
 
Gaudi::Property< bool > m_auditorInitialize { this, "AuditInitialize", false, "trigger auditor on initialize()" }
 
Gaudi::Property< bool > m_auditorStart { this, "AuditStart", false, "trigger auditor on start()" }
 
Gaudi::Property< bool > m_auditorStop { this, "AuditStop", false, "trigger auditor on stop()" }
 
Gaudi::Property< bool > m_auditorFinalize { this, "AuditFinalize", false, "trigger auditor on finalize()" }
 
Gaudi::Property< bool > m_auditorReinitialize { this, "AuditReinitialize", false, "trigger auditor on reinitialize()" }
 
Gaudi::Property< bool > m_auditorRestart { this, "AuditRestart", false, "trigger auditor on restart()" }
 
Gaudi::Property< bool > m_autoRetrieveTools
 
Gaudi::Property< bool > m_checkToolDeps
 
SmartIF< IAuditorSvcm_pAuditorSvc
 Auditor Service.
 

Detailed Description

The Chrono & Stat Sservice: service implements the IChronoStatSvc interface and provides the basic chronometry and some statistical counts needed by all applications.

Author
: Vanya BELYAEV Ivan..nosp@m.Bely.nosp@m.aev@i.nosp@m.tep..nosp@m.ru @daate: December 1, 1999

Definition at line 46 of file ChronoStatSvc.h.

Member Typedef Documentation

◆ ChronoMap

using ChronoStatSvc::ChronoMap = std::map<IChronoStatSvc::ChronoTag, ChronoEntity>

some useful typedefs

Definition at line 50 of file ChronoStatSvc.h.

◆ StatMap

using ChronoStatSvc::StatMap = std::map<IChronoStatSvc::StatTag, StatEntity>

Definition at line 51 of file ChronoStatSvc.h.

◆ TimeMap

using ChronoStatSvc::TimeMap = std::map<ChronoTag, std::vector<IChronoSvc::ChronoTime>>
private

Definition at line 209 of file ChronoStatSvc.h.

Constructor & Destructor Documentation

◆ ChronoStatSvc() [1/3]

ChronoStatSvc::ChronoStatSvc ( const std::string & name,
ISvcLocator * svcloc )
inline

Default constructor.

Parameters
nameservice instance name
svclocpointer to service locator

Definition at line 118 of file ChronoStatSvc.h.

118: base_class( name, svcloc ) {}
const std::string & name() const override
Retrieve name of the service.
Definition Service.cpp:333

◆ ChronoStatSvc() [2/3]

ChronoStatSvc::ChronoStatSvc ( )
privatedelete

◆ ChronoStatSvc() [3/3]

ChronoStatSvc::ChronoStatSvc ( const ChronoStatSvc & )
privatedelete

◆ ~ChronoStatSvc()

ChronoStatSvc::~ChronoStatSvc ( )
overridedefault

Member Function Documentation

◆ chrono()

const ChronoEntity * ChronoStatSvc::chrono ( const IChronoStatSvc::ChronoTag & t) const
override

extract the chrono entity for the given tag (name)

See also
IChronoStatSvc
Parameters
tchrono tag(name)
Returns
pointer to chrono entity

Definition at line 344 of file ChronoStatSvc.cpp.

344 {
345 auto lock = std::scoped_lock{ m_mutex };
346 auto it = m_chronoEntities.find( t );
347 return m_chronoEntities.end() != it ? &( it->second ) : nullptr;
348}
std::mutex m_mutex
Mutex protecting m_chronoEntities.
ChronoMap m_chronoEntities
chrono part

◆ chronoDelta()

IChronoStatSvc::ChronoTime ChronoStatSvc::chronoDelta ( const IChronoStatSvc::ChronoTag & chronoTag,
IChronoStatSvc::ChronoType theType )
override

Implementation of IchronoStatSvc::chronoDelta.

See also
IChronoStatSvc

Definition at line 293 of file ChronoStatSvc.cpp.

294 {
295 return getEntity( chronoTag ).delta( theType );
296}
IChronoSvc::ChronoTime delta(IChronoSvc::ChronoType type) const
return the last delta-time of type "type"
ChronoEntity & getEntity(const ChronoTag &chronoTag)

◆ chronoPrint()

void ChronoStatSvc::chronoPrint ( const IChronoStatSvc::ChronoTag & chronoTag)
override

Implementation of IChronoStatSvc::chronoPrint.

See also
IChronoStatSvc

Definition at line 300 of file ChronoStatSvc.cpp.

300 {
301 MsgStream log( msgSvc(), chronoTag );
302 if ( m_printUserTime ) { log << m_chronoPrintLevel << getEntity( chronoTag ).outputUserTime() << endmsg; }
303 if ( m_printSystemTime ) { log << m_chronoPrintLevel << getEntity( chronoTag ).outputSystemTime() << endmsg; }
304}
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition MsgStream.h:198
std::string outputSystemTime() const
print the chrono ;
std::string outputUserTime() const
print the chrono ;
Gaudi::Property< bool > m_printUserTime
MSG::Level m_chronoPrintLevel
level of info printing
Gaudi::Property< bool > m_printSystemTime
const SmartIF< IMessageSvc > & msgSvc() const
The standard message service.

◆ chronoStart()

ChronoEntity * ChronoStatSvc::chronoStart ( const IChronoStatSvc::ChronoTag & chronoTag)
override

Implementation of IChronoStatSvc::chronoStart.

See also
IChronoStatSvc

Definition at line 277 of file ChronoStatSvc.cpp.

277 {
278 ChronoEntity& entity = getEntity( chronoTag );
279 entity.start();
280 return &entity;
281}
IChronoSvc::ChronoStatus start()
start the current chrono

◆ chronoStatus()

IChronoStatSvc::ChronoStatus ChronoStatSvc::chronoStatus ( const IChronoStatSvc::ChronoTag & chronoTag)
override

Implementation of IChronoStatSvc::chronoStatus.

See also
IChronoStatSvc

Definition at line 308 of file ChronoStatSvc.cpp.

308 {
309 return getEntity( chronoTag ).status();
310}
IChronoSvc::ChronoStatus status() const
return the status of chrono

◆ chronoStop()

const ChronoEntity * ChronoStatSvc::chronoStop ( const IChronoStatSvc::ChronoTag & chronoTag)
override

Implementation of IChronoStatSvc::chronoStop.

See also
IChronoStatSvc

Definition at line 285 of file ChronoStatSvc.cpp.

285 {
286 ChronoEntity& entity = getEntity( chronoTag );
287 entity.stop();
288 return &entity;
289}
IChronoSvc::ChronoStatus stop()
stop the chrono

◆ finalize()

StatusCode ChronoStatSvc::finalize ( )
override

Implementation of IService::finalize()

stop its own chrono

Is the final chrono table to be printed?

decoration

CONTINUE

CONTINUE

stop chrono (if it is still in RUNNING status)

print to std::cout

print to MsgStream

decoration

CONTINUE

CONTINUE

stop chrono (if it is still in RUNNING status)

print to std::cout

print to MsgStream

decoration

CONTINUE

CONTINUE

stop chrono (if it is still in RUNNING status)

print to std::cout

print to MsgStream

clear the temporary container

the final decoration

Is the final stat table to be printed?

< finalize the base class

Definition at line 123 of file ChronoStatSvc.cpp.

123 {
124 std::string local = name() + ".finalize()";
126 MsgStream main_log( msgSvc(), local );
129 chronoStop( name() );
130
131 if ( m_ofd.is_open() ) {
132 debug() << "writing per-event timing data to '" << m_perEventFile << "'" << endmsg;
133 for ( const auto& itr : m_perEvtTime ) {
134 m_ofd << itr.first.substr( 0, itr.first.length() - 8 ) << " ";
135 for ( const auto& itt : itr.second ) { m_ofd << " " << (long int)( itt ); }
136 m_ofd << std::endl;
137 }
138
139 m_ofd.close();
140 }
141
146 MsgStream log( msgSvc(), "*****Chrono*****" );
147 const std::string stars( ( m_chronoCoutFlag ) ? 126 : 100, '*' );
148 if ( m_chronoCoutFlag ) {
149 std::cout << stars << std::endl;
150 if ( isMT() ) { std::cout << "WARNING: MT job; statistics are unreliable" << std::endl; }
151 std::cout << local << " The Final CPU consumption (Chrono) Table "
152 << ( m_chronoOrderFlag ? "(ordered)" : "(not ordered)" ) << std::endl;
153 std::cout << stars << std::endl;
154 } else {
155 log << m_chronoPrintLevel << stars << endmsg;
156 if ( isMT() ) { log << m_chronoPrintLevel << "WARNING: MT job; statistics are unreliable" << endmsg; }
157 log << m_chronoPrintLevel << " The Final CPU consumption ( Chrono ) Table "
158 << ( m_chronoOrderFlag ? "(ordered)" : "(not ordered)" ) << endmsg;
159 log << m_chronoPrintLevel << stars << endmsg;
160 }
162 { // prepare container for printing
163 std::vector<std::pair<ChronoEntity*, const ChronoTag*>> tmpCont;
164 tmpCont.reserve( m_chronoEntities.size() );
165 for ( auto& it : m_chronoEntities ) { tmpCont.emplace_back( &it.second, &it.first ); }
166 // sort it
167 if ( m_chronoOrderFlag ) std::sort( tmpCont.begin(), tmpCont.end(), CompareFirstOfPointerPair );
168 // print User Time statistics
169 if ( m_printUserTime ) {
170 for ( auto iter = tmpCont.begin(); tmpCont.end() != iter; ++iter ) {
171 //
172 ChronoEntity* entity = iter->first;
173 if ( !entity ) { continue; }
174 const ChronoTag* tag = iter->second;
175 if ( !tag ) { continue; }
177 entity->stop();
179 if ( m_chronoCoutFlag )
180 {
181 std::cout << *tag << "\t" << entity->outputUserTime() << std::endl;
182 } else
183 {
184 MsgStream( msgSvc(), *tag ) << m_chronoPrintLevel << entity->outputUserTime() << endmsg;
185 }
186 //
187 }
188 }
190 if ( m_printSystemTime ) {
194 std::cout << stars << std::endl;
195 } else if ( m_printUserTime && !m_chronoCoutFlag ) {
196 log << m_chronoPrintLevel << stars << endmsg;
197 }
199 for ( auto iter = tmpCont.begin(); tmpCont.end() != iter; ++iter ) {
201 ChronoEntity* entity = iter->first;
202 if ( !entity ) { continue; }
203 const ChronoTag* tag = iter->second;
204 if ( !tag ) { continue; }
206 entity->stop();
208 if ( m_chronoCoutFlag )
209 {
210 std::cout << *tag << "\t" << entity->outputSystemTime() << std::endl;
211 } else
212 {
213 MsgStream( msgSvc(), *tag ) << m_chronoPrintLevel << entity->outputSystemTime() << endmsg;
214 }
215 //
216 }
217 }
219 if ( m_printEllapsedTime ) {
223 std::cout << stars << std::endl;
224 } else if ( ( m_printUserTime || m_printSystemTime ) && !m_chronoCoutFlag ) {
225 log << m_chronoPrintLevel << stars << endmsg;
226 }
228 for ( const auto& i : tmpCont ) {
230 ChronoEntity* entity = i.first;
231 if ( !entity ) { continue; }
232 const ChronoTag* tag = i.second;
233 if ( !tag ) { continue; }
235 entity->stop();
237 if ( m_chronoCoutFlag )
238 {
239 std::cout << *tag << "\t" << entity->outputElapsedTime() << std::endl;
240 } else
241 {
242 MsgStream( msgSvc(), *tag ) << m_chronoPrintLevel << entity->outputElapsedTime() << endmsg;
243 }
244 //
245 }
246 }
248 tmpCont.clear();
249 }
251 if ( m_chronoCoutFlag ) {
252 std::cout << stars << std::endl;
253 } else {
254 log << m_chronoPrintLevel << stars << endmsg;
255 }
256 }
257
259
261 if ( m_statTableFlag ) { printStats(); }
262
263 if ( !m_statsOutFileName.value().empty() ) { saveStats(); }
264
265 // clear the maps.
266 m_chronoEntities.clear();
267 m_perEvtTime.clear();
268 m_statEntities.clear();
269
270 main_log << MSG::INFO << " Service finalized successfully " << endmsg;
271
272 return Service::finalize();
273}
constexpr struct CompareFirstOfPointerPair_t CompareFirstOfPointerPair
std::string outputElapsedTime() const
print the chrono ;
Gaudi::Property< std::string > m_statsOutFileName
bool isMT() const
void saveStats()
dump the statistics into an ASCII file for offline processing
StatMap m_statEntities
stat part
Gaudi::Property< bool > m_statTableFlag
Gaudi::Property< bool > m_chronoOrderFlag
Gaudi::Property< bool > m_chronoTableFlag
Gaudi::Property< bool > m_chronoCoutFlag
TimeMap m_perEvtTime
std::ofstream m_ofd
const ChronoEntity * chronoStop(const IChronoStatSvc::ChronoTag &chronoTag) override
Implementation of IChronoStatSvc::chronoStop.
Gaudi::Property< std::string > m_perEventFile
Gaudi::Property< bool > m_printEllapsedTime
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
StatusCode finalize() override
Definition Service.cpp:223
@ INFO
Definition IMessageSvc.h:22

◆ getEntity()

ChronoEntity & ChronoStatSvc::getEntity ( const ChronoTag & chronoTag)
inlineprivate

Definition at line 150 of file ChronoStatSvc.h.

150 {
151 auto lock = std::scoped_lock{ m_mutex };
152 return m_chronoEntities[chronoTag];
153 }

◆ handle()

void ChronoStatSvc::handle ( const Incident & incident)
override

Definition at line 509 of file ChronoStatSvc.cpp.

509 {
510
511 if ( !m_ofd.is_open() ) return;
512
513 auto lock = std::scoped_lock{ m_mutex };
514 for ( const auto& itr : m_chronoEntities ) {
515 if ( itr.first.find( ":Execute" ) == std::string::npos ) continue;
516
517 auto itm = m_perEvtTime.find( itr.first );
518 if ( itm == m_perEvtTime.end() ) {
519 m_perEvtTime[itr.first] = { itr.second.delta( IChronoSvc::ELAPSED ) };
520 } else {
521 itm->second.push_back( itr.second.delta( IChronoSvc::ELAPSED ) );
522 }
523 }
524}

◆ initialize()

StatusCode ChronoStatSvc::initialize ( )
override

Implementation of IService::initialize()

start its own chrono

Definition at line 91 of file ChronoStatSvc.cpp.

91 {
92 StatusCode sc = Service::initialize();
93 if ( sc.isFailure() ) return sc;
94
95 // only add an EndEvent listener if per-event output requested
96 if ( !m_perEventFile.empty() ) {
97 m_ofd.open( m_perEventFile );
98 if ( !m_ofd.is_open() ) {
99 error() << "unable to open per-event output file \"" << m_perEventFile << "\"" << endmsg;
100 return StatusCode::FAILURE;
101 } else {
102 auto ii = serviceLocator()->service<IIncidentSvc>( "IncidentSvc" );
103 if ( !ii ) {
104 error() << "Unable to find IncidentSvc" << endmsg;
105 return StatusCode::FAILURE;
106 }
107 ii->addListener( this, IncidentType::EndEvent );
108 }
109 }
110
116 chronoStart( name() );
118 return StatusCode::SUCCESS;
119}
ChronoEntity * chronoStart(const IChronoStatSvc::ChronoTag &chronoTag) override
Implementation of IChronoStatSvc::chronoStart.
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
virtual SmartIF< IService > & service(const Gaudi::Utils::TypeNameString &typeName, const bool createIf=true)=0
Returns a smart pointer to a service.
SmartIF< ISvcLocator > & serviceLocator() const override
Retrieve pointer to service locator.
Definition Service.cpp:336
StatusCode initialize() override
Definition Service.cpp:118
bool isFailure() const
Definition StatusCode.h:129
constexpr static const auto SUCCESS
Definition StatusCode.h:99
constexpr static const auto FAILURE
Definition StatusCode.h:100

◆ int2level()

static MSG::Level ChronoStatSvc::int2level ( int l)
inlinestaticprivate

Definition at line 156 of file ChronoStatSvc.h.

156 {
157 return static_cast<MSG::Level>(
158 std::max( std::min( l, static_cast<int>( MSG::FATAL ) ), static_cast<int>( MSG::NIL ) ) );
159 }
@ NIL
Definition IMessageSvc.h:22
@ FATAL
Definition IMessageSvc.h:22

◆ isMT()

bool ChronoStatSvc::isMT ( ) const
private

Definition at line 430 of file ChronoStatSvc.cpp.

430 {
431 bool isMT = false;
432 if ( m_hiveWhiteBoardSvc.retrieve().isFailure() ) {
433 error() << "Cannot retrieve HiveWhiteBoardSvc";
434 } else {
435 // In non-MT mode, `EventDataSvc' does not have an IHiveWhiteBoard interface.
436 const SmartIF<IHiveWhiteBoard> wb( m_hiveWhiteBoardSvc.get() );
437 if ( wb && wb->getNumberOfStores() > 1 ) { isMT = true; }
438 }
439 return isMT;
440}
ServiceHandle< IInterface > m_hiveWhiteBoardSvc

◆ merge()

void ChronoStatSvc::merge ( const ChronoStatSvc & css)

Compound assignment operator.

Definition at line 63 of file ChronoStatSvc.cpp.

63 {
64
65 // Add the content of the maps, leave the rest unchanged
66
67 auto lock = std::scoped_lock{ m_mutex, css.m_mutex };
68 // Merge Chronomaps
69 for ( auto& item : css.m_chronoEntities ) {
70 const IChronoStatSvc::ChronoTag& key = item.first;
71 const ChronoEntity& val = item.second;
72 if ( m_chronoEntities.count( key ) )
73 m_chronoEntities[key] += val;
74 else
75 m_chronoEntities.insert( std::pair<IChronoStatSvc::ChronoTag, ChronoEntity>( key, val ) );
76 }
77
78 // Merge StatMaps
79 for ( auto& item : css.m_statEntities ) {
80 const IChronoStatSvc::StatTag& key = item.first;
81 const StatEntity& val = item.second;
82 if ( m_statEntities.count( key ) )
83 m_statEntities[key] += val;
84 else
85 m_statEntities.emplace( key, val );
86 }
87}

◆ operator=()

ChronoStatSvc & ChronoStatSvc::operator= ( const ChronoStatSvc & )
privatedelete

◆ printStats()

void ChronoStatSvc::printStats ( )
protected

nothing to print?

CONTINUE

CONTINUE

decoration

Definition at line 444 of file ChronoStatSvc.cpp.

444 {
446 if ( m_statEntities.empty() ) { return; }
447
448 MsgStream log( msgSvc(), "******Stat******" );
450 const std::string stars( ( m_statCoutFlag ) ? 126 : 100, '*' );
452 if ( m_statCoutFlag ) {
453 std::cout << stars << std::endl;
454 if ( isMT() ) { std::cout << "WARNING: MT job; statistics are unreliable" << std::endl; }
455 std::cout << " The Final stat Table " << ( m_statOrderFlag ? "(ordered)" : "(not ordered)" ) << std::endl;
456 std::cout << stars << std::endl;
457 } else {
458 log << m_statPrintLevel << stars << endmsg;
459 if ( isMT() ) { log << (MSG::Level)m_chronoPrintLevel << "WARNING: MT job; statistics are unreliable" << endmsg; }
460 log << m_statPrintLevel << " The Final stat Table " << ( m_statOrderFlag ? "(ordered)" : "(not ordered)" )
461 << endmsg;
462 log << m_statPrintLevel << stars << endmsg;
463 }
464
465 {
466 // prepare container for printing
467 typedef std::pair<const StatEntity*, const StatTag*> SPair;
468 typedef std::vector<SPair> SCont;
469 SCont tmpCont;
470 std::transform( std::begin( m_statEntities ), std::end( m_statEntities ), std::back_inserter( tmpCont ),
471 []( StatMap::const_reference i ) { return std::make_pair( &i.second, &i.first ); } );
472 // sort it
473 if ( m_statOrderFlag ) std::sort( tmpCont.begin(), tmpCont.end(), CompareFirstOfPointerPair );
474 // print the table header
475 if ( m_statCoutFlag ) {
476 std::cout << m_header.value() << std::endl;
477 } else {
478 log << m_statPrintLevel << m_header.value() << endmsg;
479 }
480
481 // loop over counters and print them:
482 for ( const auto& iter : tmpCont ) {
484 const StatEntity* entity = iter.first;
485 if ( !entity ) { continue; }
486 const StatTag* tag = iter.second;
487 if ( !tag ) { continue; }
489 if ( m_statCoutFlag ) {
490 entity->print( std::cout, true, *tag, m_useEffFormat, "%|-15.15s|%|17t|" );
491 } else {
492 std::ostringstream ost;
493 entity->print( ost, true, *tag, m_useEffFormat, "%|-15.15s|%|17t|" );
494 log << m_statPrintLevel << ost.str() << endmsg;
495 }
496 }
497 tmpCont.clear();
498 }
500 if ( m_statCoutFlag ) {
501 std::cout << stars << std::endl;
502 } else {
503 log << m_statPrintLevel << stars << endmsg;
504 }
505}
Gaudi::Property< bool > m_statCoutFlag
Gaudi::Property< std::string > m_header
Gaudi::Property< bool > m_useEffFormat
MSG::Level m_statPrintLevel
level of info printing
Gaudi::Property< bool > m_statOrderFlag
std::ostream & print(std::ostream &o, bool tableFormat, std::string_view name, bool flag=true, std::string_view fmtHead="%|-48.48s|%|27t|") const
Definition StatEntity.h:160

◆ saveStats()

void ChronoStatSvc::saveStats ( )
private

dump the statistics into an ASCII file for offline processing

CONTINUE

CONTINUE

Definition at line 363 of file ChronoStatSvc.cpp.

363 {
364 std::ofstream out( m_statsOutFileName.value(), std::ios_base::out | std::ios_base::trunc );
365 if ( !out.good() ) {
366 info() << "Could not open the output file for writing chrono statistics [" << m_statsOutFileName.value() << "]"
367 << endmsg;
368 return;
369 } else {
370 // format it our way
371 out << std::scientific << std::setprecision( 8 );
372 }
373
374 // ChronoEntity
375 std::vector<std::pair<const ChronoEntity*, const ChronoTag*>> chronos;
376 {
377 auto lock = std::scoped_lock{ m_mutex };
378 chronos.reserve( m_chronoEntities.size() );
379 std::transform( std::begin( m_chronoEntities ), std::end( m_chronoEntities ), std::back_inserter( chronos ),
380 []( ChronoMap::const_reference i ) { return std::make_pair( &i.second, &i.first ); } );
381 }
382
383 // sort it
384 std::sort( std::begin( chronos ), std::end( chronos ), CompareFirstOfPointerPair );
385
386 // print User Time statistics
387 for ( const auto& iter : chronos ) {
388 //
389 const ChronoEntity* entity = iter.first;
390 if ( !entity ) { continue; }
391
392 const ChronoTag* tag = iter.second;
393 if ( !tag ) { continue; }
394
395 // create an entry in the .INI-like table
396 out << "\n[" << *tag << "]\n";
397
398 // user
399 out << "cpu_user_total = " << entity->uTotalTime() << "\n";
400 out << "cpu_user_min = " << entity->uMinimalTime() << "\n";
401 out << "cpu_user_mean = " << entity->uMeanTime() << "\n";
402 out << "cpu_user_RMS = " << entity->uRMSTime() << "\n";
403 out << "cpu_user_max = " << entity->uMaximalTime() << "\n";
404 out << "cpu_user_nbr = " << entity->nOfMeasurements() << "\n";
405
406 // system
407 out << "\n"; // just for clarity
408 out << "cpu_system_total = " << entity->kTotalTime() << "\n";
409 out << "cpu_system_min = " << entity->kMinimalTime() << "\n";
410 out << "cpu_system_mean = " << entity->kMeanTime() << "\n";
411 out << "cpu_system_RMS = " << entity->kRMSTime() << "\n";
412 out << "cpu_system_max = " << entity->kMaximalTime() << "\n";
413 out << "cpu_system_nbr = " << entity->nOfMeasurements() << "\n";
414
415 // real
416 out << "\n"; // just for clarity
417 out << "cpu_real_total = " << entity->eTotalTime() << "\n";
418 out << "cpu_real_min = " << entity->eMinimalTime() << "\n";
419 out << "cpu_real_mean = " << entity->eMeanTime() << "\n";
420 out << "cpu_real_RMS = " << entity->eRMSTime() << "\n";
421 out << "cpu_real_max = " << entity->eMaximalTime() << "\n";
422 out << "cpu_real_nbr = " << entity->nOfMeasurements() << "\n";
423 }
424
425 out << std::endl;
426}
double kMaximalTime() const
maximal measurement for kernel time
double kTotalTime() const
total Kernel time
double eMinimalTime() const
minimal measurement for elapsed time
double eMeanTime() const
average Elapsed 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
double uRMSTime() const
r.m.s User Time
double eMaximalTime() const
maximal measurement for elapsed time
double kMinimalTime() const
minimal measurement for kernel 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
double kRMSTime() const
r.m.s Kernel Time
MsgStream & info() const
shortcut for the method msgStream(MSG::INFO)

◆ stat() [1/2]

void ChronoStatSvc::stat ( const IChronoStatSvc::StatTag & statTag,
const IChronoStatSvc::StatFlag & statFlag )
override

Implementation of IChronoStatSvc::stat add statistical information to the entity , tagged by its name.

See also
IChronoStatSvc

Definition at line 314 of file ChronoStatSvc.cpp.

314 {
315 auto theIter = m_statEntities.find( statTag );
316
317 StatEntity* theStat = nullptr;
318 // if new entity, specify the number of events to be skipped
319 if ( theIter == m_statEntities.end() ) {
320 // new stat entity
321 StatEntity& theSe = m_statEntities[statTag];
322 theStat = &theSe;
323 } else {
324 // existing stat entity
325 theStat = &theIter->second;
326 }
327
328 theStat->addFlag( statFlag );
329}
unsigned long addFlag(const double v)
Definition StatEntity.h:84

◆ stat() [2/2]

StatEntity * ChronoStatSvc::stat ( const IChronoStatSvc::StatTag & t)
override

extract the stat entity for the given tag (name)

See also
IChronoStatSvc
Parameters
tstat tag(name)
Returns
pointer to stat entity

Definition at line 356 of file ChronoStatSvc.cpp.

356 {
357 auto it = m_statEntities.find( t );
358 return m_statEntities.end() != it ? &( it->second ) : nullptr;
359}

◆ statPrint()

void ChronoStatSvc::statPrint ( const IChronoStatSvc::ChronoTag & statTag)
override

prints (using message service) info about statistical entity, tagged by its name

See also
IChronoStatSvc

Definition at line 333 of file ChronoStatSvc.cpp.

333 {
334 MsgStream log( msgSvc(), statTag );
335 log << m_statPrintLevel << m_statEntities[statTag] << endmsg;
336}

Member Data Documentation

◆ m_chronoCoutFlag

Gaudi::Property<bool> ChronoStatSvc::m_chronoCoutFlag
private
Initial value:
{ this, "ChronoDestinationCout", false,
"define the destination of the table to be printed" }

Definition at line 176 of file ChronoStatSvc.h.

176 { this, "ChronoDestinationCout", false,
177 "define the destination of the table to be printed" };

◆ m_chronoEntities

ChronoMap ChronoStatSvc::m_chronoEntities
private

chrono part

Definition at line 162 of file ChronoStatSvc.h.

◆ m_chronoOrderFlag

Gaudi::Property<bool> ChronoStatSvc::m_chronoOrderFlag { this, "ChronoTableToBeOrdered", true, "should the printout be ordered" }
private

Definition at line 181 of file ChronoStatSvc.h.

181{ this, "ChronoTableToBeOrdered", true, "should the printout be ordered" };

◆ m_chronoPrintLevel

MSG::Level ChronoStatSvc::m_chronoPrintLevel = MSG::INFO
private

level of info printing

Definition at line 167 of file ChronoStatSvc.h.

◆ m_chronoTableFlag

Gaudi::Property<bool> ChronoStatSvc::m_chronoTableFlag
private
Initial value:
{ this, "ChronoPrintOutTable", true,
"decide if the final printout should be performed" }

Definition at line 174 of file ChronoStatSvc.h.

174 { this, "ChronoPrintOutTable", true,
175 "decide if the final printout should be performed" };

◆ m_header

Gaudi::Property<std::string> ChronoStatSvc::m_header
private
Initial value:
{
this, "StatTableHeader",
" | Counter | # | sum | mean/eff^* | rms/err^* | min | max |",
"The header row for the output Stat-table" }

Definition at line 198 of file ChronoStatSvc.h.

198 {
199 this, "StatTableHeader",
200 " | Counter | # | sum | mean/eff^* | rms/err^* | min | max |",
201 "The header row for the output Stat-table" };

◆ m_hiveWhiteBoardSvc

ServiceHandle<IInterface> ChronoStatSvc::m_hiveWhiteBoardSvc { this, "HiveWhiteBoardSvc", "EventDataSvc" }
private

Definition at line 207 of file ChronoStatSvc.h.

207{ this, "HiveWhiteBoardSvc", "EventDataSvc" };

◆ m_intChronoPrintLevel

Gaudi::Property<int> ChronoStatSvc::m_intChronoPrintLevel
private
Initial value:
{
this, "ChronoPrintLevel", MSG::INFO, [this]( auto& ) { m_chronoPrintLevel = int2level( m_intChronoPrintLevel ); },
"print level" }
static MSG::Level int2level(int l)
Gaudi::Property< int > m_intChronoPrintLevel

Definition at line 178 of file ChronoStatSvc.h.

178 {
179 this, "ChronoPrintLevel", MSG::INFO, [this]( auto& ) { m_chronoPrintLevel = int2level( m_intChronoPrintLevel ); },
180 "print level" };

◆ m_intStatPrintLevel

Gaudi::Property<int> ChronoStatSvc::m_intStatPrintLevel
private
Initial value:
{ this, "StatPrintLevel", MSG::INFO,
[this]( auto& ) { m_statPrintLevel = int2level( m_intStatPrintLevel ); },
"print level" }
Gaudi::Property< int > m_intStatPrintLevel

Definition at line 189 of file ChronoStatSvc.h.

189 { this, "StatPrintLevel", MSG::INFO,
190 [this]( auto& ) { m_statPrintLevel = int2level( m_intStatPrintLevel ); },
191 "print level" };

◆ m_mutex

std::mutex ChronoStatSvc::m_mutex
mutableprivate

Mutex protecting m_chronoEntities.

Definition at line 164 of file ChronoStatSvc.h.

◆ m_ofd

std::ofstream ChronoStatSvc::m_ofd
private

Definition at line 211 of file ChronoStatSvc.h.

◆ m_perEventFile

Gaudi::Property<std::string> ChronoStatSvc::m_perEventFile { this, "PerEventFile", "", "File name for per-event deltas" }
private

Definition at line 205 of file ChronoStatSvc.h.

205{ this, "PerEventFile", "", "File name for per-event deltas" };

◆ m_perEvtTime

TimeMap ChronoStatSvc::m_perEvtTime
private

Definition at line 210 of file ChronoStatSvc.h.

◆ m_printEllapsedTime

Gaudi::Property<bool> ChronoStatSvc::m_printEllapsedTime { this, "PrintEllapsedTime", false }
private

Definition at line 184 of file ChronoStatSvc.h.

184{ this, "PrintEllapsedTime", false };

◆ m_printSystemTime

Gaudi::Property<bool> ChronoStatSvc::m_printSystemTime { this, "PrintSystemTime", false }
private

Definition at line 183 of file ChronoStatSvc.h.

183{ this, "PrintSystemTime", false };

◆ m_printUserTime

Gaudi::Property<bool> ChronoStatSvc::m_printUserTime { this, "PrintUserTime", true }
private

Definition at line 182 of file ChronoStatSvc.h.

182{ this, "PrintUserTime", true };

◆ m_statCoutFlag

Gaudi::Property<bool> ChronoStatSvc::m_statCoutFlag
private
Initial value:
{ this, "StatDestinationCout", false,
"define the destination of the table to be printed" }

Definition at line 187 of file ChronoStatSvc.h.

187 { this, "StatDestinationCout", false,
188 "define the destination of the table to be printed" };

◆ m_statEntities

StatMap ChronoStatSvc::m_statEntities
private

stat part

Definition at line 170 of file ChronoStatSvc.h.

◆ m_statOrderFlag

Gaudi::Property<bool> ChronoStatSvc::m_statOrderFlag { this, "StatTableToBeOrdered", true, "should the printout be ordered" }
private

Definition at line 192 of file ChronoStatSvc.h.

192{ this, "StatTableToBeOrdered", true, "should the printout be ordered" };

◆ m_statPrintLevel

MSG::Level ChronoStatSvc::m_statPrintLevel = MSG::INFO
private

level of info printing

Definition at line 172 of file ChronoStatSvc.h.

◆ m_statsOutFileName

Gaudi::Property<std::string> ChronoStatSvc::m_statsOutFileName
private
Initial value:
{
this, "AsciiStatsOutputFile", "",
"Name of the output file storing the stats. If empty, no statistics will be saved (default)" }

Definition at line 194 of file ChronoStatSvc.h.

194 {
195 this, "AsciiStatsOutputFile", "",
196 "Name of the output file storing the stats. If empty, no statistics will be saved (default)" };

◆ m_statTableFlag

Gaudi::Property<bool> ChronoStatSvc::m_statTableFlag
private
Initial value:
{ this, "StatPrintOutTable", true,
"decide if the final printout should be performed" }

Definition at line 185 of file ChronoStatSvc.h.

185 { this, "StatPrintOutTable", true,
186 "decide if the final printout should be performed" };

◆ m_useEffFormat

Gaudi::Property<bool> ChronoStatSvc::m_useEffFormat
private
Initial value:
{ this, "UseEfficiencyRowFormat", true,
"Use the special format for printout of efficiency counters" }

Definition at line 202 of file ChronoStatSvc.h.

202 { this, "UseEfficiencyRowFormat", true,
203 "Use the special format for printout of efficiency counters" };

The documentation for this class was generated from the following files: