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
 
const bool m_excludeSource
 
unsigned int m_maxNModules = 0
 
std::vector< std::string > m_modulesToExclude
 
unsigned int m_nModules
 
unsigned int m_nTimeSums = 0
 
const unsigned int m_padding
 
std::atomic< bool > m_spinLock
 
bool m_startedTiming
 
std::chrono::steady_clock::time_point m_time
 
std::unique_ptr< std::atomic< std::chrono::steady_clock::rep >[]> m_timeSums
 
const bool m_trackGlobalBeginRun
 

Detailed Description

Definition at line 30 of file ConcurrentModuleTimer.cc.

Constructor & Destructor Documentation

◆ ConcurrentModuleTimer()

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

Definition at line 73 of file ConcurrentModuleTimer.cc.

74  : m_modulesToExclude(iConfig.getUntrackedParameter<std::vector<std::string>>("modulesToExclude")),
75  m_time(),
76  m_nModules(0),
77  m_padding(iConfig.getUntrackedParameter<unsigned int>("padding")),
78  m_spinLock{false},
79  m_startedTiming(false),
80  m_excludeSource(iConfig.getUntrackedParameter<bool>("excludeSource")),
81  m_trackGlobalBeginRun(iConfig.getUntrackedParameter<bool>("trackGlobalBeginRun")) {
82  if (not m_modulesToExclude.empty()) {
83  iReg.watchPreModuleConstruction([this](ModuleDescription const& iMod) {
84  for (auto const& name : m_modulesToExclude) {
85  if (iMod.moduleLabel() == name) {
86  m_excludedModuleIds.push_back(iMod.id());
87  break;
88  }
89  }
90  });
91  iReg.watchPreModuleDestruction([this](ModuleDescription const& iMod) {
92  auto found = std::find(m_excludedModuleIds.begin(), m_excludedModuleIds.end(), iMod.id());
93  if (found != m_excludedModuleIds.end()) {
95  }
96  });
97  iReg.watchPreModuleEvent([this](StreamContext const&, ModuleCallingContext const& iContext) {
98  if (trackModule(iContext)) {
99  start();
100  }
101  });
102  iReg.watchPostModuleEvent([this](StreamContext const&, ModuleCallingContext const& iContext) {
103  if (trackModule(iContext)) {
104  stop();
105  }
106  });
107 
108  iReg.watchPreModuleEventDelayedGet([this](StreamContext const&, ModuleCallingContext const& iContext) {
109  if (trackModule(iContext)) {
110  if (iContext.state() == ModuleCallingContext::State::kRunning) {
111  stop();
112  }
113  }
114  });
115  iReg.watchPostModuleEventDelayedGet([this](StreamContext const&, ModuleCallingContext const& iContext) {
116  if (trackModule(iContext)) {
117  if (iContext.state() == ModuleCallingContext::State::kRunning) {
118  start();
119  }
120  }
121  });
122 
123  } else {
124  //apply to all modules so can use faster version
125  iReg.watchPreModuleEvent([this](StreamContext const&, ModuleCallingContext const&) { start(); });
126  iReg.watchPostModuleEvent([this](StreamContext const&, ModuleCallingContext const&) { stop(); });
127 
128  iReg.watchPreModuleEventDelayedGet([this](StreamContext const&, ModuleCallingContext const& iContext) {
129  if (iContext.state() == ModuleCallingContext::State::kRunning) {
130  stop();
131  }
132  });
133  iReg.watchPostModuleEventDelayedGet([this](StreamContext const&, ModuleCallingContext const& iContext) {
134  if (iContext.state() == ModuleCallingContext::State::kRunning) {
135  start();
136  }
137  });
138  if (m_trackGlobalBeginRun) {
139  iReg.watchPreModuleGlobalBeginRun([this](GlobalContext const&, ModuleCallingContext const&) {
140  if (not m_startedTiming) {
142  m_startedTiming = true;
143  }
144 
145  start();
146  });
147  iReg.watchPostModuleGlobalBeginRun([this](GlobalContext const&, ModuleCallingContext const&) { stop(); });
148  }
149  }
150 
151  iReg.watchPreallocate([this](edm::service::SystemBounds const& iBounds) {
152  m_nTimeSums = iBounds.maxNumberOfThreads() + 1 + m_padding;
153  m_timeSums = std::make_unique<std::atomic<std::chrono::steady_clock::rep>[]>(m_nTimeSums);
154  for (unsigned int i = 0; i < m_nTimeSums; ++i) {
155  m_timeSums[i] = 0;
156  }
157  });
158 
159  iReg.watchPreSourceEvent([this](StreamID) {
160  if (not m_startedTiming) {
162  m_startedTiming = true;
163  }
164  if (not m_excludeSource) {
165  start();
166  }
167  });
168  if (not m_excludeSource) {
169  iReg.watchPostSourceEvent([this](StreamID) { stop(); });
170  }
171 }
bool trackModule(ModuleCallingContext const &iContext) const
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
std::vector< std::string > m_modulesToExclude
std::chrono::steady_clock::time_point m_time
std::vector< unsigned int > m_excludedModuleIds
unsigned int maxNumberOfThreads() const
Definition: SystemBounds.h:38
std::unique_ptr< std::atomic< std::chrono::steady_clock::rep >[]> m_timeSums

