ATLAS Offline Software
Public Member Functions | Public Attributes | Protected Attributes | Private Attributes | List of all members
MonitorThreadOccupancy Class Reference

Concrete implementation of Monitor to monitor utilisation of individual threads in a MT job. More...

#include <MonitorThreadOccupancy.h>

Inheritance diagram for MonitorThreadOccupancy:
Collaboration diagram for MonitorThreadOccupancy:

Public Member Functions

 MonitorThreadOccupancy ()=delete
 Forbid default constructor. More...
 
 MonitorThreadOccupancy (const std::string &name, const MonitoredRange *parent)
 Construct monitor. More...
 
virtual ~MonitorThreadOccupancy ()=default
 Default destructor. More...
 
MonitorThreadOccupancyoperator= (const MonitorThreadOccupancy &)=delete
 Forbid assignment. More...
 
 MonitorThreadOccupancy (const MonitorThreadOccupancy &)=delete
 Forbid copy. More...
 
virtual StatusCode newEvent (const CostData &data, const float weight=1.) override
 Concrete dispatch method. More...
 
virtual std::unique_ptr< CounterBasenewCounter (const std::string &name) override
 Concrete counter instantiation. More...
 
StatusCode postProcess (float weight)
 Get the global start and stop timestamps over all threads and sync these to the individual threads. More...
 
const std::string & getName () const
 Getter for Monitor's name. More...
 
const MonitoredRangegetParent () const
 Return cached non-owning const ptr to this Monitor's parent Range. More...
 
TH1 * bookGetPointer (TH1 *hist, const std::string &tDir="") const
 Appends Monitor name (to histogram path) and forwards histogram book request to parent Range. More...
 
bool counterExists (const std::string &name) const
 Check if a counter of a given name exists. More...
 
CounterBasegetCounter (const std::string &name)
 Retrieve counter by name. More...
 
virtual StatusCode endEvent (float weight=1.)
 Called by the framework. More...
 
MsgStream & msg ()
 Logging. More...
 
MsgStream & msg (const MSG::Level lvl)
 Logging on a given level. More...
 
bool msgLvl (const MSG::Level lvl)
 Returns if requested level is same or higher than logging level. More...
 

Public Attributes

std::unordered_map< uint32_t, std::string > m_threadToCounterMap
 Map thread's hash ID to a counting numeral embedded in a string. More...
 
size_t m_threadCounter
 Count how many unique thread ID we have seen. More...
 

Protected Attributes

std::unordered_map< std::string, std::unique_ptr< CounterBase > > m_counters
 Storage of Monitor's collection of Counters. More...
 
MsgStream m_msgStream
 Logging member. More...
 

Private Attributes

const std::string m_name
 Monitor's name. More...
 
const MonitoredRangem_parent
 Monitor's parent Range. More...
 

Detailed Description

Concrete implementation of Monitor to monitor utilisation of individual threads in a MT job.

Definition at line 14 of file MonitorThreadOccupancy.h.

Constructor & Destructor Documentation

◆ MonitorThreadOccupancy() [1/3]

MonitorThreadOccupancy::MonitorThreadOccupancy ( )
delete

Forbid default constructor.

◆ MonitorThreadOccupancy() [2/3]

MonitorThreadOccupancy::MonitorThreadOccupancy ( const std::string &  name,
const MonitoredRange parent 
)

Construct monitor.

Parameters
[in]nameMonitor's name
[in]parentMonitor's parent Range, cached non-owning pointer.

Definition at line 8 of file MonitorThreadOccupancy.cxx.

◆ ~MonitorThreadOccupancy()

virtual MonitorThreadOccupancy::~MonitorThreadOccupancy ( )
virtualdefault

Default destructor.

◆ MonitorThreadOccupancy() [3/3]

MonitorThreadOccupancy::MonitorThreadOccupancy ( const MonitorThreadOccupancy )
delete

Forbid copy.

Member Function Documentation

◆ bookGetPointer()

TH1 * MonitorBase::bookGetPointer ( TH1 *  hist,
const std::string &  tDir = "" 
) const
inherited

Appends Monitor name (to histogram path) and forwards histogram book request to parent Range.

Parameters
[in]histBare pointer to histogram. Ownership transferred to THistSvc.
[in]tDirHistogram name & directory.
Returns
Cached pointer to histogram. Used to fill histogram without having to perform THishSvc lookup.

Definition at line 37 of file Trigger/TrigCost/TrigCostAnalysis/src/MonitorBase.cxx.

37  {
38  std::string dir = getName();
39  if (tDir != "") {
40  dir += "/";
41  dir += tDir;
42  }
43  return getParent()->bookGetPointer(hist, dir);
44 }

◆ counterExists()

bool MonitorBase::counterExists ( const std::string &  name) const
inherited

