51 #include <sys/resource.h>
57 static std::string
d2str(
double d) {
65 if(gettimeofday(&t, 0) < 0)
66 throw cms::Exception(
"SysCallFailed",
"Failed call to gettimeofday");
67 return static_cast<double>(t.tv_sec) + (static_cast<double>(t.tv_usec) * 1E-6);
72 getrusage(RUSAGE_SELF, &usage);
74 double totalCPUTime = 0.0;
76 totalCPUTime = (double)usage.ru_utime.tv_sec + (
double(usage.ru_utime.tv_usec) * 1E-6);
78 totalCPUTime += (double)usage.ru_stime.tv_sec + (
double(usage.ru_stime.tv_usec) * 1E-6);
88 curr_module_time_(0.),
90 summary_only_(iPS.getUntrackedParameter<bool>(
"summaryOnly")),
91 report_summary_(iPS.getUntrackedParameter<bool>(
"useJobReport")),
96 total_event_count_(0) {
114 desc.
addUntracked<
bool>(
"summaryOnly",
false)->setComment(
115 "If 'true' do not report timing for each event");
116 desc.
addUntracked<
bool>(
"useJobReport",
true)->setComment(
117 "If 'true' write summary information to JobReport");
118 descriptions.
add(
"Timing", desc);
120 "This service reports the time it takes to run each module in a job.");
131 <<
"TimeReport> Report activated" <<
"\n"
132 <<
"TimeReport> Report columns headings for events: "
133 <<
"eventnum runnum timetaken\n"
134 <<
"TimeReport> Report columns headings for modules: "
135 <<
"eventnum runnum modulelabel modulename timetakeni\n"
150 <<
"TimeReport> Time report complete in "
151 << total_job_time <<
" seconds"
153 <<
" Time Summary: \n"
156 <<
" - Avg event: " << average_event_time <<
"\n"
157 <<
" - Total job: " << total_job_time <<
"\n"
158 <<
" CPU Summary: \n"
161 <<
" - Avg event: " << average_event_cpu <<
"\n"
162 <<
" - Total job: " << total_job_cpu <<
"\n"
168 std::map<std::string, std::string> reportData;
172 reportData.insert(std::make_pair(
"AvgEventTime",
d2str(average_event_time)));
173 reportData.insert(std::make_pair(
"TotalJobTime",
d2str(total_job_time)));
176 reportData.insert(std::make_pair(
"AvgEventCPU",
d2str(average_event_cpu)));
177 reportData.insert(std::make_pair(
"TotalJobCPU",
d2str(total_job_cpu)));
178 reportData.insert(std::make_pair(
"TotalEventCPU",
d2str(total_event_cpu_)));
180 reportSvc->reportPerformanceSummary(
"Timing", reportData);
228 LogPrint(
"TimeModule") <<
"TimeModule> "
EventNumber_t event() const
ParameterDescriptionBase * addUntracked(U const &iLabel, T const &value)
void watchPostEndJob(PostEndJob::slot_type const &iSlot)
void watchPostModule(PostModule::slot_type const &iSlot)
void watchPreProcessEvent(PreProcessEvent::slot_type const &iSlot)
std::string const & moduleName() const
void preModule(ModuleDescription const &)
std::string const & moduleLabel() const
void watchPreModule(PreModule::slot_type const &iSlot)
void watchPostProcessEvent(PostProcessEvent::slot_type const &iSlot)
Timing(ParameterSet const &, ActivityRegistry &)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
void postModule(ModuleDescription const &)
void setComment(std::string const &value)
static std::string d2str(double d)
void add(std::string const &label, ParameterSetDescription const &psetDescription)
void preEventProcessing(EventID const &, Timestamp const &)
void postEventProcessing(Event const &, EventSetup const &)
void watchPostBeginJob(PostBeginJob::slot_type const &iSlot)
convenience function for attaching to signal