CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes
edm::service::Timing Class Reference

#include <Timing.h>

Inheritance diagram for edm::service::Timing:
edm::TimingServiceBase

Public Member Functions

virtual void addToCPUTime (StreamID id, double iTime) override
 
 Timing (ParameterSet const &, ActivityRegistry &)
 
 ~Timing ()
 
- Public Member Functions inherited from edm::TimingServiceBase
 TimingServiceBase ()
 
virtual ~TimingServiceBase ()
 

Static Public Member Functions

static void fillDescriptions (edm::ConfigurationDescriptions &descriptions)
 

Private Member Functions

void postBeginJob ()
 
void postEndJob ()
 
void postEvent (StreamContext const &)
 
void postModule (StreamContext const &, ModuleCallingContext const &)
 
void preEvent (StreamContext const &)
 
void preModule (StreamContext const &, ModuleCallingContext const &)
 

Private Attributes

std::vector< double > curr_events_time_
 
double curr_job_cpu_
 
double curr_job_time_
 
std::atomic< double > last_run_cpu_
 
std::atomic< double > last_run_time_
 
std::vector< double > max_events_time_
 
std::vector< double > min_events_time_
 
bool report_summary_
 
std::vector< double > sum_events_time_
 
bool summary_only_
 
std::atomic< unsigned long > total_event_count_
 

Detailed Description

Definition at line 25 of file Timing.h.

Constructor & Destructor Documentation

edm::service::Timing::Timing ( ParameterSet const &  iPS,
ActivityRegistry iRegistry 
)

Definition at line 68 of file Timing.cc.

References edm::signalslot::Signal< T >::connect(), curr_events_time_, edm::service::getCPU(), edm::service::getTime(), last_run_cpu_, last_run_time_, max_events_time_, edm::service::SystemBounds::maxNumberOfStreams(), min_events_time_, postBeginJob(), postEndJob(), postEvent(), edm::ActivityRegistry::postGlobalEndRunSignal_, postModule(), edm::ActivityRegistry::preallocateSignal_, preEvent(), preModule(), sum_events_time_, summary_only_, edm::ActivityRegistry::watchPostBeginJob(), edm::ActivityRegistry::watchPostEndJob(), edm::ActivityRegistry::watchPostEvent(), edm::ActivityRegistry::watchPostModuleEvent(), edm::ActivityRegistry::watchPreEvent(), and edm::ActivityRegistry::watchPreModuleEvent().

68  :
69  curr_job_time_(0.),
70  curr_job_cpu_(0.),
72  summary_only_(iPS.getUntrackedParameter<bool>("summaryOnly")),
73  report_summary_(iPS.getUntrackedParameter<bool>("useJobReport")),
77  iRegistry.watchPostBeginJob(this, &Timing::postBeginJob);
78  iRegistry.watchPostEndJob(this, &Timing::postEndJob);
79 
80  iRegistry.watchPreEvent(this, &Timing::preEvent);
81  iRegistry.watchPostEvent(this, &Timing::postEvent);
82 
83  if(not summary_only_) {
84  iRegistry.watchPreModuleEvent(this, &Timing::preModule);
85  iRegistry.watchPostModuleEvent(this, &Timing::postModule);
86  }
87 
88  iRegistry.preallocateSignal_.connect([this](service::SystemBounds const& iBounds){
89  auto nStreams = iBounds.maxNumberOfStreams();
90  curr_events_time_.resize(nStreams,0.);
91  sum_events_time_.resize(nStreams,0.);
92  max_events_time_.resize(nStreams,0.);
93  min_events_time_.resize(nStreams,1.E6);
94  });
95 
96  iRegistry.postGlobalEndRunSignal_.connect([this](edm::GlobalContext const&) {
99  });
100  }
std::vector< double > sum_events_time_
Definition: Timing.h:59
double curr_job_time_
Definition: Timing.h:45
std::atomic< double > last_run_cpu_
Definition: Timing.h:49
std::vector< double > max_events_time_
Definition: Timing.h:57
bool report_summary_
Definition: Timing.h:52
std::vector< double > curr_events_time_
Definition: Timing.h:50
static double getCPU()
Definition: Timing.cc:47
void postEvent(StreamContext const &)
Definition: Timing.cc:189
double curr_job_cpu_
Definition: Timing.h:46
std::atomic< double > last_run_time_
Definition: Timing.h:48
std::atomic< unsigned long > total_event_count_
Definition: Timing.h:60
static double getTime()
Definition: Timing.cc:40
void postModule(StreamContext const &, ModuleCallingContext const &)
Definition: Timing.cc:213
void preEvent(StreamContext const &)
Definition: Timing.cc:184
void preModule(StreamContext const &, ModuleCallingContext const &)
Definition: Timing.cc:208
std::vector< double > min_events_time_
Definition: Timing.h:58
edm::service::Timing::~Timing ( )

