29 #include <sys/resource.h> 97 if(gettimeofday(&t, 0) < 0)
98 throw cms::Exception(
"SysCallFailed",
"Failed call to gettimeofday");
99 return static_cast<double>(t.tv_sec) + (static_cast<double>(t.tv_usec) * 1E-6);
104 getrusage(RUSAGE_SELF, &usage);
106 double totalCPUTime = 0.0;
108 totalCPUTime = (double)usage.ru_utime.tv_sec + (
double(usage.ru_utime.tv_usec) * 1E-6);
110 totalCPUTime += (double)usage.ru_stime.tv_sec + (
double(usage.ru_stime.tv_usec) * 1E-6);
113 getrusage(RUSAGE_CHILDREN, &usage);
114 totalCPUTime += (double)usage.ru_utime.tv_sec + (
double(usage.ru_utime.tv_usec) * 1E-6);
115 totalCPUTime += (double)usage.ru_stime.tv_sec + (
double(usage.ru_stime.tv_usec) * 1E-6);
125 static thread_local std::vector<double> s_stack;
135 summary_only_(iPS.getUntrackedParameter<bool>(
"summaryOnly")),
181 desc.
addUntracked<
bool>(
"summaryOnly",
false)->setComment(
182 "If 'true' do not report timing for each event");
183 desc.
addUntracked<
bool>(
"useJobReport",
true)->setComment(
184 "If 'true' write summary information to JobReport");
185 descriptions.
add(
"Timing", desc);
187 "This service reports the time it takes to run each module in a job.");
196 <<
"TimeReport> Report activated" <<
"\n" 197 <<
"TimeReport> Report columns headings for events: " 198 <<
"eventnum runnum timetaken\n" 199 <<
"TimeReport> Report columns headings for modules: " 200 <<
"eventnum runnum modulelabel modulename timetakeni\n" 219 total_loop_time = 0.0;
220 total_loop_cpu = 0.0;
223 double sum_all_events_time = 0;
226 double average_event_time = 0.0;
231 double event_throughput = 0.0;
232 if(total_loop_time != 0.0) {
237 <<
"TimeReport> Time report complete in " 238 << total_job_time <<
" seconds" 240 <<
" Time Summary: \n" 241 <<
" - Min event: " << min_event_time <<
"\n" 242 <<
" - Max event: " << max_event_time <<
"\n" 243 <<
" - Avg event: " << average_event_time <<
"\n" 244 <<
" - Total loop: " <<total_loop_time <<
"\n" 245 <<
" - Total job: " << total_job_time <<
"\n" 246 <<
" Event Throughput: "<< event_throughput <<
" ev/s\n" 247 <<
" CPU Summary: \n" 248 <<
" - Total loop: " << total_loop_cpu <<
"\n" 249 <<
" - Total job: " << total_job_cpu <<
"\n";
253 std::map<std::string, std::string> reportData;
255 reportData.insert(std::make_pair(
"MinEventTime",
d2str(min_event_time)));
256 reportData.insert(std::make_pair(
"MaxEventTime",
d2str(max_event_time)));
257 reportData.insert(std::make_pair(
"AvgEventTime",
d2str(average_event_time)));
258 reportData.insert(std::make_pair(
"EventThroughput",
d2str(event_throughput)));
259 reportData.insert(std::make_pair(
"TotalJobTime",
d2str(total_job_time)));
260 reportData.insert(std::make_pair(
"TotalJobCPU",
d2str(total_job_cpu)));
261 reportData.insert(std::make_pair(
"TotalLoopCPU",
d2str(total_loop_cpu)));
262 reportData.insert(std::make_pair(
"NumberOfStreams",
ui2str(
nStreams_)));
263 reportData.insert(std::make_pair(
"NumberOfThreads",
ui2str(
nThreads_)));
264 reportSvc->reportPerformanceSummary(
"Timing", reportData);
280 auto const & eventID = iStream.
eventID();
283 << eventID.event() <<
" " 284 << eventID.run() <<
" " 300 assert(modStack.size() > 0);
301 double curr_module_time = modStack.back();
303 double t =
getTime() - curr_module_time;
306 for(
auto& waitingModuleStartTime : modStack) {
307 waitingModuleStartTime +=
t;
309 auto const & eventID = iStream.
eventID();
312 LogPrint(
"TimeModule") <<
"TimeModule> " 313 << eventID.event() <<
" " 314 << eventID.run() <<
" " 315 << desc.moduleLabel() <<
" " 316 << desc.moduleName() <<
" " std::vector< double > sum_events_time_
unsigned int maxNumberOfThreads() const
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)
virtual double getTotalCPU() const override
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
static std::string ui2str(unsigned int i)
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