ATLAS Offline Software
Loading...
Searching...
No Matches
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
26public:
27
28 static const MSG::Level s_resourceMonThreshold = MSG::DEBUG;
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
51private:
52 typedef long long TMem;//bytes
54 clock_t m_deltaCPU{};
55 int m_count{};
56 static TMem currentVMem();
57};
58
59std::ostream& operator << ( std::ostream& os, const AthMonBench& br);
60
62// Inlines //
64
65inline void AthMonBench::reset(){
66 m_deltaMem = 0;
67 m_deltaCPU = 0;
68 m_count = 0;
69}
70
71inline 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:
95inline void AthMonBench::operator-=(const AthMonBench& o) {
98 m_count -= o.m_count;
99}
100
104 m_count += o.m_count;
105}
106
107//To get results:
108inline double AthMonBench::deltaMem_mb() const { return valid()?m_deltaMem/(1024.0*1024.0*m_count): -99.99; }
109inline double AthMonBench::deltaCPU_ms() const { return valid()?m_deltaCPU*1.0e3/double(m_count*CLOCKS_PER_SEC) : -99.99; }
110inline bool AthMonBench::valid() const { return m_count>0; }
111inline void AthMonBench::setUnitCount() { if (valid()) m_count=1; }
112
113#endif
std::ostream & operator<<(std::ostream &os, const AthMonBench &br)
AthMonBench()=default
void reset()
Definition AthMonBench.h:65
bool valid() const
double deltaCPU_ms() const
void setUnitCount()
void operator-=(const AthMonBench &o)
Definition AthMonBench.h:95
double deltaMem_mb() const
static const MSG::Level s_resourceMonThreshold
Definition AthMonBench.h:28
void operator+=(const AthMonBench &o)
long long TMem
Definition AthMonBench.h:52
~AthMonBench()=default
bool isReset() const
Definition AthMonBench.h:71
clock_t m_deltaCPU
Definition AthMonBench.h:54
static TMem currentVMem()
void finishMeasurement()
Definition AthMonBench.h:83
TMem m_deltaMem
Definition AthMonBench.h:53
void startMeasurement()
Definition AthMonBench.h:76