Definition at line 102 of file Timing.cc.

102  {
103  }

Member Function Documentation

void edm::service::Timing::addToCPUTime ( StreamID  id,
double  iTime 
)
overridevirtual

Extra CPU time used by a job but not seen by cmsRun The value should be in seconds. This function is safe to call from multiple threads

Implements edm::TimingServiceBase.

Definition at line 105 of file Timing.cc.

References curr_job_cpu_.

105  {
106  //For accounting purposes we effectively can say we started earlier
107  curr_job_cpu_ -= iTime;
108  }
double curr_job_cpu_
Definition: Timing.h:46
void edm::service::Timing::fillDescriptions ( edm::ConfigurationDescriptions descriptions)
static

Definition at line 111 of file Timing.cc.

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

111  {
113  desc.addUntracked<bool>("summaryOnly", false)->setComment(
114  "If 'true' do not report timing for each event");
115  desc.addUntracked<bool>("useJobReport", true)->setComment(
116  "If 'true' write summary information to JobReport");
117  descriptions.add("Timing", desc);
118  descriptions.setComment(
119  "This service reports the time it takes to run each module in a job.");
120  }
void setComment(std::string const &value)
void add(std::string const &label, ParameterSetDescription const &psetDescription)
void edm::service::Timing::postBeginJob ( )
private

Definition at line 122 of file Timing.cc.

References curr_job_cpu_, curr_job_time_, edm::service::getCPU(), edm::service::getTime(), and summary_only_.

Referenced by Timing().

122  {
124  curr_job_cpu_ = getCPU();
125 
126  if(not summary_only_) {
127  LogImportant("TimeReport")
128  << "TimeReport> Report activated" << "\n"
129  << "TimeReport> Report columns headings for events: "
130  << "eventnum runnum timetaken\n"
131  << "TimeReport> Report columns headings for modules: "
132  << "eventnum runnum modulelabel modulename timetakeni\n"
133  << "TimeReport> JobTime=" << curr_job_time_ << " JobCPU=" << curr_job_cpu_ << "\n";
134  }
135  }
double curr_job_time_
Definition: Timing.h:45
static double getCPU()
Definition: Timing.cc:47
double curr_job_cpu_
Definition: Timing.h:46
static double getTime()
Definition: Timing.cc:40
void edm::service::Timing::postEndJob ( )
private

Definition at line 137 of file Timing.cc.

References curr_job_cpu_, curr_job_time_, edm::service::d2str(), edm::service::getCPU(), edm::service::getTime(), last_run_cpu_, last_run_time_, max_events_time_, min_events_time_, report_summary_, sum_events_time_, edmStreamStallGrapher::t, and total_event_count_.

Referenced by Timing().

