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
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 36 of file Timing.cc.

Constructor & Destructor Documentation

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

Definition at line 113 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().

113  :
114  curr_job_time_(0.),
115  curr_job_cpu_(0.),
117  summary_only_(iPS.getUntrackedParameter<bool>("summaryOnly")),
118  report_summary_(iPS.getUntrackedParameter<bool>("useJobReport")),
121  total_event_count_(0) {
122  iRegistry.watchPostBeginJob(this, &Timing::postBeginJob);
123  iRegistry.watchPostEndJob(this, &Timing::postEndJob);
124 
125  iRegistry.watchPreEvent(this, &Timing::preEvent);
126  iRegistry.watchPostEvent(this, &Timing::postEvent);
127 
128  if(not summary_only_) {
129  iRegistry.watchPreModuleEvent(this, &Timing::preModule);
130  iRegistry.watchPostModuleEvent(this, &Timing::postModule);
131  }
132 
133  iRegistry.preallocateSignal_.connect([this](service::SystemBounds const& iBounds){
134  auto nStreams = iBounds.maxNumberOfStreams();
135  curr_events_time_.resize(nStreams,0.);
136  sum_events_time_.resize(nStreams,0.);
137  max_events_time_.resize(nStreams,0.);
138  min_events_time_.resize(nStreams,1.E6);
139  });
140 
141  iRegistry.postGlobalEndRunSignal_.connect([this](edm::GlobalContext const&) {
143  last_run_cpu_ = getCPU();
144  });
145  }
std::vector< double > sum_events_time_
Definition: Timing.cc:70
double curr_job_time_
Definition: Timing.cc:56
std::atomic< double > last_run_cpu_
Definition: Timing.cc:60
std::vector< double > max_events_time_
Definition: Timing.cc:68
std::vector< double > curr_events_time_
Definition: Timing.cc:61
static double getCPU()
Definition: Timing.cc:92
void postEvent(StreamContext const &)
Definition: Timing.cc:234
double curr_job_cpu_
Definition: Timing.cc:57
std::atomic< double > last_run_time_
Definition: Timing.cc:59
std::atomic< unsigned long > total_event_count_
Definition: Timing.cc:71
static double getTime()
Definition: Timing.cc:85
void postModule(StreamContext const &, ModuleCallingContext const &)
Definition: Timing.cc:258
void preEvent(StreamContext const &)
Definition: Timing.cc:229
void preModule(StreamContext const &, ModuleCallingContext const &)
Definition: Timing.cc:253
std::vector< double > min_events_time_
Definition: Timing.cc:69
edm::service::Timing::~Timing ( )

Definition at line 147 of file Timing.cc.

147  {
148  }

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 150 of file Timing.cc.

References curr_job_cpu_.

150  {
151  //For accounting purposes we effectively can say we started earlier
152  curr_job_cpu_ -= iTime;
153  }
double curr_job_cpu_
Definition: Timing.cc:57
void edm::service::Timing::fillDescriptions ( edm::ConfigurationDescriptions descriptions)
static

Definition at line 156 of file Timing.cc.

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

156  {
158  desc.addUntracked<bool>("summaryOnly", false)->setComment(
159  "If 'true' do not report timing for each event");
160  desc.addUntracked<bool>("useJobReport", true)->setComment(
161  "If 'true' write summary information to JobReport");
162  descriptions.add("Timing", desc);
163  descriptions.setComment(
164  "This service reports the time it takes to run each module in a job.");
165  }
void setComment(std::string const &value)
void add(std::string const &label, ParameterSetDescription const &psetDescription)
void edm::service::Timing::postBeginJob ( )
private

Definition at line 167 of file Timing.cc.

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

Referenced by Timing().

167  {
169  curr_job_cpu_ = getCPU();
170 
171  if(not summary_only_) {
172  LogImportant("TimeReport")
173  << "TimeReport> Report activated" << "\n"
174  << "TimeReport> Report columns headings for events: "
175  << "eventnum runnum timetaken\n"
176  << "TimeReport> Report columns headings for modules: "
177  << "eventnum runnum modulelabel modulename timetakeni\n"
178  << "TimeReport> JobTime=" << curr_job_time_ << " JobCPU=" << curr_job_cpu_ << "\n";
179  }
180  }
double curr_job_time_
Definition: Timing.cc:56
static double getCPU()
Definition: Timing.cc:92
double curr_job_cpu_
Definition: Timing.cc:57
static double getTime()
Definition: Timing.cc:85
void edm::service::Timing::postEndJob ( )
private

Definition at line 182 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_, lumiQTWidget::t, and total_event_count_.

Referenced by Timing().

