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;
74 summary_only_(iPS.getUntrackedParameter<bool>(
"summaryOnly")),
75 report_summary_(iPS.getUntrackedParameter<bool>(
"useJobReport")),
80 total_event_count_(0) {
109 desc.
addUntracked<
bool>(
"summaryOnly",
false)->setComment(
110 "If 'true' do not report timing for each event");
111 desc.
addUntracked<
bool>(
"useJobReport",
true)->setComment(
112 "If 'true' write summary information to JobReport");
113 descriptions.
add(
"Timing", desc);
115 "This service reports the time it takes to run each module in a job.");
124 <<
"TimeReport> Report activated" <<
"\n"
125 <<
"TimeReport> Report columns headings for events: "
126 <<
"eventnum runnum timetaken\n"
127 <<
"TimeReport> Report columns headings for modules: "
128 <<
"eventnum runnum modulelabel modulename timetakeni\n"
138 double total_event_cpu = 0.;
153 <<
"TimeReport> Time report complete in "
154 << total_job_time <<
" seconds"
156 <<
" Time Summary: \n"
157 <<
" - Min event: " << min_event_time <<
"\n"
158 <<
" - Max event: " << max_event_time <<
"\n"
159 <<
" - Avg event: " << average_event_time <<
"\n"
160 <<
" - Total job: " << total_job_time <<
"\n"
161 <<
" CPU Summary: \n"
162 <<
" - Min event: " << min_event_cpu <<
"\n"
163 <<
" - Max event: " << max_event_cpu <<
"\n"
164 <<
" - Avg event: " << average_event_cpu <<
"\n"
165 <<
" - Total job: " << total_job_cpu <<
"\n"
166 <<
" - Total event: " << total_event_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)));
175 reportData.insert(std::make_pair(
"TotalJobTime",
d2str(total_job_time)));
176 reportData.insert(std::make_pair(
"MinEventCPU",
d2str(min_event_cpu)));
177 reportData.insert(std::make_pair(
"MaxEventCPU",
d2str(max_event_cpu)));
178 reportData.insert(std::make_pair(
"AvgEventCPU",
d2str(average_event_cpu)));
179 reportData.insert(std::make_pair(
"TotalJobCPU",
d2str(total_job_cpu)));
180 reportData.insert(std::make_pair(
"TotalEventCPU",
d2str(total_event_cpu)));
182 reportSvc->reportPerformanceSummary(
"Timing", reportData);
200 auto const & eventID = iStream.
eventID();
203 << eventID.event() <<
" "
204 << eventID.run() <<
" "
205 << curr_event_time <<
" "
206 << curr_event_cpu <<
" "
224 assert(modStack.size() > 0);
225 double curr_module_time = modStack.back();
227 double t =
getTime() - curr_module_time;
230 for(
auto& waitingModuleStartTime : modStack) {
231 waitingModuleStartTime +=
t;
233 auto const & eventID = iStream.
eventID();
236 LogPrint(
"TimeModule") <<
"TimeModule> "
237 << eventID.event() <<
" "
238 << eventID.run() <<
" "
239 << desc.moduleLabel() <<
" "
240 << desc.moduleName() <<
" "
void watchPreEvent(PreEvent::slot_type const &iSlot)
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 &)
std::vector< double > curr_events_cpu_
Preallocate preallocateSignal_
signal is emitted before beginJob
unsigned int maxNumberOfStreams() const
std::vector< double > total_events_cpu_
Timing(ParameterSet const &, ActivityRegistry &)
ModuleDescription const * moduleDescription() const
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
StreamID const & streamID() const
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)
std::vector< double > max_events_cpu_
std::vector< double > min_events_cpu_
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