CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes
edm::service::Timing Class Reference

#include <Timing.h>

Inheritance diagram for edm::service::Timing:
edm::TimingServiceBase

Public Member Functions

virtual void addToCPUTime (StreamID id, double iTime) override
 
 Timing (ParameterSet const &, ActivityRegistry &)
 
 ~Timing ()
 
- Public Member Functions inherited from edm::TimingServiceBase
 TimingServiceBase ()
 
virtual ~TimingServiceBase ()
 

Static Public Member Functions

static void fillDescriptions (edm::ConfigurationDescriptions &descriptions)
 

Private Member Functions

void postBeginJob ()
 
void postEndJob ()
 
void postEvent (StreamContext const &)
 
void postModule (StreamContext const &, ModuleCallingContext const &)
 
void preEvent (StreamContext const &)
 
void preModule (StreamContext const &, ModuleCallingContext const &)
 

Private Attributes

std::vector< double > curr_events_cpu_
 
std::vector< double > curr_events_time_
 
double curr_job_cpu_
 
double curr_job_time_
 
std::vector< double > max_events_cpu_
 
std::vector< double > max_events_time_
 
std::vector< double > min_events_cpu_
 
std::vector< double > min_events_time_
 
bool report_summary_
 
bool summary_only_
 
std::atomic< unsigned long > total_event_count_
 
std::vector< double > total_events_cpu_
 

Detailed Description

Definition at line 25 of file Timing.h.

Constructor & Destructor Documentation

edm::service::Timing::Timing ( ParameterSet const &  iPS,
ActivityRegistry iRegistry 
)

Definition at line 68 of file Timing.cc.

References edm::signalslot::Signal< T >::connect(), curr_events_cpu_, curr_events_time_, max_events_cpu_, max_events_time_, edm::service::SystemBounds::maxNumberOfStreams(), min_events_cpu_, min_events_time_, postBeginJob(), postEndJob(), postEvent(), postModule(), edm::ActivityRegistry::preallocateSignal_, preEvent(), preModule(), summary_only_, total_events_cpu_, edm::ActivityRegistry::watchPostBeginJob(), edm::ActivityRegistry::watchPostEndJob(), edm::ActivityRegistry::watchPostEvent(), edm::ActivityRegistry::watchPostModuleEvent(), edm::ActivityRegistry::watchPreEvent(), and edm::ActivityRegistry::watchPreModuleEvent().

68  :
69  curr_job_time_(0.),
70  curr_job_cpu_(0.),
74  summary_only_(iPS.getUntrackedParameter<bool>("summaryOnly")),
75  report_summary_(iPS.getUntrackedParameter<bool>("useJobReport")),
81  iRegistry.watchPostBeginJob(this, &Timing::postBeginJob);
82  iRegistry.watchPostEndJob(this, &Timing::postEndJob);
83 
84  iRegistry.watchPreEvent(this, &Timing::preEvent);
85  iRegistry.watchPostEvent(this, &Timing::postEvent);
86 
87  if(not summary_only_) {
88  iRegistry.watchPreModuleEvent(this, &Timing::preModule);
89  iRegistry.watchPostModuleEvent(this, &Timing::postModule);
90  }
91 
92  iRegistry.preallocateSignal_.connect([this](service::SystemBounds const& iBounds){
93  auto nStreams = iBounds.maxNumberOfStreams();
94  curr_events_time_.resize(nStreams,0.);
95  curr_events_cpu_.resize(nStreams,0.);
96  total_events_cpu_.resize(nStreams,0.);
97  max_events_time_.resize(nStreams,0.);
98  max_events_cpu_.resize(nStreams,0.);
99  min_events_time_.resize(nStreams,1.E6);
100  min_events_cpu_.resize(nStreams,1.E6);
101  });
102  }
double curr_job_time_
Definition: Timing.h:45
std::vector< double > max_events_time_
Definition: Timing.h:56
bool report_summary_
Definition: Timing.h:51
std::vector< double > curr_events_time_
Definition: Timing.h:47
void postEvent(StreamContext const &)
Definition: Timing.cc:198
double curr_job_cpu_
Definition: Timing.h:46
std::vector< double > curr_events_cpu_
Definition: Timing.h:48
std::vector< double > total_events_cpu_
Definition: Timing.h:49
std::atomic< unsigned long > total_event_count_
Definition: Timing.h:60
std::vector< double > max_events_cpu_
Definition: Timing.h:57
std::vector< double > min_events_cpu_
Definition: Timing.h:59
void postModule(StreamContext const &, ModuleCallingContext const &)
Definition: Timing.cc:227
void preEvent(StreamContext const &)
Definition: Timing.cc:192
void preModule(StreamContext const &, ModuleCallingContext const &)
Definition: Timing.cc:222
std::vector< double > min_events_time_
Definition: Timing.h:58
edm::service::Timing::~Timing ( )

