29 #include <sys/resource.h>
98 if(gettimeofday(&t, 0) < 0)
99 throw cms::Exception(
"SysCallFailed",
"Failed call to gettimeofday");
100 return static_cast<double>(t.tv_sec) + (static_cast<double>(t.tv_usec) * 1E-6);
105 getrusage(RUSAGE_SELF, &usage);
107 double totalCPUTime = 0.0;
109 totalCPUTime = (double)usage.ru_utime.tv_sec + (
double(usage.ru_utime.tv_usec) * 1E-6);
111 totalCPUTime += (double)usage.ru_stime.tv_sec + (
double(usage.ru_stime.tv_usec) * 1E-6);
120 static thread_local std::vector<double> s_stack;
128 summary_only_(iPS.getUntrackedParameter<bool>(
"summaryOnly")),
129 report_summary_(iPS.getUntrackedParameter<bool>(
"useJobReport")),
132 total_event_count_(0),
133 begin_lumi_count_(0),
134 begin_run_count_(0) {
174 desc.
addUntracked<
bool>(
"summaryOnly",
false)->setComment(
175 "If 'true' do not report timing for each event");
176 desc.
addUntracked<
bool>(
"useJobReport",
true)->setComment(
177 "If 'true' write summary information to JobReport");
178 descriptions.
add(
"Timing", desc);
180 "This service reports the time it takes to run each module in a job.");
189 <<
"TimeReport> Report activated" <<
"\n"
190 <<
"TimeReport> Report columns headings for events: "
191 <<
"eventnum runnum timetaken\n"
192 <<
"TimeReport> Report columns headings for modules: "
193 <<
"eventnum runnum modulelabel modulename timetakeni\n"
210 double sum_all_events_time = 0;
215 <<
"TimeReport> Time report complete in "
216 << total_job_time <<
" seconds"
218 <<
" Time Summary: \n"
219 <<
" - Min event: " << min_event_time <<
"\n"
220 <<
" - Max event: " << max_event_time <<
"\n"
221 <<
" - Avg event: " << average_event_time <<
"\n"
222 <<
" - Total loop: " <<total_loop_time <<
"\n"
223 <<
" - Total job: " << total_job_time <<
"\n"
225 <<
" CPU Summary: \n"
226 <<
" - Total loop: " << total_loop_cpu <<
"\n"
227 <<
" - Total job: " << total_job_cpu <<
"\n"
228 <<
" Processing Summary: \n"
235 std::map<std::string, std::string> reportData;
237 reportData.insert(std::make_pair(
"MinEventTime",
d2str(min_event_time)));
238 reportData.insert(std::make_pair(
"MaxEventTime",
d2str(max_event_time)));
239 reportData.insert(std::make_pair(
"AvgEventTime",
d2str(average_event_time)));
241 reportData.insert(std::make_pair(
"TotalJobTime",
d2str(total_job_time)));
242 reportData.insert(std::make_pair(
"TotalJobCPU",
d2str(total_job_cpu)));
243 reportData.insert(std::make_pair(
"TotalLoopCPU",
d2str(total_loop_cpu)));
245 reportSvc->reportPerformanceSummary(
"Timing", reportData);
247 std::map<std::string, std::string> reportData1;
250 reportData1.insert(std::make_pair(
"NumberBeginRunCalls",
ui2str(begin_run_count_)));
251 reportSvc->reportPerformanceSummary(
"ProcessingSummary", reportData1);
267 auto const & eventID = iStream.
eventID();
270 << eventID.event() <<
" "
271 << eventID.run() <<
" "
287 assert(modStack.size() > 0);
288 double curr_module_time = modStack.back();
290 double t =
getTime() - curr_module_time;
293 for(
auto& waitingModuleStartTime : modStack) {
294 waitingModuleStartTime +=
t;
296 auto const & eventID = iStream.
eventID();
299 LogPrint(
"TimeModule") <<
"TimeModule> "
300 << eventID.event() <<
" "
301 << eventID.run() <<
" "
302 << desc.moduleLabel() <<
" "
303 << desc.moduleName() <<
" "
std::vector< double > sum_events_time_
void watchPreEvent(PreEvent::slot_type const &iSlot)
std::atomic< double > last_run_cpu_
#define DEFINE_FWK_SERVICE_MAKER(concrete, maker)
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 &)
void watchPostGlobalBeginLumi(PostGlobalBeginLumi::slot_type const &iSlot)
std::atomic< unsigned long > begin_lumi_count_
edm::serviceregistry::AllArgsMaker< edm::TimingServiceBase, Timing > TimingMaker
Preallocate preallocateSignal_
signal is emitted before beginJob
unsigned int maxNumberOfStreams() const
void watchPostGlobalBeginRun(PostGlobalBeginRun::slot_type const &iSlot)
void postGlobalBeginRun(GlobalContext 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
static std::string ui2str(unsigned int i)
void setComment(std::string const &value)
void postGlobalBeginLumi(GlobalContext const &)
std::atomic< unsigned long > begin_run_count_
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