29 #include <sys/resource.h> 119 if(gettimeofday(&t, 0) < 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.size() > 0);
155 double curr_module_time = modStack.back();
157 double t =
getTime() - curr_module_time;
173 summary_only_(iPS.getUntrackedParameter<bool>(
"summaryOnly")),
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" 315 total_loop_time = 0.0;
316 total_loop_cpu = 0.0;
319 double sum_all_events_time = 0;
322 double average_event_time = 0.0;
327 double event_throughput = 0.0;
328 if(total_loop_time != 0.0) {
333 <<
"TimeReport> Time report complete in " 334 << total_job_time <<
" seconds" 336 <<
" Time Summary: \n" 337 <<
" - Min event: " << min_event_time <<
"\n" 338 <<
" - Max event: " << max_event_time <<
"\n" 339 <<
" - Avg event: " << average_event_time <<
"\n" 340 <<
" - Total loop: " <<total_loop_time <<
"\n" 341 <<
" - Total job: " << total_job_time <<
"\n" 342 <<
" Event Throughput: "<< event_throughput <<
" ev/s\n" 343 <<
" CPU Summary: \n" 344 <<
" - Total loop: " << total_loop_cpu <<
"\n" 345 <<
" - Total job: " << total_job_cpu <<
"\n";
349 std::map<std::string, std::string> reportData;
351 reportData.insert(std::make_pair(
"MinEventTime",
d2str(min_event_time)));
352 reportData.insert(std::make_pair(
"MaxEventTime",
d2str(max_event_time)));
353 reportData.insert(std::make_pair(
"AvgEventTime",
d2str(average_event_time)));
354 reportData.insert(std::make_pair(
"EventThroughput",
d2str(event_throughput)));
355 reportData.insert(std::make_pair(
"TotalJobTime",
d2str(total_job_time)));
356 reportData.insert(std::make_pair(
"TotalJobCPU",
d2str(total_job_cpu)));
357 reportData.insert(std::make_pair(
"TotalLoopCPU",
d2str(total_loop_cpu)));
358 reportData.insert(std::make_pair(
"NumberOfStreams",
ui2str(
nStreams_)));
359 reportData.insert(std::make_pair(
"NumberOfThreads",
ui2str(
nThreads_)));
360 reportSvc->reportPerformanceSummary(
"Timing", reportData);
376 auto const & eventID = iStream.
eventID();
379 << eventID.event() <<
" " 380 << eventID.run() <<
" " 389 auto const & eventID = iStream.
eventID();
393 LogPrint(
"TimeModule") <<
"TimeModule> " 394 << eventID.event() <<
" " 395 << eventID.run() <<
" " 396 << desc.moduleLabel() <<
" " 397 << desc.moduleName() <<
" " 469 <<
"ExcessiveTime: Module used " << t
470 <<
" 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)
virtual 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)
void watchPreModuleGlobalBeginLumi(PreModuleGlobalBeginLumi::slot_type const &iSlot)
void watchPostModuleStreamEndRun(PostModuleStreamEndRun::slot_type const &iSlot)
StreamID const & streamID() const
virtual 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