28 #include <sys/resource.h>
42 if(gettimeofday(&t, 0) < 0)
43 throw cms::Exception(
"SysCallFailed",
"Failed call to gettimeofday");
44 return static_cast<double>(t.tv_sec) + (static_cast<double>(t.tv_usec) * 1E-6);
49 getrusage(RUSAGE_SELF, &usage);
51 double totalCPUTime = 0.0;
53 totalCPUTime = (double)usage.ru_utime.tv_sec + (
double(usage.ru_utime.tv_usec) * 1E-6);
55 totalCPUTime += (double)usage.ru_stime.tv_sec + (
double(usage.ru_stime.tv_usec) * 1E-6);
64 static thread_local std::vector<double> s_stack;
72 summary_only_(iPS.getUntrackedParameter<bool>(
"summaryOnly")),
73 report_summary_(iPS.getUntrackedParameter<bool>(
"useJobReport")),
76 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.");
128 <<
"TimeReport> Report activated" <<
"\n"
129 <<
"TimeReport> Report columns headings for events: "
130 <<
"eventnum runnum timetaken\n"
131 <<
"TimeReport> Report columns headings for modules: "
132 <<
"eventnum runnum modulelabel modulename timetakeni\n"
149 double sum_all_events_time = 0;
154 <<
"TimeReport> Time report complete in "
155 << total_job_time <<
" seconds"
157 <<
" Time Summary: \n"
158 <<
" - Min event: " << min_event_time <<
"\n"
159 <<
" - Max event: " << max_event_time <<
"\n"
160 <<
" - Avg event: " << average_event_time <<
"\n"
161 <<
" - Total loop: " <<total_loop_time <<
"\n"
162 <<
" - Total job: " << total_job_time <<
"\n"
164 <<
" CPU Summary: \n"
165 <<
" - Total loop: " << total_loop_cpu <<
"\n"
166 <<
" - Total job: " << total_job_cpu <<
"\n";
170 std::map<std::string, std::string> reportData;
172 reportData.insert(std::make_pair(
"MinEventTime",
d2str(min_event_time)));
173 reportData.insert(std::make_pair(
"MaxEventTime",
d2str(max_event_time)));
174 reportData.insert(std::make_pair(
"AvgEventTime",
d2str(average_event_time)));
176 reportData.insert(std::make_pair(
"TotalJobTime",
d2str(total_job_time)));
177 reportData.insert(std::make_pair(
"TotalJobCPU",
d2str(total_job_cpu)));
178 reportData.insert(std::make_pair(
"TotalLoopCPU",
d2str(total_loop_cpu)));
180 reportSvc->reportPerformanceSummary(
"Timing", reportData);
196 auto const & eventID = iStream.
eventID();
199 << eventID.event() <<
" "
200 << eventID.run() <<
" "
216 assert(modStack.size() > 0);
217 double curr_module_time = modStack.back();
219 double t =
getTime() - curr_module_time;
222 for(
auto& waitingModuleStartTime : modStack) {
223 waitingModuleStartTime +=
t;
225 auto const & eventID = iStream.
eventID();
228 LogPrint(
"TimeModule") <<
"TimeModule> "
229 << eventID.event() <<
" "
230 << eventID.run() <<
" "
231 << desc.moduleLabel() <<
" "
232 << desc.moduleName() <<
" "
std::vector< double > sum_events_time_
void watchPreEvent(PreEvent::slot_type const &iSlot)
std::atomic< double > last_run_cpu_
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 watchPostEvent(PostEvent::slot_type const &iSlot)
void watchPostModuleEvent(PostModuleEvent::slot_type const &iSlot)
void postEvent(StreamContext const &)
Preallocate preallocateSignal_
signal is emitted before beginJob
unsigned int maxNumberOfStreams() const
Timing(ParameterSet const &, ActivityRegistry &)
ModuleDescription const * moduleDescription() const
std::atomic< double > last_run_time_
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
StreamID const & streamID() const
virtual void addToCPUTime(StreamID id, double iTime) override
void setComment(std::string const &value)
unsigned int value() const
std::atomic< unsigned long > total_event_count_
static std::vector< double > & moduleTimeStack()
static std::string d2str(double d)
void add(std::string const &label, ParameterSetDescription const &psetDescription)
PostGlobalEndRun postGlobalEndRunSignal_
EventID const & eventID() const
void postModule(StreamContext const &, ModuleCallingContext const &)
void preEvent(StreamContext const &)
void preModule(StreamContext const &, ModuleCallingContext const &)
std::vector< double > min_events_time_
void watchPostBeginJob(PostBeginJob::slot_type const &iSlot)
convenience function for attaching to signal