ATLAS Offline Software
MetricsSvc.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #include <EventLoop/Job.h>
6 #include <EventLoop/StatusCode.h>
7 #include <EventLoop/Worker.h>
8 #include <EventLoop/MetricsSvc.h>
9 #include <RootCoreUtils/Assert.h>
10 #include <TBenchmark.h>
11 #include <TFile.h>
12 #include <TTree.h>
13 #include <TTreeCache.h>
14 
16 
17 
18 namespace EL
19 {
20  const std::string MetricsSvc::name = "Metrics";
21 }
22 
24 {
25  RCU_INVARIANT (this != 0);
26 }
27 
28 const char *EL::MetricsSvc :: GetName() const
29 {
30  RCU_READ_INVARIANT (this);
31  return name.c_str();
32 }
33 
34 
36  : m_fileMetrics (0), m_jobMetrics (0), m_filesRead (0)
37  , m_eventsRead (0), m_benchmark (0)
38 {
39  RCU_NEW_INVARIANT (this);
40 }
41 
42 
43 
45 {
46  RCU_DESTROY_INVARIANT (this);
47  if (m_benchmark) { delete m_benchmark; }
48 }
49 
50 
51 
53 {
54  RCU_CHANGE_INVARIANT (this);
55  m_benchmark = new TBenchmark;
56  m_benchmark->Start("loopmetrics");
57  wk()->addOutput (m_fileMetrics = new TTree ("EventLoop_Metrics/cacheStats",
58  "TTree cache stats per file"));
59  wk()->addOutput (m_jobMetrics = new TTree ("EventLoop_Metrics/jobs",
60  "event throughput per job"));
61  return EL::StatusCode::SUCCESS;
62 }
63 
64 
65 
67 {
68  RCU_CHANGE_INVARIANT (this);
69  m_filesRead ++;
70  return EL::StatusCode::SUCCESS;
71 }
72 
73 
74 
76 {
77  RCU_CHANGE_INVARIANT (this);
78  RCU_ASSERT(m_fileMetrics);
79  RCU_ASSERT(wk()->inputFile());
80  RCU_ASSERT(wk()->tree());
81  TTreeCache *tc = (TTreeCache*)wk()->inputFile()->GetCacheRead(wk()->tree());
82  if (tc) {
83  Int_t nBranches = tc->GetCachedBranches()->GetEntries();
84  m_fileMetrics->Branch ("nBranches", &nBranches, "nBranches/I");
85  Int_t nLearn = tc->GetLearnEntries();
86  m_fileMetrics->Branch ("learnEntries", &nLearn, "learnEntries/I");
87  Double_t eff = tc->GetEfficiency ();
88  m_fileMetrics->Branch ("cacheEfficiency", &eff, "cacheEfficiency/D");
89  Double_t effRel = tc->GetEfficiencyRel ();
90  m_fileMetrics->Branch ("cacheEfficiencyRel", &effRel, "cacheEfficiencyRel/D");
91  Long64_t bytesRead = tc->GetBytesRead ();
92  m_fileMetrics->Branch ("bytesRead", &bytesRead, "bytesRead/L");
93  Int_t readCalls = tc->GetReadCalls ();
94  m_fileMetrics->Branch ("readCalls", &readCalls, "readCalls/I");
95  Long64_t ncBytesRead = tc->GetNoCacheBytesRead ();
96  m_fileMetrics->Branch ("noCacheBytesRead", &ncBytesRead, "noCacheBytesRead/L");
97  Int_t ncReadCalls = tc->GetNoCacheReadCalls ();
98  m_fileMetrics->Branch ("noCacheReadCalls", &ncReadCalls, "noCacheReadCalls/I");
99  Int_t readahead = TFile::GetReadaheadSize ();
100  m_fileMetrics->Branch ("readaheadSize", &readahead, "readaheadSize/I");
101  Long64_t bytesReadExtra = tc->GetBytesReadExtra ();
102  m_fileMetrics->Branch ("bytesReadExtra", &bytesReadExtra, "bytesReadExtra/L");
103  m_fileMetrics->Fill ();
104  }
105  return EL::StatusCode::SUCCESS;
106 }
107 
108 
109 
111 {
112  RCU_CHANGE_INVARIANT (this);
113  m_eventsRead ++;
114  return EL::StatusCode::SUCCESS;
115 }
116 
117 
118 
120 {
121  RCU_CHANGE_INVARIANT (this);
122  m_benchmark->Stop("loopmetrics");
123  m_jobMetrics->Branch("eventsRead", &m_eventsRead, "eventsRead/I");
124  m_jobMetrics->Branch("filesRead", &m_filesRead, "filesRead/I");
125  Float_t realTime = m_benchmark->GetRealTime("loopmetrics");
126  m_jobMetrics->Branch("loopWallTime", &realTime, "loopWallTime/F");
127  Float_t cpuTime = m_benchmark->GetCpuTime("loopmetrics");
128  m_jobMetrics->Branch("loopCpuTime", &cpuTime, "loopCpuTime/F");
129  Float_t evtsWallSec = m_eventsRead / (realTime != 0 ? realTime : 1.);
130  m_jobMetrics->Branch("eventsPerWallSec", &evtsWallSec, "eventsPerWallSec/F");
131  Float_t evtsCpuSec = m_eventsRead / (cpuTime != 0 ? cpuTime : 1.);
132  m_jobMetrics->Branch("eventsPerCpuSec", &evtsCpuSec, "eventsPerCpuSec/F");
133  m_jobMetrics->Fill();
134  return EL::StatusCode::SUCCESS;
135 }
EL::MetricsSvc::fileExecute
virtual StatusCode fileExecute() override
effects: do all the processing that needs to be done once per file guarantee: no-fail
Definition: MetricsSvc.cxx:66
EL::MetricsSvc::name
static const std::string name
description: the name of the service
Definition: MetricsSvc.h:26
EL::MetricsSvc::~MetricsSvc
~MetricsSvc()
effects: standard destructor.
Definition: MetricsSvc.cxx:44
Job.h
tree
TChain * tree
Definition: tile_monitor.h:30
Assert.h
EL::MetricsSvc::histFinalize
virtual StatusCode histFinalize() override
effects: do the job post-processing guarantee: basic failures: out of memory failures: in/out trees o...
Definition: MetricsSvc.cxx:119
CaloCondBlobAlgs_fillNoiseFromASCII.inputFile
string inputFile
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:17
EL::MetricsSvc::histInitialize
virtual StatusCode histInitialize() override
effects: create the output TTrees guarantee: basic failures: out of memory failures: output already e...
Definition: MetricsSvc.cxx:52
EL::MetricsSvc::execute
virtual StatusCode execute() override
effects: process the next event guarantee: no-fail
Definition: MetricsSvc.cxx:110
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
EL
This module defines the arguments passed from the BATCH driver to the BATCH worker.
Definition: AlgorithmWorkerData.h:24
ClassImp
ClassImp(EL::MetricsSvc) namespace EL
Definition: MetricsSvc.cxx:15
RCU_INVARIANT
#define RCU_INVARIANT(x)
Definition: Assert.h:201
EL::MetricsSvc::GetName
virtual const char * GetName() const override
effects: return the name of this algorithm guarantee: no-fail
Definition: MetricsSvc.cxx:28
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
RCU_DESTROY_INVARIANT
#define RCU_DESTROY_INVARIANT(x)
Definition: Assert.h:235
EL::MetricsSvc::MetricsSvc
MetricsSvc()
effects: standard constructor.
Definition: MetricsSvc.cxx:35
Worker.h
StatusCode.h
MetricsSvc.h
RCU_CHANGE_INVARIANT
#define RCU_CHANGE_INVARIANT(x)
Definition: Assert.h:231
dqt_zlumi_alleff_HIST.eff
int eff
Definition: dqt_zlumi_alleff_HIST.py:113
EL::MetricsSvc
Definition: MetricsSvc.h:19
RCU_ASSERT
#define RCU_ASSERT(x)
Definition: Assert.h:222
EL::MetricsSvc::endOfFile
virtual StatusCode endOfFile() override
effects: do the post-processing for each input file guarantee: basic failures: out of memory failures...
Definition: MetricsSvc.cxx:75
RCU_READ_INVARIANT
#define RCU_READ_INVARIANT(x)
Definition: Assert.h:229
RCU_NEW_INVARIANT
#define RCU_NEW_INVARIANT(x)
Definition: Assert.h:233
EL::MetricsSvc::testInvariant
void testInvariant() const
effects: test the invariant of this object guarantee: no-fail
Definition: MetricsSvc.cxx:23