◆ ~ConcurrentModuleTimer()

ConcurrentModuleTimer::~ConcurrentModuleTimer ( )

Definition at line 173 of file ConcurrentModuleTimer.cc.

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

173  {
174  std::cout << "Maximum concurrent running modules: " << m_maxNModules << std::endl;
175  std::cout << "Fraction of time running n Modules simultaneously" << std::endl;
176  for (unsigned int i = 0; i < m_nTimeSums; ++i) {
177  std::cout << i << " " << m_timeSums[i] / double(m_timeSums[0]) << " " << m_timeSums[i] << std::endl;
178  }
179 }
std::unique_ptr< std::atomic< std::chrono::steady_clock::rep >[]> m_timeSums

Member Function Documentation

◆ fillDescriptions()

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

Definition at line 262 of file ConcurrentModuleTimer.cc.

References edm::ConfigurationDescriptions::add(), and submitPVResolutionJobs::desc.

262  {
264  desc.addUntracked<std::vector<std::string>>("modulesToExclude", std::vector<std::string>{})
265  ->setComment("Module labels to exclude from the timing measurements");
266  desc.addUntracked<bool>("excludeSource", false)->setComment("Exclude the time the source is running");
267  desc.addUntracked<unsigned int>("padding", 0)
268  ->setComment(
269  "[Expert use only] Extra possible concurrent modules beyond thread count.\n Only useful in debugging "
270  "possible framework scheduling problems.");
271  desc.addUntracked<bool>("trackGlobalBeginRun", false)
272  ->setComment("Check for concurrent modules during global begin run");
273  descriptions.add("ConcurrentModuleTimer", desc);
274 }
void add(std::string const &label, ParameterSetDescription const &psetDescription)

◆ start()

void ConcurrentModuleTimer::start ( )
private

Definition at line 201 of file ConcurrentModuleTimer.cc.

References cms::cuda::assert(), change_name::diff, mps_fire::i, m_maxNModules, m_nModules, m_nTimeSums, m_spinLock, m_time, m_timeSums, and submitPVValidationJobs::now.

Referenced by progressbar.ProgressBar::__next__().

