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::ConcurrentModuleTimer ( edm::ParameterSet const &  iConfig,
edm::ActivityRegistry iAR 
)

Definition at line 68 of file ConcurrentModuleTimer.cc.

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 }

◆ ~ConcurrentModuleTimer()

ConcurrentModuleTimer::~ConcurrentModuleTimer ( )

Definition at line 149 of file ConcurrentModuleTimer.cc.

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 }

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

Member Function Documentation

◆ fillDescriptions()

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

Definition at line 234 of file ConcurrentModuleTimer.cc.

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 }

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

◆ start()

void ConcurrentModuleTimer::start ( )
private

Definition at line 176 of file ConcurrentModuleTimer.cc.

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 }

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

Referenced by progressbar.ProgressBar::__next__().

◆ stop()

void ConcurrentModuleTimer::stop ( )
private

Definition at line 197 of file ConcurrentModuleTimer.cc.

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 }

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

◆ trackModule()

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

Definition at line 221 of file ConcurrentModuleTimer.cc.

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 }

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

Member Data Documentation

◆ m_excludedModuleIds

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

Definition at line 41 of file ConcurrentModuleTimer.cc.

Referenced by trackModule().

◆ m_excludeSource

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

Definition at line 47 of file ConcurrentModuleTimer.cc.

◆ m_modulesToExclude

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

Definition at line 40 of file ConcurrentModuleTimer.cc.

◆ m_nModules

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

Definition at line 44 of file ConcurrentModuleTimer.cc.

Referenced by start(), and stop().

◆ m_nTimeSums

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

Definition at line 43 of file ConcurrentModuleTimer.cc.

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

◆ m_spinLock

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

Definition at line 45 of file ConcurrentModuleTimer.cc.

Referenced by start(), and stop().

◆ m_startedTiming

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

Definition at line 46 of file ConcurrentModuleTimer.cc.

◆ m_time

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

Definition at line 42 of file ConcurrentModuleTimer.cc.

Referenced by start(), and stop().

◆ m_timeSums

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

Definition at line 39 of file ConcurrentModuleTimer.cc.

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

change_name.diff
diff
Definition: change_name.py:13
mps_fire.i
i
Definition: mps_fire.py:355
edm::service::ConcurrentModuleTimer::m_modulesToExclude
std::vector< std::string > m_modulesToExclude
Definition: ConcurrentModuleTimer.cc:40
edm::service::ConcurrentModuleTimer::m_nModules
unsigned int m_nModules
Definition: ConcurrentModuleTimer.cc:44
gather_cfg.cout
cout
Definition: gather_cfg.py:144
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
edm::service::ConcurrentModuleTimer::m_timeSums
std::unique_ptr< std::atomic< std::chrono::high_resolution_clock::rep >[]> m_timeSums
Definition: ConcurrentModuleTimer.cc:39
cms::cuda::assert
assert(be >=bs)
edm::service::ConcurrentModuleTimer::m_excludedModuleIds
std::vector< unsigned int > m_excludedModuleIds
Definition: ConcurrentModuleTimer.cc:41
edm::service::ConcurrentModuleTimer::m_spinLock
std::atomic< bool > m_spinLock
Definition: ConcurrentModuleTimer.cc:45
fileCollector.now
now
Definition: fileCollector.py:207
edm::service::ConcurrentModuleTimer::m_nTimeSums
unsigned int m_nTimeSums
Definition: ConcurrentModuleTimer.cc:43
edm::ConfigurationDescriptions::add
void add(std::string const &label, ParameterSetDescription const &psetDescription)
Definition: ConfigurationDescriptions.cc:57
edm::service::ConcurrentModuleTimer::m_time
std::chrono::high_resolution_clock::time_point m_time
Definition: ConcurrentModuleTimer.cc:42
edm::service::ConcurrentModuleTimer::stop
void stop()
Definition: ConcurrentModuleTimer.cc:197
edm::ParameterSetDescription::addUntracked
ParameterDescriptionBase * addUntracked(U const &iLabel, T const &value)
Definition: ParameterSetDescription.h:100
edm::service::SystemBounds
Definition: SystemBounds.h:29
edm::service::SystemBounds::maxNumberOfThreads
unsigned int maxNumberOfThreads() const
Definition: SystemBounds.h:38
edm::service::ConcurrentModuleTimer::start
void start()
Definition: ConcurrentModuleTimer.cc:176
edm::service::ConcurrentModuleTimer::m_excludeSource
bool m_excludeSource
Definition: ConcurrentModuleTimer.cc:47
edm::service::ConcurrentModuleTimer::m_startedTiming
bool m_startedTiming
Definition: ConcurrentModuleTimer.cc:46
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
edm::ModuleCallingContext::State::kRunning
edm::service::ConcurrentModuleTimer::trackModule
bool trackModule(ModuleCallingContext const &iContext) const
Definition: ConcurrentModuleTimer.cc:221