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 27 of file ConcurrentModuleTimer.cc.

Constructor & Destructor Documentation

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

Definition at line 62 of file ConcurrentModuleTimer.cc.

62  :
63 m_time(),
64 m_nModules(0),
65 m_spinLock{false},
66 m_startedTiming(false)
67 {
68  iReg.watchPreModuleEvent([this](StreamContext const&, ModuleCallingContext const&){
69  start();
70  });
71  iReg.watchPostModuleEvent([this](StreamContext const&, ModuleCallingContext const&){
72  stop();
73  });
74 
75  iReg.watchPreModuleEventDelayedGet([this](StreamContext const&, ModuleCallingContext const&){
76  stop();
77  });
78  iReg.watchPostModuleEventDelayedGet([this](StreamContext const&, ModuleCallingContext const&){
79  start();
80  });
81 
82  iReg.watchPreallocate([this](edm::service::SystemBounds const& iBounds){
83  m_nTimeSums =iBounds.maxNumberOfThreads()+1;
84  m_timeSums.reset(new std::atomic<std::chrono::high_resolution_clock::rep>[m_nTimeSums]);
85  for(unsigned int i=0; i<m_nTimeSums;++i) {
86  m_timeSums[i]=0;
87  }
88  });
89 
90  iReg.watchPreSourceEvent([this](StreamID){
91  if(not m_startedTiming) {
93  m_startedTiming=true;
94  }
95  start();
96  });
97  iReg.watchPostSourceEvent([this](StreamID){
98  stop();
99  });
100 }
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 102 of file ConcurrentModuleTimer.cc.

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

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

Member Function Documentation

void ConcurrentModuleTimer::start ( void  )
private

Definition at line 132 of file ConcurrentModuleTimer.cc.

References diffTreeTool::diff, i, m_nModules, m_spinLock, m_time, m_timeSums, and cmsPerfSuiteHarvest::now.

Referenced by progressbar.ProgressBar::__next__().

133 {
134  auto const newTime =std::chrono::high_resolution_clock::now();
135  std::chrono::high_resolution_clock::time_point oldTime;
136  bool expected = false;
137  unsigned int nModules;
138  while (not m_spinLock.compare_exchange_strong(expected,true,std::memory_order_acq_rel)){
139  expected = false;
140  }
141  {
142  oldTime = m_time;
143  m_time = newTime;
144  nModules = ++m_nModules;
145  m_spinLock.store(false,std::memory_order_release);
146  }
147  assert(nModules <m_nTimeSums);
148  auto diff = newTime - oldTime;
149  for(unsigned int i=0;i<nModules;++i) {
150  m_timeSums[i].fetch_add(diff.count());
151  }
152 }
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
void ConcurrentModuleTimer::stop ( )
private

Definition at line 155 of file ConcurrentModuleTimer.cc.

References diffTreeTool::diff, i, m_nModules, m_spinLock, m_time, m_timeSums, and cmsPerfSuiteHarvest::now.

156 {
157  auto const newTime =std::chrono::high_resolution_clock::now();
158  std::chrono::high_resolution_clock::time_point oldTime;
159  bool expected = false;
160  unsigned int nModules;
161  while (not m_spinLock.compare_exchange_weak(expected,true,std::memory_order_acq_rel)){
162  expected = false;
163  }
164  {
165  oldTime = m_time;
166  m_time = newTime;
167  nModules = m_nModules--;
168  m_spinLock.store(false,std::memory_order_release);
169  }
170  assert(nModules <m_nTimeSums);
171  auto diff = newTime - oldTime;
172  for(unsigned int i=0;i<=nModules;++i) {
173  m_timeSums[i].fetch_add(diff.count());
174  }
175 }
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

Member Data Documentation

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

Definition at line 39 of file ConcurrentModuleTimer.cc.

Referenced by start(), and stop().

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

Definition at line 38 of file ConcurrentModuleTimer.cc.

Referenced by ~ConcurrentModuleTimer().

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

Definition at line 40 of file ConcurrentModuleTimer.cc.

Referenced by start(), and stop().

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

Definition at line 41 of file ConcurrentModuleTimer.cc.

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

Definition at line 37 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 36 of file ConcurrentModuleTimer.cc.

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