201  {
202  auto const newTime = std::chrono::steady_clock::now();
203  std::chrono::steady_clock::time_point oldTime;
204  bool expected = false;
205  unsigned int nModules;
206  while (not m_spinLock.compare_exchange_strong(expected, true, std::memory_order_acq_rel)) {
207  expected = false;
208  }
209  {
210  oldTime = m_time;
211  m_time = newTime;
212  nModules = ++m_nModules;
213  if (nModules > m_maxNModules) {
214  m_maxNModules = nModules;
215  }
216  m_spinLock.store(false, std::memory_order_release);
217  }
218  assert(nModules < m_nTimeSums);
219  auto diff = newTime - oldTime;
220  for (unsigned int i = 0; i < nModules; ++i) {
221  m_timeSums[i].fetch_add(diff.count());
222  }
223 }
assert(be >=bs)
std::chrono::steady_clock::time_point m_time
std::unique_ptr< std::atomic< std::chrono::steady_clock::rep >[]> m_timeSums

◆ stop()

void ConcurrentModuleTimer::stop ( )
private

Definition at line 225 of file ConcurrentModuleTimer.cc.

References cms::cuda::assert(), change_name::diff, mps_fire::i, m_nModules, m_nTimeSums, m_spinLock, m_time, m_timeSums, and submitPVValidationJobs::now.

225  {
226  auto const newTime = std::chrono::steady_clock::now();
227  std::chrono::steady_clock::time_point oldTime;
228  bool expected = false;
229  unsigned int nModules;
230  while (not m_spinLock.compare_exchange_weak(expected, true, std::memory_order_acq_rel)) {
231  expected = false;
232  }
233  {
234  oldTime = m_time;
235  m_time = newTime;
236  nModules = m_nModules--;
237  m_spinLock.store(false, std::memory_order_release);
238  }
239  assert(nModules < m_nTimeSums);
240  auto diff = newTime - oldTime;
241  for (unsigned int i = 0; i <= nModules; ++i) {
242  m_timeSums[i].fetch_add(diff.count());
243  }
244 }
assert(be >=bs)
std::chrono::steady_clock::time_point m_time
std::unique_ptr< std::atomic< std::chrono::steady_clock::rep >[]> m_timeSums

◆ trackModule()

bool ConcurrentModuleTimer::trackModule ( ModuleCallingContext const &  iContext) const
private

Definition at line 249 of file ConcurrentModuleTimer.cc.

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

249  {
250  auto modId = iContext.moduleDescription()->id();
251  for (auto const id : m_excludedModuleIds) {
252  if (modId == id) {
253  return false;
254  }
255  }
256  return true;
257 }
std::vector< unsigned int > m_excludedModuleIds

Member Data Documentation

◆ m_excludedModuleIds

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

Definition at line 43 of file ConcurrentModuleTimer.cc.

Referenced by trackModule().

◆ m_excludeSource

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

Definition at line 51 of file ConcurrentModuleTimer.cc.

◆ m_maxNModules

unsigned int edm::service::ConcurrentModuleTimer::m_maxNModules = 0
private

Definition at line 47 of file ConcurrentModuleTimer.cc.

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

◆ m_modulesToExclude

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

Definition at line 42 of file ConcurrentModuleTimer.cc.

◆ m_nModules

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

Definition at line 46 of file ConcurrentModuleTimer.cc.

Referenced by start(), and stop().

◆ m_nTimeSums

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

Definition at line 45 of file ConcurrentModuleTimer.cc.

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

◆ m_padding

const unsigned int edm::service::ConcurrentModuleTimer::m_padding
private

Definition at line 48 of file ConcurrentModuleTimer.cc.

◆ m_spinLock

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

Definition at line 49 of file ConcurrentModuleTimer.cc.

Referenced by start(), and stop().

◆ m_startedTiming

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

Definition at line 50 of file ConcurrentModuleTimer.cc.

◆ m_time

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

Definition at line 44 of file ConcurrentModuleTimer.cc.

Referenced by start(), and stop().

◆ m_timeSums

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

Definition at line 41 of file ConcurrentModuleTimer.cc.

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

◆ m_trackGlobalBeginRun

const bool edm::service::ConcurrentModuleTimer::m_trackGlobalBeginRun
private

Definition at line 52 of file ConcurrentModuleTimer.cc.