ATLAS Offline Software
Loading...
Searching...
No Matches
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
20
21using namespace PerfMonTest;
22
23
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
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
65double 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}
#define ATH_MSG_INFO(x)
#define ATH_MSG_DEBUG(x)
virtual StatusCode execute() override
Gaudi::Property< float > m_rmsCpuTime
Property to setup the RMS (in ms) of CPU time to consume.
double burn(unsigned long nIterations)
std::default_random_engine m_random
Random number setup.
std::normal_distribution< double > m_distribution
Gaudi::Property< float > m_meanCpuTime
Property to setup the mean (in ms) of CPU time to consume.
virtual StatusCode initialize() override
PerfMonTestPolyVectorAlg.h Example for the memory optimization tutorial.