31 #include <TDirectory.h>
33 #include <TObjString.h>
37 using namespace Gaudi;
38 typedef const string&
CSTR;
40 #define S_OK StatusCode::SUCCESS
41 #define S_FAIL StatusCode::FAILURE
58 if ( !status.
isSuccess() )
return error(
"Failed to initialize Service base class." );
60 m_incidentSvc = service(
"IncidentSvc" );
61 if ( !m_incidentSvc )
return error(
"Unable to localize interface from service:IncidentSvc" );
63 m_incidentSvc->addListener(
this, IncidentType::BeginEvent, 1,
false,
false );
64 m_incidentSvc->addListener(
this,
"NEW_STREAM", 1,
false,
false );
65 m_incidentSvc->addListener(
this,
"CONNECTED_OUTPUT", 1,
false,
false );
67 if ( m_ioPerfStats.empty() )
return error(
"Performance monitoring file IOPerfStats was not defined." );
69 TDirectory::TContext ctxt(
nullptr );
70 m_perfFile.reset(
new TFile( m_ioPerfStats.value().c_str(),
"RECREATE" ) );
71 if ( !m_perfFile )
return error(
"Could not create ROOT file." );
73 if ( !( m_perfTree =
new TTree(
"T",
"performance measurement" ) ) )
return error(
"Could not create tree." );
75 m_perfTree->Branch(
"utime", &m_utime,
"utime/l" );
76 m_perfTree->Branch(
"stime", &m_stime,
"stime/l" );
77 m_perfTree->Branch(
"vsize", &m_vsize,
"vsize/l" );
78 m_perfTree->Branch(
"rss", &m_rss,
"rss/L" );
79 m_perfTree->Branch(
"time", &m_time,
"time/L" );
81 m_perfTree->Branch(
"event_number", &m_eventNumber,
"event_number/L" );
82 m_perfTree->Branch(
"event_type", &m_eventType,
"event_type/I" );
84 if ( m_setStreams.empty() ) m_setStreams =
"undefined";
85 if ( m_basketSize.empty() ) m_basketSize =
"undefined";
86 if ( m_bufferSize.empty() ) m_bufferSize =
"undefined";
87 if ( m_splitLevel.empty() ) m_splitLevel =
"undefined";
89 auto map =
new TMap();
90 map->Add(
new TObjString(
"streams" ),
new TObjString( m_setStreams.value().c_str() ) );
91 map->Add(
new TObjString(
"basket_size" ),
new TObjString( m_basketSize.value().c_str() ) );
92 map->Add(
new TObjString(
"buffer_size" ),
new TObjString( m_bufferSize.value().c_str() ) );
93 map->Add(
new TObjString(
"split_level" ),
new TObjString( m_splitLevel.value().c_str() ) );
94 map->Write(
"params", TObject::kSingleKey );
98 void RootPerfMonSvc::record(
EventType eventType ) {
100 m_eventType = eventType;
101 m_utime = data.
utime;
102 m_stime = data.
stime;
103 m_vsize = data.
vsize;
109 void RootPerfMonSvc::handle(
const Incident& incident ) {
111 if ( !
t.compare( IncidentType::BeginEvent ) ) {
116 if ( !
t.compare(
"CONNECTED_OUTPUT" ) ) { m_outputs.insert( incident.
source() ); }
123 auto map =
new TMap();
124 for (
const auto& i : m_outputs ) {
125 const char* fn = i.c_str();
126 Long_t
id, siz, flags, tim;
127 if ( 0 == gSystem->GetPathInfo( fn, &
id, &siz, &flags, &tim ) ) {
129 map->Add(
new TObjString( fn ),
new TObjString( text ) );
132 TDirectory::TContext ctxt( m_perfFile.get() );
133 map->Write(
"Outputs", TObject::kSingleKey );
142 m_incidentSvc.reset();