LArSoft  v06_85_00
Liquid Argon Software toolkit - http://larsoft.org/
art::TimeTracker Class Reference

Classes

struct  Config
 
struct  PerScheduleData
 

Public Types

using Parameters = ServiceTable< Config >
 

Public Member Functions

 TimeTracker (ServiceTable< Config > const &, ActivityRegistry &)
 

Private Types

template<unsigned SIZE>
using name_array = cet::sqlite::name_array< SIZE >
 
using timeSource_t = cet::sqlite::Ntuple< uint32_t, uint32_t, uint32_t, string, double >
 
using timeEvent_t = cet::sqlite::Ntuple< uint32_t, uint32_t, uint32_t, double >
 
using timeModule_t = cet::sqlite::Ntuple< uint32_t, uint32_t, uint32_t, string, string, string, double >
 

Private Member Functions

void prePathProcessing (string const &)
 
void postSourceConstruction (ModuleDescription const &)
 
void postEndJob ()
 
void preEventReading ()
 
void postEventReading (Event const &)
 
void preEventProcessing (Event const &)
 
void postEventProcessing (Event const &)
 
void startTime (ModuleDescription const &)
 
void recordTime (ModuleDescription const &md, string const &suffix)
 
void logToDatabase_ (Statistics const &evt, std::vector< Statistics > const &modules)
 
void logToDestination_ (Statistics const &evt, std::vector< Statistics > const &modules)
 

Private Attributes

std::vector< PerScheduleDatadata_
 
bool printSummary_
 
cet::sqlite::Connection db_
 
bool overwriteContents_
 
string sourceType_ {}
 
name_array< 5u > timeSourceTuple_
 
name_array< 4u > timeEventTuple_
 
name_array< 7u > timeModuleTuple_
 
timeSource_t timeSourceTable_
 
timeEvent_t timeEventTable_
 
timeModule_t timeModuleTable_
 

Detailed Description

Definition at line 102 of file TimeTracker_service.cc.

Member Typedef Documentation

template<unsigned SIZE>
using art::TimeTracker::name_array = cet::sqlite::name_array<SIZE>
private

Definition at line 151 of file TimeTracker_service.cc.

using art::TimeTracker::timeEvent_t = cet::sqlite::Ntuple<uint32_t, uint32_t, uint32_t, double>
private

Definition at line 158 of file TimeTracker_service.cc.

using art::TimeTracker::timeModule_t = cet::sqlite:: Ntuple<uint32_t, uint32_t, uint32_t, string, string, string, double>
private

Definition at line 160 of file TimeTracker_service.cc.

using art::TimeTracker::timeSource_t = cet::sqlite::Ntuple<uint32_t, uint32_t, uint32_t, string, double>
private

Definition at line 157 of file TimeTracker_service.cc.

Constructor & Destructor Documentation

art::TimeTracker::TimeTracker ( ServiceTable< Config > const &  config,
ActivityRegistry iRegistry 
)
explicit

Definition at line 170 of file TimeTracker_service.cc.

References data_, db_, art::ServiceHandle< T, SCOPE >::get(), overwriteContents_, postEndJob(), postEventProcessing(), postEventReading(), postSourceConstruction(), preEventProcessing(), preEventReading(), prePathProcessing(), recordTime(), s, startTime(), timeEventTable_, timeEventTuple_, timeModuleTable_, timeModuleTuple_, timeSourceTable_, and timeSourceTuple_.

