ATLAS Offline Software
AthMonBench.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 
7 // //
8 // Header file for class AthMonBench //
9 // //
10 // Description: Helper class for taking LWhists-aware //
11 // per-mon-tool benchmarks of CPU and mem. //
12 // //
13 // Author: Thomas H. Kittelmann (Thomas.Kittelmann@cern.ch) //
14 // Initial version: June 2009 //
15 // //
17 
18 #ifndef ATHMONBENCH_H
19 #define ATHMONBENCH_H
20 
21 #include <ctime>
22 #include <sstream>
23 #include <ostream>
24 #include "LWHists/LWHistStats.h"
25 #include "GaudiKernel/IMessageSvc.h"
26 
27 class AthMonBench {
28 public:
29 
31 
32  AthMonBench();
33  ~AthMonBench() = default;
34 
35  //Modify:
36  void reset();
37  bool isReset() const;
38  void setUnitCount();//To avoid normalising when accessing results (for "Total" kind of reports)
39 
40  //Taking data:
41  void startMeasurement();
42  void finishMeasurement();
43 
44  //For adding/subtracting individual measurements:
45  void operator-=(const AthMonBench& o);
46  void operator+=(const AthMonBench& o);
47 
48  //Access results:
49  double deltaMemLW_mb() const;
50  double deltaMemOther_mb() const;
51  double deltaCPU_ms() const;
52  bool valid() const;
53 
54 private:
55  typedef long long TMem;//bytes
58  clock_t m_deltaCPU;
59  int m_count;
61 };
62 
63 std::ostream& operator << ( std::ostream& os, const AthMonBench& br);
64 
66 // Inlines //
69 
70 inline void AthMonBench::reset()
71 {
72  m_deltaMemLW = 0;
73  m_deltaMemOther = 0;
74  m_deltaCPU = 0;
75  m_count = 0;
76 }
77 
78 inline bool AthMonBench::isReset() const {
80 }
81 
82 //For creating single measurements
84  if (!isReset())
85  m_count = -99999;
88  m_deltaCPU = clock();
89 }
90 
94  m_deltaCPU = clock() - m_deltaCPU;
95  ++m_count;
96  if (m_count!=1) {
97  //Something is wrong:
98  reset();
99  m_count = -99999;
100  }
101 }
102 
103 //For adding/subtracting individual measurements:
104 inline void AthMonBench::operator-=(const AthMonBench& o) {
107  m_deltaCPU -= o.m_deltaCPU;
108  m_count -= o.m_count;
109 }
110 
111 inline void AthMonBench::operator+=(const AthMonBench& o) {
114  m_deltaCPU += o.m_deltaCPU;
115  m_count += o.m_count;
116 }
117 
118 //To get results:
119 inline double AthMonBench::deltaMemLW_mb() const { return valid()?m_deltaMemLW/(1024.0*1024.0*m_count): -99.99; }
120 inline double AthMonBench::deltaMemOther_mb() const { return valid()?m_deltaMemOther/(1024.0*1024.0*m_count): -99.99; }
121 inline double AthMonBench::deltaCPU_ms() const { return valid()?m_deltaCPU*1.0e3/double(m_count*CLOCKS_PER_SEC) : -99.99; }
122 inline bool AthMonBench::valid() const { return m_count>0; }
123 inline void AthMonBench::setUnitCount() { if (valid()) m_count=1; }
124 
125 #endif
AthMonBench::operator+=
void operator+=(const AthMonBench &o)
Definition: AthMonBench.h:111
AthMonBench::valid
bool valid() const
Definition: AthMonBench.h:122
LWHistStats.h
AthMonBench::m_deltaCPU
clock_t m_deltaCPU
Definition: AthMonBench.h:58
AthMonBench::m_count
int m_count
Definition: AthMonBench.h:59
AthMonBench::deltaMemOther_mb
double deltaMemOther_mb() const
Definition: AthMonBench.h:120
AthMonBench::m_deltaMemOther
TMem m_deltaMemOther
Definition: AthMonBench.h:57
AthMonBench::deltaCPU_ms
double deltaCPU_ms() const
Definition: AthMonBench.h:121
AthMonBench::finishMeasurement
void finishMeasurement()
Definition: AthMonBench.h:91
AthMonBench::m_deltaMemLW
TMem m_deltaMemLW
Definition: AthMonBench.h:56
LWHistStats::getTotalPoolMemUsed
static long long getTotalPoolMemUsed()
Definition: LWHistStats.cxx:27
TrigConf::MSGTC::Level
Level
Definition: Trigger/TrigConfiguration/TrigConfBase/TrigConfBase/MsgStream.h:21
AthMonBench::deltaMemLW_mb
double deltaMemLW_mb() const
Definition: AthMonBench.h:119
AthMonBench::TMem
long long TMem
Definition: AthMonBench.h:55
xAOD::double
double
Definition: CompositeParticle_v1.cxx:159
AthMonBench::operator-=
void operator-=(const AthMonBench &o)
Definition: AthMonBench.h:104
ReadFromCoolCompare.os
os
Definition: ReadFromCoolCompare.py:231
AthMonBench::~AthMonBench
~AthMonBench()=default
AthMonBench::isReset
bool isReset() const
Definition: AthMonBench.h:78
AthMonBench::s_resourceMonThreshold
static const MSG::Level s_resourceMonThreshold
Definition: AthMonBench.h:30
AthMonBench::startMeasurement
void startMeasurement()
Definition: AthMonBench.h:83
AthMonBench::currentVMem_ExcludingLWPools
static TMem currentVMem_ExcludingLWPools()
Definition: AthMonBench.cxx:9
AthMonBench::reset
void reset()
Definition: AthMonBench.h:70
DEBUG
#define DEBUG
Definition: page_access.h:11
operator<<
std::ostream & operator<<(std::ostream &os, const AthMonBench &br)
Definition: AthMonBench.cxx:29
AthMonBench::AthMonBench
AthMonBench()
Definition: AthMonBench.h:68
AthMonBench::setUnitCount
void setUnitCount()
Definition: AthMonBench.h:123
AthMonBench
Definition: AthMonBench.h:27
PlotCalibFromCool.br
br
Definition: PlotCalibFromCool.py:355