182  {
183  double total_job_time = getTime() - curr_job_time_;
184 
185  double total_job_cpu = getCPU() - curr_job_cpu_;
186 
187  double min_event_time = *(std::min_element(min_events_time_.begin(),
188  min_events_time_.end()));
189  double max_event_time = *(std::max_element(max_events_time_.begin(),
190  max_events_time_.end()));
191  auto total_loop_time = last_run_time_ - curr_job_time_;
192  auto total_loop_cpu = last_run_cpu_ - curr_job_cpu_;
193 
194  double sum_all_events_time = 0;
195  for(auto t : sum_events_time_) { sum_all_events_time += t; }
196  double average_event_time = sum_all_events_time / total_event_count_;
197 
198  LogImportant("TimeReport")
199  << "TimeReport> Time report complete in "
200  << total_job_time << " seconds"
201  << "\n"
202  << " Time Summary: \n"
203  << " - Min event: " << min_event_time << "\n"
204  << " - Max event: " << max_event_time << "\n"
205  << " - Avg event: " << average_event_time << "\n"
206  << " - Total loop: " <<total_loop_time <<"\n"
207  << " - Total job: " << total_job_time << "\n"
208  << " Event Throughput: "<<total_event_count_/ total_loop_time<<" ev/s\n"
209  << " CPU Summary: \n"
210  << " - Total loop: " << total_loop_cpu << "\n"
211  << " - Total job: " << total_job_cpu << "\n";
212 
213  if(report_summary_) {
214  Service<JobReport> reportSvc;
215  std::map<std::string, std::string> reportData;
216 
217  reportData.insert(std::make_pair("MinEventTime", d2str(min_event_time)));
218  reportData.insert(std::make_pair("MaxEventTime", d2str(max_event_time)));
219  reportData.insert(std::make_pair("AvgEventTime", d2str(average_event_time)));
220  reportData.insert(std::make_pair("EventThroughput", d2str(total_event_count_/total_loop_time)));
221  reportData.insert(std::make_pair("TotalJobTime", d2str(total_job_time)));
222  reportData.insert(std::make_pair("TotalJobCPU", d2str(total_job_cpu)));
223  reportData.insert(std::make_pair("TotalLoopCPU", d2str(total_loop_cpu)));
224 
225  reportSvc->reportPerformanceSummary("Timing", reportData);
226  }
227  }
std::vector< double > sum_events_time_
Definition: Timing.cc:70
double curr_job_time_
Definition: Timing.cc:56
std::atomic< double > last_run_cpu_
Definition: Timing.cc:60
std::vector< double > max_events_time_
Definition: Timing.cc:68
static double getCPU()
Definition: Timing.cc:92
double curr_job_cpu_
Definition: Timing.cc:57
std::atomic< double > last_run_time_
Definition: Timing.cc:59
std::atomic< unsigned long > total_event_count_
Definition: Timing.cc:71
static std::string d2str(double d)
static double getTime()
Definition: Timing.cc:85
std::vector< double > min_events_time_
Definition: Timing.cc:69
void edm::service::Timing::postEvent ( StreamContext const &  iStream)
private

Definition at line 234 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().

234  {
235  auto index = iStream.streamID().value();
236 
237  double curr_event_time = getTime() - curr_events_time_[index];
238  sum_events_time_[index] +=curr_event_time;
239 
240  if(not summary_only_) {
241  auto const & eventID = iStream.eventID();
242  LogPrint("TimeEvent")
243  << "TimeEvent> "
244  << eventID.event() << " "
245  << eventID.run() << " "
246  << curr_event_time ;
247  }
248  if(curr_event_time > max_events_time_[index]) max_events_time_[index] = curr_event_time;
249  if(curr_event_time < min_events_time_[index]) min_events_time_[index] = curr_event_time;
251  }
std::vector< double > sum_events_time_
Definition: Timing.cc:70
std::vector< double > max_events_time_
Definition: Timing.cc:68
std::vector< double > curr_events_time_
Definition: Timing.cc:61
std::atomic< unsigned long > total_event_count_
Definition: Timing.cc:71
static double getTime()
Definition: Timing.cc:85
std::vector< double > min_events_time_
Definition: Timing.cc:69
void edm::service::Timing::postModule ( StreamContext const &  iStream,
ModuleCallingContext const &  iModule 
)
private

Definition at line 258 of file Timing.cc.

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

Referenced by Timing().

258  {
259  //LogInfo("TimeModule")
260  auto& modStack = moduleTimeStack();
261  assert(modStack.size() > 0);
262  double curr_module_time = modStack.back();
263  modStack.pop_back();
264  double t = getTime() - curr_module_time;
265  //move waiting module start times forward to account
266  // for the fact that they were paused while this module ran
267  for(auto& waitingModuleStartTime : modStack) {
268  waitingModuleStartTime +=t;
269  }
270  auto const & eventID = iStream.eventID();
271  auto const & desc = *(iModule.moduleDescription());
272 
273  LogPrint("TimeModule") << "TimeModule> "
274  << eventID.event() << " "
275  << eventID.run() << " "
276  << desc.moduleLabel() << " "
277  << desc.moduleName() << " "
278  << t;
279  }
assert(m_qm.get())
static std::vector< double > & moduleTimeStack()
Definition: Timing.cc:108
static double getTime()
Definition: Timing.cc:85
void edm::service::Timing::preEvent ( StreamContext const &  iStream)
private

Definition at line 229 of file Timing.cc.

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

Referenced by Timing().

229  {
230  auto index = iStream.streamID().value();
232  }
std::vector< double > curr_events_time_
Definition: Timing.cc:61
static double getTime()
Definition: Timing.cc:85
void edm::service::Timing::preModule ( StreamContext const &  ,
ModuleCallingContext const &   
)
private

Definition at line 253 of file Timing.cc.

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

Referenced by Timing().

253  {
254  auto & modStack = moduleTimeStack();
255  modStack.push_back(getTime());
256  }
static std::vector< double > & moduleTimeStack()
Definition: Timing.cc:108
static double getTime()
Definition: Timing.cc:85

Member Data Documentation

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

Definition at line 61 of file Timing.cc.

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

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

Definition at line 57 of file Timing.cc.

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

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

Definition at line 56 of file Timing.cc.

Referenced by postBeginJob(), and postEndJob().

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

Definition at line 60 of file Timing.cc.

Referenced by postEndJob(), and Timing().

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

Definition at line 59 of file Timing.cc.

Referenced by postEndJob(), and Timing().

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

Definition at line 68 of file Timing.cc.

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

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

Definition at line 69 of file Timing.cc.

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

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

Definition at line 63 of file Timing.cc.

Referenced by postEndJob().

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

Definition at line 70 of file Timing.cc.

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

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

Definition at line 62 of file Timing.cc.

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

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

Definition at line 71 of file Timing.cc.

Referenced by postEndJob(), and postEvent().