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 = 0
 
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 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().

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  if (not m_modulesToExclude.empty()) {
76  iReg.watchPreModuleConstruction([this](ModuleDescription const& iMod) {
77  for (auto const& name : m_modulesToExclude) {
78  if (iMod.moduleLabel() == name) {
79  m_excludedModuleIds.push_back(iMod.id());
80  break;
81  }
82  }
83  });
84  iReg.watchPreModuleEvent([this](StreamContext const&, ModuleCallingContext const& iContext) {
85  if (trackModule(iContext)) {
86  start();
87  }
88  });
89  iReg.watchPostModuleEvent([this](StreamContext const&, ModuleCallingContext const& iContext) {
90  if (trackModule(iContext)) {
91  stop();
92  }
93  });
94 
95  iReg.watchPreModuleEventDelayedGet([this](StreamContext const&, ModuleCallingContext const& iContext) {
96  if (trackModule(iContext)) {
97  if (iContext.state() == ModuleCallingContext::State::kRunning) {
98  stop();
99  }
100  }
101  });
102  iReg.watchPostModuleEventDelayedGet([this](StreamContext const&, ModuleCallingContext const& iContext) {
103  if (trackModule(iContext)) {
104  if (iContext.state() == ModuleCallingContext::State::kRunning) {
105  start();
106  }
107  }
108  });
109 
110  } else {
111  //apply to all modules so can use faster version
112  iReg.watchPreModuleEvent([this](StreamContext const&, ModuleCallingContext const&) { start(); });
113  iReg.watchPostModuleEvent([this](StreamContext const&, ModuleCallingContext const&) { stop(); });
114 
115  iReg.watchPreModuleEventDelayedGet([this](StreamContext const&, ModuleCallingContext const& iContext) {
116  if (iContext.state() == ModuleCallingContext::State::kRunning) {
117  stop();
118  }
119  });
120  iReg.watchPostModuleEventDelayedGet([this](StreamContext const&, ModuleCallingContext const& iContext) {
121  if (iContext.state() == ModuleCallingContext::State::kRunning) {
122  start();
123  }
124  });
125  }
126 
127  iReg.watchPreallocate([this](edm::service::SystemBounds const& iBounds) {
128  m_nTimeSums = iBounds.maxNumberOfThreads() + 1;
129  m_timeSums.reset(new std::atomic<std::chrono::high_resolution_clock::rep>[m_nTimeSums]);
130  for (unsigned int i = 0; i < m_nTimeSums; ++i) {
131  m_timeSums[i] = 0;
132  }
133  });
134 
135  iReg.watchPreSourceEvent([this](StreamID) {
136  if (not m_startedTiming) {
138  m_startedTiming = true;
139  }
140  if (not m_excludeSource) {
141  start();
142  }
143  });
144  if (not m_excludeSource) {
145  iReg.watchPostSourceEvent([this](StreamID) { stop(); });
146  }
147 }
unsigned int maxNumberOfThreads() const
Definition: SystemBounds.h:38
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 149 of file ConcurrentModuleTimer.cc.

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

149  {
150  std::cout << "Fraction of time running n Modules simultaneously" << std::endl;
151  for (unsigned int i = 0; i < m_nTimeSums; ++i) {
152  std::cout << i << " " << m_timeSums[i] / double(m_timeSums[0]) << " " << m_timeSums[i] << std::endl;
153  }
154 }
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 234 of file ConcurrentModuleTimer.cc.

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

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

Definition at line 176 of file ConcurrentModuleTimer.cc.

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

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

176  {
177  auto const newTime = std::chrono::high_resolution_clock::now();
178  std::chrono::high_resolution_clock::time_point oldTime;
179  bool expected = false;
180  unsigned int nModules;
181  while (not m_spinLock.compare_exchange_strong(expected, true, std::memory_order_acq_rel)) {
182  expected = false;
183  }
184  {
185  oldTime = m_time;
186  m_time = newTime;
187  nModules = ++m_nModules;
188  m_spinLock.store(false, std::memory_order_release);
189  }
190  assert(nModules < m_nTimeSums);
191  auto diff = newTime - oldTime;
192  for (unsigned int i = 0; i < nModules; ++i) {
193  m_timeSums[i].fetch_add(diff.count());
194  }
195 }
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 197 of file ConcurrentModuleTimer.cc.

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

Referenced by ConcurrentModuleTimer().

197  {
198  auto const newTime = std::chrono::high_resolution_clock::now();
199  std::chrono::high_resolution_clock::time_point oldTime;
200  bool expected = false;
201  unsigned int nModules;
202  while (not m_spinLock.compare_exchange_weak(expected, true, std::memory_order_acq_rel)) {
203  expected = false;
204  }
205  {
206  oldTime = m_time;
207  m_time = newTime;
208  nModules = m_nModules--;
209  m_spinLock.store(false, std::memory_order_release);
210  }
211  assert(nModules < m_nTimeSums);
212  auto diff = newTime - oldTime;
213  for (unsigned int i = 0; i <= nModules; ++i) {
214  m_timeSums[i].fetch_add(diff.count());
215  }
216 }
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 221 of file ConcurrentModuleTimer.cc.

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

Referenced by ConcurrentModuleTimer().

221  {
222  auto modId = iContext.moduleDescription()->id();
223  for (auto const id : m_excludedModuleIds) {
224  if (modId == id) {
225  return false;
226  }
227  }
228  return true;
229 }
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 = 0
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