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 <src/ChronoStatSvc.h>

Inheritance diagram for ChronoStatSvc:
Collaboration diagram for ChronoStatSvc:

Public Types

typedef std::map< IChronoStatSvc::ChronoTag, ChronoEntityChronoMap
 some useful typedefs More...
 
typedef std::map< IChronoStatSvc::StatTag, StatEntityStatMap
 
- Public Types inherited from extends< BASE, Interfaces >
using base_class = extends
 Typedef to this class. More...
 
using extend_interfaces_base = extend_interfaces< Interfaces...>
 Typedef to the base of this class. More...
 
using base_class = extends
 Typedef to this class. More...
 
using extend_interfaces_base = extend_interfaces< Interfaces...>
 Typedef to the base of this class. More...
 
- Public Types inherited from extend_interfaces< Interfaces...>
using ext_iids = typename Gaudi::interface_list_cat< typename Interfaces::ext_iids...>::type
 take union of the ext_iids of all Interfaces... More...
 
using ext_iids = typename Gaudi::interface_list_cat< typename Interfaces::ext_iids...>::type
 take union of the ext_iids of all Interfaces... More...
 

Public Member Functions

StatusCode initialize () override
 Implementation of IService::initialize() More...
 
StatusCode finalize () override
 Implementation of IService::finalize() More...
 
virtual ChronoEntitychronoStart (const IChronoStatSvc::ChronoTag &chronoTag) override
 Implementation of IChronoStatSvc::chronoStart. More...
 
virtual const ChronoEntitychronoStop (const IChronoStatSvc::ChronoTag &chronoTag) override
 Implementation of IChronoStatSvc::chronoStop. More...
 
virtual IChronoStatSvc::ChronoTime chronoDelta (const IChronoStatSvc::ChronoTag &chronoTag, IChronoStatSvc::ChronoType theType) override
 Implementation of IchronoStatSvc::chronoDelta. More...
 
virtual void chronoPrint (const IChronoStatSvc::ChronoTag &chronoTag) override
 Implementation of IChronoStatSvc::chronoPrint. More...
 
virtual ChronoStatus chronoStatus (const IChronoStatSvc::ChronoTag &chronoTag) override
 Implementation of IChronoStatSvc::chronoStatus. More...
 
virtual 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. More...
 
virtual void statPrint (const IChronoStatSvc::ChronoTag &statTag) override
 prints (using message service) info about statistical entity, tagged by its name More...
 
virtual const ChronoEntitychrono (const IChronoStatSvc::ChronoTag &t) const override
 extract the chrono entity for the given tag (name) More...
 
virtual const StatEntitystat (const IChronoStatSvc::StatTag &t) const override
 extract the stat entity for the given tag (name) More...
 
 ChronoStatSvc (const std::string &name, ISvcLocator *svcloc)
 Default constructor. More...
 
void merge (const ChronoStatSvc &css)
 Compound assignment operator. More...
 
 ~ChronoStatSvc () override=default
 Destructor. More...
 
void handle (const Incident &incident) override
 
- Public Member Functions inherited from extends< BASE, Interfaces >
void * i_cast (const InterfaceID &tid) const override
 Implementation of IInterface::i_cast. More...
 
StatusCode queryInterface (const InterfaceID &ti, void **pp) override
 Implementation of IInterface::queryInterface. More...
 
std::vector< std::string > getInterfaceNames () const override
 Implementation of IInterface::getInterfaceNames. More...
 
 ~extends () override=default
 Virtual destructor. More...
 
void * i_cast (const InterfaceID &tid) const override
 Implementation of IInterface::i_cast. More...
 
StatusCode queryInterface (const InterfaceID &ti, void **pp) override
 Implementation of IInterface::queryInterface. More...
 
std::vector< std::string > getInterfaceNames () const override
 Implementation of IInterface::getInterfaceNames. More...
 
 ~extends () override=default
 Virtual destructor. More...
 
- Public Member Functions inherited from extend_interfaces< Interfaces...>
 ~extend_interfaces () override=default
 Virtual destructor. More...
 
 ~extend_interfaces () override=default
 Virtual destructor. More...
 

Protected Member Functions

void printStats ()
 

Private Types

typedef std::map< ChronoTag, std::vector< IChronoSvc::ChronoTime > > TimeMap
 

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 More...
 

Private Attributes

ChronoMap m_chronoEntities
 chrono part More...
 
int m_intChronoPrintLevel
 level of info printing More...
 
MSG::Level m_chronoPrintLevel = MSG::INFO
 
bool m_chronoTableFlag
 flag for printing the final table More...
 
bool m_chronoCoutFlag
 flag for destination of the the final table More...
 
bool m_chronoOrderFlag
 flag for formattion the final statistic table More...
 
bool m_printUserTime
 flag for printing User quantities More...
 
bool m_printSystemTime
 flag for printing System quantities More...
 
bool m_printEllapsedTime
 flag for printing Ellapsed quantities More...
 
long m_numberOfSkippedEventsForMemStat
 
StatMap m_statEntities
 stat part More...
 
