29 #include <sys/resource.h>
87 if(gettimeofday(&t, 0) < 0)
88 throw cms::Exception(
"SysCallFailed",
"Failed call to gettimeofday");
89 return static_cast<double>(t.tv_sec) + (static_cast<double>(t.tv_usec) * 1E-6);
94 getrusage(RUSAGE_SELF, &usage);
96 double totalCPUTime = 0.0;
98 totalCPUTime = (double)usage.ru_utime.tv_sec + (
double(usage.ru_utime.tv_usec) * 1E-6);
100 totalCPUTime += (double)usage.ru_stime.tv_sec + (
double(usage.ru_stime.tv_usec) * 1E-6);
109 static thread_local std::vector<double> s_stack;
117 summary_only_(iPS.getUntrackedParameter<bool>(
"summaryOnly")),
118 report_summary_(iPS.getUntrackedParameter<bool>(
"useJobReport")),
121 total_event_count_(0) {
158 desc.
addUntracked<
bool>(
"summaryOnly",
false)->setComment(
159 "If 'true' do not report timing for each event");
160 desc.
addUntracked<
bool>(
"useJobReport",
true)->setComment(
161 "If 'true' write summary information to JobReport");
162 descriptions.
add(
"Timing", desc);
164 "This service reports the time it takes to run each module in a job.");
173 <<
"TimeReport> Report activated" <<
"\n"
174 <<
"TimeReport> Report columns headings for events: "
175 <<
"eventnum runnum timetaken\n"
176 <<
"TimeReport> Report columns headings for modules: "
177 <<
"eventnum runnum modulelabel modulename timetakeni\n"
194 double sum_all_events_time = 0;
199 <<
"TimeReport> Time report complete in "
200 << total_job_time <<
" seconds"
202 <<
" Time Summary: \n"
203 <<
" - Min event: " << min_event_time <<
"\n"
204 <<
" - Max event: " << max_event_time <<
"\n"
205 <<
" - Avg event: " << average_event_time <<
"\n"
206 <<
" - Total loop: " <<total_loop_time <<
"\n"
207 <<
" - Total job: " << total_job_time <<
"\n"
209 <<
" CPU Summary: \n"
210 <<
" - Total loop: " << total_loop_cpu <<
"\n"
211 <<
" - Total job: " << total_job_cpu <<
"\n";
215 std::map<std::string, std::string> reportData;
217 reportData.insert(std::make_pair(
"MinEventTime",
d2str(min_event_time)));
218 reportData.insert(std::make_pair(
"MaxEventTime",
d2str(max_event_time)));
219 reportData.insert(std::make_pair(
"AvgEventTime",
d2str(average_event_time)));
221 reportData.insert(std::make_pair(
"TotalJobTime",
d2str(total_job_time)));
222 reportData.insert(std::make_pair(
"TotalJobCPU",
d2str(total_job_cpu)));
223 reportData.insert(std::make_pair(
"TotalLoopCPU",
d2str(total_loop_cpu)));
225 reportSvc->reportPerformanceSummary(
"Timing", reportData);
241 auto const & eventID = iStream.
eventID();
244 << eventID.event() <<
" "
245 << eventID.run() <<
" "
261 assert(modStack.size() > 0);
262 double curr_module_time = modStack.back();
264 double t =
getTime() - curr_module_time;
267 for(
auto& waitingModuleStartTime : modStack) {
268 waitingModuleStartTime +=
t;
270 auto const & eventID = iStream.
eventID();
273 LogPrint(
"TimeModule") <<
"TimeModule> "
274 << eventID.event() <<
" "
275 << eventID.run() <<
" "
276 << desc.moduleLabel() <<
" "
277 << 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 &)
edm::serviceregistry::AllArgsMaker< edm::TimingServiceBase, Timing > TimingMaker
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