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 for (const xAOD::TrigComposite* tc : data.costCollection()) {
27 const uint32_t slot = tc->getDetail<uint32_t>("slot");
28 if (slot != data.onlineSlot()){
29 isMultiSlot = true;
30 break;
31 }
32 }
33
34 if (!isMultiSlot){
35 ATH_MSG_DEBUG("Saving data from multiple slots to master slot was not enabled - ThreadOccupancy Monitoring won't be executed");
36 return StatusCode::SUCCESS;
37 }
38
39 for (const xAOD::TrigComposite* tc : data.costCollection()) {
40 const uint32_t threadID = tc->getDetail<uint32_t>("thread");
41 if (m_threadToCounterMap.count(threadID) == 0) {
42 std::stringstream threadIDStr;
43 threadIDStr << "Thread_" << std::setfill('0') << std::setw(5) << threadID;
44 m_threadToCounterMap[threadID] = threadIDStr.str();
45 }
46 ATH_CHECK( getCounter(m_threadToCounterMap[threadID])->newEvent(data, tc->index(), weight) );
47 }
48
49 ATH_CHECK( postProcess(weight) );
50
51
52 return StatusCode::SUCCESS;
53}
54
55
56StatusCode MonitorThreadOccupancy::postProcess(float weight) {
57 uint64_t lowTimestamp = std::numeric_limits<uint64_t>::max();
58 uint64_t highTimestamp = 0;
59 for (const auto& nameCounterPair : m_counters) {
60 const CounterThread* ptr = dynamic_cast<const CounterThread*>(nameCounterPair.second.get());
61 if (ptr){
62 lowTimestamp = std::min(lowTimestamp, ptr->getLowTimestamp());
63 highTimestamp = std::max(highTimestamp, ptr->getHighTimestamp());
64 }
65 }
66 for (auto& nameCounterPair : m_counters) {
67 CounterThread* ptr = dynamic_cast<CounterThread*>(nameCounterPair.second.get());
68 if (!ptr)[[unlikely]] {
69 ATH_MSG_WARNING ("MonitorThreadOccupancy::postProcess: dynamic cast failure" );
70 continue;
71 }
72 ptr->setAllThreadsTimestamps(lowTimestamp, highTimestamp);
73 ATH_CHECK( ptr->postProcess(weight) );
74 }
75 return StatusCode::SUCCESS;
76}
77
78
79std::unique_ptr<CounterBase> MonitorThreadOccupancy::newCounter(const std::string& name) {
80 return std::make_unique<CounterThread>(name, this);
81}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
char data[hepevt_bytes_allocation_ATLAS]
Definition HepEvt.cxx:11
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)