ATLAS Offline Software
HiveExSvc.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #include "HiveExSvc.h"
6 #include "GaudiKernel/ISvcLocator.h"
7 #include "GaudiKernel/ConcurrencyFlags.h"
8 #include "GaudiKernel/EventContext.h"
9 
10 #include <map>
11 
12 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
13 
14 HiveExSvc::HiveExSvc(const std::string& name, ISvcLocator* svc)
15  : base_class( name, svc ) {}
16 
17 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
18 
20 
21 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
22 
25 
26  size_t nslots = Gaudi::Concurrency::ConcurrencyFlags::numConcurrentEvents();
27  if (nslots == 0) {
28  nslots = 1;
29  }
30 
31  ATH_MSG_INFO("initialize structures of size " << nslots);
32 
33  // initialize the structures with the number of concurrent events
34  m_times.resize( nslots );
35  m_locks.resize( nslots );
36  for ( auto & m : m_locks ) {
37  m = std::make_unique<std::mutex>();
38  }
39 
40  return StatusCode::SUCCESS;
41 }
42 
43 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
44 
47  ATH_MSG_INFO("finalize");
48 
49  // calculate the standard deviation of the sleep times
50  std::map<std::string,unsigned int> sum;
51  std::map<std::string,unsigned int> sumSq;
52  std::map<std::string,unsigned int> num;
53 
54  for (const auto &ve : m_times) {
55  for (const auto &e : ve) {
56  sum[e.algName] += e.sleep_time;
57  sumSq[e.algName] += e.sleep_time * e.sleep_time;
58  num[e.algName] ++;
59  }
60  }
61 
62  info() << "listing timing by alg:";
63  for (const auto &s : sum) {
64  float avg = s.second/num[s.first];
65  float sig = sqrt( ( sumSq[s.first] - 2*s.second*avg + num[s.first]*avg*avg )/(num[s.first]) );
66  info() << "\n " << s.first
67  << " avg: " << avg << " sig: " << sig;
68  }
69  info() << endmsg;
70 
71  return StatusCode::SUCCESS;
72 }
73 
74 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
75 
76 void
77 HiveExSvc::add(const std::string& algName, const unsigned int& time) {
78 
79  // even though we have separate data structures per concurrent
80  // event (slot), we can't be sure that multiple threads aren't
81  // processing the same slot at the same time, so need to lock the mutex.
82  // this reduces the waiting for a lock, compared with locking the
83  // whole structure, as it's unlikely that we'll have the same Alg in
84  // different concurrent events executing at the same time.
85 
86  // for a true lock-free design, we would need a separate container for
87  // each Algorithm in each slot
88 
89  EventContext::ContextID_t slot = Gaudi::Hive::currentContextId();
90  std::lock_guard<std::mutex> lock ( *m_locks[slot] );
91  m_times[slot].push_back( tDat(algName, time) );
92 }
93 
grepfile.info
info
Definition: grepfile.py:38
AllowedVariables::e
e
Definition: AsgElectronSelectorTool.cxx:37
HiveExSvc::initialize
virtual StatusCode initialize() override
Definition: HiveExSvc.cxx:24
HiveExSvc::HiveExSvc
HiveExSvc(const std::string &name, ISvcLocator *svc)
Definition: HiveExSvc.cxx:14
python.SystemOfUnits.s
int s
Definition: SystemOfUnits.py:131
python.SystemOfUnits.m
int m
Definition: SystemOfUnits.py:91
HiveExSvc::tDat
Definition: HiveExSvc.h:38
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
xAOD::JetAlgorithmType::algName
const std::string & algName(ID id)
Converts a JetAlgorithmType::ID into a string.
Definition: JetContainerInfo.cxx:67
HiveExSvc::m_times
std::vector< std::list< tDat > > m_times
Definition: HiveExSvc.h:45
HiveExSvc::m_locks
std::vector< std::unique_ptr< std::mutex > > m_locks
Definition: HiveExSvc.h:49
convertTimingResiduals.sum
sum
Definition: convertTimingResiduals.py:55
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
Recovery.avg
def avg(a, b)
Definition: Recovery.py:79
python.BuildSignatureFlags.sig
sig
Definition: BuildSignatureFlags.py:218
HiveExSvc.h
Simple service that accumulates timings for Algorithms by name.
Handler::svc
AthROOTErrorHandlerSvc * svc
Definition: AthROOTErrorHandlerSvc.cxx:10
trigbs_pickEvents.num
num
Definition: trigbs_pickEvents.py:76
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
HiveExSvc::~HiveExSvc
virtual ~HiveExSvc()
Definition: HiveExSvc.cxx:19
HiveExSvc::add
virtual void add(const std::string &, const unsigned int &) override
Definition: HiveExSvc.cxx:77
CaloSwCorrections.time
def time(flags, cells_name, *args, **kw)
Definition: CaloSwCorrections.py:242
HiveExSvc::finalize
virtual StatusCode finalize() override
Definition: HiveExSvc.cxx:46