CMS 3D CMS Logo

List of all members | Public Member Functions | Static 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 ()
 

Static Public Member Functions

static void fillDescriptions (edm::ConfigurationDescriptions &descriptions)
 

Private Member Functions

void start ()
 
void stop ()
 
bool trackModule (ModuleCallingContext const &iContext) const
 

Private Attributes

std::vector< unsigned int > m_excludedModuleIds
 
bool m_excludeSource
 
std::vector< std::string > m_modulesToExclude
 
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 29 of file ConcurrentModuleTimer.cc.

Constructor & Destructor Documentation

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

Definition at line 68 of file ConcurrentModuleTimer.cc.

References mps_fire::i, edm::ModuleDescription::id(), edm::ModuleCallingContext::kRunning, m_excludedModuleIds, m_excludeSource, m_modulesToExclude, m_nTimeSums, m_startedTiming, m_time, m_timeSums, edm::service::SystemBounds::maxNumberOfThreads(), edm::ModuleDescription::moduleLabel(), dataset::name, cmsPerfSuiteHarvest::now, start(), edm::ModuleCallingContext::state(), stop(), and trackModule().

68  :
69 m_modulesToExclude(iConfig.getUntrackedParameter<std::vector<std::string>>("modulesToExclude")),
70 m_time(),
71 m_nModules(0),
72 m_spinLock{false},
73 m_startedTiming(false),
74 m_excludeSource(iConfig.getUntrackedParameter<bool>("excludeSource"))
75 {
76  if(not m_modulesToExclude.empty()) {
77  iReg.watchPreModuleConstruction( [this](ModuleDescription const& iMod) {
78  for(auto const& name: m_modulesToExclude) {
79  if( iMod.moduleLabel() == name) {
80  m_excludedModuleIds.push_back(iMod.id());
81  break;
82  }
83  }
84  });
85  iReg.watchPreModuleEvent([this](StreamContext const&, ModuleCallingContext const& iContext){
86  if(trackModule(iContext)) {
87  start();
88  }
89  });
90  iReg.watchPostModuleEvent([this](StreamContext const&, ModuleCallingContext const& iContext){
91  if(trackModule(iContext)) {
92  stop();
93  }
94  });
95 
96  iReg.watchPreModuleEventDelayedGet([this](StreamContext const&, ModuleCallingContext const& iContext){
97  if(trackModule(iContext)) {
98  if(iContext.state() == ModuleCallingContext::State::kRunning) {
99  stop();
100  }
101  }
102  });
103  iReg.watchPostModuleEventDelayedGet([this](StreamContext const&, ModuleCallingContext const& iContext){
104  if(trackModule(iContext)) {
105  if(iContext.state() == ModuleCallingContext::State::kRunning) {
106  start();
107  }
108  }
109  });
110 
111  } else {
112  //apply to all modules so can use faster version
113  iReg.watchPreModuleEvent([this](StreamContext const&, ModuleCallingContext const&){
114  start();
115  });
116  iReg.watchPostModuleEvent([this](StreamContext const&, ModuleCallingContext const&){
117  stop();
118  });
119 
120  iReg.watchPreModuleEventDelayedGet([this](StreamContext const&, ModuleCallingContext const& iContext){
121  if(iContext.state() == ModuleCallingContext::State::kRunning) {
122  stop();
123  }
124  });
125  iReg.watchPostModuleEventDelayedGet([this](StreamContext const&, ModuleCallingContext const& iContext){
126  if(iContext.state() == ModuleCallingContext::State::kRunning) {
127  start();
128  }
129  });
130  }
131 
132  iReg.watchPreallocate([this](edm::service::SystemBounds const& iBounds){
133  m_nTimeSums =iBounds.maxNumberOfThreads()+1;
134  m_timeSums.reset(new std::atomic<std::chrono::high_resolution_clock::rep>[m_nTimeSums]);
135  for(unsigned int i=0; i<m_nTimeSums;++i) {
136  m_timeSums[i]=0;
137  }
138  });
139 
140  iReg.watchPreSourceEvent([this](StreamID){
141  if(not m_startedTiming) {
143  m_startedTiming=true;
144  }
145  if(not m_excludeSource) {
146  start();
147  }
148  });
149  if(not m_excludeSource) {
150  iReg.watchPostSourceEvent([this](StreamID){
151  stop();
152  });
153  }
154 }
unsigned int maxNumberOfThreads() const
Definition: SystemBounds.h:46
std::vector< std::string > m_modulesToExclude
std::chrono::high_resolution_clock::time_point m_time
std::vector< unsigned int > m_excludedModuleIds
bool trackModule(ModuleCallingContext const &iContext) const
std::unique_ptr< std::atomic< std::chrono::high_resolution_clock::rep >[]> m_timeSums
ConcurrentModuleTimer::~ConcurrentModuleTimer ( )

Definition at line 156 of file ConcurrentModuleTimer.cc.

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

156  {
157 
158  std::cout <<"Fraction of time running n Modules simultaneously"<<std::endl;
159  for (unsigned int i=0; i<m_nTimeSums; ++i) {
160  std::cout <<i<<" "<<m_timeSums[i]/double(m_timeSums[0])<<" "<<m_timeSums[i]<<std::endl;
161  }
162 
163 }
std::unique_ptr< std::atomic< std::chrono::high_resolution_clock::rep >[]> m_timeSums

