The Gaudi Framework  master (37c0b60a)
ChronoStatSvc.h
Go to the documentation of this file.
1 /***********************************************************************************\
2 * (c) Copyright 1998-2024 CERN for the benefit of the LHCb and ATLAS collaborations *
3 * *
4 * This software is distributed under the terms of the Apache version 2 licence, *
5 * copied verbatim in the file "LICENSE". *
6 * *
7 * In applying this licence, CERN does not waive the privileges and immunities *
8 * granted to it by virtue of its status as an Intergovernmental Organization *
9 * or submit itself to any jurisdiction. *
10 \***********************************************************************************/
11 #pragma once
12 // ============================================================================
13 // include files
14 // ============================================================================
15 // STD & STL
16 // ============================================================================
17 #include <atomic>
18 #include <fstream>
19 #include <functional>
20 #include <map>
21 #include <mutex>
22 #include <string>
23 // ============================================================================
24 // GaudiKernel
25 // ============================================================================
28 #include <GaudiKernel/Kernel.h>
29 #include <GaudiKernel/Service.h>
32 // ============================================================================
34 // ============================================================================
35 class ISvcLocator;
36 class IMessageSvc;
37 // ============================================================================
46 class ChronoStatSvc : public extends<Service, IChronoStatSvc, IIncidentListener> {
47 public:
48  // ============================================================================
52  // ============================================================================
53 public:
54  // ============================================================================
56  StatusCode initialize() override;
58  StatusCode finalize() override;
59  // ============================================================================
60 public:
61  // ============================================================================
65  ChronoEntity* chronoStart( const IChronoStatSvc::ChronoTag& chronoTag ) override;
66  // ============================================================================
70  const ChronoEntity* chronoStop( const IChronoStatSvc::ChronoTag& chronoTag ) override;
71  // ============================================================================
75  IChronoStatSvc::ChronoTime chronoDelta( const IChronoStatSvc::ChronoTag& chronoTag,
76  IChronoStatSvc::ChronoType theType ) override;
77  // ============================================================================
81  void chronoPrint( const IChronoStatSvc::ChronoTag& chronoTag ) override;
82  // ============================================================================
86  ChronoStatus chronoStatus( const IChronoStatSvc::ChronoTag& chronoTag ) override;
87  // ============================================================================
92  void stat( const IChronoStatSvc::StatTag& statTag, const IChronoStatSvc::StatFlag& statFlag ) override;
93  // ============================================================================
98  void statPrint( const IChronoStatSvc::ChronoTag& statTag ) override;
99  // ============================================================================
105  const ChronoEntity* chrono( const IChronoStatSvc::ChronoTag& t ) const override;
106  // ============================================================================
112  StatEntity* stat( const IChronoStatSvc::StatTag& t ) override;
113  // ============================================================================
118  ChronoStatSvc( const std::string& name, ISvcLocator* svcloc ) : base_class( name, svcloc ) {}
119 
121  void merge( const ChronoStatSvc& css );
122  // ============================================================================
123 
124 public:
125  void handle( const Incident& incident ) override;
126 
127 protected:
128  // ============================================================================
129  // print the "Stat" part of the ChronoStatSvc
130  void printStats();
131  // ============================================================================
132 private:
133  // ============================================================================
134  // default/copy constructor and assignment are disabled
135  ChronoStatSvc() = delete;
136  ChronoStatSvc( const ChronoStatSvc& ) = delete;
137  ChronoStatSvc& operator=( const ChronoStatSvc& ) = delete;
138  // ============================================================================
140  void saveStats();
141  // ============================================================================
142 public:
143  // ============================================================================
144  // Standard Destructor
145  ~ChronoStatSvc() override = default;
146  // ============================================================================
147 private:
148  bool isMT() const;
149 
150  ChronoEntity& getEntity( const ChronoTag& chronoTag ) {
151  auto lock = std::scoped_lock{ m_mutex };
152  return m_chronoEntities[chronoTag];
153  }
154 
155  // basically limit the integer to MSG::Level range
156  static MSG::Level int2level( int l ) {
157  return static_cast<MSG::Level>(
158  std::max( std::min( l, static_cast<int>( MSG::FATAL ) ), static_cast<int>( MSG::NIL ) ) );
159  }
160  // ============================================================================
165 
168 
173 
174  Gaudi::Property<bool> m_chronoTableFlag{ this, "ChronoPrintOutTable", true,
175  "decide if the final printout should be performed" };
176  Gaudi::Property<bool> m_chronoCoutFlag{ this, "ChronoDestinationCout", false,
177  "define the destination of the table to be printed" };
179  this, "ChronoPrintLevel", MSG::INFO, [this]( auto& ) { m_chronoPrintLevel = int2level( m_intChronoPrintLevel ); },
180  "print level" };
181  Gaudi::Property<bool> m_chronoOrderFlag{ this, "ChronoTableToBeOrdered", true, "should the printout be ordered" };
182  Gaudi::Property<bool> m_printUserTime{ this, "PrintUserTime", true };
183  Gaudi::Property<bool> m_printSystemTime{ this, "PrintSystemTime", false };
184  Gaudi::Property<bool> m_printEllapsedTime{ this, "PrintEllapsedTime", false };
185  Gaudi::Property<bool> m_statTableFlag{ this, "StatPrintOutTable", true,
186  "decide if the final printout should be performed" };
187  Gaudi::Property<bool> m_statCoutFlag{ this, "StatDestinationCout", false,
188  "define the destination of the table to be printed" };
190  [this]( auto& ) { m_statPrintLevel = int2level( m_intStatPrintLevel ); },
191  "print level" };
192  Gaudi::Property<bool> m_statOrderFlag{ this, "StatTableToBeOrdered", true, "should the printout be ordered" };
193 
195  this, "AsciiStatsOutputFile", "",
196  "Name of the output file storing the stats. If empty, no statistics will be saved (default)" };
197 
199  this, "StatTableHeader",
200  " | Counter | # | sum | mean/eff^* | rms/err^* | min | max |",
201  "The header row for the output Stat-table" };
202  Gaudi::Property<bool> m_useEffFormat{ this, "UseEfficiencyRowFormat", true,
203  "Use the special format for printout of efficiency counters" };
204 
205  Gaudi::Property<std::string> m_perEventFile{ this, "PerEventFile", "", "File name for per-event deltas" };
206 
207  ServiceHandle<IInterface> m_hiveWhiteBoardSvc{ this, "HiveWhiteBoardSvc", "EventDataSvc" };
208 
212 
213  // ============================================================================
214 };
215 // ============================================================================
216 // The END
217 // ============================================================================
ChronoStatSvc::m_header
Gaudi::Property< std::string > m_header
Definition: ChronoStatSvc.h:198
ChronoStatSvc::m_printSystemTime
Gaudi::Property< bool > m_printSystemTime
Definition: ChronoStatSvc.h:183
ChronoStatSvc::m_chronoOrderFlag
Gaudi::Property< bool > m_chronoOrderFlag
Definition: ChronoStatSvc.h:181
ChronoStatSvc::m_intStatPrintLevel
Gaudi::Property< int > m_intStatPrintLevel
Definition: ChronoStatSvc.h:189
std::string
STL class.
ChronoEntity
Definition: ChronoEntity.h:31
IMessageSvc
Definition: IMessageSvc.h:47
MSG::INFO
@ INFO
Definition: IMessageSvc.h:25
ServiceHandle< IInterface >
ChronoStatSvc::getEntity
ChronoEntity & getEntity(const ChronoTag &chronoTag)
Definition: ChronoStatSvc.h:150
ChronoStatSvc::m_chronoEntities
ChronoMap m_chronoEntities
chrono part
Definition: ChronoStatSvc.h:162
ChronoStatSvc::finalize
StatusCode finalize() override
Implementation of IService::finalize()
Definition: ChronoStatSvc.cpp:126
StatEntity
backward compatible StatEntity class.
Definition: StatEntity.h:23
ISvcLocator
Definition: ISvcLocator.h:46
ChronoStatSvc::m_statCoutFlag
Gaudi::Property< bool > m_statCoutFlag
Definition: ChronoStatSvc.h:187
ChronoStatSvc::chronoStatus
ChronoStatus chronoStatus(const IChronoStatSvc::ChronoTag &chronoTag) override
Implementation of IChronoStatSvc::chronoStatus.
Definition: ChronoStatSvc.cpp:311
ChronoStatSvc::m_statEntities
StatMap m_statEntities
stat part
Definition: ChronoStatSvc.h:170
ServiceHandle.h
ChronoStatSvc::merge
void merge(const ChronoStatSvc &css)
Compound assignment operator.
Definition: ChronoStatSvc.cpp:66
ChronoStatSvc::stat
void stat(const IChronoStatSvc::StatTag &statTag, const IChronoStatSvc::StatFlag &statFlag) override
Implementation of IChronoStatSvc::stat add statistical information to the entity ,...
Definition: ChronoStatSvc.cpp:317
ChronoStatSvc::chronoDelta
IChronoStatSvc::ChronoTime chronoDelta(const IChronoStatSvc::ChronoTag &chronoTag, IChronoStatSvc::ChronoType theType) override
Implementation of IchronoStatSvc::chronoDelta.
Definition: ChronoStatSvc.cpp:296
ChronoStatSvc::chronoStop
const ChronoEntity * chronoStop(const IChronoStatSvc::ChronoTag &chronoTag) override
Implementation of IChronoStatSvc::chronoStop.
Definition: ChronoStatSvc.cpp:288
bug_34121.t
t
Definition: bug_34121.py:31
ChronoStatSvc::statPrint
void statPrint(const IChronoStatSvc::ChronoTag &statTag) override
prints (using message service) info about statistical entity, tagged by its name
Definition: ChronoStatSvc.cpp:336
ChronoStatSvc::saveStats
void saveStats()
dump the statistics into an ASCII file for offline processing
Definition: ChronoStatSvc.cpp:366
ChronoStatSvc::m_printUserTime
Gaudi::Property< bool > m_printUserTime
Definition: ChronoStatSvc.h:182
ChronoStatSvc::m_mutex
std::mutex m_mutex
Mutex protecting m_chronoEntities.
Definition: ChronoStatSvc.h:164
Service::name
const std::string & name() const override
Retrieve name of the service
Definition: Service.cpp:332
StatusCode
Definition: StatusCode.h:65
ChronoStatSvc::int2level
static MSG::Level int2level(int l)
Definition: ChronoStatSvc.h:156
ChronoStatSvc::printStats
void printStats()
Definition: ChronoStatSvc.cpp:447
std::ofstream
STL class.
ChronoStatSvc::~ChronoStatSvc
~ChronoStatSvc() override=default
CommonMessaging
Definition: CommonMessaging.h:66
ChronoStatSvc::m_printEllapsedTime
Gaudi::Property< bool > m_printEllapsedTime
Definition: ChronoStatSvc.h:184
ChronoStatSvc::m_chronoTableFlag
Gaudi::Property< bool > m_chronoTableFlag
Definition: ChronoStatSvc.h:174
ChronoStatSvc::ChronoStatSvc
ChronoStatSvc()=delete
ChronoStatSvc::m_useEffFormat
Gaudi::Property< bool > m_useEffFormat
Definition: ChronoStatSvc.h:202
ChronoStatSvc::m_chronoPrintLevel
MSG::Level m_chronoPrintLevel
level of info printing
Definition: ChronoStatSvc.h:167
std::map< IChronoStatSvc::ChronoTag, ChronoEntity >
ChronoStatSvc::isMT
bool isMT() const
Definition: ChronoStatSvc.cpp:433
extends
Base class used to extend a class implementing other interfaces.
Definition: extends.h:20
ChronoStatSvc::m_perEvtTime
TimeMap m_perEvtTime
Definition: ChronoStatSvc.h:210
MSG::FATAL
@ FATAL
Definition: IMessageSvc.h:25
Service.h
ChronoStatSvc::m_intChronoPrintLevel
Gaudi::Property< int > m_intChronoPrintLevel
Definition: ChronoStatSvc.h:178
std::min
T min(T... args)
ChronoStatSvc::m_ofd
std::ofstream m_ofd
Definition: ChronoStatSvc.h:211
ChronoStatSvc::m_hiveWhiteBoardSvc
ServiceHandle< IInterface > m_hiveWhiteBoardSvc
Definition: ChronoStatSvc.h:207
MSG::Level
Level
Definition: IMessageSvc.h:25
ChronoStatSvc::m_statTableFlag
Gaudi::Property< bool > m_statTableFlag
Definition: ChronoStatSvc.h:185
ThreadLocalContext.h
ChronoStatSvc::ChronoStatSvc
ChronoStatSvc(const ChronoStatSvc &)=delete
ChronoStatSvc::chronoStart
ChronoEntity * chronoStart(const IChronoStatSvc::ChronoTag &chronoTag) override
Implementation of IChronoStatSvc::chronoStart.
Definition: ChronoStatSvc.cpp:280
IChronoStatSvc.h
ChronoStatSvc::m_statOrderFlag
Gaudi::Property< bool > m_statOrderFlag
Definition: ChronoStatSvc.h:192
gaudirun.l
dictionary l
Definition: gaudirun.py:583
IIncidentListener.h
MSG::NIL
@ NIL
Definition: IMessageSvc.h:25
Kernel.h
ChronoStatSvc::m_chronoCoutFlag
Gaudi::Property< bool > m_chronoCoutFlag
Definition: ChronoStatSvc.h:176
ChronoStatSvc::m_statPrintLevel
MSG::Level m_statPrintLevel
level of info printing
Definition: ChronoStatSvc.h:172
ChronoStatSvc::handle
void handle(const Incident &incident) override
Definition: ChronoStatSvc.cpp:512
ChronoStatSvc::initialize
StatusCode initialize() override
Implementation of IService::initialize()
Definition: ChronoStatSvc.cpp:94
std::mutex
STL class.
ChronoStatSvc::m_perEventFile
Gaudi::Property< std::string > m_perEventFile
Definition: ChronoStatSvc.h:205
ChronoStatSvc::chronoPrint
void chronoPrint(const IChronoStatSvc::ChronoTag &chronoTag) override
Implementation of IChronoStatSvc::chronoPrint.
Definition: ChronoStatSvc.cpp:303
std::max
T max(T... args)
Incident
Definition: Incident.h:27
ChronoStatSvc::m_statsOutFileName
Gaudi::Property< std::string > m_statsOutFileName
Definition: ChronoStatSvc.h:194
ChronoStatSvc::operator=
ChronoStatSvc & operator=(const ChronoStatSvc &)=delete
Gaudi::Property< bool >
ChronoStatSvc::chrono
const ChronoEntity * chrono(const IChronoStatSvc::ChronoTag &t) const override
extract the chrono entity for the given tag (name)
Definition: ChronoStatSvc.cpp:347
ChronoStatSvc
Definition: ChronoStatSvc.h:46
ChronoStatSvc::ChronoStatSvc
ChronoStatSvc(const std::string &name, ISvcLocator *svcloc)
Default constructor.
Definition: ChronoStatSvc.h:118