137  {
138  double total_job_time = getTime() - curr_job_time_;
139 
140  double total_job_cpu = getCPU() - curr_job_cpu_;
141 
142  double min_event_time = *(std::min_element(min_events_time_.begin(),
143  min_events_time_.end()));
144  double max_event_time = *(std::max_element(max_events_time_.begin(),
145  max_events_time_.end()));
146  auto total_loop_time = last_run_time_ - curr_job_time_;
147  auto total_loop_cpu = last_run_cpu_ - curr_job_cpu_;
148 
149  double sum_all_events_time = 0;
150  for(auto t : sum_events_time_) { sum_all_events_time += t; }
151  double average_event_time = sum_all_events_time / total_event_count_;
152 
153  LogImportant("TimeReport")
154  << "TimeReport> Time report complete in "
155  << total_job_time << " seconds"
156  << "\n"
157  << " Time Summary: \n"
158  << " - Min event: " << min_event_time << "\n"
159  << " - Max event: " << max_event_time << "\n"
160  << " - Avg event: " << average_event_time << "\n"
161  << " - Total loop: " <<total_loop_time <<"\n"
162  << " - Total job: " << total_job_time << "\n"
163  << " Event Throughput: "<<total_event_count_/ total_loop_time<<" ev/s\n"
164  << " CPU Summary: \n"
165  << " - Total loop: " << total_loop_cpu << "\n"
166  << " - Total job: " << total_job_cpu << "\n";
167 
168  if(report_summary_) {
169  Service<JobReport> reportSvc;
170  std::map<std::string, std::string> reportData;
171 
172  reportData.insert(std::make_pair("MinEventTime", d2str(min_event_time)));
173  reportData.insert(std::make_pair("MaxEventTime", d2str(max_event_time)));
174  reportData.insert(std::make_pair("AvgEventTime", d2str(average_event_time)));
175  reportData.insert(std::make_pair("EventThroughput", d2str(total_event_count_/total_loop_time)));
176  reportData.insert(std::make_pair("TotalJobTime", d2str(total_job_time)));
177  reportData.insert(std::make_pair("TotalJobCPU", d2str(total_job_cpu)));
178  reportData.insert(std::make_pair("TotalLoopCPU", d2str(total_loop_cpu)));
179 
180  reportSvc->reportPerformanceSummary("Timing", reportData);
181  }
182  }
std::vector< double > sum_events_time_
Definition: Timing.h:59
double curr_job_time_
Definition: Timing.h:45
std::atomic< double > last_run_cpu_
Definition: Timing.h:49
std::vector< double > max_events_time_
Definition: Timing.h:57
bool report_summary_
Definition: Timing.h:52
static double getCPU()
Definition: Timing.cc:47
double curr_job_cpu_
Definition: Timing.h:46
std::atomic< double > last_run_time_
Definition: Timing.h:48
std::atomic< unsigned long > total_event_count_
Definition: Timing.h:60
static std::string d2str(double d)
Definition: Memory.cc:62
static double getTime()
Definition: Timing.cc:40
std::vector< double > min_events_time_
Definition: Timing.h:58
void edm::service::Timing::postEvent ( StreamContext const &  iStream)
private

Definition at line 189 of file Timing.cc.

References curr_events_time_, edm::StreamContext::eventID(), edm::service::getTime(), cmsHarvester::index, max_events_time_, min_events_time_, edm::StreamContext::streamID(), sum_events_time_, summary_only_, total_event_count_, and edm::StreamID::value().

Referenced by Timing().

189  {
190  auto index = iStream.streamID().value();
191 
192  double curr_event_time = getTime() - curr_events_time_[index];
193  sum_events_time_[index] +=curr_event_time;
194 
195  if(not summary_only_) {
196  auto const & eventID = iStream.eventID();
197  LogPrint("TimeEvent")
198  << "TimeEvent> "
199  << eventID.event() << " "
200  << eventID.run() << " "
201  << curr_event_time ;
202  }
203  if(curr_event_time > max_events_time_[index]) max_events_time_[index] = curr_event_time;
204  if(curr_event_time < min_events_time_[index]) min_events_time_[index] = curr_event_time;
206  }
std::vector< double > sum_events_time_
Definition: Timing.h:59
std::vector< double > max_events_time_
Definition: Timing.h:57
std::vector< double > curr_events_time_
Definition: Timing.h:50
std::atomic< unsigned long > total_event_count_
Definition: Timing.h:60
static double getTime()
Definition: Timing.cc:40
std::vector< double > min_events_time_
Definition: Timing.h:58
void edm::service::Timing::postModule ( StreamContext const &  iStream,
ModuleCallingContext const &  iModule 
)
private

