ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Control
PerformanceMonitoring
PerfMonTests
src
PerfMonTestCpuCruncherAlg.cxx
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3
*/
4
5
// PerfMonTestCpuCruncherAlg.cxx
6
// Implementation file for class PerfMonTest::CpuCruncherAlg
7
// Author: S.Binet<binet@cern.ch>
9
10
11
// STL includes
12
#include <chrono>
13
#include <cmath>
14
15
// FrameWork includes
16
#include "Gaudi/Property.h"
17
18
// PerfMonTests includes
19
#include "
PerfMonTestCpuCruncherAlg.h
"
20
21
using namespace
PerfMonTest
;
22
23
24
StatusCode
CpuCruncherAlg::initialize
()
25
{
26
ATH_MSG_INFO
(
"Initializing "
<< name() <<
"..."
) ;
27
28
// Random number service
29
m_distribution
= std::normal_distribution<double>(
m_meanCpuTime
,
m_rmsCpuTime
);
30
31
ATH_MSG_INFO
(
"CPU usage configuration: <"
32
<<
m_meanCpuTime
<<
"> +/- "
33
<<
m_rmsCpuTime
<<
" ms"
) ;
34
35
36
return
StatusCode::SUCCESS;
37
}
38
39
40
StatusCode
CpuCruncherAlg::execute
(
const
EventContext&
/*ctx*/
)
41
{
42
ATH_MSG_DEBUG
(
"Executing "
<< name() <<
"..."
) ;
43
44
// Volatile to avoid optimization
45
volatile
double
test_result = 0.0;
46
47
// Sample randomly - use w/ care
48
double
ms_interval =
m_distribution
(
m_random
);
49
50
ATH_MSG_DEBUG
(
"Will burn CPU for "
<< ms_interval <<
" milliseconds ..."
);
51
52
// Define the interval, do some math until the interval is exhausted
53
std::chrono::duration<float, std::milli> chrono_interval(ms_interval);
54
55
auto
start = std::chrono::system_clock::now();
56
57
while
(std::chrono::system_clock::now() - start < chrono_interval)
58
test_result +=
burn
(5000);
59
60
ATH_MSG_DEBUG
(
"Test result sum is "
<< test_result );
61
62
return
StatusCode::SUCCESS;
63
}
64
65
double
CpuCruncherAlg::burn
(
unsigned
long
nIterations = 10000000lu) {
66
67
// Volatile to avoid optimization
68
volatile
double
sum = 0.0;
69
70
double
val;
71
72
for
(
auto
idx = 0lu; idx < nIterations; ++idx) {
73
val = (double) (idx + 1) / nIterations * 0.7854;
74
sum += std::tan(std::log(val));
75
}
76
77
return
sum;
78
}
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition
AthMsgStreamMacros.h:31
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition
AthMsgStreamMacros.h:29
PerfMonTestCpuCruncherAlg.h
PerfMonTest::CpuCruncherAlg::execute
virtual StatusCode execute(const EventContext &ctx) override
Execute method.
Definition
PerfMonTestCpuCruncherAlg.cxx:40
PerfMonTest::CpuCruncherAlg::m_rmsCpuTime
Gaudi::Property< float > m_rmsCpuTime
Property to setup the RMS (in ms) of CPU time to consume.
Definition
PerfMonTestCpuCruncherAlg.h:49
PerfMonTest::CpuCruncherAlg::burn
double burn(unsigned long nIterations)
Definition
PerfMonTestCpuCruncherAlg.cxx:65
PerfMonTest::CpuCruncherAlg::m_random
std::default_random_engine m_random
Random number setup.
Definition
PerfMonTestCpuCruncherAlg.h:52
PerfMonTest::CpuCruncherAlg::m_distribution
std::normal_distribution< double > m_distribution
Definition
PerfMonTestCpuCruncherAlg.h:53
PerfMonTest::CpuCruncherAlg::m_meanCpuTime
Gaudi::Property< float > m_meanCpuTime
Property to setup the mean (in ms) of CPU time to consume.
Definition
PerfMonTestCpuCruncherAlg.h:46
PerfMonTest::CpuCruncherAlg::initialize
virtual StatusCode initialize() override
Definition
PerfMonTestCpuCruncherAlg.cxx:24
PerfMonTest
PerfMonTestPolyVectorAlg.h Example for the memory optimization tutorial.
Definition
Control/PerformanceMonitoring/PerfMonTests/src/Hit.h:7
Generated on
for ATLAS Offline Software by
1.17.0