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) {
115 desc.
addUntracked<
bool>(
"summaryOnly",
false)->setComment(
116 "If 'true' do not report timing for each event");
117 desc.
addUntracked<
bool>(
"useJobReport",
true)->setComment(
118 "If 'true' write summary information to JobReport");
119 descriptions.
add(
"Timing", desc);
121 "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"
144 double total_event_cpu = 0.;
159 <<
"TimeReport> Time report complete in "
160 << total_job_time <<
" seconds"
162 <<
" Time Summary: \n"
163 <<
" - Min event: " << min_event_time <<
"\n"
164 <<
" - Max event: " << max_event_time <<
"\n"
165 <<
" - Avg event: " << average_event_time <<
"\n"
166 <<
" - Total job: " << total_job_time <<
"\n"
167 <<
" CPU Summary: \n"
168 <<
" - Min event: " << min_event_cpu <<
"\n"
169 <<
" - Max event: " << max_event_cpu <<
"\n"
170 <<
" - Avg event: " << average_event_cpu <<
"\n"
171 <<
" - Total job: " << total_job_cpu <<
"\n"
172 <<
" - Total event: " << total_event_cpu <<
"\n";
176 std::map<std::string, std::string> reportData;
178 reportData.insert(std::make_pair(
"MinEventTime",
d2str(min_event_time)));
179 reportData.insert(std::make_pair(
"MaxEventTime",
d2str(max_event_time)));
180 reportData.insert(std::make_pair(
"AvgEventTime",
d2str(average_event_time)));
181 reportData.insert(std::make_pair(
"TotalJobTime",
d2str(total_job_time)));
182 reportData.insert(std::make_pair(
"MinEventCPU",
d2str(min_event_cpu)));
183 reportData.insert(std::make_pair(
"MaxEventCPU",
d2str(max_event_cpu)));
184 reportData.insert(std::make_pair(
"AvgEventCPU",
d2str(average_event_cpu)));
185 reportData.insert(std::make_pair(
"TotalJobCPU",
d2str(total_job_cpu)));
186 reportData.insert(std::make_pair(
"TotalEventCPU",
d2str(total_event_cpu)));
188 reportSvc->reportPerformanceSummary(
"Timing", reportData);
206 auto const & eventID = iStream.
eventID();
209 << eventID.event() <<
" "
210 << eventID.run() <<
" "
211 << curr_event_time <<
" "
212 << curr_event_cpu <<
" "
230 assert(modStack.size() > 0);
231 double curr_module_time = modStack.back();
233 double t =
getTime() - curr_module_time;
236 for(
auto& waitingModuleStartTime : modStack) {
237 waitingModuleStartTime +=
t;
239 auto const & eventID = iStream.
eventID();
242 LogPrint(
"TimeModule") <<
"TimeModule> "
243 << eventID.event() <<
" "
244 << eventID.run() <<
" "
245 << desc.moduleLabel() <<
" "
246 << 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
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)
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