| The Gaudi Framework v27r1

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

RootPerfMonSvc.cpp
Go to the documentation of this file.
1 //====================================================================
2 // RootPerfMonSvc implementation
3 //--------------------------------------------------------------------
4 //
5 // Description: Implementation of the ROOT data storage
6 //
7 // Author : M.Frank
8 //
9 //====================================================================
10
11 // Framework include files
12 #include "GaudiKernel/MsgStream.h"
13 #include "GaudiKernel/IIncidentSvc.h"
14 #include "GaudiKernel/DataIncident.h"
15 #include "GaudiKernel/Incident.h"
16 #include "GaudiKernel/System.h"
17 #include "RootCnv/RootPerfMonSvc.h"
18 #include "RootUtils.h"
19
20 #include "TDirectory.h"
21 #include "TSystem.h"
22 #include "TBranch.h"
23 #include "TMap.h"
24
25 using namespace std;
26 using namespace Gaudi;
27 typedef const string& CSTR;
28
29 #define S_OK StatusCode::SUCCESS
30 #define S_FAIL StatusCode::FAILURE
31
32 // Standard constructor
33 RootPerfMonSvc::RootPerfMonSvc(CSTR nam, ISvcLocator* svc)
34 : Service( nam, svc)
35 {
36 declareProperty("IOPerfStats", m_ioPerfStats);
37 declareProperty("Streams", m_setStreams);
38 declareProperty("BasketSize", m_basketSize);
39 declareProperty("BufferSize", m_bufferSize);
40 declareProperty("SplitLevel", m_splitLevel);
41 }
42
43 // Small routine to issue exceptions
44 StatusCode RootPerfMonSvc::error(CSTR msg) {
45 if ( m_log ) {
46 log() << MSG::ERROR << "Error: " << msg << endmsg;
47 return S_FAIL;
48 }
49 MsgStream m(msgSvc(),name());
50 m << MSG::ERROR << "Error: " << msg << endmsg;
51 return S_FAIL;
52 }
53
54 // Initialize the Db data persistency service
55 StatusCode RootPerfMonSvc::initialize() {
56 string cname;
57 StatusCode status = Service::initialize();
58 if ( !status.isSuccess() )
59 return error("Failed to initialize Service base class.");
60 m_log.reset( new MsgStream(msgSvc(),name()) );
61 m_incidentSvc = service("IncidentSvc");
62 if( !m_incidentSvc )
63 return error("Unable to localize interface from service:IncidentSvc");
64
65 m_incidentSvc->addListener(this, IncidentType::BeginEvent, 1, false, false);
66 m_incidentSvc->addListener(this, "NEW_STREAM", 1, false, false);
67 m_incidentSvc->addListener(this, "CONNECTED_OUTPUT", 1, false, false);
68
69 if (m_ioPerfStats.empty())
70 return error("Performance monitoring file IOPerfStats was not defined.");
71
72 TDirectory::TContext ctxt(nullptr);
73 m_perfFile.reset( new TFile(m_ioPerfStats.c_str(),"RECREATE") );
74 if (!m_perfFile ) return error("Could not create ROOT file.");
75
76 if (!(m_perfTree = new TTree("T", "performance measurement")))
77 return error("Could not create tree.");
78
79 m_perfTree->Branch("utime", &m_utime, "utime/l");
80 m_perfTree->Branch("stime", &m_stime, "stime/l");
81 m_perfTree->Branch("vsize", &m_vsize, "vsize/l");
82 m_perfTree->Branch("rss", &m_rss, "rss/L");
83 m_perfTree->Branch("time", &m_time, "time/L");
84 m_eventNumber = 0;
85 m_perfTree->Branch("event_number", &m_eventNumber, "event_number/L");
86 m_perfTree->Branch("event_type", &m_eventType, "event_type/I");
87
88 if (m_setStreams.empty())
89 m_setStreams = "undefined";
90 if (m_basketSize.empty())
91 m_basketSize = "undefined";
92 if (m_bufferSize.empty())
93 m_bufferSize = "undefined";
94 if (m_splitLevel.empty())
95 m_splitLevel = "undefined";
96
97 auto map = new TMap();
98 map->Add(new TObjString("streams"), new TObjString(m_setStreams.c_str()));
99 map->Add(new TObjString("basket_size"), new TObjString(m_basketSize.c_str()));
100 map->Add(new TObjString("buffer_size"), new TObjString(m_bufferSize.c_str()));
101 map->Add(new TObjString("split_level"), new TObjString(m_splitLevel.c_str()));
102 map->Write("params", TObject::kSingleKey);
103 return S_OK;
104 }
105
106 void RootPerfMonSvc::record(EventType eventType) {
107 SysProcStat data;
108 m_eventType = eventType;
109 m_utime = (ULong_t)data.utime;
110 m_stime = (ULong_t)data.stime;
111 m_vsize = (ULong_t)data.vsize;
112 m_rss = (Long_t)data.rss;
113 m_time = (Long_t)data.time;
114 m_perfTree->Fill();
115 }
116
117 void RootPerfMonSvc::handle(const Incident& incident) {
118 std::string t = incident.type();
119 if ( !t.compare(IncidentType::BeginEvent) ) {
120 m_eventNumber++;
121 record(EVENT);
122 return;
123 }
124 if ( !t.compare("CONNECTED_OUTPUT") ) {
125 m_outputs.insert(incident.source());
126 }
127 }
128
129 // Stop the performance monitoring service
130 StatusCode RootPerfMonSvc::stop() {
131 char text[64];
132 record(FSR);
133 auto map = new TMap();
134 for(const auto &i : m_outputs) {
135 const char* fn = i.c_str();
136 Long_t id, siz, flags, tim;
137 if ( 0 == gSystem->GetPathInfo(fn,&id,&siz,&flags,&tim) ) {
138 ::sprintf(text,"%ld",siz);
139 map->Add(new TObjString(fn), new TObjString(text));
140 }
141 }
142 TDirectory::TContext ctxt(m_perfFile.get());
143 map->Write("Outputs", TObject::kSingleKey);
144 return S_OK;
145 }
146
147 // Finalize the performance monitoring service
148 StatusCode RootPerfMonSvc::finalize() {
149 record(FSR);
150 log() << MSG::INFO;
151 m_log.reset();
152 m_incidentSvc.reset();
153
154 m_perfFile->Write();
155 m_perfFile->Close();
156 m_perfFile.reset();
157
158 return Service::finalize();
159 }
Gaudi::RootPerfMonSvc::handle
void handle(const Incident &incident) override
IIncidentListener override: Inform that a new incident has occurred.
Definition: RootPerfMonSvc.cpp:117
System.h
MsgStream
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
Service::initialize
StatusCode initialize() override
Definition: Service.cpp:68
Gaudi::SysProcStat::stime
long unsigned stime
Definition: SysProcStat.h:17
std::string::empty
T empty(T...args)
ISvcLocator
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Definition: ISvcLocator.h:25
RootPerfMonSvc.h
Gaudi::RootPerfMonSvc::stop
StatusCode stop() override
Definition: RootPerfMonSvc.cpp:130
Gaudi::RootPerfMonSvc::m_eventType
Int_t m_eventType
Definition: RootPerfMonSvc.h:62
Incident::type
const std::string & type() const
Access to the incident type.
Definition: Incident.h:41
Gaudi::RootPerfMonSvc::m_time
Long_t m_time
Definition: RootPerfMonSvc.h:64
Gaudi::RootPerfMonSvc::initialize
StatusCode initialize() override
Service overload: initialize the service.
Definition: RootPerfMonSvc.cpp:55
Service::finalize
StatusCode finalize() override
Definition: Service.cpp:193
Gaudi::RootPerfMonSvc::m_eventNumber
Long_t m_eventNumber
Definition: RootPerfMonSvc.h:64
GaudiMP.FdsRegistry.msg
tuple msg
Definition: FdsRegistry.py:8
MsgStream.h
Gaudi::RootPerfMonSvc::m_stime
ULong_t m_stime
Definition: RootPerfMonSvc.h:63
Gaudi::RootPerfMonSvc::m_perfFile
std::unique_ptr< TFile > m_perfFile
Definition: RootPerfMonSvc.h:58
Incident::source
const std::string & source() const
Access to the source of the incident.
Definition: Incident.h:47
StatusCode::isSuccess
bool isSuccess() const
Test for a status code of SUCCESS.
Definition: StatusCode.h:76
Gaudi::RootPerfMonSvc::record
virtual void record(EventType eventType)
Definition: RootPerfMonSvc.cpp:106
S_OK
#define S_OK
Definition: RootPerfMonSvc.cpp:29
Gaudi::RootPerfMonSvc::finalize
StatusCode finalize() override
Service overload: Finalize the service.
Definition: RootPerfMonSvc.cpp:148
S_FAIL
#define S_FAIL
Definition: RootPerfMonSvc.cpp:30
std
STL namespace.
Gaudi::RootPerfMonSvc::m_ioPerfStats
std::string m_ioPerfStats
Property: Enable TTree IOperfStats if not empty; otherwise perf stat file name.
Definition: RootPerfMonSvc.h:47
Gaudi::RootPerfMonSvc::m_vsize
ULong_t m_vsize
Definition: RootPerfMonSvc.h:63
std::map
STL class.
Gaudi::RootPerfMonSvc::m_incidentSvc
SmartIF< IIncidentSvc > m_incidentSvc
Reference to incident service.
Definition: RootPerfMonSvc.h:45
Gaudi::RootPerfMonSvc::m_utime
ULong_t m_utime
Definition: RootPerfMonSvc.h:63
std::string
STL class.
Incident.h
Service::name
const std::string & name() const override
Retrieve name of the service.
Definition: Service.cpp:319
Gaudi::RootPerfMonSvc::EventType
EventType
Definition: RootPerfMonSvc.h:67
CommonMessagingBase::error
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
Definition: CommonMessaging.h:118
Gaudi::SysProcStat::vsize
long unsigned vsize
Definition: SysProcStat.h:17
IIncidentSvc.h
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
Gaudi::SysProcStat::time
long time
Definition: SysProcStat.h:23
Gaudi::Units::m
constexpr double m
Definition: SystemOfUnits.h:93
Gaudi::RootPerfMonSvc::m_splitLevel
std::string m_splitLevel
Definition: RootPerfMonSvc.h:54
RootUtils.h
CSTR
const string & CSTR
Definition: RootPerfMonSvc.cpp:27
Gaudi::RootPerfMonSvc::m_setStreams
std::string m_setStreams
Definition: RootPerfMonSvc.h:51
std::unique_ptr::reset
T reset(T...args)
Gaudi::RootPerfMonSvc::m_bufferSize
std::string m_bufferSize
Definition: RootPerfMonSvc.h:53
std::unique_ptr::get
T get(T...args)
std::set::insert
T insert(T...args)
Gaudi::RootPerfMonSvc::m_perfTree
TTree * m_perfTree
Definition: RootPerfMonSvc.h:56
Gaudi::RootPerfMonSvc::log
MsgStream & log() const
Helper: Use message streamer.
Definition: RootPerfMonSvc.h:73
Gaudi::RootPerfMonSvc::m_basketSize
std::string m_basketSize
Definition: RootPerfMonSvc.h:52
Gaudi::SysProcStat::utime
long unsigned utime
Definition: SysProcStat.h:17
Gaudi::RootPerfMonSvc::EVENT
Definition: RootPerfMonSvc.h:67
Gaudi::RootPerfMonSvc::FSR
Definition: RootPerfMonSvc.h:67
std::string::c_str
T c_str(T...args)
Gaudi::RootPerfMonSvc::m_rss
Long_t m_rss
Definition: RootPerfMonSvc.h:64
Incident
Base class for all Incidents (computing events).
Definition: Incident.h:17
IIncidentSvc::addListener
virtual void addListener(IIncidentListener *lis, const std::string &type="", long priority=0, bool rethrow=false, bool singleShot=false)=0
Add listener.
CommonMessagingBase::msgSvc
SmartIF< IMessageSvc > & msgSvc() const
The standard message service.
Definition: CommonMessaging.h:73
MSG::ERROR
Definition: IMessageSvc.h:21
Gaudi::SysProcStat::rss
long int rss
Definition: SysProcStat.h:20
Service::service
StatusCode service(const std::string &name, const T *&psvc, bool createIf=true) const
Access a service by name, creating it if it doesn't already exist.
Definition: Service.h:144
SmartIF::reset
void reset(TYPE *ptr=nullptr)
Set the internal pointer to the passed one disposing of the old one.
Definition: SmartIF.h:88
Gaudi::SysProcStat
Definition: SysProcStat.h:12
Service::declareProperty
Property * declareProperty(const std::string &name, T &property, const std::string &doc="none") const
Declare the named property.
Definition: Service.h:215
MSG::INFO
Definition: IMessageSvc.h:19
Gaudi::RootPerfMonSvc::m_outputs
std::set< std::string > m_outputs
Definition: RootPerfMonSvc.h:60
Service
Base class for all services.
Definition: Service.h:36
DataIncident.h
ana.i
list i
Definition: ana.py:128
Gaudi::RootPerfMonSvc::m_log
std::unique_ptr< MsgStream > m_log
Message streamer.
Definition: RootPerfMonSvc.h:49
Gaudi
Helper functions to set/get the application return code.
Definition: __init__.py:1
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
std::string::compare
T compare(T...args)