CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Timing.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: Services
4 // Class : Timing
5 //
6 // Implementation:
7 //
8 // Original Author: Jim Kowalkowski
9 //
10 
12 
29 
30 #include <iostream>
31 #include <sstream>
32 #include <sys/resource.h>
33 #include <sys/time.h>
34 #include <atomic>
35 #include <exception>
36 
37 namespace edm {
38 
39  namespace eventsetup {
40  struct ComponentDescription;
41  class DataKey;
42  class EventSetupRecordKey;
43  } // namespace eventsetup
44 
45  namespace service {
46  class Timing : public TimingServiceBase {
47  public:
49  ~Timing() override;
50 
51  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
52 
53  void addToCPUTime(double iTime) override;
54  double getTotalCPU() const override;
55 
56  private:
58  void postBeginJob();
59  void postEndJob();
60 
61  void preEvent(StreamContext const&);
62  void postEvent(StreamContext const&);
63  void lastPostEvent(double curr_event_time, unsigned int index, StreamContext const& iStream);
64 
66 
69 
72 
73  void preSourceRun(RunIndex);
74  void postSourceRun(RunIndex);
75 
76  void preOpenFile(std::string const&, bool);
77  void postOpenFile(std::string const&, bool);
78 
79  void preModule(ModuleDescription const& md);
80  void postModule(ModuleDescription const& md);
81 
84 
85  void postGlobalBeginRun(GlobalContext const&);
87 
90 
91  double postCommon() const;
92 
93  struct CountAndTime {
94  public:
95  CountAndTime(unsigned int count, double time) : count_(count), time_(time) {}
96  unsigned int count_;
97  double time_;
98  };
99 
100  void accumulateTimeBegin(std::atomic<CountAndTime*>& countAndTime, double& accumulatedTime);
101  void accumulateTimeEnd(std::atomic<CountAndTime*>& countAndTime, double& accumulatedTime);
102 
103  double curr_job_time_; // seconds
104  double curr_job_cpu_; // seconds
105  std::atomic<double> extra_job_cpu_; //seconds
106  //use last run time for determining end of processing
107  std::atomic<double> end_loop_time_;
108  std::atomic<double> end_loop_cpu_;
109  std::vector<double> curr_events_time_; // seconds
112  double threshold_;
113  //
114  // Min Max and total event times for each Stream.
115  // Used for summary at end of job
116  std::vector<double> max_events_time_; // seconds
117  std::vector<double> min_events_time_; // seconds
118  std::vector<double> sum_events_time_;
119  std::atomic<unsigned long> total_event_count_;
120  std::atomic<unsigned long> begin_lumi_count_;
121  std::atomic<unsigned long> begin_run_count_;
122  unsigned int nStreams_;
123  unsigned int nThreads_;
124 
126 
127  std::atomic<CountAndTime*> countAndTimeForLock_;
129 
131  CMS_THREAD_GUARD(countAndTimeForGet_) double accumulatedTimeForGet_;
132 
133  std::vector<std::unique_ptr<std::atomic<unsigned int>>> countSubProcessesPreEvent_;
134  std::vector<std::unique_ptr<std::atomic<unsigned int>>> countSubProcessesPostEvent_;
135 
137  unsigned int nSubProcesses_;
138  };
139  } // namespace service
140 } // namespace edm
141 
142 namespace edm {
143  namespace service {
144 
145  static std::string d2str(double d) {
146  std::stringstream t;
147  t << d;
148  return t.str();
149  }
150 
151  static std::string ui2str(unsigned int i) {
152  std::stringstream t;
153  t << i;
154  return t.str();
155  }
156 
157  static double getTime() {
158  struct timeval t;
159  if (gettimeofday(&t, nullptr) < 0)
160  throw cms::Exception("SysCallFailed", "Failed call to gettimeofday");
161  return static_cast<double>(t.tv_sec) + (static_cast<double>(t.tv_usec) * 1E-6);
162  }
163 
164  static double getChildrenCPU() {
165  struct rusage usage;
166 
167  getrusage(RUSAGE_CHILDREN, &usage);
168  double totalCPUTime = (double)usage.ru_utime.tv_sec + (double(usage.ru_utime.tv_usec) * 1E-6);
169  totalCPUTime += (double)usage.ru_stime.tv_sec + (double(usage.ru_stime.tv_usec) * 1E-6);
170 
171  return totalCPUTime;
172  }
173 
174  static double getCPU() {
175  struct rusage usage;
176  getrusage(RUSAGE_SELF, &usage);
177 
178  double totalCPUTime = 0.0;
179  // User code
180  totalCPUTime = (double)usage.ru_utime.tv_sec + (double(usage.ru_utime.tv_usec) * 1E-6);
181  // System functions
182  totalCPUTime += (double)usage.ru_stime.tv_sec + (double(usage.ru_stime.tv_usec) * 1E-6);
183 
184  // Additionally, add in CPU usage from our child processes.
185  getrusage(RUSAGE_CHILDREN, &usage);
186  totalCPUTime += (double)usage.ru_utime.tv_sec + (double(usage.ru_utime.tv_usec) * 1E-6);
187  totalCPUTime += (double)usage.ru_stime.tv_sec + (double(usage.ru_stime.tv_usec) * 1E-6);
188 
189  return totalCPUTime;
190  }
191 
192  //NOTE: We use a per thread stack for module times since unscheduled
193  // exectuion or tbb task spawning can cause a module to run on the
194  // same thread as an already running module
195  static std::vector<double>& moduleTimeStack() {
196  static thread_local std::vector<double> s_stack;
197  return s_stack;
198  }
199 
200  static double popStack() {
201  auto& modStack = moduleTimeStack();
202  assert(!modStack.empty());
203  double curr_module_time = modStack.back();
204  modStack.pop_back();
205  double t = getTime() - curr_module_time;
206  return t;
207  }
208 
209  static void pushStack(bool configuredInTopLevelProcess) {
210  if (!configuredInTopLevelProcess) {
211  return;
212  }
213  auto& modStack = moduleTimeStack();
214  modStack.push_back(getTime());
215  }
216 
218  : curr_job_time_(0.),
219  curr_job_cpu_(0.),
220  extra_job_cpu_(0.0),
221  end_loop_time_(0.0),
222  end_loop_cpu_(0.0),
224  summary_only_(iPS.getUntrackedParameter<bool>("summaryOnly")),
225  report_summary_(iPS.getUntrackedParameter<bool>("useJobReport")),
226  threshold_(iPS.getUntrackedParameter<double>("excessiveTimeThreshold")),
231  begin_run_count_(0),
232  countAndTimeZero_{0, 0.0},
233  countAndTimeForLock_{&countAndTimeZero_},
234  accumulatedTimeForLock_{0.0},
235  countAndTimeForGet_{&countAndTimeZero_},
236  accumulatedTimeForGet_{0.0},
237  configuredInTopLevelProcess_{false},
238  nSubProcesses_{0} {
239  iRegistry.watchPreBeginJob(this, &Timing::preBeginJob);
240  iRegistry.watchPostBeginJob(this, &Timing::postBeginJob);
241  iRegistry.preEndJobSignal_.connect([this]() {
242  end_loop_time_ = getTime();
243  end_loop_cpu_ = getCPU();
244  });
245  iRegistry.watchPostEndJob(this, &Timing::postEndJob);
246 
247  iRegistry.watchPreEvent(this, &Timing::preEvent);
248  iRegistry.watchPostEvent(this, &Timing::postEvent);
249 
250  bool checkThreshold = true;
251  if (threshold_ <= 0.0) {
252  //we need to ignore the threshold check
253  threshold_ = std::numeric_limits<double>::max();
254  checkThreshold = false;
255  }
256 
257  if ((not summary_only_) || (checkThreshold)) {
258  iRegistry.watchPreModuleEvent(this, &Timing::preModuleStream);
259  iRegistry.watchPostModuleEvent(this, &Timing::postModuleEvent);
260  }
261  if (checkThreshold) {
262  iRegistry.watchPreSourceEvent(this, &Timing::preSourceEvent);
263  iRegistry.watchPostSourceEvent(this, &Timing::postSourceEvent);
264 
265  iRegistry.watchPreSourceLumi(this, &Timing::preSourceLumi);
266  iRegistry.watchPostSourceLumi(this, &Timing::postSourceLumi);
267 
268  iRegistry.watchPreSourceRun(this, &Timing::preSourceRun);
269  iRegistry.watchPostSourceRun(this, &Timing::postSourceRun);
270 
271  iRegistry.watchPreOpenFile(this, &Timing::preOpenFile);
272  iRegistry.watchPostOpenFile(this, &Timing::postOpenFile);
273 
274  iRegistry.watchPreEventReadFromSource(this, &Timing::preModuleStream);
275  iRegistry.watchPostEventReadFromSource(this, &Timing::postModuleStream);
276 
277  iRegistry.watchPreModuleConstruction(this, &Timing::preModule);
278  iRegistry.watchPostModuleConstruction(this, &Timing::postModule);
279 
280  iRegistry.watchPreModuleDestruction(this, &Timing::preModule);
281  iRegistry.watchPostModuleDestruction(this, &Timing::postModule);
282 
283  iRegistry.watchPreModuleBeginJob(this, &Timing::preModule);
284  iRegistry.watchPostModuleBeginJob(this, &Timing::postModule);
285 
286  iRegistry.watchPreModuleEndJob(this, &Timing::preModule);
287  iRegistry.watchPostModuleEndJob(this, &Timing::postModule);
288 
289  iRegistry.watchPreModuleStreamBeginRun(this, &Timing::preModuleStream);
290  iRegistry.watchPostModuleStreamBeginRun(this, &Timing::postModuleStream);
291  iRegistry.watchPreModuleStreamEndRun(this, &Timing::preModuleStream);
292  iRegistry.watchPostModuleStreamEndRun(this, &Timing::postModuleStream);
293 
294  iRegistry.watchPreModuleStreamBeginLumi(this, &Timing::preModuleStream);
295  iRegistry.watchPostModuleStreamBeginLumi(this, &Timing::postModuleStream);
296  iRegistry.watchPreModuleStreamEndLumi(this, &Timing::preModuleStream);
297  iRegistry.watchPostModuleStreamEndLumi(this, &Timing::postModuleStream);
298 
299  iRegistry.watchPreModuleGlobalBeginRun(this, &Timing::preModuleGlobal);
300  iRegistry.watchPostModuleGlobalBeginRun(this, &Timing::postModuleGlobal);
301  iRegistry.watchPreModuleGlobalEndRun(this, &Timing::preModuleGlobal);
302  iRegistry.watchPostModuleGlobalEndRun(this, &Timing::postModuleGlobal);
303 
304  iRegistry.watchPreModuleGlobalBeginLumi(this, &Timing::preModuleGlobal);
305  iRegistry.watchPostModuleGlobalBeginLumi(this, &Timing::postModuleGlobal);
306  iRegistry.watchPreModuleGlobalEndLumi(this, &Timing::preModuleGlobal);
307  iRegistry.watchPostModuleGlobalEndLumi(this, &Timing::postModuleGlobal);
308 
309  iRegistry.watchPreSourceConstruction(this, &Timing::preModule);
310  iRegistry.watchPostSourceConstruction(this, &Timing::postModule);
311  }
312 
313  iRegistry.watchPostGlobalBeginRun(this, &Timing::postGlobalBeginRun);
314  iRegistry.watchPostGlobalBeginLumi(this, &Timing::postGlobalBeginLumi);
315 
316  iRegistry.preallocateSignal_.connect([this](service::SystemBounds const& iBounds) {
317  nStreams_ = iBounds.maxNumberOfStreams();
318  nThreads_ = iBounds.maxNumberOfThreads();
319  curr_events_time_.resize(nStreams_, 0.);
320  sum_events_time_.resize(nStreams_, 0.);
321  max_events_time_.resize(nStreams_, 0.);
322  min_events_time_.resize(nStreams_, 1.E6);
323  for (unsigned int i = 0; i < nStreams_; ++i) {
324  countSubProcessesPreEvent_.emplace_back(std::make_unique<std::atomic<unsigned int>>(0));
325  countSubProcessesPostEvent_.emplace_back(std::make_unique<std::atomic<unsigned int>>(0));
326  }
327  });
328  }
329 
331 
332  void Timing::addToCPUTime(double iTime) {
333  //For accounting purposes we effectively can say we started earlier
334  double expected = extra_job_cpu_.load();
335  while (not extra_job_cpu_.compare_exchange_strong(expected, expected + iTime)) {
336  }
337  }
338 
339  double Timing::getTotalCPU() const { return getCPU(); }
340 
343  desc.addUntracked<bool>("summaryOnly", false)->setComment("If 'true' do not report timing for each event");
344  desc.addUntracked<bool>("useJobReport", true)->setComment("If 'true' write summary information to JobReport");
345  desc.addUntracked<double>("excessiveTimeThreshold", 0.)
346  ->setComment(
347  "Amount of time in seconds before reporting a module or source has taken excessive time. A value of 0.0 "
348  "turns off this reporting.");
349  descriptions.add("Timing", desc);
350  descriptions.setComment("This service reports the time it takes to run each module in a job.");
351  }
352 
353  void Timing::preBeginJob(PathsAndConsumesOfModulesBase const& pathsAndConsumes, ProcessContext const& pc) {
354  if (pc.isSubProcess()) {
355  ++nSubProcesses_;
356  } else {
357  configuredInTopLevelProcess_ = true;
358  }
359  }
360 
362  if (!configuredInTopLevelProcess_) {
363  return;
364  }
366  curr_job_cpu_ = getCPU();
367 
368  if (not summary_only_) {
369  LogImportant("TimeReport") << "TimeReport> Report activated"
370  << "\n"
371  << "TimeReport> Report columns headings for events: "
372  << "eventnum runnum timetaken\n"
373  << "TimeReport> Report columns headings for modules: "
374  << "eventnum runnum modulelabel modulename timetakeni\n"
375  << "TimeReport> JobTime=" << curr_job_time_ << " JobCPU=" << curr_job_cpu_ << "\n";
376  }
377  }
378 
380  if (!configuredInTopLevelProcess_) {
381  LogImportant("TimeReport") << "\nTimeReport> This instance of the Timing Service will be disabled because it "
382  "is configured in a SubProcess.\n"
383  << "If multiple instances of the TimingService were configured only the one in the "
384  "top level process will function.\n"
385  << "The other instance(s) will simply print this message and do nothing.\n\n";
386  return;
387  }
388 
389  const double job_end_time = getTime();
390  const double job_end_cpu = getCPU();
391  double total_job_time = job_end_time - jobStartTime();
392 
393  double total_job_cpu = job_end_cpu + extra_job_cpu_;
394 
395  const double job_end_children_cpu = getChildrenCPU();
396 
397  const double total_initialization_time = curr_job_time_ - jobStartTime();
398  const double total_initialization_cpu = curr_job_cpu_;
399 
400  if (0.0 == jobStartTime()) {
401  //did not capture beginning time
402  total_job_time = job_end_time - curr_job_time_;
403  total_job_cpu = job_end_cpu + extra_job_cpu_ - curr_job_cpu_;
404  }
405 
406  double min_event_time = *(std::min_element(min_events_time_.begin(), min_events_time_.end()));
407  double max_event_time = *(std::max_element(max_events_time_.begin(), max_events_time_.end()));
408 
409  auto total_loop_time = end_loop_time_ - curr_job_time_;
410  auto total_loop_cpu = end_loop_cpu_ + extra_job_cpu_ - curr_job_cpu_;
411 
412  if (end_loop_time_ == 0.0) {
413  total_loop_time = 0.0;
414  total_loop_cpu = 0.0;
415  }
416 
417  double sum_all_events_time = 0;
418  for (auto t : sum_events_time_) {
419  sum_all_events_time += t;
420  }
421 
422  double average_event_time = 0.0;
423  if (total_event_count_ != 0) {
424  average_event_time = sum_all_events_time / total_event_count_;
425  }
426 
427  double event_throughput = 0.0;
428  if (total_loop_time != 0.0) {
429  event_throughput = total_event_count_ / total_loop_time;
430  }
431 
432  LogImportant("TimeReport") << "TimeReport> Time report complete in " << total_job_time << " seconds"
433  << "\n"
434  << " Time Summary: \n"
435  << " - Min event: " << min_event_time << "\n"
436  << " - Max event: " << max_event_time << "\n"
437  << " - Avg event: " << average_event_time << "\n"
438  << " - Total loop: " << total_loop_time << "\n"
439  << " - Total init: " << total_initialization_time << "\n"
440  << " - Total job: " << total_job_time << "\n"
441  << " - EventSetup Lock: " << accumulatedTimeForLock_ << "\n"
442  << " - EventSetup Get: " << accumulatedTimeForGet_ << "\n"
443  << " Event Throughput: " << event_throughput << " ev/s\n"
444  << " CPU Summary: \n"
445  << " - Total loop: " << total_loop_cpu << "\n"
446  << " - Total init: " << total_initialization_cpu << "\n"
447  << " - Total extra: " << extra_job_cpu_ << "\n"
448  << " - Total children: " << job_end_children_cpu << "\n"
449  << " - Total job: " << total_job_cpu << "\n"
450  << " Processing Summary: \n"
451  << " - Number of Events: " << total_event_count_ << "\n"
452  << " - Number of Global Begin Lumi Calls: " << begin_lumi_count_ << "\n"
453  << " - Number of Global Begin Run Calls: " << begin_run_count_ << "\n";
454 
455  if (report_summary_) {
456  Service<JobReport> reportSvc;
457  std::map<std::string, std::string> reportData;
458 
459  reportData.insert(std::make_pair("MinEventTime", d2str(min_event_time)));
460  reportData.insert(std::make_pair("MaxEventTime", d2str(max_event_time)));
461  reportData.insert(std::make_pair("AvgEventTime", d2str(average_event_time)));
462  reportData.insert(std::make_pair("EventThroughput", d2str(event_throughput)));
463  reportData.insert(std::make_pair("TotalJobTime", d2str(total_job_time)));
464  reportData.insert(std::make_pair("TotalJobCPU", d2str(total_job_cpu)));
465  reportData.insert(std::make_pair("TotalJobChildrenCPU", d2str(job_end_children_cpu)));
466  reportData.insert(std::make_pair("TotalLoopTime", d2str(total_loop_time)));
467  reportData.insert(std::make_pair("TotalLoopCPU", d2str(total_loop_cpu)));
468  reportData.insert(std::make_pair("TotalInitTime", d2str(total_initialization_time)));
469  reportData.insert(std::make_pair("TotalInitCPU", d2str(total_initialization_cpu)));
470  reportData.insert(std::make_pair("NumberOfStreams", ui2str(nStreams_)));
471  reportData.insert(std::make_pair("NumberOfThreads", ui2str(nThreads_)));
472  reportData.insert(std::make_pair("EventSetup Lock", d2str(accumulatedTimeForLock_)));
473  reportData.insert(std::make_pair("EventSetup Get", d2str(accumulatedTimeForGet_)));
474  reportSvc->reportPerformanceSummary("Timing", reportData);
475 
476  std::map<std::string, std::string> reportData1;
477  reportData1.insert(std::make_pair("NumberEvents", ui2str(total_event_count_)));
478  reportData1.insert(std::make_pair("NumberBeginLumiCalls", ui2str(begin_lumi_count_)));
479  reportData1.insert(std::make_pair("NumberBeginRunCalls", ui2str(begin_run_count_)));
480  reportSvc->reportPerformanceSummary("ProcessingSummary", reportData1);
481  }
482  }
483 
484  void Timing::preEvent(StreamContext const& iStream) {
485  if (!configuredInTopLevelProcess_) {
486  return;
487  }
488  auto index = iStream.streamID().value();
489  if (nSubProcesses_ == 0u) {
491  } else {
492  unsigned int count = ++(*countSubProcessesPreEvent_[index]);
493  if (count == 1) {
495  } else if (count == (nSubProcesses_ + 1)) {
496  *countSubProcessesPreEvent_[index] = 0;
497  }
498  }
499  }
500 
501  void Timing::postEvent(StreamContext const& iStream) {
502  if (!configuredInTopLevelProcess_) {
503  return;
504  }
505  auto index = iStream.streamID().value();
506  if (nSubProcesses_ == 0u) {
507  lastPostEvent(getTime() - curr_events_time_[index], index, iStream);
508  } else {
509  unsigned int count = ++(*countSubProcessesPostEvent_[index]);
510  if (count == (nSubProcesses_ + 1)) {
511  lastPostEvent(getTime() - curr_events_time_[index], index, iStream);
512  *countSubProcessesPostEvent_[index] = 0;
513  }
514  }
515  }
516 
517  void Timing::lastPostEvent(double curr_event_time, unsigned int index, StreamContext const& iStream) {
518  sum_events_time_[index] += curr_event_time;
519 
520  if (not summary_only_) {
521  auto const& eventID = iStream.eventID();
522  LogPrint("TimeEvent") << "TimeEvent> " << eventID.event() << " " << eventID.run() << " " << curr_event_time;
523  }
524  if (curr_event_time > max_events_time_[index])
525  max_events_time_[index] = curr_event_time;
526  if (curr_event_time < min_events_time_[index])
527  min_events_time_[index] = curr_event_time;
529  }
530 
531  void Timing::postModuleEvent(StreamContext const& iStream, ModuleCallingContext const& iModule) {
532  if (!configuredInTopLevelProcess_) {
533  return;
534  }
535  auto const& eventID = iStream.eventID();
536  auto const& desc = *(iModule.moduleDescription());
537  double t = postCommon();
538  if (not summary_only_) {
539  LogPrint("TimeModule") << "TimeModule> " << eventID.event() << " " << eventID.run() << " " << desc.moduleLabel()
540  << " " << desc.moduleName() << " " << t;
541  }
542  }
543 
544  void Timing::preSourceEvent(StreamID sid) { pushStack(configuredInTopLevelProcess_); }
545 
547 
548  void Timing::preSourceLumi(LuminosityBlockIndex index) { pushStack(configuredInTopLevelProcess_); }
549 
551 
552  void Timing::preSourceRun(RunIndex index) { pushStack(configuredInTopLevelProcess_); }
553 
555 
556  void Timing::preOpenFile(std::string const& lfn, bool b) { pushStack(configuredInTopLevelProcess_); }
557 
558  void Timing::postOpenFile(std::string const& lfn, bool b) { postCommon(); }
559 
560  void Timing::preModule(ModuleDescription const&) { pushStack(configuredInTopLevelProcess_); }
561 
563 
565  pushStack(configuredInTopLevelProcess_);
566  }
567 
569 
571  if (!configuredInTopLevelProcess_) {
572  return;
573  }
574  if (!gc.processContext()->isSubProcess()) {
576  }
577  }
578 
580  if (!configuredInTopLevelProcess_) {
581  return;
582  }
583  if (!gc.processContext()->isSubProcess()) {
585  }
586  }
587 
589  pushStack(configuredInTopLevelProcess_);
590  }
591 
593 
594  double Timing::postCommon() const {
595  if (!configuredInTopLevelProcess_) {
596  return 0.0;
597  }
598  double t = popStack();
599  if (t > threshold_) {
600  LogError("ExcessiveTime")
601  << "ExcessiveTime: Module used " << t
602  << " seconds of time which exceeds the error threshold configured in the Timing Service of " << threshold_
603  << " seconds.";
604  }
605  return t;
606  }
607 
608  void Timing::accumulateTimeBegin(std::atomic<CountAndTime*>& countAndTime, double& accumulatedTime) {
609  double newTime = getTime();
610  auto newStat = std::make_unique<CountAndTime>(0, newTime);
611 
612  CountAndTime* oldStat = countAndTime.load();
613  while (true) {
614  if (oldStat == nullptr) {
615  oldStat = countAndTime.load();
616  } else if (countAndTime.compare_exchange_strong(oldStat, nullptr)) {
617  break;
618  }
619  }
620 
621  newStat->count_ = oldStat->count_ + 1;
622  if (oldStat->count_ != 0) {
623  accumulatedTime += (newTime - oldStat->time_) * oldStat->count_;
624  }
625  countAndTime.store(newStat.release());
626  if (oldStat != &countAndTimeZero_) {
627  delete oldStat;
628  }
629  }
630 
631  void Timing::accumulateTimeEnd(std::atomic<CountAndTime*>& countAndTime, double& accumulatedTime) {
632  double newTime = getTime();
633 
634  CountAndTime* oldStat = countAndTime.load();
635  while (true) {
636  if (oldStat == nullptr) {
637  oldStat = countAndTime.load();
638  } else if (countAndTime.compare_exchange_strong(oldStat, nullptr)) {
639  break;
640  }
641  }
642 
643  if (oldStat->count_ == 1) {
644  accumulatedTime += newTime - oldStat->time_;
645  countAndTime.store(&countAndTimeZero_);
646  } else {
647  try {
648  auto newStat = std::make_unique<CountAndTime>(oldStat->count_ - 1, newTime);
649  accumulatedTime += (newTime - oldStat->time_) * oldStat->count_;
650  countAndTime.store(newStat.release());
651  } catch (std::exception&) {
652  countAndTime.store(oldStat);
653  throw;
654  }
655  }
656  delete oldStat;
657  }
658  } // namespace service
659 } // namespace edm
660 
662 
std::vector< double > sum_events_time_
Definition: Timing.cc:118
void setComment(std::string const &value)
double curr_job_time_
Definition: Timing.cc:103
#define DEFINE_FWK_SERVICE_MAKER(concrete, maker)
Definition: ServiceMaker.h:100
std::vector< double > max_events_time_
Definition: Timing.cc:116
ParameterDescriptionBase * addUntracked(U const &iLabel, T const &value)
std::vector< double > curr_events_time_
Definition: Timing.cc:109
void preModule(ModuleDescription const &md)
Definition: Timing.cc:560
static double getCPU()
Definition: Timing.cc:174
void postEvent(StreamContext const &)
Definition: Timing.cc:501
void preModuleStream(StreamContext const &, ModuleCallingContext const &)
Definition: Timing.cc:588
double curr_job_cpu_
Definition: Timing.cc:104
std::atomic< unsigned long > begin_lumi_count_
Definition: Timing.cc:120
void lastPostEvent(double curr_event_time, unsigned int index, StreamContext const &iStream)
Definition: Timing.cc:517
Log< level::Error, false > LogError
void accumulateTimeBegin(std::atomic< CountAndTime * > &countAndTime, double &accumulatedTime)
Definition: Timing.cc:608
void preSourceLumi(LuminosityBlockIndex)
Definition: Timing.cc:548
std::unique_ptr< T, impl::DeviceDeleter > unique_ptr
assert(be >=bs)
unsigned int nThreads_
Definition: Timing.cc:123
void preOpenFile(std::string const &, bool)
Definition: Timing.cc:556
unsigned int nStreams_
Definition: Timing.cc:122
void preModuleGlobal(GlobalContext const &, ModuleCallingContext const &)
Definition: Timing.cc:564
void postModule(ModuleDescription const &md)
Definition: Timing.cc:562
tuple d
Definition: ztail.py:151
void postGlobalBeginRun(GlobalContext const &)
Definition: Timing.cc:570
void preSourceRun(RunIndex)
Definition: Timing.cc:552
void postModuleStream(StreamContext const &, ModuleCallingContext const &)
Definition: Timing.cc:592
std::atomic< CountAndTime * > countAndTimeForGet_
Definition: Timing.cc:130
void accumulateTimeEnd(std::atomic< CountAndTime * > &countAndTime, double &accumulatedTime)
Definition: Timing.cc:631
std::atomic< double > end_loop_time_
Definition: Timing.cc:107
Timing(ParameterSet const &, ActivityRegistry &)
Definition: Timing.cc:217
CountAndTime(unsigned int count, double time)
Definition: Timing.cc:95
ModuleDescription const * moduleDescription() const
void postModuleEvent(StreamContext const &, ModuleCallingContext const &)
Definition: Timing.cc:531
#define CMS_THREAD_GUARD(_var_)
Log< level::Error, true > LogImportant
void postSourceLumi(LuminosityBlockIndex)
Definition: Timing.cc:550
static void pushStack(bool configuredInTopLevelProcess)
Definition: Timing.cc:209
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: Timing.cc:341
std::atomic< double > end_loop_cpu_
Definition: Timing.cc:108
~Timing() override
Definition: Timing.cc:330
std::atomic< CountAndTime * > countAndTimeForLock_
Definition: Timing.cc:127
double accumulatedTimeForLock_
Definition: Timing.cc:128
Log< level::Warning, true > LogPrint
double getTotalCPU() const override
Definition: Timing.cc:339
std::vector< std::unique_ptr< std::atomic< unsigned int > > > countSubProcessesPreEvent_
Definition: Timing.cc:133
static double jobStartTime()
std::vector< std::unique_ptr< std::atomic< unsigned int > > > countSubProcessesPostEvent_
Definition: Timing.cc:134
StreamID const & streamID() const
Definition: StreamContext.h:54
static std::string ui2str(unsigned int i)
Definition: Timing.cc:151
void setComment(std::string const &value)
void postGlobalBeginLumi(GlobalContext const &)
Definition: Timing.cc:579
std::atomic< unsigned long > begin_run_count_
Definition: Timing.cc:121
unsigned int value() const
Definition: StreamID.h:43
std::atomic< unsigned long > total_event_count_
Definition: Timing.cc:119
static std::vector< double > & moduleTimeStack()
Definition: Timing.cc:195
void addToCPUTime(double iTime) override
Definition: Timing.cc:332
double b
Definition: hdecay.h:118
static std::string d2str(double d)
void add(std::string const &label, ParameterSetDescription const &psetDescription)
double postCommon() const
Definition: Timing.cc:594
bool configuredInTopLevelProcess_
Definition: Timing.cc:136
edm::serviceregistry::AllArgsMaker< edm::TimingServiceBase, Timing > TimingMaker
Definition: Timing.cc:663
ProcessContext const * processContext() const
Definition: GlobalContext.h:64
void postSourceRun(RunIndex)
Definition: Timing.cc:554
double accumulatedTimeForGet_
Definition: Timing.cc:131
void postModuleGlobal(GlobalContext const &, ModuleCallingContext const &)
Definition: Timing.cc:568
void preBeginJob(PathsAndConsumesOfModulesBase const &, ProcessContext const &)
Definition: Timing.cc:353
CountAndTime countAndTimeZero_
Definition: Timing.cc:125
void postOpenFile(std::string const &, bool)
Definition: Timing.cc:558
static double getTime()
Definition: Timing.cc:157
void postSourceEvent(StreamID)
Definition: Timing.cc:546
EventID const & eventID() const
Definition: StreamContext.h:59
std::atomic< double > extra_job_cpu_
Definition: Timing.cc:105
static double popStack()
Definition: Timing.cc:200
bool isSubProcess() const
void preSourceEvent(StreamID)
Definition: Timing.cc:544
void preEvent(StreamContext const &)
Definition: Timing.cc:484
static double getChildrenCPU()
Definition: Timing.cc:164
std::vector< double > min_events_time_
Definition: Timing.cc:117
unsigned int nSubProcesses_
Definition: Timing.cc:137