int m_intStatPrintLevel
 level of info printing More...
 
MSG::Level m_statPrintLevel = MSG::INFO
 
bool m_statTableFlag
 flag for printing the final table More...
 
bool m_statCoutFlag
 flag for destination of the t he final table More...
 
bool m_statOrderFlag
 flag for formattion the final statistic table More...
 
StringProperty m_statsOutFileName
 Name of the output file where we'll dump the stats. More...
 
std::string m_header
 the header row More...
 
std::string m_format1
 format for regular statistical printout rows More...
 
std::string m_format2
 format for "efficiency" statistical printout rows More...
 
bool m_useEffFormat = true
 flag to use the special "efficiency" format More...
 
TimeMap m_perEvtTime
 
std::string m_perEventFile
 
std::ofstream m_ofd
 

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 : December 1, 1999

Definition at line 33 of file ChronoStatSvc.h.

Member Typedef Documentation

typedef std::map<IChronoStatSvc::ChronoTag,ChronoEntity> ChronoStatSvc::ChronoMap

some useful typedefs

Definition at line 38 of file ChronoStatSvc.h.

typedef std::map<IChronoStatSvc::StatTag,StatEntity> ChronoStatSvc::StatMap

Definition at line 39 of file ChronoStatSvc.h.

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

Definition at line 191 of file ChronoStatSvc.h.

Constructor & Destructor Documentation

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

Default constructor.

Parameters
nameservice instance name
svclocpointer to servcie locator

decide if the final printout should be performed

define the destination of the table to be printed

print level

if printout is to be performed, should one take care about some ordering?

if User Time information to be printed?

if System Time information to be printed?

if Ellapsed Time information to be printed?

deside if the final printout should be performed

define the destination of the table to be printed

print level

if printout is to be performed, should one take care about some ordering?

Definition at line 60 of file ChronoStatSvc.cpp.