Definition at line 104 of file Timing.cc.

104  {
105  }

Member Function Documentation

void edm::service::Timing::addToCPUTime ( StreamID  id,
double  iTime 
)
overridevirtual

Extra CPU time used by a job but not seen by cmsRun The value should be in seconds. This function is safe to call from multiple threads

Implements edm::TimingServiceBase.

Definition at line 107 of file Timing.cc.

References curr_events_cpu_.

107  {
108  //For accounting purposes we effectively can saw we started earlier
109  curr_events_cpu_[id.value()] -= iTime;
110  }
std::vector< double > curr_events_cpu_
Definition: Timing.h:48
void edm::service::Timing::fillDescriptions ( edm::ConfigurationDescriptions descriptions)
static

Definition at line 113 of file Timing.cc.

References edm::ConfigurationDescriptions::add(), edm::ParameterSetDescription::addUntracked(), and edm::ConfigurationDescriptions::setComment().

113  {
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);
120  descriptions.setComment(
121  "This service reports the time it takes to run each module in a job.");
122  }
void setComment(std::string const &value)
void add(std::string const &label, ParameterSetDescription const &psetDescription)
void edm::service::Timing::postBeginJob ( )
private

Definition at line 124 of file Timing.cc.

References curr_job_cpu_, curr_job_time_, edm::service::getCPU(), edm::service::getTime(), and summary_only_.

Referenced by Timing().

124  {
126  curr_job_cpu_ = getCPU();
127 
128  if(not summary_only_) {
129  LogImportant("TimeReport")
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"
135  << "TimeReport> JobTime=" << curr_job_time_ << " JobCPU=" << curr_job_cpu_ << "\n";
136  }
137  }
double curr_job_time_
Definition: Timing.h:45
static double getCPU()
Definition: Timing.cc:47
double curr_job_cpu_
Definition: Timing.h:46
static double getTime()
void edm::service::Timing::postEndJob ( )
private

Definition at line 139 of file Timing.cc.

References curr_job_cpu_, curr_job_time_, edm::service::d2str(), edm::service::getCPU(), edm::service::getTime(), max_events_cpu_, max_events_time_, min_events_cpu_, min_events_time_, report_summary_, edmStreamStallGrapher::t, total_event_count_, and total_events_cpu_.

Referenced by Timing().

