The Gaudi Framework  v32r2 (46d42edc)
ChronoStatSvc.h
Go to the documentation of this file.
1 #pragma once
2 // ============================================================================
3 // include files
4 // ============================================================================
5 // STD & STL
6 // ============================================================================
7 #include <atomic>
8 #include <fstream>
9 #include <functional>
10 #include <map>
11 #include <mutex>
12 #include <string>
13 // ============================================================================
14 // GaudiKernel
15 // ============================================================================
18 #include "GaudiKernel/Kernel.h"
19 #include "GaudiKernel/Service.h"
22 // ============================================================================
24 // ============================================================================
25 class ISvcLocator;
26 class IMessageSvc;
27 // ============================================================================
36 class ChronoStatSvc : public extends<Service, IChronoStatSvc, IIncidentListener> {
37 public:
38  // ============================================================================
42  // ============================================================================
43 public:
44  // ============================================================================
46  StatusCode initialize() override;
48  StatusCode finalize() override;
49  // ============================================================================
50 public:
51  // ============================================================================
55  ChronoEntity* chronoStart( const IChronoStatSvc::ChronoTag& chronoTag ) override;
56  // ============================================================================
60  const ChronoEntity* chronoStop( const IChronoStatSvc::ChronoTag& chronoTag ) override;
61  // ============================================================================
65  IChronoStatSvc::ChronoTime chronoDelta( const IChronoStatSvc::ChronoTag& chronoTag,
66  IChronoStatSvc::ChronoType theType ) override;
67  // ============================================================================
71  void chronoPrint( const IChronoStatSvc::ChronoTag& chronoTag ) override;
72  // ============================================================================
76  ChronoStatus chronoStatus( const IChronoStatSvc::ChronoTag& chronoTag ) override;
77  // ============================================================================
82  void stat( const IChronoStatSvc::StatTag& statTag, const IChronoStatSvc::StatFlag& statFlag ) override;
83  // ============================================================================
88  void statPrint( const IChronoStatSvc::ChronoTag& statTag ) override;
89  // ============================================================================
95  const ChronoEntity* chrono( const IChronoStatSvc::ChronoTag& t ) const override;
96  // ============================================================================
102  StatEntity* stat( const IChronoStatSvc::StatTag& t ) override;
103  // ============================================================================
108  ChronoStatSvc( const std::string& name, ISvcLocator* svcloc ) : base_class( name, svcloc ) {}
109 
111  void merge( const ChronoStatSvc& css );
112  // ============================================================================
113 
114 public:
115  void handle( const Incident& incident ) override;
116 
117 protected:
118  // ============================================================================
119  // print the "Stat" part of the ChronoStatSvc
120  void printStats();
121  // ============================================================================
122 private:
123  // ============================================================================
124  // default/copy constructor and assignment are disabled
125  ChronoStatSvc() = delete;
126  ChronoStatSvc( const ChronoStatSvc& ) = delete;
127  ChronoStatSvc& operator=( const ChronoStatSvc& ) = delete;
128  // ============================================================================
130  void saveStats();
131  // ============================================================================
132 public:
133  // ============================================================================
134  // Standard Destructor
135  ~ChronoStatSvc() override = default;
136  // ============================================================================
137 private:
138  bool isMT() const;
139 
140  ChronoEntity& getEntity( const ChronoTag& chronoTag ) {
141  lock_t lock( m_mutex );
142  return m_chronoEntities[chronoTag];
143  }
144 
145  // basically limit the integer to MSG::Level range
146  static MSG::Level int2level( int l ) {
147  return static_cast<MSG::Level>(
148  std::max( std::min( l, static_cast<int>( MSG::FATAL ) ), static_cast<int>( MSG::NIL ) ) );
149  };
150  // ============================================================================
156 
159 
164 
165  Gaudi::Property<bool> m_chronoTableFlag{this, "ChronoPrintOutTable", true,
166  "decide if the final printout should be performed"};
167  Gaudi::Property<bool> m_chronoCoutFlag{this, "ChronoDestinationCout", false,
168  "define the destination of the table to be printed"};
170  this, "ChronoPrintLevel", MSG::INFO, [this]( auto& ) { m_chronoPrintLevel = int2level( m_intChronoPrintLevel ); },
171  "print level"};
172  Gaudi::Property<bool> m_chronoOrderFlag{this, "ChronoTableToBeOrdered", true, "should the printout be ordered"};
173  Gaudi::Property<bool> m_printUserTime{this, "PrintUserTime", true};
174  Gaudi::Property<bool> m_printSystemTime{this, "PrintSystemTime", false};
175  Gaudi::Property<bool> m_printEllapsedTime{this, "PrintEllapsedTime", false};
176  Gaudi::Property<bool> m_statTableFlag{this, "StatPrintOutTable", true,
177  "decide if the final printout should be performed"};
178  Gaudi::Property<bool> m_statCoutFlag{this, "StatDestinationCout", false,
179  "define the destination of the table to be printed"};
181  [this]( auto& ) { m_statPrintLevel = int2level( m_intStatPrintLevel ); },
182  "print level"};
183  Gaudi::Property<bool> m_statOrderFlag{this, "StatTableToBeOrdered", true, "should the printout be ordered"};
184 
186  this, "AsciiStatsOutputFile", "",
187  "Name of the output file storing the stats. If empty, no statistics will be saved (default)"};
188 
190  this, "StatTableHeader",
191  " | Counter | # | sum | mean/eff^* | rms/err^* | min | max |",
192  "The header row for the output Stat-table"};
193  Gaudi::Property<bool> m_useEffFormat{this, "UseEfficiencyRowFormat", true,
194  "Use the special format for printout of efficiency counters"};
195 
196  Gaudi::Property<std::string> m_perEventFile{this, "PerEventFile", "", "File name for per-event deltas"};
197 
198  ServiceHandle<IInterface> m_hiveWhiteBoardSvc{this, "HiveWhiteBoardSvc", "EventDataSvc"};
199 
203 
204  // ============================================================================
205 };
206 // ============================================================================
207 // The END
208 // ============================================================================
Gaudi::Property< int > m_intStatPrintLevel
ChronoStatSvc & operator=(const ChronoStatSvc &)=delete
ChronoEntity & getEntity(const ChronoTag &chronoTag)
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Definition: ISvcLocator.h:25
ChronoStatus chronoStatus(const IChronoStatSvc::ChronoTag &chronoTag) override
Implementation of IChronoStatSvc::chronoStatus.
Gaudi::Property< std::string > m_header
Implementation of property with value of concrete type.
Definition: Property.h:352
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
Gaudi::Property< bool > m_statCoutFlag
IChronoStatSvc::ChronoTime chronoDelta(const IChronoStatSvc::ChronoTag &chronoTag, IChronoStatSvc::ChronoType theType) override
Implementation of IchronoStatSvc::chronoDelta.
Gaudi::Property< bool > m_chronoOrderFlag
Gaudi::Property< bool > m_printUserTime
std::mutex m_mutex
Mutex protecting m_chronoEntities.
void stat(const IChronoStatSvc::StatTag &statTag, const IChronoStatSvc::StatFlag &statFlag) override
Implementation of IChronoStatSvc::stat add statistical information to the entity ,...
void statPrint(const IChronoStatSvc::ChronoTag &statTag) override
prints (using message service) info about statistical entity, tagged by its name
STL class.
T min(T... args)
const std::string & name() const override
Retrieve name of the service.
Definition: Service.cpp:274
STL class.
void merge(const ChronoStatSvc &css)
Compound assignment operator.
ChronoStatSvc()=delete
Gaudi::Property< bool > m_useEffFormat
void saveStats()
dump the statistics into an ASCII file for offline processing
Gaudi::Property< int > m_intChronoPrintLevel
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:50
TimeMap m_perEvtTime
static MSG::Level int2level(int l)
The IMessage is the interface implemented by the message service.
Definition: IMessageSvc.h:37
const ChronoEntity * chronoStop(const IChronoStatSvc::ChronoTag &chronoTag) override
Implementation of IChronoStatSvc::chronoStop.
Gaudi::Property< bool > m_statOrderFlag
~ChronoStatSvc() override=default
Gaudi::Property< bool > m_chronoTableFlag
ServiceHandle< IInterface > m_hiveWhiteBoardSvc
std::ofstream m_ofd
T max(T... args)
MSG::Level m_chronoPrintLevel
level of info printing
StatusCode initialize() override
Implementation of IService::initialize()
dictionary l
Definition: gaudirun.py:523
Gaudi::Property< bool > m_printEllapsedTime
Base class used to extend a class implementing other interfaces.
Definition: extends.h:10
void handle(const Incident &incident) override
Gaudi::Property< bool > m_statTableFlag
std::map< IChronoStatSvc::ChronoTag, ChronoEntity > ChronoMap
some useful typedefs
Definition: ChronoStatSvc.h:40
Base class for all Incidents (computing events).
Definition: Incident.h:17
ChronoEntity * chronoStart(const IChronoStatSvc::ChronoTag &chronoTag) override
Implementation of IChronoStatSvc::chronoStart.
std::lock_guard< std::mutex > lock_t
bool isMT() const
Gaudi::Property< std::string > m_statsOutFileName
MSG::Level m_statPrintLevel
level of info printing
Gaudi::Property< bool > m_chronoCoutFlag
ChronoStatSvc(const std::string &name, ISvcLocator *svcloc)
Default constructor.
void chronoPrint(const IChronoStatSvc::ChronoTag &chronoTag) override
Implementation of IChronoStatSvc::chronoPrint.
The Chrono & Stat Sservice: service implements the IChronoStatSvc interface and provides the basic ch...
Definition: ChronoStatSvc.h:36
ChronoMap m_chronoEntities
chrono part
Gaudi::Property< bool > m_printSystemTime
StatusCode finalize() override
Implementation of IService::finalize()
Gaudi::Property< std::string > m_perEventFile
const ChronoEntity * chrono(const IChronoStatSvc::ChronoTag &t) const override
extract the chrono entity for the given tag (name)