53 template <
typename S,
typename T>
54 inline bool operator()(
const std::pair<S*, T*>& p1,
const std::pair<S*, T*>& p2 )
const {
70 const IChronoStatSvc::ChronoTag& key = item.first;
75 m_chronoEntities.insert( std::pair<IChronoStatSvc::ChronoTag, ChronoEntity>( key, val ) );
80 const IChronoStatSvc::StatTag& key = item.first;
98 if ( !
m_ofd.is_open() ) {
124 std::string local =
name() +
".finalize()";
131 if (
m_ofd.is_open() ) {
134 m_ofd << itr.first.substr( 0, itr.first.length() - 8 ) <<
" ";
135 for (
const auto& itt : itr.second ) {
m_ofd <<
" " << (
long int)( itt ); }
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 "
153 std::cout << stars << std::endl;
163 std::vector<std::pair<ChronoEntity*, const ChronoTag*>> tmpCont;
165 for (
auto& it :
m_chronoEntities ) { tmpCont.emplace_back( &it.second, &it.first ); }
170 for (
auto iter = tmpCont.begin(); tmpCont.end() != iter; ++iter ) {
173 if ( !entity ) {
continue; }
174 const ChronoTag* tag = iter->second;
175 if ( !tag ) {
continue; }
181 std::cout << *tag <<
"\t" << entity->
outputUserTime() << std::endl;
194 std::cout << stars << std::endl;
199 for (
auto iter = tmpCont.begin(); tmpCont.end() != iter; ++iter ) {
202 if ( !entity ) {
continue; }
203 const ChronoTag* tag = iter->second;
204 if ( !tag ) {
continue; }
223 std::cout << stars << std::endl;
228 for (
const auto& i : tmpCont ) {
231 if ( !entity ) {
continue; }
232 const ChronoTag* tag = i.second;
233 if ( !tag ) {
continue; }
252 std::cout << stars << std::endl;
294 IChronoStatSvc::ChronoType theType ) {
314void ChronoStatSvc::stat(
const IChronoStatSvc::StatTag& statTag,
const IChronoStatSvc::StatFlag& statFlag ) {
325 theStat = &theIter->second;
345 auto lock = std::scoped_lock{
m_mutex };
364 std::ofstream out(
m_statsOutFileName.value(), std::ios_base::out | std::ios_base::trunc );
366 info() <<
"Could not open the output file for writing chrono statistics [" <<
m_statsOutFileName.value() <<
"]"
371 out << std::scientific << std::setprecision( 8 );
375 std::vector<std::pair<const ChronoEntity*, const ChronoTag*>> chronos;
377 auto lock = std::scoped_lock{
m_mutex };
380 []( ChronoMap::const_reference i ) {
return std::make_pair( &i.second, &i.first ); } );
387 for (
const auto& iter : chronos ) {
390 if ( !entity ) {
continue; }
392 const ChronoTag* tag = iter.second;
393 if ( !tag ) {
continue; }
396 out <<
"\n[" << *tag <<
"]\n";
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";
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";
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";
433 error() <<
"Cannot retrieve HiveWhiteBoardSvc";
437 if ( wb && wb->getNumberOfStores() > 1 ) {
isMT =
true; }
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;
467 typedef std::pair<const StatEntity*, const StatTag*> SPair;
468 typedef std::vector<SPair> SCont;
471 []( StatMap::const_reference i ) {
return std::make_pair( &i.second, &i.first ); } );
476 std::cout <<
m_header.value() << std::endl;
482 for (
const auto& iter : tmpCont ) {
485 if ( !entity ) {
continue; }
486 const StatTag* tag = iter.second;
487 if ( !tag ) {
continue; }
492 std::ostringstream ost;
501 std::cout << stars << std::endl;
511 if ( !
m_ofd.is_open() )
return;
513 auto lock = std::scoped_lock{
m_mutex };
515 if ( itr.first.find(
":Execute" ) == std::string::npos )
continue;
constexpr struct CompareFirstOfPointerPair_t CompareFirstOfPointerPair
HepRndm::Engine< TripleRand > e2
HepRndm::Engine< DualRand > e1
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
#define DECLARE_COMPONENT(type)
a small helper class for implementation of ChronoStatSvc service, It also could be used as some local...
std::string outputSystemTime() const
print the chrono ;
double kMaximalTime() const
maximal measurement for kernel time
double kTotalTime() const
total Kernel time
double eMinimalTime() const
minimal measurement for elapsed time
IChronoSvc::ChronoTime delta(IChronoSvc::ChronoType type) const
return the last delta-time of type "type"
IChronoSvc::ChronoStatus start()
start the current chrono
IChronoSvc::ChronoStatus stop()
stop the chrono
double eMeanTime() const
average Elapsed Time
IChronoSvc::ChronoStatus status() const
return the status of chrono
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
std::string outputElapsedTime() const
print the chrono ;
double kMeanTime() const
average Kernel Time
double uMinimalTime() const
minimal measurement for user time
double eTotalTime() const
total Elapsed time
double eRMSTime() const
r.m.s Elapsed Time
std::string outputUserTime() const
print the chrono ;
double kRMSTime() const
r.m.s Kernel Time
The Chrono & Stat Sservice: service implements the IChronoStatSvc interface and provides the basic ch...
ChronoStatus chronoStatus(const IChronoStatSvc::ChronoTag &chronoTag) override
Implementation of IChronoStatSvc::chronoStatus.
Gaudi::Property< bool > m_statCoutFlag
Gaudi::Property< std::string > m_statsOutFileName
Gaudi::Property< std::string > m_header
ServiceHandle< IInterface > m_hiveWhiteBoardSvc
StatusCode initialize() override
Implementation of IService::initialize()
ChronoEntity * chronoStart(const IChronoStatSvc::ChronoTag &chronoTag) override
Implementation of IChronoStatSvc::chronoStart.
IChronoStatSvc::ChronoTime chronoDelta(const IChronoStatSvc::ChronoTag &chronoTag, IChronoStatSvc::ChronoType theType) override
Implementation of IchronoStatSvc::chronoDelta.
void saveStats()
dump the statistics into an ASCII file for offline processing
StatusCode finalize() override
Implementation of IService::finalize()
StatMap m_statEntities
stat part
const ChronoEntity * chrono(const IChronoStatSvc::ChronoTag &t) const override
extract the chrono entity for the given tag (name)
Gaudi::Property< bool > m_statTableFlag
Gaudi::Property< bool > m_chronoOrderFlag
std::mutex m_mutex
Mutex protecting m_chronoEntities.
Gaudi::Property< bool > m_chronoTableFlag
Gaudi::Property< bool > m_chronoCoutFlag
void stat(const IChronoStatSvc::StatTag &statTag, const IChronoStatSvc::StatFlag &statFlag) override
Implementation of IChronoStatSvc::stat add statistical information to the entity ,...
ChronoMap m_chronoEntities
chrono part
Gaudi::Property< bool > m_printUserTime
ChronoEntity & getEntity(const ChronoTag &chronoTag)
MSG::Level m_chronoPrintLevel
level of info printing
const ChronoEntity * chronoStop(const IChronoStatSvc::ChronoTag &chronoTag) override
Implementation of IChronoStatSvc::chronoStop.
Gaudi::Property< bool > m_useEffFormat
MSG::Level m_statPrintLevel
level of info printing
void handle(const Incident &incident) override
ChronoStatSvc(const std::string &name, ISvcLocator *svcloc)
Default constructor.
void chronoPrint(const IChronoStatSvc::ChronoTag &chronoTag) override
Implementation of IChronoStatSvc::chronoPrint.
Gaudi::Property< std::string > m_perEventFile
void statPrint(const IChronoStatSvc::ChronoTag &statTag) override
prints (using message service) info about statistical entity, tagged by its name
Gaudi::Property< bool > m_printSystemTime
void merge(const ChronoStatSvc &css)
Compound assignment operator.
Gaudi::Property< bool > m_statOrderFlag
Gaudi::Property< bool > m_printEllapsedTime
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
const SmartIF< IMessageSvc > & msgSvc() const
The standard message service.
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
MsgStream & info() const
shortcut for the method msgStream(MSG::INFO)
The interface implemented by the IncidentSvc service.
virtual void addListener(IIncidentListener *lis, const std::string &type="", long priority=0, bool rethrow=false, bool singleShot=false)=0
Add listener.
virtual SmartIF< IService > & service(const Gaudi::Utils::TypeNameString &typeName, const bool createIf=true)=0
Returns a smart pointer to a service.
Base class for all Incidents (computing events).
Definition of the MsgStream class used to transmit messages.
SmartIF< ISvcLocator > & serviceLocator() const override
Retrieve pointer to service locator.
StatusCode finalize() override
const std::string & name() const override
Retrieve name of the service.
StatusCode initialize() override
Small smart pointer class with automatic reference counting for IInterface.
backward compatible StatEntity class.
unsigned long addFlag(const double v)
std::ostream & print(std::ostream &o, bool tableFormat, std::string_view name, bool flag=true, std::string_view fmtHead="%|-48.48s|%|27t|") const
This class is used for returning status codes from appropriate routines.
constexpr static const auto SUCCESS
constexpr static const auto FAILURE
bool operator()(const std::pair< S *, T * > &p1, const std::pair< S *, T * > &p2) const