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
26const char *EL::MetricsSvc :: GetName() const
27{
28 RCU_READ_INVARIANT (this);
29 return name.c_str();
30}
31
32
33EL::MetricsSvc :: MetricsSvc ()
35 , m_eventsRead (0), m_benchmark (0)
36{
37 RCU_NEW_INVARIANT (this);
38}
39
40
41
42EL::MetricsSvc :: ~MetricsSvc ()
43{
45 if (m_benchmark) { delete m_benchmark; }
46}
47
48
49
50EL::StatusCode EL::MetricsSvc :: histInitialize ()
51{
53 m_benchmark = new TBenchmark;
54 m_benchmark->Start("loopmetrics");
55 wk()->addOutput (m_fileMetrics = new TTree ("EventLoop_Metrics/cacheStats",
56 "TTree cache stats per file"));
57 wk()->addOutput (m_jobMetrics = new TTree ("EventLoop_Metrics/jobs",
58 "event throughput per job"));
59
60 // Create the per-file branches once, pointing at the member buffers, so
61 // that the branch addresses stay valid across every per-file Fill().
62 m_fileMetrics->Branch ("nBranches", &m_nBranches, "nBranches/I");
63 m_fileMetrics->Branch ("learnEntries", &m_nLearn, "learnEntries/I");
64 m_fileMetrics->Branch ("cacheEfficiency", &m_cacheEfficiency, "cacheEfficiency/D");
65 m_fileMetrics->Branch ("cacheEfficiencyRel", &m_cacheEfficiencyRel, "cacheEfficiencyRel/D");
66 m_fileMetrics->Branch ("bytesRead", &m_bytesRead, "bytesRead/L");
67 m_fileMetrics->Branch ("readCalls", &m_readCalls, "readCalls/I");
68 m_fileMetrics->Branch ("noCacheBytesRead", &m_noCacheBytesRead, "noCacheBytesRead/L");
69 m_fileMetrics->Branch ("noCacheReadCalls", &m_noCacheReadCalls, "noCacheReadCalls/I");
70 m_fileMetrics->Branch ("readaheadSize", &m_readaheadSize, "readaheadSize/I");
71 m_fileMetrics->Branch ("bytesReadExtra", &m_bytesReadExtra, "bytesReadExtra/L");
72 return EL::StatusCode::SUCCESS;
73}
74
75
76
77EL::StatusCode EL::MetricsSvc :: fileExecute ()
78{
80 m_filesRead ++;
81 return EL::StatusCode::SUCCESS;
82}
83
84
85
86EL::StatusCode EL::MetricsSvc :: endOfFile ()
87{
90 RCU_ASSERT(wk()->inputFile());
91 RCU_ASSERT(wk()->tree());
92 TTreeCache *tc = (TTreeCache*)wk()->inputFile()->GetCacheRead(wk()->tree());
93 if (tc) {
94 // update the member buffers wired to the branches in histInitialize
95 m_nBranches = tc->GetCachedBranches()->GetEntries();
96 m_nLearn = tc->GetLearnEntries();
97 m_cacheEfficiency = tc->GetEfficiency ();
98 m_cacheEfficiencyRel = tc->GetEfficiencyRel ();
99 m_bytesRead = tc->GetBytesRead ();
100 m_readCalls = tc->GetReadCalls ();
101 m_noCacheBytesRead = tc->GetNoCacheBytesRead ();
102 m_noCacheReadCalls = tc->GetNoCacheReadCalls ();
103 m_readaheadSize = TFile::GetReadaheadSize ();
104 m_bytesReadExtra = tc->GetBytesReadExtra ();
105 m_fileMetrics->Fill ();
106 }
107 return EL::StatusCode::SUCCESS;
108}
109
110
111
112EL::StatusCode EL::MetricsSvc :: execute ()
113{
115 m_eventsRead ++;
116 return EL::StatusCode::SUCCESS;
117}
118
119
120
121EL::StatusCode EL::MetricsSvc :: histFinalize ()
122{
124 m_benchmark->Stop("loopmetrics");
125 m_jobMetrics->Branch("eventsRead", &m_eventsRead, "eventsRead/I");
126 m_jobMetrics->Branch("filesRead", &m_filesRead, "filesRead/I");
127 Float_t realTime = m_benchmark->GetRealTime("loopmetrics");
128 m_jobMetrics->Branch("loopWallTime", &realTime, "loopWallTime/F");
129 Float_t cpuTime = m_benchmark->GetCpuTime("loopmetrics");
130 m_jobMetrics->Branch("loopCpuTime", &cpuTime, "loopCpuTime/F");
131 Float_t evtsWallSec = m_eventsRead / (realTime != 0 ? realTime : 1.);
132 m_jobMetrics->Branch("eventsPerWallSec", &evtsWallSec, "eventsPerWallSec/F");
133 Float_t evtsCpuSec = m_eventsRead / (cpuTime != 0 ? cpuTime : 1.);
134 m_jobMetrics->Branch("eventsPerCpuSec", &evtsCpuSec, "eventsPerCpuSec/F");
135 m_jobMetrics->Fill();
136 return EL::StatusCode::SUCCESS;
137}
#define RCU_ASSERT(x)
Definition Assert.h:210
#define RCU_DESTROY_INVARIANT(x)
Definition Assert.h:223
#define RCU_CHANGE_INVARIANT(x)
Definition Assert.h:219
#define RCU_NEW_INVARIANT(x)
Definition Assert.h:221
#define RCU_READ_INVARIANT(x)
Definition Assert.h:217
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
Int_t m_noCacheReadCalls
Definition MetricsSvc.h:132
TTree * m_fileMetrics
description: the file cache metrics
Definition MetricsSvc.h:100
TTree * m_jobMetrics
description: the job metrics
Definition MetricsSvc.h:104
Long64_t m_noCacheBytesRead
Definition MetricsSvc.h:131
Double_t m_cacheEfficiency
Definition MetricsSvc.h:127
Long64_t m_bytesRead
Definition MetricsSvc.h:129
Int_t m_nBranches
buffers for the per-file cache-stats branches
Definition MetricsSvc.h:125
Int_t m_readaheadSize
Definition MetricsSvc.h:133
Long64_t m_bytesReadExtra
Definition MetricsSvc.h:134
Double_t m_cacheEfficiencyRel
Definition MetricsSvc.h:128
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