ATLAS Offline Software
Loading...
Searching...
No Matches
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>
7#include <EventLoop/Worker.h>
10#include <TBenchmark.h>
11#include <TFile.h>
12#include <TTree.h>
13#include <TTreeCache.h>
14
16
17
18namespace EL
19{
20 const std::string MetricsSvc::name = "Metrics";
21}
22
23void EL::MetricsSvc :: testInvariant () const
24{
25 RCU_INVARIANT (this != 0);
26}
27
28const char *EL::MetricsSvc :: GetName() const
29{
30 RCU_READ_INVARIANT (this);
31 return name.c_str();
32}
33
34
35EL::MetricsSvc :: MetricsSvc ()
37 , m_eventsRead (0), m_benchmark (0)
38{
39 RCU_NEW_INVARIANT (this);
40}
41
42
43
44EL::MetricsSvc :: ~MetricsSvc ()
45{
47 if (m_benchmark) { delete m_benchmark; }
48}
49
50
51
52EL::StatusCode EL::MetricsSvc :: histInitialize ()
53{
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
66EL::StatusCode EL::MetricsSvc :: fileExecute ()
67{
69 m_filesRead ++;
70 return EL::StatusCode::SUCCESS;
71}
72
73
74
75EL::StatusCode EL::MetricsSvc :: endOfFile ()
76{
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
110EL::StatusCode EL::MetricsSvc :: execute ()
111{
113 m_eventsRead ++;
114 return EL::StatusCode::SUCCESS;
115}
116
117
118
119EL::StatusCode EL::MetricsSvc :: histFinalize ()
120{
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}
#define RCU_INVARIANT(x)
Definition Assert.h:201
#define RCU_ASSERT(x)
Definition Assert.h:222
#define RCU_DESTROY_INVARIANT(x)
Definition Assert.h:235
#define RCU_CHANGE_INVARIANT(x)
Definition Assert.h:231
#define RCU_NEW_INVARIANT(x)
Definition Assert.h:233
#define RCU_READ_INVARIANT(x)
Definition Assert.h:229
static Double_t tc
ClassImp(EL::MetricsSvc) namespace EL
IWorker * wk() const
description: the worker that is controlling us guarantee: no-fail
Int_t m_filesRead
description: the number of files processed
Definition MetricsSvc.h:108
Int_t m_eventsRead
description: the number of events processed
Definition MetricsSvc.h:112
TTree * m_fileMetrics
description: the file cache metrics
Definition MetricsSvc.h:100
TTree * m_jobMetrics
description: the job metrics
Definition MetricsSvc.h:104
TBenchmark * m_benchmark
description: the benchmark object used rationale: this is a pointer to avoid including the header in ...
Definition MetricsSvc.h:117
static const std::string name
description: the name of the service
Definition MetricsSvc.h:26
This module defines the arguments passed from the BATCH driver to the BATCH worker.
::StatusCode StatusCode
StatusCode definition for legacy code.
TChain * tree