Check if a counter of a given name exists.

Parameters
[in]nameName of Counter.
Returns
True if counter already exists.

Definition at line 47 of file Trigger/TrigCost/TrigCostAnalysis/src/MonitorBase.cxx.

47  {
48  return (m_counters.count(name) == 1);
49 }

◆ endEvent()

StatusCode MonitorBase::endEvent ( float  weight = 1.)
virtualinherited

Called by the framework.

Causes per-Event Variables to fill their histograms with their accumulated data.

Definition at line 29 of file Trigger/TrigCost/TrigCostAnalysis/src/MonitorBase.cxx.

29  {
30  for (auto& nameCounterPair : m_counters ) {
31  ATH_CHECK( nameCounterPair.second->endEvent(weight) );
32  }
33  return StatusCode::SUCCESS;
34 }

◆ getCounter()

CounterBase * MonitorBase::getCounter ( const std::string &  name)
inherited

Retrieve counter by name.

If no such counter exists, a new one will be instanced and returned.

Parameters
[in]nameName of Counter.
Returns
Mutable base-class pointer to Counter.

Definition at line 52 of file Trigger/TrigCost/TrigCostAnalysis/src/MonitorBase.cxx.

52  {
53  auto it = m_counters.find(name);
54  if (it != m_counters.end()) {
55  return it->second.get();
56  }
57  // If no counter exists, then we make a new one on the fly & return it.
58  auto result = m_counters.insert( std::make_pair(name, newCounter(name)) ); // newCounter is specialised
59  it = result.first;
60  return it->second.get();
61 }

◆ getName()

const std::string & MonitorBase::getName ( ) const
inherited

Getter for Monitor's name.

Returns
Counter's name const string reference.

Definition at line 19 of file Trigger/TrigCost/TrigCostAnalysis/src/MonitorBase.cxx.

19  {
20  return m_name;
21 }

◆ getParent()

const MonitoredRange * MonitorBase::getParent ( ) const
inherited

Return cached non-owning const ptr to this Monitor's parent Range.

Returns
Cached pointer parent Range.

Definition at line 24 of file Trigger/TrigCost/TrigCostAnalysis/src/MonitorBase.cxx.

24  {
25  return m_parent;
26 }

◆ msg() [1/2]

MsgStream & MonitorBase::msg ( )
inherited

Logging.

Returns
Message stream reference.

Definition at line 64 of file Trigger/TrigCost/TrigCostAnalysis/src/MonitorBase.cxx.

64  {
65  return m_msgStream;
66 }

◆ msg() [2/2]

MsgStream & MonitorBase::msg ( const MSG::Level  lvl)
inherited

Logging on a given level.

Parameters
[in]lvlVerbosity level
Returns
Message stream reference.

Definition at line 68 of file Trigger/TrigCost/TrigCostAnalysis/src/MonitorBase.cxx.

68  {
69  return m_msgStream << lvl;
70 }

◆ msgLvl()

bool MonitorBase::msgLvl ( const MSG::Level  lvl)
inherited

Returns if requested level is same or higher than logging level.

Parameters
[in]lvlVerbosity level
Returns
If requested level is same or higher than logging level

Definition at line 72 of file Trigger/TrigCost/TrigCostAnalysis/src/MonitorBase.cxx.

72  {
73  return lvl >= m_msgStream.level();
74 }

◆ newCounter()

std::unique_ptr< CounterBase > MonitorThreadOccupancy::newCounter ( const std::string &  name)
overridevirtual

Concrete counter instantiation.

Mints named counter of CounterThread type.

Parameters
[in]nameName of Counter to mint.
Returns
Owning unique ptr object typed on the CounterBase base class which points to concrete Counter of specialised type.

Implements MonitorBase.

Definition at line 69 of file MonitorThreadOccupancy.cxx.

69  {
70  return std::make_unique<CounterThread>(name, this);
71 }

◆ newEvent()

StatusCode MonitorThreadOccupancy::newEvent ( const CostData data,
const float  weight = 1. 
)
overridevirtual

Concrete dispatch method.

Iterate over all Algorithms in event data and dispatch to owned Counters

Parameters
[in]dataAccess to event data
[in]weightGlobal event weight

Implements MonitorBase.

Definition at line 14 of file MonitorThreadOccupancy.cxx.

14  {
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 
46 
47 
48  return StatusCode::SUCCESS;
49 }

◆ operator=()

MonitorThreadOccupancy& MonitorThreadOccupancy::operator= ( const MonitorThreadOccupancy )
delete

Forbid assignment.

◆ postProcess()

StatusCode MonitorThreadOccupancy::postProcess ( float  weight)

Get the global start and stop timestamps over all threads and sync these to the individual threads.

Definition at line 52 of file MonitorThreadOccupancy.cxx.

52  {
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 }

Member Data Documentation

