ATLAS Offline Software
Loading...
Searching...
No Matches
MonitorThreadOccupancy.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
3*/
4
7
9 : MonitorBase(name, parent),
11 m_threadCounter(0) {}
12
13
14StatusCode MonitorThreadOccupancy::newEvent(const CostData& data, const float weight) {
15 // Only look at events in the master slot
16 if (not data.isMasterSlot()) {
17 return StatusCode::SUCCESS;
18 }
19
20 // Check if we ran with EnableMultiSlot=true - in the master slot (online slot) there are algorithms executed on different slot
21 bool isMultiSlot = false;
22 for (const xAOD::TrigComposite* tc : data.costCollection()) {
23 const uint32_t slot = tc->getDetail<uint32_t>("slot");
24 if (slot != data.onlineSlot()){
25 isMultiSlot = true;
26 break;
27 }
28 }
29
30 if (!isMultiSlot){
31 ATH_MSG_DEBUG("Saving data from multiple slots to master slot was not enabled - ThreadOccupancy Monitoring won't be executed");
32 return StatusCode::SUCCESS;
33 }
34
35 for (const xAOD::TrigComposite* tc : data.costCollection()) {
36 const uint32_t threadID = tc->getDetail<uint32_t>("thread");
37 if (m_threadToCounterMap.count(threadID) == 0) {
38 std::stringstream threadIDStr;
39 threadIDStr << "Thread_" << std::setfill('0') << std::setw(5) << threadID;
40 m_threadToCounterMap[threadID] = threadIDStr.str();
41 }
42 ATH_CHECK( getCounter(m_threadToCounterMap[threadID])->newEvent(data, tc->index(), weight) );
43 }
44
45 ATH_CHECK( postProcess(weight) );
46
47
48 return StatusCode::SUCCESS;
49}
50
51
52StatusCode MonitorThreadOccupancy::postProcess(float weight) {
53 uint64_t lowTimestamp = std::numeric_limits<uint64_t>::max();
54 uint64_t highTimestamp = 0;
55 for (const auto& nameCounterPair : m_counters) {
56 const CounterThread* ptr = dynamic_cast<const CounterThread*>(nameCounterPair.second.get());
57 lowTimestamp = std::min(lowTimestamp, ptr->getLowTimestamp());
58 highTimestamp = std::max(highTimestamp, ptr->getHighTimestamp());
59 }
60 for (auto& nameCounterPair : m_counters) {
61 CounterThread* ptr = dynamic_cast<CounterThread*>(nameCounterPair.second.get());
62 ptr->setAllThreadsTimestamps(lowTimestamp, highTimestamp);
63 ATH_CHECK( ptr->postProcess(weight) );
64 }
65 return StatusCode::SUCCESS;
66}
67
68
69std::unique_ptr<CounterBase> MonitorThreadOccupancy::newCounter(const std::string& name) {
70 return std::make_unique<CounterThread>(name, this);
71}
#define ATH_CHECK
Evaluate an expression and check for errors.
#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.