61  : base_class( name , svcloc )
62  //
63  // the header row
64  , m_header ( " Counter | # | sum | mean/eff^* | rms/err^* | min | max |")
65  // format for regular statistical printout rows
66  , m_format1 ( " %|-15.15s|%|17t||%|10d| |%|11.7g| |%|#11.5g| |%|#11.5g| |%|#12.5g| |%|#12.5g| |" )
67  // format for "efficiency" statistical printout rows
68  , m_format2 ( "*%|-15.15s|%|17t||%|10d| |%|11.5g| |(%|#9.7g| +- %|-#9.7g|)%%| ------- | ------- |" )
69 {
71  declareProperty ( "ChronoPrintOutTable" ,
72  m_chronoTableFlag = true );
74  declareProperty ( "ChronoDestinationCout" ,
75  m_chronoCoutFlag = false );
77  declareProperty ( "ChronoPrintLevel" ,
81  declareProperty ( "ChronoTableToBeOrdered" ,
82  m_chronoOrderFlag = true );
84  declareProperty ( "PrintUserTime" ,
85  m_printUserTime = true );
87  declareProperty ( "PrintSystemTime" ,
88  m_printSystemTime = false );
90  declareProperty ( "PrintEllapsedTime" ,
91  m_printEllapsedTime = false );
94  declareProperty ( "StatPrintOutTable" ,
95  m_statTableFlag = true );
97  declareProperty ( "StatDestinationCout" ,
98  m_statCoutFlag = false );
100  declareProperty ( "StatPrintLevel" ,
104  declareProperty ( "StatTableToBeOrdered" ,
105  m_statOrderFlag = true );
106 
107  // specify the number of events to be skipped by the memory auditor
108  // in order to better spot memory leak
109  declareProperty ( "NumberOfSkippedEventsForMemStat" ,
111 
112  declareProperty( "AsciiStatsOutputFile",
113  m_statsOutFileName = "",
114  "Name of the output file storing the stats. If empty, no"
115  " statistics will be saved (default)" );
116 
117  declareProperty
118  ( "StatTableHeader" , m_header ,
119  "The header row for the output Stat-table" ) ;
120  declareProperty
121  ( "RegularRowFormat" , m_format1 ,
122  "The format for the regular row in the output Stat-table" ) ;
123  declareProperty
124  ( "EfficiencyRowFormat" , m_format2 ,
125  "The format for the regular row in the output Stat-table" ) ;
126  declareProperty
127  ( "UseEfficiencyRowFormat" , m_useEffFormat ,
128  "Use the special format for printout of efficiency counters" ) ;
129 
130  declareProperty
131  ( "PerEventFile", m_perEventFile="",
132  "File name for per-event deltas" );
133 
134 }
bool m_useEffFormat
flag to use the special "efficiency" format
int m_intStatPrintLevel
level of info printing
bool m_chronoOrderFlag
flag for formattion the final statistic table
bool m_printUserTime
flag for printing User quantities
bool m_printEllapsedTime
flag for printing Ellapsed quantities
std::string m_header
the header row
StringProperty m_statsOutFileName
Name of the output file where we'll dump the stats.
extends base_class
Typedef to this class.
Definition: extends.h:14
long m_numberOfSkippedEventsForMemStat
std::string m_format2
format for "efficiency" statistical printout rows
bool m_chronoTableFlag
flag for printing the final table
int m_intChronoPrintLevel
level of info printing
bool m_statOrderFlag
flag for formattion the final statistic table
bool m_statTableFlag
flag for printing the final table
bool m_statCoutFlag
flag for destination of the t he final table
bool m_printSystemTime
flag for printing System quantities
std::string m_perEventFile
bool m_chronoCoutFlag
flag for destination of the the final table
std::string m_format1
format for regular statistical printout rows
ChronoStatSvc::~ChronoStatSvc ( )
overridedefault

Destructor.

ChronoStatSvc::ChronoStatSvc ( )
privatedelete
ChronoStatSvc::ChronoStatSvc ( const ChronoStatSvc )
privatedelete

Member Function Documentation

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

extract the chrono entity for the given tag (name)

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

Definition at line 485 of file ChronoStatSvc.cpp.

486 {
487  auto it = m_chronoEntities.find ( t ) ;
488  return m_chronoEntities.end() != it ? &(it->second) : nullptr;
489 }
ChronoMap m_chronoEntities
chrono part
IChronoStatSvc::ChronoTime ChronoStatSvc::chronoDelta ( const IChronoStatSvc::ChronoTag &  chronoTag,
IChronoStatSvc::ChronoType  theType 
)
overridevirtual

Implementation of IchronoStatSvc::chronoDelta.

See also
IChronoStatSvc

Definition at line 413 of file ChronoStatSvc.cpp.

415 {
416  return m_chronoEntities[ chronoTag ].delta( theType );
417 }
ChronoMap m_chronoEntities
chrono part
void ChronoStatSvc::chronoPrint ( const IChronoStatSvc::ChronoTag &  chronoTag)
overridevirtual

Implementation of IChronoStatSvc::chronoPrint.

See also
IChronoStatSvc

Definition at line 422 of file ChronoStatSvc.cpp.

423 {
424  MsgStream log ( msgSvc() , chronoTag );
425  if( m_printUserTime ) {
427  << m_chronoEntities[ chronoTag ].outputUserTime ()
428  << endmsg;
429  }
430  if( m_printSystemTime ) {
432  << m_chronoEntities[ chronoTag ].outputSystemTime()
433  << endmsg;
434  }
435 }
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
bool m_printUserTime
flag for printing User quantities
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
MSG::Level m_chronoPrintLevel
bool m_printSystemTime
flag for printing System quantities
ChronoMap m_chronoEntities
chrono part
ChronoEntity * ChronoStatSvc::chronoStart ( const IChronoStatSvc::ChronoTag &  chronoTag)
overridevirtual

Implementation of IChronoStatSvc::chronoStart.

See also
IChronoStatSvc

Definition at line 391 of file ChronoStatSvc.cpp.

392 {
393  ChronoEntity& entity = m_chronoEntities [ chronoTag ] ;
394  entity.start() ;
395  return &entity ;
396 }
a small helper class for implementation of ChronoStatSvc service, It also could be used as some local...
Definition: ChronoEntity.h:21
IChronoSvc::ChronoStatus start()
start the current chrono
ChronoMap m_chronoEntities
chrono part
IChronoStatSvc::ChronoStatus ChronoStatSvc::chronoStatus ( const IChronoStatSvc::ChronoTag &  chronoTag)
overridevirtual

Implementation of IChronoStatSvc::chronoStatus.

See also
IChronoStatSvc

Definition at line 441 of file ChronoStatSvc.cpp.

442 { return m_chronoEntities[ chronoTag ].status(); }
ChronoMap m_chronoEntities
chrono part
const ChronoEntity * ChronoStatSvc::chronoStop ( const IChronoStatSvc::ChronoTag &  chronoTag)
overridevirtual

Implementation of IChronoStatSvc::chronoStop.

See also
IChronoStatSvc

Definition at line 402 of file ChronoStatSvc.cpp.

403 {
404  ChronoEntity& entity = m_chronoEntities [ chronoTag ] ;
405  entity.stop() ;
406  return &entity ;
407 }
a small helper class for implementation of ChronoStatSvc service, It also could be used as some local...
Definition: ChronoEntity.h:21
IChronoSvc::ChronoStatus stop()
stop the chrono
ChronoMap m_chronoEntities
chrono part
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 231 of file ChronoStatSvc.cpp.

232 {
233  std::string local = name()+".finalize()";
235  MsgStream main_log( msgSvc() , local );
238  chronoStop( name() ) ;
239 
240  if (m_ofd.is_open()) {
241  MsgStream log(msgSvc(), name());
242  log << MSG::DEBUG << "writing per-event timing data to '" << m_perEventFile << "'" << endmsg;
243  for (const auto& itr:m_perEvtTime) {
244  m_ofd << itr.first.substr(0,itr.first.length()-8 ) << " ";
245  for (const auto& itt:itr.second) {
246  m_ofd << " " << (long int)(itt);
247  }
248  m_ofd << std::endl;
249  }
250 
251  m_ofd.close();
252  }
253 
256  if ( m_chronoTableFlag &&
257  !m_chronoEntities.empty() &&
259  {
261  MsgStream log( msgSvc() , "*****Chrono*****" );
262  const std::string stars( ( m_chronoCoutFlag ) ? 126 : 100 , '*' );
263  if( m_chronoCoutFlag )
264  {
265  std::cout << stars << std::endl;
266  std::cout << local << " The Final CPU consumption (Chrono) Table "
267  << ( m_chronoOrderFlag ? "(ordered)" : "(not ordered)" ) << std::endl;
268  std::cout << stars << std::endl;
269  }
270  else
271  {
273  << stars << endmsg;
275  << " The Final CPU consumption ( Chrono ) Table "
276  << ( m_chronoOrderFlag ? "(ordered)" : "(not ordered)" ) << endmsg;
277  log << (MSG::Level) m_chronoPrintLevel << stars << endmsg;
278  }
280  { // prepare container for printing
281  std::vector<std::pair<ChronoEntity*,const ChronoTag*>> tmpCont;
282  tmpCont.reserve(m_chronoEntities.size());
283  for( auto& it : m_chronoEntities )
284  { tmpCont.emplace_back( &it.second , &it.first ) ; }
285  // sort it
286  if( m_chronoOrderFlag ) std::sort( tmpCont.begin(), tmpCont.end(),
288  // print User Time statistics
289  if( m_printUserTime )
290  {
291  for( auto iter = tmpCont.begin() ; tmpCont.end() != iter ; ++iter )
292  {
293  //
294  ChronoEntity* entity = iter->first ; if( !entity ) { continue ; }
295  const ChronoTag* tag = iter->second ; if( !tag ) { continue ; }
296  entity->stop();
298  if ( m_chronoCoutFlag )
300  { std::cout << *tag << "\t" << entity->outputUserTime () << std::endl ; }
301  else
302  {
303  MsgStream(msgSvc(), *tag)
304  << m_chronoPrintLevel << entity->outputUserTime () << endmsg ;
305  }
306  //
307  }
308  }
310  if( m_printSystemTime )
311  {
315  { std::cout << stars << std::endl; }
316  else if ( m_printUserTime && !m_chronoCoutFlag )
317  { log << (MSG::Level) m_chronoPrintLevel << stars << endmsg; }
319  for( auto iter = tmpCont.begin() ; tmpCont.end() != iter ; ++iter )
320  {
322  ChronoEntity* entity = iter->first ; if( !entity ) { continue ; }
323  const ChronoTag* tag = iter->second ; if( !tag ) { continue ; }
324  entity->stop();
326  if ( m_chronoCoutFlag )
328  { std::cout << *tag << "\t" << entity->outputSystemTime() << std::endl ; }
329  else
330  {
331  MsgStream(msgSvc(), *tag)
332  << m_chronoPrintLevel << entity->outputSystemTime() << endmsg ;
333  }
334  //
335  }
336  }
338  if( m_printEllapsedTime )
339  {
343  { std::cout << stars << std::endl; }
344  else if ( ( m_printUserTime || m_printSystemTime ) && !m_chronoCoutFlag )
345  { log << (MSG::Level) m_chronoPrintLevel << stars << endmsg; }
347  for( const auto& i : tmpCont )
348  {
350  ChronoEntity* entity = i.first ; if( !entity ) { continue ; }
351  const ChronoTag* tag = i.second ; if( !tag ) { continue ; }
352  entity->stop();
354  if ( m_chronoCoutFlag )
356  { std::cout << *tag << "\t" << entity->outputElapsedTime() << std::endl ; }
357  else
358  {
359  MsgStream(msgSvc(), *tag)
360  << m_chronoPrintLevel << entity->outputElapsedTime() << endmsg ;
361  }
362  //
363  }
364  }
366  tmpCont.clear();
367  }
369  if( m_chronoCoutFlag ) { std::cout << stars << std::endl; }
370  else { log << m_chronoPrintLevel << stars << endmsg; }
371  }
372 
374 
376  if ( m_statTableFlag ) { printStats () ; }
377 
378  if ( !m_statsOutFileName.value().empty() ) {
379  saveStats();
380  }
381 
382  main_log << MSG::INFO << " Service finalized successfully " << endmsg;
383 
384  return Service::finalize();
385 }
std::string outputElapsedTime() const
print the chrono ;
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
bool m_chronoOrderFlag
flag for formattion the final statistic table
bool m_printUserTime
flag for printing User quantities
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
StatusCode finalize() override
Definition: Service.cpp:188
bool m_printEllapsedTime
flag for printing Ellapsed quantities
a small helper class for implementation of ChronoStatSvc service, It also could be used as some local...
Definition: ChronoEntity.h:21
StringProperty m_statsOutFileName
Name of the output file where we'll dump the stats.
std::string outputSystemTime() const
print the chrono ;
bool m_chronoTableFlag
flag for printing the final table
void saveStats()
dump the statistics into an ASCII file for offline processing
constexpr struct CompareFirstOfPointerPair_t CompareFirstOfPointerPair
void clear(STATE_TYPE _i=std::ios_base::failbit)
Definition: MsgStream.h:222
TimeMap m_perEvtTime
virtual const ChronoEntity * chronoStop(const IChronoStatSvc::ChronoTag &chronoTag) override
Implementation of IChronoStatSvc::chronoStop.
std::ofstream m_ofd
bool m_statTableFlag
flag for printing the final table
const TYPE & value() const
explicit conversion
Definition: Property.h:341
MSG::Level m_chronoPrintLevel
std::string outputUserTime() const
print the chrono ;
bool m_printSystemTime
flag for printing System quantities
std::string m_perEventFile
bool m_chronoCoutFlag
flag for destination of the the final table
IChronoSvc::ChronoStatus stop()
stop the chrono
list i
Definition: ana.py:128
ChronoMap m_chronoEntities
chrono part
void ChronoStatSvc::handle ( const Incident incident)
override

Definition at line 653 of file ChronoStatSvc.cpp.

653  {
654 
655  if (! m_ofd.is_open()) return;
656 
657  for (const auto& itr:m_chronoEntities) {
658  if (itr.first.find(":Execute") == std::string::npos) continue;
659 
660  auto itm = m_perEvtTime.find(itr.first);
661  if (itm == m_perEvtTime.end()) {
662  m_perEvtTime[itr.first] = { itr.second.delta(IChronoSvc::ELAPSED) };
663  } else {
664  itm->second.push_back( itr.second.delta(IChronoSvc::ELAPSED) );
665  }
666  }
667 }
tuple itm
Definition: ana.py:57
TimeMap m_perEvtTime
std::ofstream m_ofd
ChronoMap m_chronoEntities
chrono part
StatusCode ChronoStatSvc::initialize ( )
override

Implementation of IService::initialize()

redefine some "properties"

start its own chrono

Definition at line 166 of file ChronoStatSvc.cpp.

167 {
169  if ( sc.isFailure() ) return sc;
171  MsgStream log( msgSvc() , this->name() );
172 
173  // Set my own properties
174  sc = setProperties();
175 
176  if (sc.isFailure()) {
177  log << MSG::ERROR << "setting my properties" << endmsg;
178  return StatusCode::FAILURE;
179  }
180 
181  // only add an EndEvent listener if per-event output requested
182  if (!m_perEventFile.empty()) {
183  m_ofd.open(m_perEventFile);
184  if (!m_ofd.is_open()) {
185  log << MSG::ERROR << "unable to open per-event output file \""
186  << m_perEventFile << "\"" << endmsg;
187  return StatusCode::FAILURE;
188  } else {
189  auto ii = serviceLocator()->service<IIncidentSvc>("IncidentSvc");
190  if ( !ii) {
191  log << MSG::ERROR << "Unable to find IncidentSvc" << endmsg;
192  return StatusCode::FAILURE;
193  }
194  ii->addListener(this, IncidentType::EndEvent);
195  }
196  }
197 
198  log << MSG::INFO << " Number of skipped events for MemStat"
200 
214  if( m_chronoTableFlag &&
215  !m_printUserTime &&
217  !m_printEllapsedTime ) { m_printUserTime = true ; }
219  if( m_printUserTime ||
224  chronoStart( name() ) ;
226  return StatusCode::SUCCESS;
227 }
int m_intStatPrintLevel
level of info printing
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
StatusCode initialize() override
Definition: Service.cpp:63
bool m_printUserTime
flag for printing User quantities
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
bool m_printEllapsedTime
flag for printing Ellapsed quantities
long m_numberOfSkippedEventsForMemStat
bool isFailure() const
Test for a status code of FAILURE.
Definition: StatusCode.h:86
bool m_chronoTableFlag
flag for printing the final table
int m_intChronoPrintLevel
level of info printing
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
std::ofstream m_ofd
MSG::Level m_chronoPrintLevel
bool m_printSystemTime
flag for printing System quantities
virtual ChronoEntity * chronoStart(const IChronoStatSvc::ChronoTag &chronoTag) override
Implementation of IChronoStatSvc::chronoStart.
std::string m_perEventFile
MSG::Level m_statPrintLevel
The interface implemented by the IncidentSvc service.
Definition: IIncidentSvc.h:21
void ChronoStatSvc::merge ( const ChronoStatSvc css)

Compound assignment operator.

Definition at line 138 of file ChronoStatSvc.cpp.

138  {
139 
140  // Add the content of the maps, leave the rest unchanged
141 
142  // Merge Chronomaps
143  for (auto& item : css.m_chronoEntities){
144  const IChronoStatSvc::ChronoTag& key = item.first;
145  const ChronoEntity& val = item.second;
146  if (m_chronoEntities.count(key))
147  m_chronoEntities[key]+=val;
148  else
149  m_chronoEntities.insert (std::pair<IChronoStatSvc::ChronoTag,ChronoEntity>(key,val));
150  }
151 
152  // Merge StatMaps
153  for (auto& item : css.m_statEntities){
154  const IChronoStatSvc::StatTag& key = item.first;
155  const StatEntity& val = item.second;
156  if (m_statEntities.count(key))
157  m_statEntities[key]+=val;
158  else
159  m_statEntities.insert (std::pair<IChronoStatSvc::StatTag,StatEntity>(key,val));
160  }
161 
162 }
StatMap m_statEntities
stat part
a small helper class for implementation of ChronoStatSvc service, It also could be used as some local...
Definition: ChronoEntity.h:21
tuple item
print s1,s2
Definition: ana.py:146
The basic counter used for Monitoring purposes.
Definition: StatEntity.h:64
ChronoMap m_chronoEntities
chrono part
ChronoStatSvc& ChronoStatSvc::operator= ( const ChronoStatSvc )
privatedelete
void ChronoStatSvc::printStats ( )
protected

nothing to print?

CONTINUE

CONTINUE

decoration

Definition at line 580 of file ChronoStatSvc.cpp.

581 {
583  if ( m_statEntities.empty() ) { return ; }
584 
585  MsgStream log ( msgSvc() , "******Stat******" ) ;
587  const std::string stars( ( m_statCoutFlag ) ? 126 : 100 , '*' ) ;
589  if ( m_statCoutFlag )
590  {
591  std::cout << stars << std::endl;
592  std::cout << " The Final stat Table "
593  << ( m_statOrderFlag ? "(ordered)" : "(not ordered)" ) << std::endl;
594  std::cout << stars << std::endl;
595  }
596  else
597  {
598  log << m_statPrintLevel << stars << endmsg;
599  log << m_statPrintLevel << " The Final stat Table "
600  << ( m_statOrderFlag ? "(ordered)" : "(not ordered)" ) << endmsg;
601  log << m_statPrintLevel << stars << endmsg;
602  }
603 
604  {
605  // prepare container for printing
606  typedef std::pair<const StatEntity*,const StatTag*> SPair;
607  typedef std::vector<SPair> SCont;
608  SCont tmpCont;
610  std::back_inserter(tmpCont),
611  [](StatMap::const_reference i)
612  { return std::make_pair( &i.second, &i.first); } );
613  // sort it
614  if ( m_statOrderFlag ) std::sort( tmpCont.begin(), tmpCont.end(),
616  // print the table header
617  if ( m_statCoutFlag ) { std::cout << m_header << std::endl ; }
618  else { log << m_statPrintLevel << m_header << endmsg ; }
619 
620  // loop over counters and print them:
621  for ( const auto& iter : tmpCont ) {
623  const StatEntity* entity = iter.first ;
624  if ( !entity ) { continue ; }
625  const StatTag* tag = iter.second ;
626  if ( !tag ) { continue ; }
627  if ( m_statCoutFlag )
629  {
630  std::cout
632  ( *tag , *entity , m_useEffFormat , m_format1 , m_format2 )
633  << std::endl;
634  }
635  else
636  {
637  log
640  ( *tag , *entity , m_useEffFormat , m_format1 , m_format2 )
641  << endmsg ;
642  }
643  }
644  tmpCont.clear();
645  }
647  if ( m_statCoutFlag ) { std::cout << stars << std::endl; }
648  else { log << m_statPrintLevel << stars << endmsg; }
649 }
bool m_useEffFormat
flag to use the special "efficiency" format
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
StatMap m_statEntities
stat part
std::string m_header
the header row
auto begin(reverse_wrapper< T > &w)
Definition: reverse.h:45
std::string m_format2
format for "efficiency" statistical printout rows
bool m_statOrderFlag
flag for formattion the final statistic table
constexpr struct CompareFirstOfPointerPair_t CompareFirstOfPointerPair
auto end(reverse_wrapper< T > &w)
Definition: reverse.h:47
void clear(STATE_TYPE _i=std::ios_base::failbit)
Definition: MsgStream.h:222
bool m_statCoutFlag
flag for destination of the t he final table
GAUDI_API std::string formatAsTableRow(const StatEntity &counter, const bool flag, const std::string &format1=" |%|7d| |%|11.7g| |%|#11.5g| |%|#10.5g| |%|#10.5g| |%|#10.5g| |", const std::string &format2="*|%|7d| |%|11.5g| |(%|#9.7g| +- %|-#8.6g|)%%| ----- | ----- |")
print the counter in a form of the table row
Definition: StatEntity.cpp:299
MSG::Level m_statPrintLevel
The basic counter used for Monitoring purposes.
Definition: StatEntity.h:64
list i
Definition: ana.py:128
std::string m_format1
format for regular statistical printout rows
void ChronoStatSvc::saveStats ( )
private

dump the statistics into an ASCII file for offline processing

CONTINUE

CONTINUE

Definition at line 506 of file ChronoStatSvc.cpp.

507 {
508  std::ofstream out( m_statsOutFileName.value(),
509  std::ios_base::out | std::ios_base::trunc );
510  if ( !out.good() ) {
511  MsgStream msg( msgSvc() , name() );
512  msg << MSG::INFO
513  << "Could not open the output file for writing chrono statistics ["
514  << m_statsOutFileName.value() << "]"
515  << endmsg;
516  return;
517  } else {
518  // format it our way
519  out << std::scientific << std::setprecision(8) ;
520  }
521 
522  // ChronoEntity
523  std::vector<std::pair<const ChronoEntity*, const ChronoTag*> > chronos;
524  chronos.reserve(m_chronoEntities.size() );
526  std::back_inserter(chronos),
527  [](ChronoMap::const_reference i)
528  { return std::make_pair( &i.second, &i.first ); } );
529 
530  // sort it
531  std::sort( std::begin(chronos) ,
532  std::end(chronos) ,
534 
535  // print User Time statistics
536  for( const auto& iter : chronos ) {
537  //
538  const ChronoEntity* entity = iter.first;
539  if( !entity ) { continue ; }
540 
541  const ChronoTag* tag = iter.second ;
542  if( !tag ) { continue ; }
543 
544  // create an entry in the .INI-like table
545  out << "\n[" << *tag << "]\n";
546 
547  // user
548  out << "cpu_user_total = " << entity->uTotalTime() << "\n";
549  out << "cpu_user_min = " << entity->uMinimalTime() << "\n";
550  out << "cpu_user_mean = " << entity->uMeanTime() << "\n";
551  out << "cpu_user_RMS = " << entity->uRMSTime() << "\n";
552  out << "cpu_user_max = " << entity->uMaximalTime() << "\n";
553  out << "cpu_user_nbr = " << entity->nOfMeasurements() << "\n";
554 
555  // system
556  out << "\n"; // just for clarity
557  out << "cpu_system_total = " << entity->kTotalTime() << "\n";
558  out << "cpu_system_min = " << entity->kMinimalTime() << "\n";
559  out << "cpu_system_mean = " << entity->kMeanTime() << "\n";
560  out << "cpu_system_RMS = " << entity->kRMSTime() << "\n";
561  out << "cpu_system_max = " << entity->kMaximalTime() << "\n";
562  out << "cpu_system_nbr = " << entity->nOfMeasurements() << "\n";
563 
564  // real
565  out << "\n"; // just for clarity
566  out << "cpu_real_total = " << entity->eTotalTime() << "\n";
567  out << "cpu_real_min = " << entity->eMinimalTime() << "\n";
568  out << "cpu_real_mean = " << entity->eMeanTime() << "\n";
569  out << "cpu_real_RMS = " << entity->eRMSTime() << "\n";
570  out << "cpu_real_max = " << entity->eMaximalTime() << "\n";
571  out << "cpu_real_nbr = " << entity->nOfMeasurements() << "\n";
572 
573  }
574 
575  out << std::endl;
576 }
double kMaximalTime() const
maximal measurement for kernel time
Definition: ChronoEntity.h:219
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
double uMinimalTime() const
minimal measurement for user time
Definition: ChronoEntity.h:198
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
double uTotalTime() const
total user time
Definition: ChronoEntity.h:229
a small helper class for implementation of ChronoStatSvc service, It also could be used as some local...
Definition: ChronoEntity.h:21
auto begin(reverse_wrapper< T > &w)
Definition: reverse.h:45
double kTotalTime() const
total Kernel time
Definition: ChronoEntity.h:234
StringProperty m_statsOutFileName
Name of the output file where we'll dump the stats.
double uRMSTime() const
r.m.s User Time
Definition: ChronoEntity.h:270
double kMinimalTime() const
minimal measurement for kernel time
Definition: ChronoEntity.h:204
double eMinimalTime() const
minimal measurement for elapsed time
Definition: ChronoEntity.h:209
double kRMSTime() const
r.m.s Kernel Time
Definition: ChronoEntity.h:265
double kMeanTime() const
average Kernel Time
Definition: ChronoEntity.h:250
double eMeanTime() const
average Elapsed Time
Definition: ChronoEntity.h:260
constexpr struct CompareFirstOfPointerPair_t CompareFirstOfPointerPair
auto end(reverse_wrapper< T > &w)
Definition: reverse.h:47
double eRMSTime() const
r.m.s Elapsed Time
Definition: ChronoEntity.h:275
const TYPE & value() const
explicit conversion
Definition: Property.h:341
double uMeanTime() const
average User Time
Definition: ChronoEntity.h:255
double eMaximalTime() const
maximal measurement for elapsed time
Definition: ChronoEntity.h:224
unsigned long nOfMeasurements() const
number of chrono measurements
Definition: ChronoEntity.h:194
double uMaximalTime() const
maximal measurement for user time
Definition: ChronoEntity.h:214
list i
Definition: ana.py:128
double eTotalTime() const
total Elapsed time
Definition: ChronoEntity.h:239
ChronoMap m_chronoEntities
chrono part
void ChronoStatSvc::stat ( const IChronoStatSvc::StatTag &  statTag,
const IChronoStatSvc::StatFlag &  statFlag 
)
overridevirtual

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

See also
IChronoStatSvc

Definition at line 447 of file ChronoStatSvc.cpp.

449 {
450  auto theIter=m_statEntities.find(statTag);
451 
452  StatEntity * theStat=nullptr ;
453  // if new entity, specify the number of events to be skipped
454  if (theIter==m_statEntities.end()){
455  // new stat entity
456  StatEntity& theSe = m_statEntities[ statTag ];
457  theStat=& theSe;
459  }
460  else
461  {
462  //existing stat entity
463  theStat=&theIter->second;
464  }
465 
466  theStat->addFlag ( statFlag ) ;
467 }
StatMap m_statEntities
stat part
long m_numberOfSkippedEventsForMemStat
void setnEntriesBeforeReset(unsigned long nEntriesBeforeReset)
DR specify number of entry before reset.
Definition: StatEntity.cpp:219
unsigned long addFlag(const double Flag)
add a flag
Definition: StatEntity.h:412
The basic counter used for Monitoring purposes.
Definition: StatEntity.h:64
const StatEntity * ChronoStatSvc::stat ( const IChronoStatSvc::StatTag &  t) const
overridevirtual

extract the stat entity for the given tag (name)

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

Definition at line 498 of file ChronoStatSvc.cpp.

499 {
500  auto it = m_statEntities.find ( t ) ;
501  return m_statEntities.end() != it ? &(it->second) : nullptr;
502 }
StatMap m_statEntities
stat part
void ChronoStatSvc::statPrint ( const IChronoStatSvc::ChronoTag &  statTag)
overridevirtual

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

See also
IChronoStatSvc

Definition at line 472 of file ChronoStatSvc.cpp.

473 {
474  MsgStream log ( msgSvc() , statTag ) ;
475  log << (MSG::Level) m_statPrintLevel << m_statEntities[ statTag ] << endmsg;
476 }
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
StatMap m_statEntities
stat part
MSG::Level m_statPrintLevel

Member Data Documentation

bool ChronoStatSvc::m_chronoCoutFlag
private

flag for destination of the the final table

Definition at line 152 of file ChronoStatSvc.h.

ChronoMap ChronoStatSvc::m_chronoEntities
private

chrono part

Definition at line 145 of file ChronoStatSvc.h.

bool ChronoStatSvc::m_chronoOrderFlag
private

flag for formattion the final statistic table

Definition at line 154 of file ChronoStatSvc.h.

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

Definition at line 148 of file ChronoStatSvc.h.

bool ChronoStatSvc::m_chronoTableFlag
private

flag for printing the final table

Definition at line 150 of file ChronoStatSvc.h.

std::string ChronoStatSvc::m_format1
private

format for regular statistical printout rows

Definition at line 185 of file ChronoStatSvc.h.

std::string ChronoStatSvc::m_format2
private

format for "efficiency" statistical printout rows

Definition at line 187 of file ChronoStatSvc.h.

std::string ChronoStatSvc::m_header
private

the header row

Definition at line 183 of file ChronoStatSvc.h.

int ChronoStatSvc::m_intChronoPrintLevel
private

level of info printing

Definition at line 147 of file ChronoStatSvc.h.

int ChronoStatSvc::m_intStatPrintLevel
private

level of info printing

Definition at line 169 of file ChronoStatSvc.h.

long ChronoStatSvc::m_numberOfSkippedEventsForMemStat
private

Definition at line 163 of file ChronoStatSvc.h.

std::ofstream ChronoStatSvc::m_ofd
private

Definition at line 194 of file ChronoStatSvc.h.

std::string ChronoStatSvc::m_perEventFile
private

Definition at line 193 of file ChronoStatSvc.h.

TimeMap ChronoStatSvc::m_perEvtTime
private

Definition at line 192 of file ChronoStatSvc.h.

bool ChronoStatSvc::m_printEllapsedTime
private

flag for printing Ellapsed quantities

Definition at line 160 of file ChronoStatSvc.h.

bool ChronoStatSvc::m_printSystemTime
private

flag for printing System quantities

Definition at line 158 of file ChronoStatSvc.h.

bool ChronoStatSvc::m_printUserTime
private

flag for printing User quantities

Definition at line 156 of file ChronoStatSvc.h.

bool ChronoStatSvc::m_statCoutFlag
private

flag for destination of the t he final table

Definition at line 174 of file ChronoStatSvc.h.

StatMap ChronoStatSvc::m_statEntities
private

stat part

Definition at line 166 of file ChronoStatSvc.h.

bool ChronoStatSvc::m_statOrderFlag
private

flag for formattion the final statistic table

Definition at line 176 of file ChronoStatSvc.h.

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

Definition at line 170 of file ChronoStatSvc.h.

StringProperty ChronoStatSvc::m_statsOutFileName
private

Name of the output file where we'll dump the stats.

Definition at line 180 of file ChronoStatSvc.h.

bool ChronoStatSvc::m_statTableFlag
private

flag for printing the final table

Definition at line 172 of file ChronoStatSvc.h.

bool ChronoStatSvc::m_useEffFormat = true
private

flag to use the special "efficiency" format

Definition at line 189 of file ChronoStatSvc.h.


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