Member Function Documentation

void ConcurrentModuleTimer::fillDescriptions ( edm::ConfigurationDescriptions descriptions)
static

Definition at line 250 of file ConcurrentModuleTimer.cc.

References edm::ConfigurationDescriptions::add(), edm::ParameterSetDescription::addUntracked(), and DEFINE_FWK_SERVICE.

251 {
253  desc.addUntracked<std::vector<std::string> >("modulesToExclude", std::vector<std::string>{})->setComment("Module labels to exclude from the timing measurements");
254  desc.addUntracked<bool>("excludeSource",false)->setComment("Exclude the time the source is running");
255  descriptions.add("ConcurrentModuleTimer", desc);
256 }
ParameterDescriptionBase * addUntracked(U const &iLabel, T const &value)
void add(std::string const &label, ParameterSetDescription const &psetDescription)
void ConcurrentModuleTimer::start ( void  )
private

Definition at line 186 of file ConcurrentModuleTimer.cc.

References mps_update::diff, mps_fire::i, m_nModules, m_nTimeSums, m_spinLock, m_time, m_timeSums, and cmsPerfSuiteHarvest::now.

Referenced by progressbar.ProgressBar::__next__(), and ConcurrentModuleTimer().

187 {
188  auto const newTime =std::chrono::high_resolution_clock::now();
189  std::chrono::high_resolution_clock::time_point oldTime;
190  bool expected = false;
191  unsigned int nModules;
192  while (not m_spinLock.compare_exchange_strong(expected,true,std::memory_order_acq_rel)){
193  expected = false;
194  }
195  {
196  oldTime = m_time;
197  m_time = newTime;
198  nModules = ++m_nModules;
199  m_spinLock.store(false,std::memory_order_release);
200  }
201  assert(nModules <m_nTimeSums);
202  auto diff = newTime - oldTime;
203  for(unsigned int i=0;i<nModules;++i) {
204  m_timeSums[i].fetch_add(diff.count());
205  }
206 }
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 209 of file ConcurrentModuleTimer.cc.

References mps_update::diff, mps_fire::i, m_nModules, m_nTimeSums, m_spinLock, m_time, m_timeSums, and cmsPerfSuiteHarvest::now.

Referenced by ConcurrentModuleTimer().

210 {
211  auto const newTime =std::chrono::high_resolution_clock::now();
212  std::chrono::high_resolution_clock::time_point oldTime;
213  bool expected = false;
214  unsigned int nModules;
215  while (not m_spinLock.compare_exchange_weak(expected,true,std::memory_order_acq_rel)){
216  expected = false;
217  }
218  {
219  oldTime = m_time;
220  m_time = newTime;
221  nModules = m_nModules--;
222  m_spinLock.store(false,std::memory_order_release);
223  }
224  assert(nModules <m_nTimeSums);
225  auto diff = newTime - oldTime;
226  for(unsigned int i=0;i<=nModules;++i) {
227  m_timeSums[i].fetch_add(diff.count());
228  }
229 }
std::chrono::high_resolution_clock::time_point m_time
std::unique_ptr< std::atomic< std::chrono::high_resolution_clock::rep >[]> m_timeSums
bool ConcurrentModuleTimer::trackModule ( ModuleCallingContext const &  iContext) const
private

Definition at line 235 of file ConcurrentModuleTimer.cc.

References edm::ModuleDescription::id(), m_excludedModuleIds, and edm::ModuleCallingContext::moduleDescription().

Referenced by ConcurrentModuleTimer().

236 {
237  auto modId = iContext.moduleDescription()->id();
238  for(auto const id: m_excludedModuleIds) {
239  if(modId == id) {
240  return false;
241  }
242  }
243  return true;
244 }
std::vector< unsigned int > m_excludedModuleIds

Member Data Documentation

std::vector<unsigned int> edm::service::ConcurrentModuleTimer::m_excludedModuleIds
private

Definition at line 41 of file ConcurrentModuleTimer.cc.

Referenced by ConcurrentModuleTimer(), and trackModule().

bool edm::service::ConcurrentModuleTimer::m_excludeSource
private

Definition at line 47 of file ConcurrentModuleTimer.cc.

Referenced by ConcurrentModuleTimer().

std::vector<std::string> edm::service::ConcurrentModuleTimer::m_modulesToExclude
private

Definition at line 40 of file ConcurrentModuleTimer.cc.

Referenced by ConcurrentModuleTimer().

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

Definition at line 44 of file ConcurrentModuleTimer.cc.

Referenced by start(), and stop().

unsigned int edm::service::ConcurrentModuleTimer::m_nTimeSums
private
std::atomic<bool> edm::service::ConcurrentModuleTimer::m_spinLock
private

Definition at line 45 of file ConcurrentModuleTimer.cc.

Referenced by start(), and stop().

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

Definition at line 46 of file ConcurrentModuleTimer.cc.

Referenced by ConcurrentModuleTimer().

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

Definition at line 42 of file ConcurrentModuleTimer.cc.

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

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