50 #include <sys/resource.h>
56 static std::string
d2str(
double d) {
64 if(gettimeofday(&t, 0) < 0)
65 throw cms::Exception(
"SysCallFailed",
"Failed call to gettimeofday");
66 return static_cast<double>(t.tv_sec) + (static_cast<double>(t.tv_usec) * 1E-6);
71 getrusage(RUSAGE_SELF, &usage);
73 double totalCPUTime = 0.0;
75 totalCPUTime = (double)usage.ru_utime.tv_sec + (
double(usage.ru_utime.tv_usec) * 1E-6);
77 totalCPUTime += (double)usage.ru_stime.tv_sec + (
double(usage.ru_stime.tv_usec) * 1E-6);
87 curr_module_time_(0.),
89 summary_only_(iPS.getUntrackedParameter<bool>(
"summaryOnly")),
90 report_summary_(iPS.getUntrackedParameter<bool>(
"useJobReport")),
95 total_event_count_(0) {
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);
119 "This service reports the time it takes to run each module in a job.");
130 <<
"TimeReport> Report activated" <<
"\n"
131 <<
"TimeReport> Report columns headings for events: "
132 <<
"eventnum runnum timetaken\n"
133 <<
"TimeReport> Report columns headings for modules: "
134 <<
"eventnum runnum modulelabel modulename timetakeni\n"
149 <<
"TimeReport> Time report complete in "
150 << total_job_time <<
" seconds"
152 <<
" Time Summary: \n"
155 <<
" - Avg event: " << average_event_time <<
"\n"
156 <<
" - Total job: " << total_job_time <<
"\n"
157 <<
" CPU Summary: \n"
160 <<
" - Avg event: " << average_event_cpu <<
"\n"
161 <<
" - Total job: " << total_job_cpu <<
"\n"
167 std::map<std::string, std::string> reportData;
171 reportData.insert(std::make_pair(
"AvgEventTime",
d2str(average_event_time)));
172 reportData.insert(std::make_pair(
"TotalJobTime",
d2str(total_job_time)));
175 reportData.insert(std::make_pair(
"AvgEventCPU",
d2str(average_event_cpu)));
176 reportData.insert(std::make_pair(
"TotalJobCPU",
d2str(total_job_cpu)));
177 reportData.insert(std::make_pair(
"TotalEventCPU",
d2str(total_event_cpu_)));
179 reportSvc->reportPerformanceSummary(
"Timing", reportData);
227 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