139  {
140  double total_job_time = getTime() - curr_job_time_;
141  double average_event_time = total_job_time / total_event_count_;
142 
143  double total_job_cpu = getCPU() - curr_job_cpu_;
144  double total_event_cpu = 0.;
145  for(auto t : total_events_cpu_) {
146  total_event_cpu +=t;
147  }
148  double average_event_cpu = total_event_cpu / total_event_count_;
149 
150  double min_event_time = *(std::min_element(min_events_time_.begin(),
151  min_events_time_.end()));
152  double max_event_time = *(std::max_element(max_events_time_.begin(),
153  max_events_time_.end()));
154  double min_event_cpu = *(std::min_element(min_events_cpu_.begin(),
155  min_events_cpu_.end()));
156  double max_event_cpu = *(std::max_element(max_events_cpu_.begin(),
157  max_events_cpu_.end()));
158  LogImportant("TimeReport")
159  << "TimeReport> Time report complete in "
160  << total_job_time << " seconds"
161  << "\n"
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";
173 
174  if(report_summary_) {
175  Service<JobReport> reportSvc;
176  std::map<std::string, std::string> reportData;
177 
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)));
187 
188  reportSvc->reportPerformanceSummary("Timing", reportData);
189  }
190  }
double curr_job_time_
Definition: Timing.h:45
std::vector< double > max_events_time_
Definition: Timing.h:56
bool report_summary_
Definition: Timing.h:51
static double getCPU()
Definition: Timing.cc:47
double curr_job_cpu_
Definition: Timing.h:46
std::vector< double > total_events_cpu_
Definition: Timing.h:49
std::atomic< unsigned long > total_event_count_
Definition: Timing.h:60
static std::string d2str(double d)
Definition: Memory.cc:62
std::vector< double > max_events_cpu_
Definition: Timing.h:57
std::vector< double > min_events_cpu_
Definition: Timing.h:59
static double getTime()
std::vector< double > min_events_time_
Definition: Timing.h:58
void edm::service::Timing::postEvent ( StreamContext const &  iStream)
private

Definition at line 198 of file Timing.cc.

References curr_events_cpu_, curr_events_time_, edm::StreamContext::eventID(), edm::service::getCPU(), edm::service::getTime(), cmsHarvester::index, max_events_cpu_, max_events_time_, min_events_cpu_, min_events_time_, edm::StreamContext::streamID(), summary_only_, total_event_count_, total_events_cpu_, and edm::StreamID::value().

Referenced by Timing().

198  {
199  auto index = iStream.streamID().value();
200  double curr_event_cpu = getCPU() - curr_events_cpu_[index];
201  total_events_cpu_[index] += curr_event_cpu;
202 
203  double curr_event_time = getTime() - curr_events_time_[index];
204 
205  if(not summary_only_) {
206  auto const & eventID = iStream.eventID();
207  LogPrint("TimeEvent")
208  << "TimeEvent> "
209  << eventID.event() << " "
210  << eventID.run() << " "
211  << curr_event_time << " "
212  << curr_event_cpu << " "
214  }
215  if(curr_event_time > max_events_time_[index]) max_events_time_[index] = curr_event_time;
216  if(curr_event_time < min_events_time_[index]) min_events_time_[index] = curr_event_time;
217  if(curr_event_cpu > max_events_cpu_[index]) max_events_cpu_[index] = curr_event_cpu;
218  if(curr_event_cpu < min_events_cpu_[index]) min_events_cpu_[index] = curr_event_cpu;
220  }
std::vector< double > max_events_time_
Definition: Timing.h:56
std::vector< double > curr_events_time_
Definition: Timing.h:47
static double getCPU()
Definition: Timing.cc:47
std::vector< double > curr_events_cpu_
Definition: Timing.h:48
std::vector< double > total_events_cpu_
Definition: Timing.h:49
std::atomic< unsigned long > total_event_count_
Definition: Timing.h:60
std::vector< double > max_events_cpu_
Definition: Timing.h:57
std::vector< double > min_events_cpu_
Definition: Timing.h:59
static double getTime()
std::vector< double > min_events_time_
Definition: Timing.h:58
void edm::service::Timing::postModule ( StreamContext const &  iStream,
ModuleCallingContext const &  iModule 
)
private

Definition at line 227 of file Timing.cc.

References edm::StreamContext::eventID(), edm::service::getTime(), edm::ModuleCallingContext::moduleDescription(), edm::service::moduleTimeStack(), and edmStreamStallGrapher::t.

Referenced by Timing().

