33// Package: Services
44// Class : Timing
55//
6+ /* *\class edm::service::Timing
7+ */
8+ //
69// Implementation:
710//
811// Original Author: Jim Kowalkowski
912//
1013
1114#include " DataFormats/Provenance/interface/ModuleDescription.h"
1215#include " FWCore/AbstractServices/interface/TimingServiceBase.h"
16+ #include " FWCore/Framework/interface/EventSetupRecordKey.h"
1317#include " FWCore/MessageLogger/interface/JobReport.h"
1418#include " FWCore/MessageLogger/interface/MessageLogger.h"
1519#include " FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
1620#include " FWCore/ParameterSet/interface/ParameterSet.h"
1721#include " FWCore/ParameterSet/interface/ParameterSetDescription.h"
1822#include " FWCore/ServiceRegistry/interface/ActivityRegistry.h"
23+ #include " FWCore/ServiceRegistry/interface/ESModuleCallingContext.h"
1924#include " FWCore/ServiceRegistry/interface/GlobalContext.h"
25+ #include " FWCore/ServiceRegistry/interface/ModuleCallingContext.h"
2026#include " FWCore/ServiceRegistry/interface/Service.h"
2127#include " FWCore/ServiceRegistry/interface/ServiceMaker.h"
28+ #include " FWCore/ServiceRegistry/interface/ServiceRegistryfwd.h"
2229#include " FWCore/ServiceRegistry/interface/StreamContext.h"
23- #include " FWCore/ServiceRegistry/interface/ModuleCallingContext.h"
24- #include " FWCore/ServiceRegistry/interface/ESModuleCallingContext.h"
25- #include " FWCore/ServiceRegistry/interface/ProcessContext.h"
2630#include " FWCore/ServiceRegistry/interface/SystemBounds.h"
27- #include " FWCore/Utilities/interface/Exception.h"
2831#include " FWCore/Utilities/interface/thread_safety_macros.h"
29- #include " FWCore/Framework/interface/EventSetupRecordKey.h"
32+ #include " FWCore/Utilities/interface/LuminosityBlockIndex.h"
33+ #include " FWCore/Utilities/interface/RunIndex.h"
34+ #include " FWCore/Utilities/interface/StreamID.h"
3035
31- #include < iostream>
36+ #include < atomic>
37+ #include < chrono>
38+ #include < map>
39+ #include < memory>
40+ #include < ratio>
3241#include < sstream>
42+ #include < string>
3343#include < sys/resource.h>
34- #include < sys/time.h>
35- #include < atomic>
36- #include < exception>
44+ #include < utility>
45+ #include < vector>
3746
3847namespace edm {
3948
4049 namespace eventsetup {
4150 struct ComponentDescription ;
42- class DataKey ;
43- class EventSetupRecordKey ;
4451 } // namespace eventsetup
4552
4653 namespace service {
@@ -58,15 +65,11 @@ namespace edm {
5865 double getTotalCPU () const override ;
5966
6067 private:
61- void preBeginJob (ProcessContext const &);
6268 void beginProcessing ();
6369 void postEndJob ();
6470
6571 void preEvent (StreamContext const &);
6672 void postEvent (StreamContext const &);
67- void lastPostEvent (std::chrono::steady_clock::duration curr_event_time,
68- unsigned int index,
69- StreamContext const & iStream);
7073
7174 void postModuleEvent (StreamContext const &, ModuleCallingContext const &);
7275
@@ -82,8 +85,8 @@ namespace edm {
8285 void preOpenFile (std::string const &);
8386 void postOpenFile (std::string const &);
8487
85- void preModule (ModuleDescription const & md );
86- void postModule (ModuleDescription const & md );
88+ void preModule (ModuleDescription const &);
89+ void postModule (ModuleDescription const &);
8790
8891 void preModuleGlobal (GlobalContext const &, ModuleCallingContext const &);
8992 void postModuleGlobal (GlobalContext const &, ModuleCallingContext const &);
@@ -131,12 +134,6 @@ namespace edm {
131134 std::vector<std::unique_ptr<std::atomic<time_point>>> eventSetupModuleStartTimes_;
132135 std::vector<std::pair<uintptr_t , eventsetup::EventSetupRecordKey>> eventSetupModuleCallInfo_;
133136 std::atomic<double > accumulatedEventSetupModuleTimings_ = 0 .; // seconds
134-
135- std::vector<std::unique_ptr<std::atomic<unsigned int >>> countSubProcessesPreEvent_;
136- std::vector<std::unique_ptr<std::atomic<unsigned int >>> countSubProcessesPostEvent_;
137-
138- bool configuredInTopLevelProcess_;
139- unsigned int nSubProcesses_;
140137 };
141138 } // namespace service
142139} // namespace edm
@@ -203,10 +200,7 @@ namespace edm {
203200 return t.count ();
204201 }
205202
206- static void pushStack (bool configuredInTopLevelProcess) {
207- if (!configuredInTopLevelProcess) {
208- return ;
209- }
203+ static void pushStack () {
210204 auto & modStack = moduleTimeStack ();
211205 modStack.push_back (getTime ());
212206 }
@@ -225,10 +219,7 @@ namespace edm {
225219 min_events_time_(),
226220 total_event_count_(0 ),
227221 begin_lumi_count_(0 ),
228- begin_run_count_(0 ),
229- configuredInTopLevelProcess_{false },
230- nSubProcesses_{0 } {
231- iRegistry.watchPreBeginJob (this , &Timing::preBeginJob);
222+ begin_run_count_(0 ) {
232223 iRegistry.watchBeginProcessing (this , &Timing::beginProcessing);
233224 iRegistry.watchPreEndJob ([this ]() {
234225 end_loop_time_ = getTime ();
@@ -362,11 +353,6 @@ namespace edm {
362353 eventSetupModuleStartTimes_.emplace_back (std::make_unique<std::atomic<time_point>>());
363354 }
364355 eventSetupModuleCallInfo_.resize (nThreads_);
365-
366- for (unsigned int i = 0 ; i < nStreams_; ++i) {
367- countSubProcessesPreEvent_.emplace_back (std::make_unique<std::atomic<unsigned int >>(0 ));
368- countSubProcessesPostEvent_.emplace_back (std::make_unique<std::atomic<unsigned int >>(0 ));
369- }
370356 });
371357 setTaskCallbacks (iRegistry);
372358 }
@@ -437,18 +423,7 @@ namespace edm {
437423 descriptions.setComment (" This service reports the time it takes to run each module in a job." );
438424 }
439425
440- void Timing::preBeginJob (ProcessContext const & pc) {
441- if (pc.isSubProcess ()) {
442- ++nSubProcesses_;
443- } else {
444- configuredInTopLevelProcess_ = true ;
445- }
446- }
447-
448426 void Timing::beginProcessing () {
449- if (!configuredInTopLevelProcess_) {
450- return ;
451- }
452427 curr_job_time_ = getTime ();
453428 curr_job_cpu_ = getCPU ();
454429 last_task_change_time_ = curr_job_time_;
@@ -468,15 +443,6 @@ namespace edm {
468443 }
469444
470445 void Timing::postEndJob () {
471- if (!configuredInTopLevelProcess_) {
472- LogImportant (" TimeReport" ) << " \n TimeReport> This instance of the Timing Service will be disabled because it "
473- " is configured in a SubProcess.\n "
474- << " If multiple instances of the TimingService were configured only the one in the "
475- " top level process will function.\n "
476- << " The other instance(s) will simply print this message and do nothing.\n\n " ;
477- return ;
478- }
479-
480446 const auto job_end_time = getTime ();
481447 const double job_end_cpu = getCPU ();
482448 auto total_job_time = double_seconds (job_end_time - jobStartTime ()).count ();
@@ -573,41 +539,14 @@ namespace edm {
573539 }
574540
575541 void Timing::preEvent (StreamContext const & iStream) {
576- if (!configuredInTopLevelProcess_) {
577- return ;
578- }
579542 auto index = iStream.streamID ().value ();
580- if (nSubProcesses_ == 0u ) {
581- curr_events_time_[index] = getTime ();
582- } else {
583- unsigned int count = ++(*countSubProcessesPreEvent_[index]);
584- if (count == 1 ) {
585- curr_events_time_[index] = getTime ();
586- } else if (count == (nSubProcesses_ + 1 )) {
587- *countSubProcessesPreEvent_[index] = 0 ;
588- }
589- }
543+ curr_events_time_[index] = getTime ();
590544 }
591545
592546 void Timing::postEvent (StreamContext const & iStream) {
593- if (!configuredInTopLevelProcess_) {
594- return ;
595- }
596547 auto index = iStream.streamID ().value ();
597- if (nSubProcesses_ == 0u ) {
598- lastPostEvent (getTime () - curr_events_time_[index], index, iStream);
599- } else {
600- unsigned int count = ++(*countSubProcessesPostEvent_[index]);
601- if (count == (nSubProcesses_ + 1 )) {
602- lastPostEvent (getTime () - curr_events_time_[index], index, iStream);
603- *countSubProcessesPostEvent_[index] = 0 ;
604- }
605- }
606- }
548+ std::chrono::steady_clock::duration curr_event_time = getTime () - curr_events_time_[index];
607549
608- void Timing::lastPostEvent (std::chrono::steady_clock::duration curr_event_time,
609- unsigned int index,
610- StreamContext const & iStream) {
611550 double curr_event_time_d = double_seconds (curr_event_time).count ();
612551 sum_events_time_[index] += curr_event_time_d;
613552
@@ -623,9 +562,6 @@ namespace edm {
623562 }
624563
625564 void Timing::postModuleEvent (StreamContext const & iStream, ModuleCallingContext const & iModule) {
626- if (!configuredInTopLevelProcess_) {
627- return ;
628- }
629565 auto const & eventID = iStream.eventID ();
630566 auto const & desc = *(iModule.moduleDescription ());
631567 double t = postCommon ();
@@ -635,60 +571,39 @@ namespace edm {
635571 }
636572 }
637573
638- void Timing::preSourceEvent (StreamID sid ) { pushStack (configuredInTopLevelProcess_ ); }
574+ void Timing::preSourceEvent (StreamID) { pushStack (); }
639575
640- void Timing::postSourceEvent (StreamID sid ) { postCommon (); }
576+ void Timing::postSourceEvent (StreamID) { postCommon (); }
641577
642- void Timing::preSourceLumi (LuminosityBlockIndex index ) { pushStack (configuredInTopLevelProcess_ ); }
578+ void Timing::preSourceLumi (LuminosityBlockIndex) { pushStack (); }
643579
644- void Timing::postSourceLumi (LuminosityBlockIndex index ) { postCommon (); }
580+ void Timing::postSourceLumi (LuminosityBlockIndex) { postCommon (); }
645581
646- void Timing::preSourceRun (RunIndex index ) { pushStack (configuredInTopLevelProcess_ ); }
582+ void Timing::preSourceRun (RunIndex) { pushStack (); }
647583
648- void Timing::postSourceRun (RunIndex index ) { postCommon (); }
584+ void Timing::postSourceRun (RunIndex) { postCommon (); }
649585
650- void Timing::preOpenFile (std::string const & lfn ) { pushStack (configuredInTopLevelProcess_ ); }
586+ void Timing::preOpenFile (std::string const &) { pushStack (); }
651587
652- void Timing::postOpenFile (std::string const & lfn ) { postCommon (); }
588+ void Timing::postOpenFile (std::string const &) { postCommon (); }
653589
654- void Timing::preModule (ModuleDescription const &) { pushStack (configuredInTopLevelProcess_ ); }
590+ void Timing::preModule (ModuleDescription const &) { pushStack (); }
655591
656- void Timing::postModule (ModuleDescription const & desc ) { postCommon (); }
592+ void Timing::postModule (ModuleDescription const &) { postCommon (); }
657593
658- void Timing::preModuleGlobal (GlobalContext const &, ModuleCallingContext const &) {
659- pushStack (configuredInTopLevelProcess_);
660- }
594+ void Timing::preModuleGlobal (GlobalContext const &, ModuleCallingContext const &) { pushStack (); }
661595
662596 void Timing::postModuleGlobal (GlobalContext const &, ModuleCallingContext const & mcc) { postCommon (); }
663597
664- void Timing::postGlobalBeginRun (GlobalContext const & gc) {
665- if (!configuredInTopLevelProcess_) {
666- return ;
667- }
668- if (!gc.processContext ()->isSubProcess ()) {
669- ++begin_run_count_;
670- }
671- }
598+ void Timing::postGlobalBeginRun (GlobalContext const & gc) { ++begin_run_count_; }
672599
673- void Timing::postGlobalBeginLumi (GlobalContext const & gc) {
674- if (!configuredInTopLevelProcess_) {
675- return ;
676- }
677- if (!gc.processContext ()->isSubProcess ()) {
678- ++begin_lumi_count_;
679- }
680- }
600+ void Timing::postGlobalBeginLumi (GlobalContext const & gc) { ++begin_lumi_count_; }
681601
682- void Timing::preModuleStream (StreamContext const &, ModuleCallingContext const &) {
683- pushStack (configuredInTopLevelProcess_);
684- }
602+ void Timing::preModuleStream (StreamContext const &, ModuleCallingContext const &) { pushStack (); }
685603
686604 void Timing::postModuleStream (StreamContext const &, ModuleCallingContext const & mcc) { postCommon (); }
687605
688606 double Timing::postCommon () const {
689- if (!configuredInTopLevelProcess_) {
690- return 0.0 ;
691- }
692607 double t = popStack ();
693608 if (t > threshold_) {
694609 LogError (" ExcessiveTime" )
0 commit comments