29 #include <sys/resource.h> 119 if(gettimeofday(&t,
nullptr) < 0)
120 throw cms::Exception(
"SysCallFailed",
"Failed call to gettimeofday");
121 return static_cast<double>(t.tv_sec) + (static_cast<double>(t.tv_usec) * 1E-6);
126 getrusage(RUSAGE_SELF, &usage);
128 double totalCPUTime = 0.0;
130 totalCPUTime = (double)usage.ru_utime.tv_sec + (
double(usage.ru_utime.tv_usec) * 1E-6);
132 totalCPUTime += (double)usage.ru_stime.tv_sec + (
double(usage.ru_stime.tv_usec) * 1E-6);
135 getrusage(RUSAGE_CHILDREN, &usage);
136 totalCPUTime += (double)usage.ru_utime.tv_sec + (
double(usage.ru_utime.tv_usec) * 1E-6);
137 totalCPUTime += (double)usage.ru_stime.tv_sec + (
double(usage.ru_stime.tv_usec) * 1E-6);
147 static thread_local std::vector<double> s_stack;
154 assert(!modStack.empty());
155 double curr_module_time = modStack.back();
157 double t =
getTime() - curr_module_time;
175 threshold_(iPS.getUntrackedParameter<double>(
"excessiveTimeThreshold")),
185 bool checkThreshold =
true;
189 checkThreshold =
false;
275 desc.
addUntracked<
bool>(
"summaryOnly",
false)->setComment(
276 "If 'true' do not report timing for each event");
277 desc.
addUntracked<
bool>(
"useJobReport",
true)->setComment(
278 "If 'true' write summary information to JobReport");
280 "Amount of time in seconds before reporting a module or source has taken excessive time. A value of 0.0 turns off this reporting.");
281 descriptions.
add(
"Timing", desc);
283 "This service reports the time it takes to run each module in a job.");
292 <<
"TimeReport> Report activated" <<
"\n" 293 <<
"TimeReport> Report columns headings for events: " 294 <<
"eventnum runnum timetaken\n" 295 <<
"TimeReport> Report columns headings for modules: " 296 <<
"eventnum runnum modulelabel modulename timetakeni\n" 302 const double job_end_time =
getTime();
303 const double job_end_cpu =
getCPU();
306 double total_job_cpu = job_end_cpu;
326 total_loop_time = 0.0;
327 total_loop_cpu = 0.0;
330 double sum_all_events_time = 0;
333 double average_event_time = 0.0;
338 double event_throughput = 0.0;
339 if(total_loop_time != 0.0) {
344 <<
"TimeReport> Time report complete in " 345 << total_job_time <<
" seconds" 347 <<
" Time Summary: \n" 348 <<
" - Min event: " << min_event_time <<
"\n" 349 <<
" - Max event: " << max_event_time <<
"\n" 350 <<
" - Avg event: " << average_event_time <<
"\n" 351 <<
" - Total loop: " << total_loop_time <<
"\n" 352 <<
" - Total init: " << total_initialization_time <<
"\n" 353 <<
" - Total job: " << total_job_time <<
"\n" 354 <<
" Event Throughput: "<< event_throughput <<
" ev/s\n" 355 <<
" CPU Summary: \n" 356 <<
" - Total loop: " << total_loop_cpu <<
"\n" 357 <<
" - Total init: " << total_initialization_cpu <<
"\n" 358 <<
" - Total job: " << total_job_cpu <<
"\n";
362 std::map<std::string, std::string> reportData;
364 reportData.insert(std::make_pair(
"MinEventTime",
d2str(min_event_time)));
365 reportData.insert(std::make_pair(
"MaxEventTime",
d2str(max_event_time)));
366 reportData.insert(std::make_pair(
"AvgEventTime",
d2str(average_event_time)));
367 reportData.insert(std::make_pair(
"EventThroughput",
d2str(event_throughput)));
368 reportData.insert(std::make_pair(
"TotalJobTime",
d2str(total_job_time)));
369 reportData.insert(std::make_pair(
"TotalJobCPU",
d2str(total_job_cpu)));
370 reportData.insert(std::make_pair(
"TotalLoopTime",
d2str(total_loop_time)));
371 reportData.insert(std::make_pair(
"TotalLoopCPU",
d2str(total_loop_cpu)));
372 reportData.insert(std::make_pair(
"TotalInitTime",
d2str(total_initialization_time)));
373 reportData.insert(std::make_pair(
"TotalInitCPU",
d2str(total_initialization_cpu)));
374 reportData.insert(std::make_pair(
"NumberOfStreams",
ui2str(
nStreams_)));
375 reportData.insert(std::make_pair(
"NumberOfThreads",
ui2str(
nThreads_)));
376 reportSvc->reportPerformanceSummary(
"Timing", reportData);
392 auto const & eventID = iStream.
eventID();
395 << eventID.event() <<
" " 396 << eventID.run() <<
" " 405 auto const & eventID = iStream.
eventID();
409 LogPrint(
"TimeModule") <<
"TimeModule> " 410 << eventID.event() <<
" " 411 << eventID.run() <<
" " 412 << desc.moduleLabel() <<
" " 413 << desc.moduleName() <<
" " 485 <<
"ExcessiveTime: Module used " << t
486 <<
" seconds of time which exceeds the error threshold configured in the Timing Service of " void watchPostModuleGlobalEndLumi(PostModuleGlobalEndLumi::slot_type const &iSlot)
void watchPostModuleConstruction(PostModuleConstruction::slot_type const &iSlot)
std::vector< double > sum_events_time_
unsigned int maxNumberOfThreads() const
void watchPreModuleGlobalBeginRun(PreModuleGlobalBeginRun::slot_type const &iSlot)
void setComment(std::string const &value)
void watchPreEvent(PreEvent::slot_type const &iSlot)
std::atomic< double > last_run_cpu_
#define DEFINE_FWK_SERVICE_MAKER(concrete, maker)
std::vector< double > max_events_time_
ParameterDescriptionBase * addUntracked(U const &iLabel, T const &value)
void watchPostEndJob(PostEndJob::slot_type const &iSlot)
std::vector< double > curr_events_time_
void watchPreModuleEvent(PreModuleEvent::slot_type const &iSlot)
void watchPreModuleConstruction(PreModuleConstruction::slot_type const &iSlot)
void watchPostEvent(PostEvent::slot_type const &iSlot)
double getTotalCPU() const override
void preModule(ModuleDescription const &md)
void watchPreSourceConstruction(PreSourceConstruction::slot_type const &iSlot)
void watchPostSourceConstruction(PostSourceConstruction::slot_type const &iSlot)
void watchPreEventReadFromSource(PreEventReadFromSource::slot_type const &iSlot)
void watchPostModuleEvent(PostModuleEvent::slot_type const &iSlot)
void watchPostModuleGlobalBeginLumi(PostModuleGlobalBeginLumi::slot_type const &iSlot)
void watchPostModuleStreamEndLumi(PostModuleStreamEndLumi::slot_type const &iSlot)
void postEvent(StreamContext const &)
void preModuleStream(StreamContext const &, ModuleCallingContext const &)
void watchPostModuleStreamBeginRun(PostModuleStreamBeginRun::slot_type const &iSlot)
void watchPostSourceEvent(PostSourceEvent::slot_type const &iSlot)
edm::serviceregistry::AllArgsMaker< edm::TimingServiceBase, Timing > TimingMaker
void watchPreModuleGlobalEndRun(PreModuleGlobalEndRun::slot_type const &iSlot)
void preOpenFile(std::string const &, bool)
void preModuleGlobal(GlobalContext const &, ModuleCallingContext const &)
void postModule(ModuleDescription const &md)
Preallocate preallocateSignal_
signal is emitted before beginJob
unsigned int maxNumberOfStreams() const
void watchPreOpenFile(PreOpenFile::slot_type const &iSlot)
void postModuleStream(StreamContext const &, ModuleCallingContext const &)
void watchPostSourceRun(PostSourceRun::slot_type const &iSlot)
Timing(ParameterSet const &, ActivityRegistry &)
void watchPreSourceLumi(PreSourceLumi::slot_type const &iSlot)
ModuleDescription const * moduleDescription() const
void postModuleEvent(StreamContext const &, ModuleCallingContext const &)
std::atomic< double > last_run_time_
void watchPreModuleEndJob(PreModuleEndJob::slot_type const &iSlot)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
void watchPreSourceRun(PreSourceRun::slot_type const &iSlot)
void watchPreModuleBeginJob(PreModuleBeginJob::slot_type const &iSlot)
static double jobStartTime()
void watchPreModuleGlobalBeginLumi(PreModuleGlobalBeginLumi::slot_type const &iSlot)
void watchPostModuleStreamEndRun(PostModuleStreamEndRun::slot_type const &iSlot)
StreamID const & streamID() const
void addToCPUTime(StreamID id, double iTime) override
static std::string ui2str(unsigned int i)
void watchPreModuleStreamBeginLumi(PreModuleStreamBeginLumi::slot_type const &iSlot)
void setComment(std::string const &value)
unsigned int value() const
void watchPostSourceLumi(PostSourceLumi::slot_type const &iSlot)
void watchPostModuleGlobalEndRun(PostModuleGlobalEndRun::slot_type const &iSlot)
void watchPostModuleStreamBeginLumi(PostModuleStreamBeginLumi::slot_type const &iSlot)
std::atomic< unsigned long > total_event_count_
void watchPreModuleStreamEndLumi(PreModuleStreamEndLumi::slot_type const &iSlot)
void watchPreModuleStreamBeginRun(PreModuleStreamBeginRun::slot_type const &iSlot)
static std::vector< double > & moduleTimeStack()
static std::string d2str(double d)
void add(std::string const &label, ParameterSetDescription const &psetDescription)
void watchPostOpenFile(PostOpenFile::slot_type const &iSlot)
double postCommon() const
PostGlobalEndRun postGlobalEndRunSignal_
void postModuleGlobal(GlobalContext const &, ModuleCallingContext const &)
void watchPreModuleStreamEndRun(PreModuleStreamEndRun::slot_type const &iSlot)
void postOpenFile(std::string const &, bool)
void watchPostModuleBeginJob(PostModuleBeginJob::slot_type const &iSlot)
void postSourceEvent(StreamID)
void watchPostEventReadFromSource(PostEventReadFromSource::slot_type const &iSlot)
void watchPostModuleGlobalBeginRun(PostModuleGlobalBeginRun::slot_type const &iSlot)
EventID const & eventID() const
void watchPreSourceEvent(PreSourceEvent::slot_type const &iSlot)
void preSourceEvent(StreamID)
void watchPostModuleEndJob(PostModuleEndJob::slot_type const &iSlot)
void preEvent(StreamContext const &)
void watchPreModuleGlobalEndLumi(PreModuleGlobalEndLumi::slot_type const &iSlot)
std::vector< double > min_events_time_
void watchPostBeginJob(PostBeginJob::slot_type const &iSlot)
convenience function for attaching to signal