| # Gaudi Framework, version v25r0 |

Home |  | Generated: Mon Feb 17 2014

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

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
RootPerfMonSvc.cpp
Go to the documentation of this file.
1 // $Id: RootPerfMonSvc.cpp,v 1.12 2010-09-27 15:43:53 frankb Exp $
2 //====================================================================
3 // RootPerfMonSvc implementation
4 //--------------------------------------------------------------------
5 //
6 // Description: Implementation of the ROOT data storage
7 //
8 // Author : M.Frank
9 //
10 //====================================================================
11
12 // Framework include files
13 #include "GaudiKernel/MsgStream.h"
14 #include "GaudiKernel/IIncidentSvc.h"
15 #include "GaudiKernel/DataIncident.h"
16 #include "GaudiKernel/Incident.h"
17 #include "GaudiKernel/System.h"
18 #include "RootCnv/RootPerfMonSvc.h"
19 #include "RootUtils.h"
20
21 #include "TDirectory.h"
22 #include "TSystem.h"
23 #include "TBranch.h"
24 #include "TMap.h"
25
26 using namespace std;
27 using namespace Gaudi;
28 typedef const string& CSTR;
29
30 #define S_OK StatusCode::SUCCESS
31 #define S_FAIL StatusCode::FAILURE
32
33 // Standard constructor
34 RootPerfMonSvc::RootPerfMonSvc(CSTR nam, ISvcLocator* svc)
35 : Service( nam, svc), m_incidentSvc(0)
36 {
37 declareProperty("IOPerfStats", m_ioPerfStats);
38 declareProperty("Streams", m_setStreams);
39 declareProperty("BasketSize", m_basketSize);
40 declareProperty("BufferSize", m_bufferSize);
41 declareProperty("SplitLevel", m_splitLevel);
42 }
43
44 // Standard destructor
45 RootPerfMonSvc::~RootPerfMonSvc() {
46 }
47
48 // Small routine to issue exceptions
49 StatusCode RootPerfMonSvc::error(CSTR msg) {
50 if ( m_log ) {
51 log() << MSG::ERROR << "Error: " << msg << endmsg;
52 return S_FAIL;
53 }
54 MsgStream m(msgSvc(),name());
55 m << MSG::ERROR << "Error: " << msg << endmsg;
56 return S_FAIL;
57 }
58
59 // Initialize the Db data persistency service
60 StatusCode RootPerfMonSvc::initialize() {
61 string cname;
62 StatusCode status = Service::initialize();
63 if ( !status.isSuccess() )
64 return error("Failed to initialize Service base class.");
65 m_log = new MsgStream(msgSvc(),name());
66 if( !(status=service("IncidentSvc", m_incidentSvc)).isSuccess() )
67 return error("Unable to localize interface from service:IncidentSvc");
68
69 m_incidentSvc->addListener(this, IncidentType::BeginEvent, 1, false, false);
70 m_incidentSvc->addListener(this, "NEW_STREAM", 1, false, false);
71 m_incidentSvc->addListener(this, "CONNECTED_OUTPUT", 1, false, false);
72
73 if (m_ioPerfStats.empty())
74 return error("Performance monitoring file IOPerfStats was not defined.");
75
76 TDirectory::TContext ctxt(0);
77 if (!(m_perfFile = new TFile(m_ioPerfStats.c_str(),"RECREATE")))
78 return error("Could not create ROOT file.");
79
80 if (!(m_perfTree = new TTree("T", "performance measurement")))
81 return error("Could not create tree.");
82
83 m_perfTree->Branch("utime", &m_utime, "utime/l");
84 m_perfTree->Branch("stime", &m_stime, "stime/l");
85 m_perfTree->Branch("vsize", &m_vsize, "vsize/l");
86 m_perfTree->Branch("rss", &m_rss, "rss/L");
87 m_perfTree->Branch("time", &m_time, "time/L");
88 m_eventNumber = 0;
89 m_perfTree->Branch("event_number", &m_eventNumber, "event_number/L");
90 m_perfTree->Branch("event_type", &m_eventType, "event_type/I");
91
92 if (m_setStreams.empty())
93 m_setStreams = "undefined";
94 if (m_basketSize.empty())
95 m_basketSize = "undefined";
96 if (m_bufferSize.empty())
97 m_bufferSize = "undefined";
98 if (m_splitLevel.empty())
99 m_splitLevel = "undefined";
100
101 TMap *map = new TMap();
102 map->Add(new TObjString("streams"), new TObjString(m_setStreams.c_str()));
103 map->Add(new TObjString("basket_size"), new TObjString(m_basketSize.c_str()));
104 map->Add(new TObjString("buffer_size"), new TObjString(m_bufferSize.c_str()));
105 map->Add(new TObjString("split_level"), new TObjString(m_splitLevel.c_str()));
106 map->Write("params", TObject::kSingleKey);
107 return S_OK;
108 }
109
110 void RootPerfMonSvc::record(EventType eventType) {
111 SysProcStat data;
112 m_eventType = eventType;
113 m_utime = (ULong_t)data.utime;
114 m_stime = (ULong_t)data.stime;
115 m_vsize = (ULong_t)data.vsize;
116 m_rss = (Long_t)data.rss;
117 m_time = (Long_t)data.time;
118 m_perfTree->Fill();
119 }
120
121 void RootPerfMonSvc::handle(const Incident& incident) {
122 std::string t = incident.type();
123 if ( !t.compare(IncidentType::BeginEvent) ) {
124 m_eventNumber++;
125 record(EVENT);
126 return;
127 }
128 if ( !t.compare("CONNECTED_OUTPUT") ) {
129 m_outputs.insert(incident.source());
130 }
131 }
132
133 // Stop the performance monitoring service
134 StatusCode RootPerfMonSvc::stop() {
135 char text[64];
136 record(FSR);
137 TMap *map = new TMap();
138 for(set<string>::const_iterator i=m_outputs.begin(); i!=m_outputs.end();++i) {
139 const char* fn = (*i).c_str();
140 Long_t id, siz, flags, tim;
141 if ( 0 == gSystem->GetPathInfo(fn,&id,&siz,&flags,&tim) ) {
142 ::sprintf(text,"%ld",siz);
143 map->Add(new TObjString(fn), new TObjString(text));
144 }
145 }
146 TDirectory::TContext ctxt(m_perfFile);
147 map->Write("Outputs", TObject::kSingleKey);
148 return S_OK;
149 }
150
151 // Finalize the performance monitoring service
152 StatusCode RootPerfMonSvc::finalize() {
153 record(FSR);
154 log() << MSG::INFO;
155 deletePtr(m_log);
156 releasePtr(m_incidentSvc);
157
158 m_perfFile->Write();
159 m_perfFile->Close();
160 deletePtr(m_perfFile);
161
162 return Service::finalize();
163 }