227  {
228  //LogInfo("TimeModule")
229  auto& modStack = moduleTimeStack();
230  assert(modStack.size() > 0);
231  double curr_module_time = modStack.back();
232  modStack.pop_back();
233  double t = getTime() - curr_module_time;
234  //move waiting module start times forward to account
235  // for the fact that they were paused while this module ran
236  for(auto& waitingModuleStartTime : modStack) {
237  waitingModuleStartTime +=t;
238  }
239  auto const & eventID = iStream.eventID();
240  auto const & desc = *(iModule.moduleDescription());
241 
242  LogPrint("TimeModule") << "TimeModule> "
243  << eventID.event() << " "
244  << eventID.run() << " "
245  << desc.moduleLabel() << " "
246  << desc.moduleName() << " "
247  << t;
248  }
static std::vector< double > & moduleTimeStack()
Definition: Timing.cc:63
static double getTime()
void edm::service::Timing::preEvent ( StreamContext const &  iStream)
private

Definition at line 192 of file Timing.cc.

References curr_events_cpu_, curr_events_time_, edm::service::getCPU(), edm::service::getTime(), cmsHarvester::index, edm::StreamContext::streamID(), and edm::StreamID::value().

Referenced by Timing().

192  {
193  auto index = iStream.streamID().value();
196  }
std::vector< double > curr_events_time_
Definition: Timing.h:47
static double getCPU()
Definition: Timing.cc:47
std::vector< double > curr_events_cpu_
Definition: Timing.h:48
static double getTime()
void edm::service::Timing::preModule ( StreamContext const &  ,
ModuleCallingContext const &   
)
private

Definition at line 222 of file Timing.cc.

References edm::service::getTime(), and edm::service::moduleTimeStack().

Referenced by Timing().

222  {
223  auto & modStack = moduleTimeStack();
224  modStack.push_back(getTime());
225  }
static std::vector< double > & moduleTimeStack()
Definition: Timing.cc:63
static double getTime()

Member Data Documentation

std::vector<double> edm::service::Timing::curr_events_cpu_
private

Definition at line 48 of file Timing.h.

Referenced by addToCPUTime(), postEvent(), preEvent(), and Timing().

std::vector<double> edm::service::Timing::curr_events_time_
private

Definition at line 47 of file Timing.h.

Referenced by postEvent(), preEvent(), and Timing().

double edm::service::Timing::curr_job_cpu_
private

Definition at line 46 of file Timing.h.

Referenced by postBeginJob(), and postEndJob().

double edm::service::Timing::curr_job_time_
private

Definition at line 45 of file Timing.h.

Referenced by postBeginJob(), and postEndJob().

std::vector<double> edm::service::Timing::max_events_cpu_
private

Definition at line 57 of file Timing.h.

Referenced by postEndJob(), postEvent(), and Timing().

std::vector<double> edm::service::Timing::max_events_time_
private

Definition at line 56 of file Timing.h.

Referenced by postEndJob(), postEvent(), and Timing().

std::vector<double> edm::service::Timing::min_events_cpu_
private

Definition at line 59 of file Timing.h.

Referenced by postEndJob(), postEvent(), and Timing().

std::vector<double> edm::service::Timing::min_events_time_
private

Definition at line 58 of file Timing.h.

Referenced by postEndJob(), postEvent(), and Timing().

bool edm::service::Timing::report_summary_
private

Definition at line 51 of file Timing.h.

Referenced by postEndJob().

bool edm::service::Timing::summary_only_
private

Definition at line 50 of file Timing.h.

Referenced by postBeginJob(), postEvent(), and Timing().

std::atomic<unsigned long> edm::service::Timing::total_event_count_
private

Definition at line 60 of file Timing.h.

Referenced by postEndJob(), and postEvent().

std::vector<double> edm::service::Timing::total_events_cpu_
private

Definition at line 49 of file Timing.h.

Referenced by postEndJob(), postEvent(), and Timing().