Definition at line 213 of file Timing.cc.

References assert(), edm::StreamContext::eventID(), edm::service::getTime(), edm::ModuleCallingContext::moduleDescription(), edm::service::moduleTimeStack(), and edmStreamStallGrapher::t.

Referenced by Timing().

213  {
214  //LogInfo("TimeModule")
215  auto& modStack = moduleTimeStack();
216  assert(modStack.size() > 0);
217  double curr_module_time = modStack.back();
218  modStack.pop_back();
219  double t = getTime() - curr_module_time;
220  //move waiting module start times forward to account
221  // for the fact that they were paused while this module ran
222  for(auto& waitingModuleStartTime : modStack) {
223  waitingModuleStartTime +=t;
224  }
225  auto const & eventID = iStream.eventID();
226  auto const & desc = *(iModule.moduleDescription());
227 
228  LogPrint("TimeModule") << "TimeModule> "
229  << eventID.event() << " "
230  << eventID.run() << " "
231  << desc.moduleLabel() << " "
232  << desc.moduleName() << " "
233  << t;
234  }
assert(m_qm.get())
static std::vector< double > & moduleTimeStack()
Definition: Timing.cc:63
static double getTime()
Definition: Timing.cc:40
void edm::service::Timing::preEvent ( StreamContext const &  iStream)
private

Definition at line 184 of file Timing.cc.

References curr_events_time_, edm::service::getTime(), cmsHarvester::index, edm::StreamContext::streamID(), and edm::StreamID::value().

Referenced by Timing().

184  {
185  auto index = iStream.streamID().value();
187  }
std::vector< double > curr_events_time_
Definition: Timing.h:50
static double getTime()
Definition: Timing.cc:40
void edm::service::Timing::preModule ( StreamContext const &  ,
ModuleCallingContext const &   
)
private

Definition at line 208 of file Timing.cc.

References edm::service::getTime(), and edm::service::moduleTimeStack().

Referenced by Timing().

208  {
209  auto & modStack = moduleTimeStack();
210  modStack.push_back(getTime());
211  }
static std::vector< double > & moduleTimeStack()
Definition: Timing.cc:63
static double getTime()
Definition: Timing.cc:40

Member Data Documentation

std::vector<double> edm::service::Timing::curr_events_time_
private

Definition at line 50 of file Timing.h.

Referenced by postEvent(), preEvent(), and Timing().

double edm::service::Timing::curr_job_cpu_
private

Definition at line 46 of file Timing.h.

Referenced by addToCPUTime(), postBeginJob(), and postEndJob().

double edm::service::Timing::curr_job_time_
private

Definition at line 45 of file Timing.h.

Referenced by postBeginJob(), and postEndJob().

std::atomic<double> edm::service::Timing::last_run_cpu_
private

Definition at line 49 of file Timing.h.

Referenced by postEndJob(), and Timing().

std::atomic<double> edm::service::Timing::last_run_time_
private

Definition at line 48 of file Timing.h.

Referenced by postEndJob(), and Timing().

std::vector<double> edm::service::Timing::max_events_time_
private

Definition at line 57 of file Timing.h.

Referenced by postEndJob(), postEvent(), and Timing().

std::vector<double> edm::service::Timing::min_events_time_
private

Definition at line 58 of file Timing.h.

Referenced by postEndJob(), postEvent(), and Timing().

bool edm::service::Timing::report_summary_
private

Definition at line 52 of file Timing.h.

Referenced by postEndJob().

std::vector<double> edm::service::Timing::sum_events_time_
private

Definition at line 59 of file Timing.h.

Referenced by postEndJob(), postEvent(), and Timing().

bool edm::service::Timing::summary_only_
private

Definition at line 51 of file Timing.h.

Referenced by postBeginJob(), postEvent(), and Timing().

std::atomic<unsigned long> edm::service::Timing::total_event_count_
private

Definition at line 60 of file Timing.h.

Referenced by postEndJob(), and postEvent().