| The Gaudi Framework v28r2-patches (bc4ad17a)

- 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 // Small routine to issue exceptions
33 StatusCode RootPerfMonSvc::error(CSTR msg) {
34 if ( m_log ) {
35 log() << MSG::ERROR << "Error: " << msg << endmsg;
36 return S_FAIL;
37 }
38 MsgStream m(msgSvc(),name());
39 m << MSG::ERROR << "Error: " << msg << endmsg;
40 return S_FAIL;
41 }
42
43 // Initialize the Db data persistency service
44 StatusCode RootPerfMonSvc::initialize() {
45 string cname;
46 StatusCode status = Service::initialize();
47 if ( !status.isSuccess() )
48 return error("Failed to initialize Service base class.");
49 m_log.reset( new MsgStream(msgSvc(),name()) );
50 m_incidentSvc = service("IncidentSvc");
51 if( !m_incidentSvc )
52 return error("Unable to localize interface from service:IncidentSvc");
53
54 m_incidentSvc->addListener(this, IncidentType::BeginEvent, 1, false, false);
55 m_incidentSvc->addListener(this, "NEW_STREAM", 1, false, false);
56 m_incidentSvc->addListener(this, "CONNECTED_OUTPUT", 1, false, false);
57
58 if (m_ioPerfStats.empty())
59 return error("Performance monitoring file IOPerfStats was not defined.");
60
61 TDirectory::TContext ctxt(nullptr);
62 m_perfFile.reset( new TFile(m_ioPerfStats.value().c_str(),"RECREATE") );
63 if (!m_perfFile ) return error("Could not create ROOT file.");
64
65 if (!(m_perfTree = new TTree("T", "performance measurement")))
66 return error("Could not create tree.");
67
68 m_perfTree->Branch("utime", &m_utime, "utime/l");
69 m_perfTree->Branch("stime", &m_stime, "stime/l");
70 m_perfTree->Branch("vsize", &m_vsize, "vsize/l");
71 m_perfTree->Branch("rss", &m_rss, "rss/L");
72 m_perfTree->Branch("time", &m_time, "time/L");
73 m_eventNumber = 0;
74 m_perfTree->Branch("event_number", &m_eventNumber, "event_number/L");
75 m_perfTree->Branch("event_type", &m_eventType, "event_type/I");
76
77 if (m_setStreams.empty())
78 m_setStreams = "undefined";
79 if (m_basketSize.empty())
80 m_basketSize = "undefined";
81 if (m_bufferSize.empty())
82 m_bufferSize = "undefined";
83 if (m_splitLevel.empty())
84 m_splitLevel = "undefined";
85
86 auto map = new TMap();
87 map->Add(new TObjString("streams"), new TObjString(m_setStreams.value().c_str()));
88 map->Add(new TObjString("basket_size"), new TObjString(m_basketSize.value().c_str()));
89 map->Add(new TObjString("buffer_size"), new TObjString(m_bufferSize.value().c_str()));
90 map->Add(new TObjString("split_level"), new TObjString(m_splitLevel.value().c_str()));
91 map->Write("params", TObject::kSingleKey);
92 return S_OK;
93 }
94
95 void RootPerfMonSvc::record(EventType eventType) {
96 SysProcStat data;
97 m_eventType = eventType;
98 m_utime = (ULong_t)data.utime;
99 m_stime = (ULong_t)data.stime;
100 m_vsize = (ULong_t)data.vsize;
101 m_rss = (Long_t)data.rss;
102 m_time = (Long_t)data.time;
103 m_perfTree->Fill();
104 }
105
106 void RootPerfMonSvc::handle(const Incident& incident) {
107 std::string t = incident.type();
108 if ( !t.compare(IncidentType::BeginEvent) ) {
109 m_eventNumber++;
110 record(EVENT);
111 return;
112 }
113 if ( !t.compare("CONNECTED_OUTPUT") ) {
114 m_outputs.insert(incident.source());
115 }
116 }
117
118 // Stop the performance monitoring service
119 StatusCode RootPerfMonSvc::stop() {
120 char text[64];
121 record(FSR);
122 auto map = new TMap();
123 for(const auto &i : m_outputs) {
124 const char* fn = i.c_str();
125 Long_t id, siz, flags, tim;
126 if ( 0 == gSystem->GetPathInfo(fn,&id,&siz,&flags,&tim) ) {
127 ::sprintf(text,"%ld",siz);
128 map->Add(new TObjString(fn), new TObjString(text));
129 }
130 }
131 TDirectory::TContext ctxt(m_perfFile.get());
132 map->Write("Outputs", TObject::kSingleKey);
133 return S_OK;
134 }
135
136 // Finalize the performance monitoring service
137 StatusCode RootPerfMonSvc::finalize() {
138 record(FSR);
139 log() << MSG::INFO;
140 m_log.reset();
141 m_incidentSvc.reset();
142
143 m_perfFile->Write();
144 m_perfFile->Close();
145 m_perfFile.reset();
146
147 return Service::finalize();
148 }
System.h
MsgStream
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
Service::initialize
StatusCode initialize() override
Definition: Service.cpp:64
Gaudi::SysProcStat::stime
long unsigned stime
Definition: SysProcStat.h:17
RootPerfMonSvc.h
Incident::type
const std::string & type() const
Access to the incident type.
Definition: Incident.h:41
gaudiComponentHelp.name
name
Definition: gaudiComponentHelp.py:28
Service::finalize
StatusCode finalize() override
Definition: Service.cpp:174
MsgStream.h
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:74
std::log
T log(T...args)
S_OK
#define S_OK
Definition: RootPerfMonSvc.cpp:29
S_FAIL
#define S_FAIL
Definition: RootPerfMonSvc.cpp:30
std
STL namespace.
std::map
STL class.
std::string
STL class.
Incident.h
Gaudi::RootPerfMonSvc::EventType
EventType
Definition: RootPerfMonSvc.h:67
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
ForwardSchedulerSimpleTest.msgSvc
msgSvc
Definition: ForwardSchedulerSimpleTest.py:112
RootUtils.h
CSTR
const string & CSTR
Definition: RootPerfMonSvc.cpp:27
Gaudi::SysProcStat::utime
long unsigned utime
Definition: SysProcStat.h:17
Incident
Base class for all Incidents (computing events).
Definition: Incident.h:17
GaudiMP.FdsRegistry.msg
msg
Definition: FdsRegistry.py:8
MSG::ERROR
Definition: IMessageSvc.h:21
Gaudi::SysProcStat::rss
long int rss
Definition: SysProcStat.h:20
Gaudi::SysProcStat
Definition: SysProcStat.h:12
MSG::INFO
Definition: IMessageSvc.h:19
DataIncident.h
std::sprintf
T sprintf(T...args)
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)