ATLAS Offline Software
Loading...
Searching...
No Matches
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
7#include <algorithm> // std::min, max
8#include <sstream>
9#include <iomanip>
10#include <limits> //std::numeric_limits<uint64_t>::max();
11
13 : MonitorBase(name, parent),
15 m_threadCounter(0) {}
16
17
18StatusCode 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
57StatusCode 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
80std::unique_ptr<CounterBase> MonitorThreadOccupancy::newCounter(const std::string& name) {
81 return std::make_unique<CounterThread>(name, this);
82}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
static Double_t tc
Caches and propagates event data to be used by monitoring algorithms.
Definition CostData.h:26
Concrete implimentation of Counter to monitor all algorithms executing on a single thread.
CounterBase * getCounter(const std::string &name)
Retrieve counter by name.
MonitorBase()=delete
Forbid default constructor.
std::unordered_map< std::string, std::unique_ptr< CounterBase > > m_counters
Storage of Monitor's collection of Counters.
MonitorThreadOccupancy()=delete
Forbid default constructor.
StatusCode postProcess(float weight)
Get the global start and stop timestamps over all threads and sync these to the individual threads.
virtual std::unique_ptr< CounterBase > newCounter(const std::string &name) override
Concrete counter instantiation.
std::unordered_map< uint32_t, std::string > m_threadToCounterMap
Map thread's hash ID to a counting numeral embedded in a string.
virtual StatusCode newEvent(const CostData &data, const float weight=1.) override
Concrete dispatch method.
size_t m_threadCounter
Count how many unique thread ID we have seen.
Container which represents a time range and holds a collection of Monitors which monitor this range.
TrigComposite_v1 TrigComposite
Declare the latest version of the class.
#define unlikely(x)