ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Trigger
TrigCost
TrigCostAnalysis
src
monitors
MonitorThreadOccupancy.cxx
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3
*/
4
5
#include "
MonitorThreadOccupancy.h
"
6
#include "
../counters/CounterThread.h
"
7
#include <algorithm>
// std::min, max
8
#include <sstream>
9
#include <iomanip>
10
#include <limits>
//std::numeric_limits<uint64_t>::max();
11
12
MonitorThreadOccupancy::MonitorThreadOccupancy
(
const
std::string& name,
const
MonitoredRange
* parent)
13
:
MonitorBase
(name, parent),
14
m_threadToCounterMap
(),
15
m_threadCounter
(0) {}
16
17
18
StatusCode
MonitorThreadOccupancy::newEvent
(
const
CostData
& data,
const
float
weight) {
19
// Only look at events in the master slot
20
if
(not data.isMasterSlot()) {
21
return
StatusCode::SUCCESS;
22
}
23
24
// Check if we ran with EnableMultiSlot=true - in the master slot (online slot) there are algorithms executed on different slot
25
bool
isMultiSlot =
false
;
26
const
std::string slotStr{
"slot"
};
27
for
(
const
xAOD::TrigComposite
*
tc
: data.costCollection()) {
28
const
uint32_t slot =
tc
->getDetail<uint32_t>(slotStr);
29
if
(slot != data.onlineSlot()){
30
isMultiSlot =
true
;
31
break
;
32
}
33
}
34
35
if
(!isMultiSlot){
36
ATH_MSG_DEBUG
(
"Saving data from multiple slots to master slot was not enabled - ThreadOccupancy Monitoring won't be executed"
);
37
return
StatusCode::SUCCESS;
38
}
39
const
std::string threadStr{
"thread"
};
40
for
(
const
xAOD::TrigComposite
*
tc
: data.costCollection()) {
41
const
uint32_t threadID =
tc
->getDetail<uint32_t>(threadStr);
42
if
(!
m_threadToCounterMap
.contains(threadID)) {
43
std::stringstream threadIDStr;
44
threadIDStr <<
"Thread_"
<< std::setfill(
'0'
) << std::setw(5) << threadID;
45
m_threadToCounterMap
[threadID] = threadIDStr.str();
46
}
47
ATH_CHECK
(
getCounter
(
m_threadToCounterMap
[threadID])->
newEvent
(data,
tc
->index(), weight) );
48
}
49
50
ATH_CHECK
(
postProcess
(weight) );
51
52
53
return
StatusCode::SUCCESS;
54
}
55
56
57
StatusCode
MonitorThreadOccupancy::postProcess
(
float
weight) {
58
uint64_t lowTimestamp = std::numeric_limits<uint64_t>::max();
59
uint64_t highTimestamp = 0;
60
for
(
const
auto
& nameCounterPair :
m_counters
) {
61
const
CounterThread
* ptr =
dynamic_cast<
const
CounterThread
*
>
(nameCounterPair.second.get());
62
if
(ptr){
63
lowTimestamp = std::min(lowTimestamp, ptr->getLowTimestamp());
64
highTimestamp = std::max(highTimestamp, ptr->getHighTimestamp());
65
}
66
}
67
for
(
auto
& nameCounterPair :
m_counters
) {
68
CounterThread
* ptr =
dynamic_cast<
CounterThread
*
>
(nameCounterPair.second.get());
69
if
(!ptr)[[
unlikely
]] {
70
ATH_MSG_WARNING
(
"MonitorThreadOccupancy::postProcess: dynamic cast failure"
);
71
continue
;
72
}
73
ptr->setAllThreadsTimestamps(lowTimestamp, highTimestamp);
74
ATH_CHECK
( ptr->postProcess(weight) );
75
}
76
return
StatusCode::SUCCESS;
77
}
78
79
80
std::unique_ptr<CounterBase>
MonitorThreadOccupancy::newCounter
(
const
std::string& name) {
81
return
std::make_unique<CounterThread>(name,
this
);
82
}
ATH_CHECK
#define ATH_CHECK
Evaluate an expression and check for errors.
Definition
AthCheckMacros.h:40
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition
AthMsgStreamMacros.h:32
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition
AthMsgStreamMacros.h:29
CounterThread.h
tc
static Double_t tc
Definition
LArPhysWaveHECTool.cxx:38
MonitorThreadOccupancy.h
CostData
Caches and propagates event data to be used by monitoring algorithms.
Definition
CostData.h:26
CounterThread
Concrete implimentation of Counter to monitor all algorithms executing on a single thread.
Definition
CounterThread.h:14
MonitorBase::getCounter
CounterBase * getCounter(const std::string &name)
Retrieve counter by name.
Definition
Trigger/TrigCost/TrigCostAnalysis/src/MonitorBase.cxx:52
MonitorBase::MonitorBase
MonitorBase()=delete
Forbid default constructor.
MonitorBase::m_counters
std::unordered_map< std::string, std::unique_ptr< CounterBase > > m_counters
Storage of Monitor's collection of Counters.
Definition
Trigger/TrigCost/TrigCostAnalysis/src/MonitorBase.h:138
MonitorThreadOccupancy::MonitorThreadOccupancy
MonitorThreadOccupancy()=delete
Forbid default constructor.
MonitorThreadOccupancy::postProcess
StatusCode postProcess(float weight)
Get the global start and stop timestamps over all threads and sync these to the individual threads.
Definition
MonitorThreadOccupancy.cxx:57
MonitorThreadOccupancy::newCounter
virtual std::unique_ptr< CounterBase > newCounter(const std::string &name) override
Concrete counter instantiation.
Definition
MonitorThreadOccupancy.cxx:80
MonitorThreadOccupancy::m_threadToCounterMap
std::unordered_map< uint32_t, std::string > m_threadToCounterMap
Map thread's hash ID to a counting numeral embedded in a string.
Definition
MonitorThreadOccupancy.h:66
MonitorThreadOccupancy::newEvent
virtual StatusCode newEvent(const CostData &data, const float weight=1.) override
Concrete dispatch method.
Definition
MonitorThreadOccupancy.cxx:18
MonitorThreadOccupancy::m_threadCounter
size_t m_threadCounter
Count how many unique thread ID we have seen.
Definition
MonitorThreadOccupancy.h:67
MonitoredRange
Container which represents a time range and holds a collection of Monitors which monitor this range.
Definition
MonitoredRange.h:29
xAOD::TrigComposite
TrigComposite_v1 TrigComposite
Declare the latest version of the class.
Definition
TrigComposite.h:16
unlikely
#define unlikely(x)
Definition
pythonic_coracool.cxx:9
Generated on
for ATLAS Offline Software by
1.17.0