172  : printSummary_{config().printSummary()}
173  , db_{ServiceHandle<DatabaseConnection>{}->get(
174  config().dbOutput().filename())}
175  , overwriteContents_{config().dbOutput().overwrite()} // table headers
176  , timeSourceTuple_{{"Run", "SubRun", "Event", "Source", "Time"}}
177  , timeEventTuple_{{"Run", "SubRun", "Event", "Time"}}
178  , timeModuleTuple_{{"Run",
179  "SubRun",
180  "Event",
181  "Path",
182  "ModuleLabel",
183  "ModuleType",
184  "Time"}} // tables
186  , timeEventTable_{db_, "TimeEvent", timeEventTuple_, overwriteContents_}
187  , timeModuleTable_{db_, "TimeModule", timeModuleTuple_, overwriteContents_}
188 {
189  // MT-TODO: Placeholder until we are multi-threaded
190  unsigned const nSchedules{1u};
191  data_.resize(nSchedules);
192 
193  iRegistry.sPostSourceConstruction.watch(this,
195  iRegistry.sPreProcessPath.watch(this, &TimeTracker::prePathProcessing);
196  iRegistry.sPostEndJob.watch(this, &TimeTracker::postEndJob);
197 
198  // Event reading
199  iRegistry.sPreSourceEvent.watch(this, &TimeTracker::preEventReading);
200  iRegistry.sPostSourceEvent.watch(this, &TimeTracker::postEventReading);
201 
202  // Event execution
203  iRegistry.sPreProcessEvent.watch(this, &TimeTracker::preEventProcessing);
204  iRegistry.sPostProcessEvent.watch(this, &TimeTracker::postEventProcessing);
205 
206  // Module execution
207  iRegistry.sPreModule.watch(this, &TimeTracker::startTime);
208  iRegistry.sPostModule.watch(
209  [this](auto const& md) { this->recordTime(md, ""s); });
210  iRegistry.sPreWriteEvent.watch(this, &TimeTracker::startTime);
211  iRegistry.sPostWriteEvent.watch(
212  [this](auto const& md) { this->recordTime(md, "(write)"s); });
213 }
Float_t s
Definition: plot.C:23
name_array< 5u > timeSourceTuple_
void startTime(ModuleDescription const &)
std::vector< PerScheduleData > data_
void prePathProcessing(string const &)
void postSourceConstruction(ModuleDescription const &)
name_array< 4u > timeEventTuple_
name_array< 7u > timeModuleTuple_
timeModule_t timeModuleTable_
cet::sqlite::Connection db_
timeSource_t timeSourceTable_
void recordTime(ModuleDescription const &md, string const &suffix)
void postEventReading(Event const &)
void postEventProcessing(Event const &)
void preEventProcessing(Event const &)

Member Function Documentation

void art::TimeTracker::logToDatabase_ ( Statistics const &  evt,
std::vector< Statistics > const &  modules 
)
private
void art::TimeTracker::logToDestination_ ( Statistics const &  evt,
std::vector< Statistics > const &  modules 
)
private

Definition at line 389 of file TimeTracker_service.cc.

References DECLARE_ART_SERVICE, DEFINE_ART_SERVICE, art::left(), art::LEGACY, max, and s.

Referenced by postEndJob().

391 {
392  std::size_t width{30};
393  auto identifier_size = [](Statistics const& s) {
394  return s.path.size() + s.mod_label.size() + s.mod_type.size() +
395  2; // Don't forget the two ':'s.
396  };
397  cet::for_all(modules, [&identifier_size, &width](auto const& mod) {
398  width = std::max(width, identifier_size(mod));
399  });
400 
401  std::ostringstream msgOss;
402  HorizontalRule const rule{width + 4 + 5 * 14 + 12};
403  msgOss << '\n'
404  << rule('=') << '\n'
405  << std::setw(width + 2) << std::left << "TimeTracker printout (sec)"
406  << boost::format(" %=12s ") % "Min" << boost::format(" %=12s ") % "Avg"
407  << boost::format(" %=12s ") % "Max"
408  << boost::format(" %=12s ") % "Median"
409  << boost::format(" %=12s ") % "RMS"
410  << boost::format(" %=10s ") % "nEvts"
411  << "\n";
412 
413  msgOss << rule('=') << '\n';
414 
415  if (evt.n == 0u) {
416  msgOss << "[ No processed events ]\n";
417  } else {
418  // N.B. setw(width) applies to the first field in
419  // ostream& art::operator<<(ostream&, Statistics const&).
420  msgOss << setw(width) << evt << '\n' << rule('-') << '\n';
421  for (auto const& mod : modules) {
422  msgOss << setw(width) << mod << '\n';
423  }
424  }
425 
426  msgOss << rule('=');
427  mf::LogAbsolute("TimeTracker") << msgOss.str();
428 }
Float_t s
Definition: plot.C:23
Int_t max
Definition: plot.C:27
constexpr auto const & left(const_AssnsIter< L, R, D, Dir > const &a, const_AssnsIter< L, R, D, Dir > const &b)
Definition: AssnsIter.h:104
MaybeLogger_< ELseverityLevel::ELsev_severe, true > LogAbsolute
void art::TimeTracker::postEndJob ( )
private

Definition at line 226 of file TimeTracker_service.cc.

References db_, logToDestination_(), printSummary_, s, sourceType_, timeEventTable_, timeModuleTable_, and timeSourceTable_.

Referenced by TimeTracker().

227 {
228  timeSourceTable_.flush();
229  timeEventTable_.flush();
230  timeModuleTable_.flush();
231 
232  if (!printSummary_)
233  return;
234 
235  using namespace cet::sqlite;
236  query_result<std::size_t> rEvents;
237  rEvents << select("count(*)").from(db_, timeEventTable_.name());
238 
239  query_result<std::size_t> rModules;
240  rModules << select("count(*)").from(db_, timeModuleTable_.name());
241 
242  auto const nEventRows = unique_value(rEvents);
243  auto const nModuleRows = unique_value(rModules);
244 
245  if (nEventRows == 0 && nModuleRows == 0) {
246  logToDestination_(Statistics{}, std::vector<Statistics>{});
247  return;
248  }
249 
250  if (nEventRows == 0 && nModuleRows != 0) {
251  std::string const errMsg{
252  "Malformed TimeTracker database. The TimeEvent table is empty, but\n"
253  "the TimeModule table is not. This can happen if an exception has\n"
254  "been thrown from a module while processing the first event. Any saved\n"
255  "database file is suspect and should not be used."};
256  mf::LogAbsolute("TimeTracker") << errMsg;
257  return;
258  }
259 
260  using namespace std;
261  // Gather statistics for full Event
262  // -- Unfortunately, this is not a simple query since the (e.g.)
263  // 'RootOutput(write)' times and the source time are not
264  // recorded in the TimeEvent rows. They must be added in.
265 
266  string const fullEventTime_ddl =
267  "CREATE TABLE temp.fullEventTime AS "
268  "SELECT Run,Subrun,Event,SUM(Time) AS FullEventTime FROM ("
269  " SELECT Run,Subrun,Event,Time FROM TimeEvent"
270  " UNION"
271  " SELECT Run,Subrun,Event,Time FROM TimeModule WHERE ModuleType LIKE "
272  "'%(write)'"
273  " UNION"
274  " SELECT Run,Subrun,Event,Time FROM TimeSource"
275  ") GROUP BY Run,Subrun,Event";
276 
277  using namespace cet::sqlite;
278  exec(db_, fullEventTime_ddl);
279  Statistics const evtStats{
280  "Full event", "", "", db_, "temp.fullEventTime", "FullEventTime"};
281  drop_table(db_, "temp.fullEventTime");
282 
283  query_result<string, string, string> r;
284  r << select_distinct("Path", "ModuleLabel", "ModuleType")
285  .from(db_, timeModuleTable_.name());
286 
287  std::vector<Statistics> modStats;
288  modStats.emplace_back(
289  "source", sourceType_ + "(read)", "", db_, "TimeSource", "Time");
290 
291  for (auto const& row : r) {
292  string path, mod_label, mod_type;
293  tie(path, mod_label, mod_type) = row;
294  create_table_as("temp.tmpModTable",
295  select("*")
296  .from(db_, "TimeModule")
297  .where("Path='"s + path + "'"s + " AND ModuleLabel='"s +
298  mod_label + "'"s + " AND ModuleType='"s +
299  mod_type + "'"s));
300  modStats.emplace_back(
301  path, mod_label, mod_type, db_, "temp.tmpModTable", "Time");
302  drop_table(db_, "temp.tmpModTable");
303  }
304 
305  logToDestination_(evtStats, modStats);
306 }
Float_t s
Definition: plot.C:23
void logToDestination_(Statistics const &evt, std::vector< Statistics > const &modules)
STL namespace.
timeModule_t timeModuleTable_
cet::sqlite::Connection db_
timeSource_t timeSourceTable_
MaybeLogger_< ELseverityLevel::ELsev_severe, true > LogAbsolute
void art::TimeTracker::postEventProcessing ( Event const &  )
private

Definition at line 350 of file TimeTracker_service.cc.

References d, data_, art::ScheduleID::first(), art::ScheduleID::id(), and timeEventTable_.

Referenced by TimeTracker().

351 {
352  // MT-TODO: Placeholder until we're multi-threaded
353  auto const sid = ScheduleID::first().id();
354  auto const& d = data_[sid];
355  auto const t = std::chrono::duration<double>{now() - d.eventStart}.count();
356  timeEventTable_.insert(
357  d.eventID.run(), d.eventID.subRun(), d.eventID.event(), t);
358 }
std::vector< PerScheduleData > data_
constexpr id_type id() const
Definition: ScheduleID.h:70
static ScheduleID first()
Definition: ScheduleID.h:82
Float_t d
Definition: plot.C:237
void art::TimeTracker::postEventReading ( Event const &  e)
private

Definition at line 327 of file TimeTracker_service.cc.

References d, data_, art::ScheduleID::first(), art::ScheduleID::id(), art::Event::id(), sourceType_, and timeSourceTable_.

Referenced by TimeTracker().

328 {
329  // MT-TODO: Placeholder until we're multi-threaded
330  auto const sid = ScheduleID::first().id();
331  auto& d = data_[sid];
332  d.eventID = e.id();
333  auto const t = std::chrono::duration<double>{now() - d.eventStart}.count();
334  timeSourceTable_.insert(
335  d.eventID.run(), d.eventID.subRun(), d.eventID.event(), sourceType_, t);
336 }
std::vector< PerScheduleData > data_
constexpr id_type id() const
Definition: ScheduleID.h:70
static ScheduleID first()
Definition: ScheduleID.h:82
Float_t d
Definition: plot.C:237
timeSource_t timeSourceTable_
Float_t e
Definition: plot.C:34
void art::TimeTracker::postSourceConstruction ( ModuleDescription const &  md)
private

Definition at line 310 of file TimeTracker_service.cc.

References art::ModuleDescription::moduleName(), and sourceType_.

Referenced by TimeTracker().

311 {
312  sourceType_ = md.moduleName();
313 }
void art::TimeTracker::preEventProcessing ( Event const &  )
private

Definition at line 340 of file TimeTracker_service.cc.

References d, data_, e, art::ScheduleID::first(), and art::ScheduleID::id().

Referenced by TimeTracker().

341 {
342  // MT-TODO: Placeholder until we're multi-threaded
343  auto const sid = ScheduleID::first().id();
344  auto& d = data_[sid];
345  assert(d.eventID == e.id());
346  d.eventStart = now();
347 }
std::vector< PerScheduleData > data_
constexpr id_type id() const
Definition: ScheduleID.h:70
static ScheduleID first()
Definition: ScheduleID.h:82
Float_t d
Definition: plot.C:237
Float_t e
Definition: plot.C:34
void art::TimeTracker::preEventReading ( )
private

Definition at line 317 of file TimeTracker_service.cc.

References d, data_, art::ScheduleID::first(), art::ScheduleID::id(), and art::EventID::invalidEvent().

Referenced by TimeTracker().

318 {
319  // MT-TODO: Placeholder until we're multi-threaded
320  auto const sid = ScheduleID::first().id();
321  auto& d = data_[sid];
322  d.eventID = EventID::invalidEvent();
323  d.eventStart = now();
324 }
static constexpr EventID invalidEvent()
Definition: EventID.h:203
std::vector< PerScheduleData > data_
constexpr id_type id() const
Definition: ScheduleID.h:70
static ScheduleID first()
Definition: ScheduleID.h:82
Float_t d
Definition: plot.C:237
void art::TimeTracker::prePathProcessing ( string const &  pathname)
private

Definition at line 217 of file TimeTracker_service.cc.

References data_, art::ScheduleID::first(), and art::ScheduleID::id().

Referenced by TimeTracker().

218 {
219  // MT-TODO: Placeholder until we're multi-threaded
220  auto const sid = ScheduleID::first().id();
221  data_[sid].pathName = pathname;
222 }
std::vector< PerScheduleData > data_
constexpr id_type id() const
Definition: ScheduleID.h:70
static ScheduleID first()
Definition: ScheduleID.h:82
void art::TimeTracker::recordTime ( ModuleDescription const &  md,
string const &  suffix 
)
private

Definition at line 371 of file TimeTracker_service.cc.

References d, data_, art::ScheduleID::first(), art::ScheduleID::id(), art::ModuleDescription::moduleLabel(), art::ModuleDescription::moduleName(), and timeModuleTable_.

Referenced by TimeTracker().

373 {
374  // MT-TODO: Placeholder until we're multi-threaded
375  auto const sid = ScheduleID::first().id();
376  auto const& d = data_[sid];
377  auto const t = std::chrono::duration<double>{now() - d.moduleStart}.count();
378  timeModuleTable_.insert(d.eventID.run(),
379  d.eventID.subRun(),
380  d.eventID.event(),
381  d.pathName,
382  desc.moduleLabel(),
383  desc.moduleName() + suffix,
384  t);
385 }
std::vector< PerScheduleData > data_
constexpr id_type id() const
Definition: ScheduleID.h:70
static ScheduleID first()
Definition: ScheduleID.h:82
timeModule_t timeModuleTable_
Float_t d
Definition: plot.C:237
void art::TimeTracker::startTime ( ModuleDescription const &  )
private

Definition at line 362 of file TimeTracker_service.cc.

References d, data_, art::ScheduleID::first(), and art::ScheduleID::id().

Referenced by TimeTracker().

363 {
364  // MT-TODO: Placeholder until we're multi-threaded
365  auto const sid = ScheduleID::first().id();
366  auto& d = data_[sid];
367  d.moduleStart = now();
368 }
std::vector< PerScheduleData > data_
constexpr id_type id() const
Definition: ScheduleID.h:70
static ScheduleID first()
Definition: ScheduleID.h:82
Float_t d
Definition: plot.C:237

Member Data Documentation

cet::sqlite::Connection art::TimeTracker::db_
private

Definition at line 146 of file TimeTracker_service.cc.

Referenced by postEndJob(), and TimeTracker().

bool art::TimeTracker::overwriteContents_
private

Definition at line 147 of file TimeTracker_service.cc.

Referenced by TimeTracker().

bool art::TimeTracker::printSummary_
private

Definition at line 145 of file TimeTracker_service.cc.

Referenced by postEndJob().

string art::TimeTracker::sourceType_ {}
private

Definition at line 148 of file TimeTracker_service.cc.

Referenced by postEndJob(), postEventReading(), and postSourceConstruction().

timeEvent_t art::TimeTracker::timeEventTable_
private

Definition at line 163 of file TimeTracker_service.cc.

Referenced by postEndJob(), postEventProcessing(), and TimeTracker().

name_array<4u> art::TimeTracker::timeEventTuple_
private

Definition at line 153 of file TimeTracker_service.cc.

Referenced by TimeTracker().

timeModule_t art::TimeTracker::timeModuleTable_
private

Definition at line 164 of file TimeTracker_service.cc.

Referenced by postEndJob(), recordTime(), and TimeTracker().

name_array<7u> art::TimeTracker::timeModuleTuple_
private

Definition at line 154 of file TimeTracker_service.cc.

Referenced by TimeTracker().

timeSource_t art::TimeTracker::timeSourceTable_
private

Definition at line 162 of file TimeTracker_service.cc.

Referenced by postEndJob(), postEventReading(), and TimeTracker().

name_array<5u> art::TimeTracker::timeSourceTuple_
private

Definition at line 152 of file TimeTracker_service.cc.

Referenced by TimeTracker().


The documentation for this class was generated from the following file: