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"
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
46 }
47 
48 // Small routine to issue exceptions
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
61  string cname;
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 
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
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
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 }
const std::string BeginEvent
Processing of a new event has started.
Definition: Incident.h:60
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
long unsigned stime
Definition: SysProcStat.h:17
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Definition: ISvcLocator.h:26
const std::string & type() const
Access to the incident type.
Definition: Incident.h:34
const std::string & source() const
Access to the source of the incident.
Definition: Incident.h:40
SmartIF< IMessageSvc > & msgSvc() const
The standard message service.
virtual void handle(const Incident &incident)
IIncidentListener override: Inform that a new incident has occurred.
bool isSuccess() const
Test for a status code of SUCCESS.
Definition: StatusCode.h:75
virtual void record(EventType eventType)
#define S_OK
MsgStream * m_log
Message streamer.
#define S_FAIL
std::string m_ioPerfStats
Property: Enable TTree IOperfStats if not empty; otherwise perf stat file name.
virtual StatusCode stop()
Stop (from RUNNING to INITIALIZED).
struct GAUDI_API map
Parametrisation class for map-like implementation.
long unsigned vsize
Definition: SysProcStat.h:17
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:30
std::string m_splitLevel
IIncidentSvc * m_incidentSvc
Reference to incident service.
const string & CSTR
const std::string CSTR
std::string m_setStreams
virtual const std::string & name() const
Retrieve name of the service.
Definition: Service.cpp:331
std::string m_bufferSize
MsgStream & log() const
Helper: Use message streamer.
virtual StatusCode initialize()
Initialization (from CONFIGURED to INITIALIZED).
Definition: Service.cpp:74
std::string m_basketSize
long unsigned utime
Definition: SysProcStat.h:17
Base class for all Incidents (computing events).
Definition: Incident.h:16
virtual StatusCode initialize()
Service overload: initialize the service.
virtual void addListener(IIncidentListener *lis, const std::string &type="", long priority=0, bool rethrow=false, bool singleShot=false)=0
Add listener.
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:142
Property * declareProperty(const std::string &name, T &property, const std::string &doc="none") const
Declare the named property.
Definition: Service.h:211
This is a number of static methods for bootstrapping the Gaudi framework.
Definition: Bootstrap.h:14
std::set< std::string > m_outputs
Base class for all services.
Definition: Service.h:33
virtual ~RootPerfMonSvc()
Standard destructor.
list i
Definition: ana.py:128
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
virtual StatusCode finalize()
Finalize (from INITIALIZED to CONFIGURED).
Definition: Service.cpp:199
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
virtual StatusCode finalize()
Service overload: Finalize the service.