ATLAS Offline Software
AthMonBench.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 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 //
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 <iosfwd>
23 #include "GaudiKernel/IMessageSvc.h"
24 
25 class AthMonBench {
26 public:
27 
29 
30  AthMonBench() = default;
31  ~AthMonBench() = default;
32 
33  //Modify:
34  void reset();
35  bool isReset() const;
36  void setUnitCount();//To avoid normalising when accessing results (for "Total" kind of reports)
37 
38  //Taking data:
39  void startMeasurement();
40  void finishMeasurement();
41 
42  //For adding/subtracting individual measurements:
43  void operator-=(const AthMonBench& o);
44  void operator+=(const AthMonBench& o);
45 
46  //Access results:
47  double deltaMem_mb() const;
48  double deltaCPU_ms() const;
49  bool valid() const;
50 
51 private:
52  typedef long long TMem;//bytes
54  clock_t m_deltaCPU{};
55  int m_count{};
56  static TMem currentVMem();
57 };
58 
59 std::ostream& operator << ( std::ostream& os, const AthMonBench& br);
60 
62 // Inlines //
64 
65 inline void AthMonBench::reset(){
66  m_deltaMem = 0;
67  m_deltaCPU = 0;
68  m_count = 0;
69 }
70 
71 inline bool AthMonBench::isReset() const {
72  return !(m_deltaMem||m_deltaCPU||m_count);
73 }
74 
75 //For creating single measurements
77  if (!isReset())
78  m_count = -99999;
80  m_deltaCPU = clock();
81 }
82 
85  m_deltaCPU = clock() - m_deltaCPU;
86  ++m_count;
87  if (m_count!=1) {
88  //Something is wrong:
89  reset();
90  m_count = -99999;
91  }
92 }
93 
94 //For adding/subtracting individual measurements:
95 inline void AthMonBench::operator-=(const AthMonBench& o) {
98  m_count -= o.m_count;
99 }
100 
101 inline void AthMonBench::operator+=(const AthMonBench& o) {
102  m_deltaMem += o.m_deltaMem;
103  m_deltaCPU += o.m_deltaCPU;
104  m_count += o.m_count;
105 }
106 
107 //To get results:
108 inline double AthMonBench::deltaMem_mb() const { return valid()?m_deltaMem/(1024.0*1024.0*m_count): -99.99; }
109 inline double AthMonBench::deltaCPU_ms() const { return valid()?m_deltaCPU*1.0e3/double(m_count*CLOCKS_PER_SEC) : -99.99; }
110 inline bool AthMonBench::valid() const { return m_count>0; }
111 inline void AthMonBench::setUnitCount() { if (valid()) m_count=1; }
112 
113 #endif
AthMonBench::operator+=
void operator+=(const AthMonBench &o)
Definition: AthMonBench.h:101
AthMonBench::valid
bool valid() const
Definition: AthMonBench.h:110
AthMonBench::currentVMem
static TMem currentVMem()
Definition: AthMonBench.cxx:22
AthMonBench::m_deltaCPU
clock_t m_deltaCPU
Definition: AthMonBench.h:54
AthMonBench::m_count
int m_count
Definition: AthMonBench.h:55
AthMonBench::AthMonBench
AthMonBench()=default
AthMonBench::deltaCPU_ms
double deltaCPU_ms() const
Definition: AthMonBench.h:109
AthMonBench::finishMeasurement
void finishMeasurement()
Definition: AthMonBench.h:83
TrigConf::MSGTC::Level
Level
Definition: Trigger/TrigConfiguration/TrigConfBase/TrigConfBase/MsgStream.h:21
AthMonBench::deltaMem_mb
double deltaMem_mb() const
Definition: AthMonBench.h:108
AthMonBench::TMem
long long TMem
Definition: AthMonBench.h:52
xAOD::double
double
Definition: CompositeParticle_v1.cxx:159
AthMonBench::operator-=
void operator-=(const AthMonBench &o)
Definition: AthMonBench.h:95
AthMonBench::m_deltaMem
TMem m_deltaMem
Definition: AthMonBench.h:53
ReadFromCoolCompare.os
os
Definition: ReadFromCoolCompare.py:231
AthMonBench::~AthMonBench
~AthMonBench()=default
AthMonBench::isReset
bool isReset() const
Definition: AthMonBench.h:71
AthMonBench::s_resourceMonThreshold
static const MSG::Level s_resourceMonThreshold
Definition: AthMonBench.h:28
AthMonBench::startMeasurement
void startMeasurement()
Definition: AthMonBench.h:76
AthMonBench::reset
void reset()
Definition: AthMonBench.h:65
DEBUG
#define DEBUG
Definition: page_access.h:11
operator<<
std::ostream & operator<<(std::ostream &os, const AthMonBench &br)
Definition: AthMonBench.cxx:37
AthMonBench::setUnitCount
void setUnitCount()
Definition: AthMonBench.h:111
AthMonBench
Definition: AthMonBench.h:25
PlotCalibFromCool.br
br
Definition: PlotCalibFromCool.py:355