| The Gaudi Framework v32r1 (f65d50dc)

ChronoStatSvc.h
Go to the documentation of this file.
1 #ifndef GAUDISVC_CHRONOSTATSVC_H__
2 #define GAUDISVC_CHRONOSTATSVC_H__
3 // ============================================================================
4 // include files
5 // ============================================================================
6 // STD & STL
7 // ============================================================================
8 #include <atomic>
9 #include <fstream>
10 #include <functional>
11 #include <map>
12 #include <mutex>
13 #include <string>
14 // ============================================================================
15 // GaudiKernel
16 // ============================================================================
17 #include "GaudiKernel/IChronoStatSvc.h"
18 #include "GaudiKernel/IIncidentListener.h"
19 #include "GaudiKernel/Kernel.h"
20 #include "GaudiKernel/Service.h"
21 #include "GaudiKernel/ServiceHandle.h"
22 #include "GaudiKernel/ThreadLocalContext.h"
23 // ============================================================================
25 // ============================================================================
26 class ISvcLocator;
27 class IMessageSvc;
28 // ============================================================================
37 class ChronoStatSvc : public extends<Service, IChronoStatSvc, IIncidentListener> {
38 public:
39 // ============================================================================
41 typedef std::map<IChronoStatSvc::ChronoTag, ChronoEntity> ChronoMap;
42 typedef std::map<IChronoStatSvc::StatTag, StatEntity> StatMap;
43 // ============================================================================
44 public:
45 // ============================================================================
47 StatusCode initialize() override;
49 StatusCode finalize() override;
50 // ============================================================================
51 public:
52 // ============================================================================
56 ChronoEntity* chronoStart( const IChronoStatSvc::ChronoTag& chronoTag ) override;
57 // ============================================================================
61 const ChronoEntity* chronoStop( const IChronoStatSvc::ChronoTag& chronoTag ) override;
62 // ============================================================================
66 IChronoStatSvc::ChronoTime chronoDelta( const IChronoStatSvc::ChronoTag& chronoTag,
67 IChronoStatSvc::ChronoType theType ) override;
68 // ============================================================================
72 void chronoPrint( const IChronoStatSvc::ChronoTag& chronoTag ) override;
73 // ============================================================================
77 ChronoStatus chronoStatus( const IChronoStatSvc::ChronoTag& chronoTag ) override;
78 // ============================================================================
83 void stat( const IChronoStatSvc::StatTag& statTag, const IChronoStatSvc::StatFlag& statFlag ) override;
84 // ============================================================================
89 void statPrint( const IChronoStatSvc::ChronoTag& statTag ) override;
90 // ============================================================================
96 const ChronoEntity* chrono( const IChronoStatSvc::ChronoTag& t ) const override;
97 // ============================================================================
103 StatEntity* stat( const IChronoStatSvc::StatTag& t ) override;
104 // ============================================================================
109 ChronoStatSvc( const std::string& name, ISvcLocator* svcloc ) : base_class( name, svcloc ) {}
110
112 void merge( const ChronoStatSvc& css );
113 // ============================================================================
114
115 public:
116 void handle( const Incident& incident ) override;
117
118 protected:
119 // ============================================================================
120 // print the "Stat" part of the ChronoStatSvc
121 void printStats();
122 // ============================================================================
123 private:
124 // ============================================================================
125 // default/copy constructor and assignment are disabled
126 ChronoStatSvc() = delete;
127 ChronoStatSvc( const ChronoStatSvc& ) = delete;
128 ChronoStatSvc& operator=( const ChronoStatSvc& ) = delete;
129 // ============================================================================
131 void saveStats();
132 // ============================================================================
133 private:
134 bool isMT() const;
135
136 ChronoEntity& getEntity( const ChronoTag& chronoTag ) {
137 lock_t lock( m_mutex );
138 return m_chronoEntities[chronoTag];
139 }
140
141 // basically limit the integer to MSG::Level range
142 static MSG::Level int2level( int l ) {
143 return static_cast<MSG::Level>(
144 std::max( std::min( l, static_cast<int>( MSG::FATAL ) ), static_cast<int>( MSG::NIL ) ) );
145 };
146 // ============================================================================
148 ChronoMap m_chronoEntities;
150 mutable std::mutex m_mutex;
151 typedef std::lock_guard<std::mutex> lock_t;
152
154 MSG::Level m_chronoPrintLevel = MSG::INFO;
155
157 StatMap m_statEntities;
159 MSG::Level m_statPrintLevel = MSG::INFO;
160
161 Gaudi::Property<bool> m_chronoTableFlag{this, "ChronoPrintOutTable", true,
162 "decide if the final printout should be performed"};
163 Gaudi::Property<bool> m_chronoCoutFlag{this, "ChronoDestinationCout", false,
164 "define the destination of the table to be printed"};
165 Gaudi::Property<int> m_intChronoPrintLevel{
166 this, "ChronoPrintLevel", MSG::INFO, [this]( auto& ) { m_chronoPrintLevel = int2level( m_intChronoPrintLevel ); },
167 "print level"};
168 Gaudi::Property<bool> m_chronoOrderFlag{this, "ChronoTableToBeOrdered", true, "should the printout be ordered"};
169 Gaudi::Property<bool> m_printUserTime{this, "PrintUserTime", true};
170 Gaudi::Property<bool> m_printSystemTime{this, "PrintSystemTime", false};
171 Gaudi::Property<bool> m_printEllapsedTime{this, "PrintEllapsedTime", false};
172 Gaudi::Property<bool> m_statTableFlag{this, "StatPrintOutTable", true,
173 "decide if the final printout should be performed"};
174 Gaudi::Property<bool> m_statCoutFlag{this, "StatDestinationCout", false,
175 "define the destination of the table to be printed"};
176 Gaudi::Property<int> m_intStatPrintLevel{this, "StatPrintLevel", MSG::INFO,
177 [this]( auto& ) { m_statPrintLevel = int2level( m_intStatPrintLevel ); },
178 "print level"};
179 Gaudi::Property<bool> m_statOrderFlag{this, "StatTableToBeOrdered", true, "should the printout be ordered"};
180
181 Gaudi::Property<std::string> m_statsOutFileName{
182 this, "AsciiStatsOutputFile", "",
183 "Name of the output file storing the stats. If empty, no statistics will be saved (default)"};
184
185 Gaudi::Property<std::string> m_header{
186 this, "StatTableHeader",
187 " | Counter | # | sum | mean/eff^* | rms/err^* | min | max |",
188 "The header row for the output Stat-table"};
189 Gaudi::Property<bool> m_useEffFormat{this, "UseEfficiencyRowFormat", true,
190 "Use the special format for printout of efficiency counters"};
191
192 Gaudi::Property<std::string> m_perEventFile{this, "PerEventFile", "", "File name for per-event deltas"};
193
194 ServiceHandle<IInterface> m_hiveWhiteBoardSvc{this, "HiveWhiteBoardSvc", "EventDataSvc"};
195
196 typedef std::map<ChronoTag, std::vector<IChronoSvc::ChronoTime>> TimeMap;
197 TimeMap m_perEvtTime;
198 std::ofstream m_ofd;
199
200 // ============================================================================
201 };
202 // ============================================================================
203 // The END
204 // ============================================================================
205 #endif // GAUDISVC_CHRONOSTATSVC_H
ChronoStatSvc::m_intStatPrintLevel
Gaudi::Property< int > m_intStatPrintLevel
Definition: ChronoStatSvc.h:176
ServiceHandle< IInterface >
ChronoStatSvc::operator=
ChronoStatSvc & operator=(const ChronoStatSvc &)=delete
ChronoStatSvc::getEntity
ChronoEntity & getEntity(const ChronoTag &chronoTag)
Definition: ChronoStatSvc.h:136
Kernel.h
ISvcLocator
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Definition: ISvcLocator.h:25
ChronoStatSvc::chronoStatus
ChronoStatus chronoStatus(const IChronoStatSvc::ChronoTag &chronoTag) override
Implementation of IChronoStatSvc::chronoStatus.
Definition: ChronoStatSvc.cpp:306
ChronoStatSvc::m_header
Gaudi::Property< std::string > m_header
Definition: ChronoStatSvc.h:185
Gaudi::Property
Implementation of property with value of concrete type.
Definition: Property.h:352
ChronoStatSvc::m_statEntities
StatMap m_statEntities
stat part
Definition: ChronoStatSvc.h:157
ChronoEntity
a small helper class for implementation of ChronoStatSvc service, It also could be used as some local...
Definition: ChronoEntity.h:21
ChronoStatSvc::m_statCoutFlag
Gaudi::Property< bool > m_statCoutFlag
Definition: ChronoStatSvc.h:174
ChronoStatSvc::chronoDelta
IChronoStatSvc::ChronoTime chronoDelta(const IChronoStatSvc::ChronoTag &chronoTag, IChronoStatSvc::ChronoType theType) override
Implementation of IchronoStatSvc::chronoDelta.
Definition: ChronoStatSvc.cpp:291
ThreadLocalContext.h
ChronoStatSvc::m_chronoOrderFlag
Gaudi::Property< bool > m_chronoOrderFlag
Definition: ChronoStatSvc.h:168
ChronoStatSvc::m_printUserTime
Gaudi::Property< bool > m_printUserTime
Definition: ChronoStatSvc.h:169
ChronoStatSvc::m_mutex
std::mutex m_mutex
Mutex protecting m_chronoEntities.
Definition: ChronoStatSvc.h:150
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:312
ChronoStatSvc::ChronoMap
std::map< IChronoStatSvc::ChronoTag, ChronoEntity > ChronoMap
some useful typedefs
Definition: ChronoStatSvc.h:41
ChronoStatSvc::statPrint
void statPrint(const IChronoStatSvc::ChronoTag &statTag) override
prints (using message service) info about statistical entity, tagged by its name
Definition: ChronoStatSvc.cpp:331
std::map< IChronoStatSvc::ChronoTag, ChronoEntity >
std::mutex
std::string
STL class.
std::min
T min(T... args)
Service.h
ChronoStatSvc::printStats
void printStats()
Definition: ChronoStatSvc.cpp:442
MSG::FATAL
Definition: IMessageSvc.h:15
Service::name
const std::string & name() const override
Retrieve name of the service.
Definition: Service.cpp:274
MSG::Level
Level
Definition: IMessageSvc.h:15
std::ofstream
STL class.
ChronoStatSvc::merge
void merge(const ChronoStatSvc &css)
Compound assignment operator.
Definition: ChronoStatSvc.cpp:56
ChronoStatSvc::TimeMap
std::map< ChronoTag, std::vector< IChronoSvc::ChronoTime > > TimeMap
Definition: ChronoStatSvc.h:196
ChronoStatSvc::ChronoStatSvc
ChronoStatSvc()=delete
ChronoStatSvc::m_useEffFormat
Gaudi::Property< bool > m_useEffFormat
Definition: ChronoStatSvc.h:189
ChronoStatSvc::saveStats
void saveStats()
dump the statistics into an ASCII file for offline processing
Definition: ChronoStatSvc.cpp:361
ChronoStatSvc::m_intChronoPrintLevel
Gaudi::Property< int > m_intChronoPrintLevel
Definition: ChronoStatSvc.h:165
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:50
ChronoStatSvc::m_perEvtTime
TimeMap m_perEvtTime
Definition: ChronoStatSvc.h:197
ChronoStatSvc::int2level
static MSG::Level int2level(int l)
Definition: ChronoStatSvc.h:142
IMessageSvc
The IMessage is the interface implemented by the message service.
Definition: IMessageSvc.h:37
ChronoStatSvc::chronoStop
const ChronoEntity * chronoStop(const IChronoStatSvc::ChronoTag &chronoTag) override
Implementation of IChronoStatSvc::chronoStop.
Definition: ChronoStatSvc.cpp:283
MSG::NIL
Definition: IMessageSvc.h:15
ChronoStatSvc::m_statOrderFlag
Gaudi::Property< bool > m_statOrderFlag
Definition: ChronoStatSvc.h:179
ChronoStatSvc::m_chronoTableFlag
Gaudi::Property< bool > m_chronoTableFlag
Definition: ChronoStatSvc.h:161
ChronoStatSvc::m_hiveWhiteBoardSvc
ServiceHandle< IInterface > m_hiveWhiteBoardSvc
Definition: ChronoStatSvc.h:194
ChronoStatSvc::m_ofd
std::ofstream m_ofd
Definition: ChronoStatSvc.h:198
ServiceHandle.h
std::max
T max(T... args)
ChronoStatSvc::m_chronoPrintLevel
MSG::Level m_chronoPrintLevel
level of info printing
Definition: ChronoStatSvc.h:154
ChronoStatSvc::initialize
StatusCode initialize() override
Implementation of IService::initialize()
Definition: ChronoStatSvc.cpp:86
gaudirun.l
dictionary l
Definition: gaudirun.py:521
ChronoStatSvc::m_printEllapsedTime
Gaudi::Property< bool > m_printEllapsedTime
Definition: ChronoStatSvc.h:171
std::lock_guard
extends
Base class used to extend a class implementing other interfaces.
Definition: extends.h:10
ChronoStatSvc::handle
void handle(const Incident &incident) override
Definition: ChronoStatSvc.cpp:507
ChronoStatSvc::m_statTableFlag
Gaudi::Property< bool > m_statTableFlag
Definition: ChronoStatSvc.h:172
Incident
Base class for all Incidents (computing events).
Definition: Incident.h:17
ChronoStatSvc::chronoStart
ChronoEntity * chronoStart(const IChronoStatSvc::ChronoTag &chronoTag) override
Implementation of IChronoStatSvc::chronoStart.
Definition: ChronoStatSvc.cpp:275
ChronoStatSvc::lock_t
std::lock_guard< std::mutex > lock_t
Definition: ChronoStatSvc.h:151
ChronoStatSvc::isMT
bool isMT() const
Definition: ChronoStatSvc.cpp:428
CommonMessaging
Definition: CommonMessaging.h:56
IIncidentListener.h
IChronoStatSvc.h
ChronoStatSvc::m_statsOutFileName
Gaudi::Property< std::string > m_statsOutFileName
Definition: ChronoStatSvc.h:181
ChronoStatSvc::m_statPrintLevel
MSG::Level m_statPrintLevel
level of info printing
Definition: ChronoStatSvc.h:159
ChronoStatSvc::m_chronoCoutFlag
Gaudi::Property< bool > m_chronoCoutFlag
Definition: ChronoStatSvc.h:163
ChronoStatSvc::ChronoStatSvc
ChronoStatSvc(const std::string &name, ISvcLocator *svcloc)
Default constructor.
Definition: ChronoStatSvc.h:109
MSG::INFO
Definition: IMessageSvc.h:15
ChronoStatSvc::chronoPrint
void chronoPrint(const IChronoStatSvc::ChronoTag &chronoTag) override
Implementation of IChronoStatSvc::chronoPrint.
Definition: ChronoStatSvc.cpp:298
ChronoStatSvc::StatMap
std::map< IChronoStatSvc::StatTag, StatEntity > StatMap
Definition: ChronoStatSvc.h:42
ChronoStatSvc
The Chrono & Stat Sservice: service implements the IChronoStatSvc interface and provides the basic ch...
Definition: ChronoStatSvc.h:37
ChronoStatSvc::m_chronoEntities
ChronoMap m_chronoEntities
chrono part
Definition: ChronoStatSvc.h:145
ChronoStatSvc::m_printSystemTime
Gaudi::Property< bool > m_printSystemTime
Definition: ChronoStatSvc.h:170
ChronoStatSvc::finalize
StatusCode finalize() override
Implementation of IService::finalize()
Definition: ChronoStatSvc.cpp:126
ChronoStatSvc::m_perEventFile
Gaudi::Property< std::string > m_perEventFile
Definition: ChronoStatSvc.h:192
ChronoStatSvc::chrono
const ChronoEntity * chrono(const IChronoStatSvc::ChronoTag &t) const override
extract the chrono entity for the given tag (name)
Definition: ChronoStatSvc.cpp:342