CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Private Member Functions | Private Attributes
edm::service::ConcurrentModuleTimer Class Reference

Public Member Functions

 ConcurrentModuleTimer (edm::ParameterSet const &iConfig, edm::ActivityRegistry &iAR)
 
 ~ConcurrentModuleTimer ()
 

Private Member Functions

void start ()
 
void stop ()
 

Private Attributes

unsigned int m_nModules
 
unsigned int m_nTimeSums
 
std::atomic< bool > m_spinLock
 
bool m_startedTiming
 
std::chrono::high_resolution_clock::time_point m_time
 
std::unique_ptr< std::atomic
< std::chrono::high_resolution_clock::rep >[]> 
m_timeSums
 

Detailed Description

Definition at line 28 of file ConcurrentModuleTimer.cc.

Constructor & Destructor Documentation

ConcurrentModuleTimer::ConcurrentModuleTimer ( edm::ParameterSet const &  iConfig,
edm::ActivityRegistry iAR 
)

Definition at line 63 of file ConcurrentModuleTimer.cc.

63  :
64 m_time(),
65 m_nModules(0),
66 m_spinLock{false},
67 m_startedTiming(false)
68 {
69  iReg.watchPreModuleEvent([this](StreamContext const&, ModuleCallingContext const&){
70  start();
71  });
72  iReg.watchPostModuleEvent([this](StreamContext const&, ModuleCallingContext const&){
73  stop();
74  });
75 
76  iReg.watchPreModuleEventDelayedGet([this](StreamContext const&, ModuleCallingContext const& iContext){
77  if(iContext.state() == ModuleCallingContext::State::kRunning) {
78  stop();
79  }
80  });
81  iReg.watchPostModuleEventDelayedGet([this](StreamContext const&, ModuleCallingContext const& iContext){
82  if(iContext.state() == ModuleCallingContext::State::kRunning) {
83  start();
84  }
85  });
86 
87  iReg.watchPreallocate([this](edm::service::SystemBounds const& iBounds){
88  m_nTimeSums =iBounds.maxNumberOfThreads()+1;
89  m_timeSums.reset(new std::atomic<std::chrono::high_resolution_clock::rep>[m_nTimeSums]);
90  for(unsigned int i=0; i<m_nTimeSums;++i) {
91  m_timeSums[i]=0;
92  }
93  });
94 
95  iReg.watchPreSourceEvent([this](StreamID){
96  if(not m_startedTiming) {
98  m_startedTiming=true;
99  }
100  start();
101  });
102  iReg.watchPostSourceEvent([this](StreamID){
103  stop();
104  });
105 }
unsigned int maxNumberOfThreads() const
Definition: SystemBounds.h:46
int i
Definition: DBlmapReader.cc:9
std::chrono::high_resolution_clock::time_point m_time
std::unique_ptr< std::atomic< std::chrono::high_resolution_clock::rep >[]> m_timeSums
ConcurrentModuleTimer::~ConcurrentModuleTimer ( )

Definition at line 107 of file ConcurrentModuleTimer.cc.

References gather_cfg::cout, i, m_nTimeSums, and m_timeSums.

107  {
108 
109  std::cout <<"Fraction of time running n Modules simultaneously"<<std::endl;
110  for (unsigned int i=0; i<m_nTimeSums; ++i) {
111  std::cout <<i<<" "<<m_timeSums[i]/double(m_timeSums[0])<<" "<<m_timeSums[i]<<std::endl;
112  }
113 
114 }
int i
Definition: DBlmapReader.cc:9
tuple cout
Definition: gather_cfg.py:145
std::unique_ptr< std::atomic< std::chrono::high_resolution_clock::rep >[]> m_timeSums

Member Function Documentation

void ConcurrentModuleTimer::start ( void  )
private

Definition at line 137 of file ConcurrentModuleTimer.cc.

References assert(), mps_update::diff, i, m_nModules, m_spinLock, m_time, m_timeSums, and fileCollector::now.

Referenced by progressbar.ProgressBar::__next__().

138 {
139  auto const newTime =std::chrono::high_resolution_clock::now();
140  std::chrono::high_resolution_clock::time_point oldTime;
141  bool expected = false;
142  unsigned int nModules;
143  while (not m_spinLock.compare_exchange_strong(expected,true,std::memory_order_acq_rel)){
144  expected = false;
145  }
146  {
147  oldTime = m_time;
148  m_time = newTime;
149  nModules = ++m_nModules;
150  m_spinLock.store(false,std::memory_order_release);
151  }
152  assert(nModules <m_nTimeSums);
153  auto diff = newTime - oldTime;
154  for(unsigned int i=0;i<nModules;++i) {
155  m_timeSums[i].fetch_add(diff.count());
156  }
157 }
int i
Definition: DBlmapReader.cc:9
assert(m_qm.get())
list diff
Definition: mps_update.py:85
std::chrono::high_resolution_clock::time_point m_time
std::unique_ptr< std::atomic< std::chrono::high_resolution_clock::rep >[]> m_timeSums
void ConcurrentModuleTimer::stop ( )
private

Definition at line 160 of file ConcurrentModuleTimer.cc.

References assert(), mps_update::diff, i, m_nModules, m_spinLock, m_time, m_timeSums, and fileCollector::now.

161 {
162  auto const newTime =std::chrono::high_resolution_clock::now();
163  std::chrono::high_resolution_clock::time_point oldTime;
164  bool expected = false;
165  unsigned int nModules;
166  while (not m_spinLock.compare_exchange_weak(expected,true,std::memory_order_acq_rel)){
167  expected = false;
168  }
169  {
170  oldTime = m_time;
171  m_time = newTime;
172  nModules = m_nModules--;
173  m_spinLock.store(false,std::memory_order_release);
174  }
175  assert(nModules <m_nTimeSums);
176  auto diff = newTime - oldTime;
177  for(unsigned int i=0;i<=nModules;++i) {
178  m_timeSums[i].fetch_add(diff.count());
179  }
180 }
int i
Definition: DBlmapReader.cc:9
assert(m_qm.get())
list diff
Definition: mps_update.py:85
std::chrono::high_resolution_clock::time_point m_time
std::unique_ptr< std::atomic< std::chrono::high_resolution_clock::rep >[]> m_timeSums

Member Data Documentation

unsigned int edm::service::ConcurrentModuleTimer::m_nModules
private

Definition at line 40 of file ConcurrentModuleTimer.cc.

Referenced by start(), and stop().

unsigned int edm::service::ConcurrentModuleTimer::m_nTimeSums
private

Definition at line 39 of file ConcurrentModuleTimer.cc.

Referenced by ~ConcurrentModuleTimer().

std::atomic<bool> edm::service::ConcurrentModuleTimer::m_spinLock
private

Definition at line 41 of file ConcurrentModuleTimer.cc.

Referenced by start(), and stop().

bool edm::service::ConcurrentModuleTimer::m_startedTiming
private

Definition at line 42 of file ConcurrentModuleTimer.cc.

std::chrono::high_resolution_clock::time_point edm::service::ConcurrentModuleTimer::m_time
private

Definition at line 38 of file ConcurrentModuleTimer.cc.

Referenced by start(), and stop().

std::unique_ptr<std::atomic<std::chrono::high_resolution_clock::rep>[]> edm::service::ConcurrentModuleTimer::m_timeSums
private

Definition at line 37 of file ConcurrentModuleTimer.cc.

Referenced by start(), stop(), and ~ConcurrentModuleTimer().