◆ m_counters

std::unordered_map< std::string, std::unique_ptr<CounterBase> > MonitorBase::m_counters
protectedinherited

Storage of Monitor's collection of Counters.

Keyed by name.

Definition at line 138 of file Trigger/TrigCost/TrigCostAnalysis/src/MonitorBase.h.

◆ m_msgStream

MsgStream MonitorBase::m_msgStream
protectedinherited

Logging member.

Definition at line 140 of file Trigger/TrigCost/TrigCostAnalysis/src/MonitorBase.h.

◆ m_name

const std::string MonitorBase::m_name
privateinherited

Monitor's name.

Definition at line 144 of file Trigger/TrigCost/TrigCostAnalysis/src/MonitorBase.h.

◆ m_parent

const MonitoredRange* MonitorBase::m_parent
privateinherited

Monitor's parent Range.

Cached non-owning const ptr.

Definition at line 145 of file Trigger/TrigCost/TrigCostAnalysis/src/MonitorBase.h.

◆ m_threadCounter

size_t MonitorThreadOccupancy::m_threadCounter

Count how many unique thread ID we have seen.

Definition at line 63 of file MonitorThreadOccupancy.h.

◆ m_threadToCounterMap

std::unordered_map<uint32_t, std::string> MonitorThreadOccupancy::m_threadToCounterMap

Map thread's hash ID to a counting numeral embedded in a string.

Definition at line 62 of file MonitorThreadOccupancy.h.


The documentation for this class was generated from the following files:
data
char data[hepevt_bytes_allocation_ATLAS]
Definition: HepEvt.cxx:11
MonitorThreadOccupancy::newEvent
virtual StatusCode newEvent(const CostData &data, const float weight=1.) override
Concrete dispatch method.
Definition: MonitorThreadOccupancy.cxx:14
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
get_generator_info.result
result
Definition: get_generator_info.py:21
MonitoredRange::bookGetPointer
TH1 * bookGetPointer(TH1 *hist, const std::string &tDir="") const
Appends Range's name (to histogram path) and forwards histogram book request to parent Athena algorit...
Definition: MonitoredRange.cxx:34
max
#define max(a, b)
Definition: cfImp.cxx:41
xAOD::uint32_t
setEventNumber uint32_t
Definition: EventInfo_v1.cxx:127
MonitorBase::m_name
const std::string m_name
Monitor's name.
Definition: Trigger/TrigCost/TrigCostAnalysis/src/MonitorBase.h:144
plotmaker.hist
hist
Definition: plotmaker.py:148
MonitorBase::newCounter
virtual std::unique_ptr< CounterBase > newCounter(const std::string &name)=0
Pure virtual Counter instantiation specialisation.
MonitorBase::m_msgStream
MsgStream m_msgStream
Logging member.
Definition: Trigger/TrigCost/TrigCostAnalysis/src/MonitorBase.h:140
skel.it
it
Definition: skel.GENtoEVGEN.py:396
CounterThread
Concrete implimentation of Counter to monitor all algorithms executing on a single thread.
Definition: CounterThread.h:14
dbg::ptr
void * ptr(T *p)
Definition: SGImplSvc.cxx:74
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:62
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:52
dqt_zlumi_pandas.weight
int weight
Definition: dqt_zlumi_pandas.py:189
MonitorBase::getParent
const MonitoredRange * getParent() const
Return cached non-owning const ptr to this Monitor's parent Range.
Definition: Trigger/TrigCost/TrigCostAnalysis/src/MonitorBase.cxx:24
MonitorBase::m_parent
const MonitoredRange * m_parent
Monitor's parent Range.
Definition: Trigger/TrigCost/TrigCostAnalysis/src/MonitorBase.h:145
MonitorBase::getCounter
CounterBase * getCounter(const std::string &name)
Retrieve counter by name.
Definition: Trigger/TrigCost/TrigCostAnalysis/src/MonitorBase.cxx:52
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
MonitorBase::getName
const std::string & getName() const
Getter for Monitor's name.
Definition: Trigger/TrigCost/TrigCostAnalysis/src/MonitorBase.cxx:19
test_pyathena.parent
parent
Definition: test_pyathena.py:15
MonitorBase::MonitorBase
MonitorBase()=delete
Forbid default constructor.
xAOD::uint64_t
uint64_t
Definition: EventInfo_v1.cxx:123
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
xAOD::TrigComposite_v1
Class used to describe composite objects in the HLT.
Definition: TrigComposite_v1.h:52
beamspotman.dir
string dir
Definition: beamspotman.py:623
min
#define min(a, b)
Definition: cfImp.cxx:40
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
MonitorThreadOccupancy::m_threadCounter
size_t m_threadCounter
Count how many unique thread ID we have seen.
Definition: MonitorThreadOccupancy.h:63