2 #pragma warning( disable : 4786 )
17 #include "GaudiKernel/Kernel.h"
18 #include "GaudiKernel/StatusCode.h"
19 #include "GaudiKernel/IChronoStatSvc.h"
20 #include "GaudiKernel/MsgStream.h"
21 #include "GaudiKernel/ChronoEntity.h"
22 #include "GaudiKernel/StatEntity.h"
23 #include "GaudiKernel/Stat.h"
24 #include "GaudiKernel/IIncidentSvc.h"
47 template <
typename S,
typename T>
48 inline bool operator() (
const std::pair<S*,T*>&
p1,
49 const std::pair<S*,T*>&
p2)
const
53 return ( !
e1 || !e2 ) || *
e1<*e2 ;
64 , m_header (
" Counter | # | sum | mean/eff^* | rms/err^* | min | max |")
66 , m_format1 (
" %|-15.15s|%|17t||%|10d| |%|11.7g| |%|#11.5g| |%|#11.5g| |%|#12.5g| |%|#12.5g| |" )
68 , m_format2 (
"*%|-15.15s|%|17t||%|10d| |%|11.5g| |(%|#9.7g| +- %|-#9.7g|)%%| ------- | ------- |" )
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 );
109 declareProperty (
"NumberOfSkippedEventsForMemStat" ,
110 m_numberOfSkippedEventsForMemStat = -1 ) ;
112 declareProperty(
"AsciiStatsOutputFile",
113 m_statsOutFileName =
"",
114 "Name of the output file storing the stats. If empty, no"
115 " statistics will be saved (default)" );
118 (
"StatTableHeader" , m_header ,
119 "The header row for the output Stat-table" ) ;
121 (
"RegularRowFormat" , m_format1 ,
122 "The format for the regular row in the output Stat-table" ) ;
124 (
"EfficiencyRowFormat" , m_format2 ,
125 "The format for the regular row in the output Stat-table" ) ;
127 (
"UseEfficiencyRowFormat" , m_useEffFormat ,
128 "Use the special format for printout of efficiency counters" ) ;
131 (
"PerEventFile", m_perEventFile=
"",
132 "File name for per-event deltas" );
144 const IChronoStatSvc::ChronoTag& key =
item.first;
149 m_chronoEntities.insert (std::pair<IChronoStatSvc::ChronoTag,ChronoEntity>(key,val));
154 const IChronoStatSvc::StatTag& key =
item.first;
159 m_statEntities.insert (std::pair<IChronoStatSvc::StatTag,StatEntity>(key,val));
174 sc = setProperties();
184 if (!
m_ofd.is_open()) {
185 log <<
MSG::ERROR <<
"unable to open per-event output file \""
189 auto ii = serviceLocator()->service<
IIncidentSvc>(
"IncidentSvc");
194 ii->addListener(
this, IncidentType::EndEvent);
198 log <<
MSG::INFO <<
" Number of skipped events for MemStat"
233 std::string local =
name()+
".finalize()";
240 if (
m_ofd.is_open()) {
244 m_ofd << itr.first.substr(0,itr.first.length()-8 ) <<
" ";
245 for (
const auto& itt:itr.second) {
246 m_ofd <<
" " << (
long int)(itt);
265 std::cout << stars << std::endl;
266 std::cout << local <<
" The Final CPU consumption (Chrono) Table "
268 std::cout << stars << std::endl;
275 <<
" The Final CPU consumption ( Chrono ) Table "
281 std::vector<std::pair<ChronoEntity*,const ChronoTag*>> tmpCont;
284 { tmpCont.emplace_back( &it.second , &it.first ) ; }
291 for(
auto iter = tmpCont.begin() ; tmpCont.end() != iter ; ++iter )
294 ChronoEntity* entity = iter->first ;
if( !entity ) { continue ; }
295 const ChronoTag* tag = iter->second ;
if( !tag ) { continue ; }
300 { std::cout << *tag <<
"\t" << entity->
outputUserTime () << std::endl ; }
315 { std::cout << stars << std::endl; }
319 for(
auto iter = tmpCont.begin() ; tmpCont.end() != iter ; ++iter )
322 ChronoEntity* entity = iter->first ;
if( !entity ) { continue ; }
323 const ChronoTag* tag = iter->second ;
if( !tag ) { continue ; }
343 { std::cout << stars << std::endl; }
347 for(
const auto&
i : tmpCont )
350 ChronoEntity* entity =
i.first ;
if( !entity ) { continue ; }
351 const ChronoTag* tag =
i.second ;
if( !tag ) { continue ; }
391 (
const ChronoTag& chronoTag )
402 (
const IChronoStatSvc::ChronoTag& chronoTag )
411 IChronoStatSvc::ChronoTime
413 (
const IChronoStatSvc::ChronoTag& chronoTag,
414 IChronoStatSvc::ChronoType theType )
416 return m_chronoEntities[ chronoTag ].delta( theType );
422 (
const IChronoStatSvc::ChronoTag& chronoTag )
425 if( m_printUserTime ) {
427 << m_chronoEntities[ chronoTag ].outputUserTime ()
430 if( m_printSystemTime ) {
432 << m_chronoEntities[ chronoTag ].outputSystemTime()
439 IChronoStatSvc::ChronoStatus
441 (
const IChronoStatSvc::ChronoTag& chronoTag )
442 {
return m_chronoEntities[ chronoTag ].status(); }
447 (
const IChronoStatSvc::StatTag & statTag ,
448 const IChronoStatSvc::StatFlag & statFlag )
450 auto theIter=m_statEntities.find(statTag);
454 if (theIter==m_statEntities.end()){
456 StatEntity& theSe = m_statEntities[ statTag ];
463 theStat=&theIter->second;
466 theStat->
addFlag ( statFlag ) ;
472 (
const IChronoStatSvc::StatTag& statTag )
475 log << (
MSG::Level) m_statPrintLevel << m_statEntities[ statTag ] <<
endmsg;
485 (
const IChronoStatSvc::ChronoTag& t )
const
487 auto it = m_chronoEntities.find ( t ) ;
488 return m_chronoEntities.end() != it ? &(it->second) :
nullptr;
498 (
const IChronoStatSvc::StatTag& t )
const
500 auto it = m_statEntities.find ( t ) ;
501 return m_statEntities.end() != it ? &(it->second) :
nullptr;
509 std::ios_base::out | std::ios_base::trunc );
513 <<
"Could not open the output file for writing chrono statistics ["
519 out << std::scientific << std::setprecision(8) ;
523 std::vector<std::pair<const ChronoEntity*, const ChronoTag*> > chronos;
526 std::back_inserter(chronos),
527 [](ChronoMap::const_reference
i)
528 {
return std::make_pair( &i.second, &i.first ); } );
536 for(
const auto& iter : chronos ) {
539 if( !entity ) { continue ; }
541 const ChronoTag* tag = iter.second ;
542 if( !tag ) { continue ; }
545 out <<
"\n[" << *tag <<
"]\n";
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";
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";
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";
591 std::cout << stars << std::endl;
592 std::cout <<
" The Final stat Table "
594 std::cout << stars << std::endl;
606 typedef std::pair<const StatEntity*,const StatTag*> SPair;
607 typedef std::vector<SPair> SCont;
610 std::back_inserter(tmpCont),
611 [](StatMap::const_reference
i)
612 {
return std::make_pair( &i.second, &i.first); } );
621 for (
const auto& iter : tmpCont ) {
624 if ( !entity ) { continue ; }
625 const StatTag* tag = iter.second ;
626 if ( !tag ) { continue ; }
655 if (!
m_ofd.is_open())
return;
658 if (itr.first.find(
":Execute") == std::string::npos)
continue;
std::string outputElapsedTime() const
print the chrono ;
bool m_useEffFormat
flag to use the special "efficiency" format
int m_intStatPrintLevel
level of info printing
double kMaximalTime() const
maximal measurement for kernel time
Definition of the MsgStream class used to transmit messages.
StatusCode initialize() override
double uMinimalTime() const
minimal measurement for user time
bool m_chronoOrderFlag
flag for formattion the final statistic table
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
bool m_printUserTime
flag for printing User quantities
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
double uTotalTime() const
total user time
virtual ChronoStatus chronoStatus(const IChronoStatSvc::ChronoTag &chronoTag) override
Implementation of IChronoStatSvc::chronoStatus.
StatusCode finalize() override
StatMap m_statEntities
stat part
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...
std::string m_header
the header row
virtual IChronoStatSvc::ChronoTime chronoDelta(const IChronoStatSvc::ChronoTag &chronoTag, IChronoStatSvc::ChronoType theType) override
Implementation of IchronoStatSvc::chronoDelta.
auto begin(reverse_wrapper< T > &w)
double kTotalTime() const
total Kernel time
StringProperty m_statsOutFileName
Name of the output file where we'll dump the stats.
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.
double uRMSTime() const
r.m.s User Time
double kMinimalTime() const
minimal measurement for kernel time
double eMinimalTime() const
minimal measurement for elapsed time
double kRMSTime() const
r.m.s Kernel Time
virtual void statPrint(const IChronoStatSvc::ChronoTag &statTag) override
prints (using message service) info about statistical entity, tagged by its name
long m_numberOfSkippedEventsForMemStat
std::string outputSystemTime() const
print the chrono ;
IChronoSvc::ChronoStatus start()
start the current chrono
std::string m_format2
format for "efficiency" statistical printout rows
bool isFailure() const
Test for a status code of FAILURE.
bool m_chronoTableFlag
flag for printing the final table
int m_intChronoPrintLevel
level of info printing
void setnEntriesBeforeReset(unsigned long nEntriesBeforeReset)
DR specify number of entry before reset.
double kMeanTime() const
average Kernel Time
double eMeanTime() const
average Elapsed Time
void merge(const ChronoStatSvc &css)
Compound assignment operator.
void saveStats()
dump the statistics into an ASCII file for offline processing
bool m_statOrderFlag
flag for formattion the final statistic table
constexpr struct CompareFirstOfPointerPair_t CompareFirstOfPointerPair
auto end(reverse_wrapper< T > &w)
This class is used for returning status codes from appropriate routines.
void clear(STATE_TYPE _i=std::ios_base::failbit)
#define DECLARE_COMPONENT(type)
virtual const ChronoEntity * chronoStop(const IChronoStatSvc::ChronoTag &chronoTag) override
Implementation of IChronoStatSvc::chronoStop.
double eRMSTime() const
r.m.s Elapsed Time
bool m_statTableFlag
flag for printing the final table
const TYPE & value() const
explicit conversion
unsigned long addFlag(const double Flag)
add a flag
MSG::Level m_chronoPrintLevel
StatusCode initialize() override
Implementation of IService::initialize()
double uMeanTime() const
average User Time
std::string outputUserTime() const
print the chrono ;
bool m_statCoutFlag
flag for destination of the t he final table
bool m_printSystemTime
flag for printing System quantities
Base class used to extend a class implementing other interfaces.
void handle(const Incident &incident) override
double eMaximalTime() const
maximal measurement for elapsed time
Base class for all Incidents (computing events).
virtual ChronoEntity * chronoStart(const IChronoStatSvc::ChronoTag &chronoTag) override
Implementation of IChronoStatSvc::chronoStart.
std::string m_perEventFile
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
unsigned long nOfMeasurements() const
number of chrono measurements
MSG::Level m_statPrintLevel
bool m_chronoCoutFlag
flag for destination of the the final table
The basic counter used for Monitoring purposes.
IChronoSvc::ChronoStatus stop()
stop the chrono
double uMaximalTime() const
maximal measurement for user time
double eTotalTime() const
total Elapsed time
virtual void chronoPrint(const IChronoStatSvc::ChronoTag &chronoTag) override
Implementation of IChronoStatSvc::chronoPrint.
The interface implemented by the IncidentSvc service.
std::string m_format1
format for regular statistical printout rows
The Chrono & Stat Sservice: service implements the IChronoStatSvc interface and provides the basic ch...
ChronoMap m_chronoEntities
chrono part
StatusCode finalize() override
Implementation of IService::finalize()
virtual const ChronoEntity * chrono(const IChronoStatSvc::ChronoTag &t) const override
extract the chrono entity for the given tag (name)