LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
art::TimeTracker Class Reference

Classes

struct  Config
 
struct  PerScheduleData
 

Public Types

using Parameters = ServiceTable< Config >
 

Public Member Functions

 TimeTracker (Parameters const &, ActivityRegistry &)
 

Static Public Attributes

static constexpr bool service_handle_allowed {false}
 

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 postSourceConstruction (ModuleDescription const &)
 
void postEndJob ()
 
void preEventReading (ScheduleContext)
 
void postEventReading (Event const &, ScheduleContext)
 
void preEventProcessing (Event const &, ScheduleContext)
 
void postEventProcessing (Event const &, ScheduleContext)
 
void startTime (ModuleContext const &mc)
 
void recordTime (ModuleContext const &mc, string const &suffix)
 
void logToDestination_ (Statistics const &evt, vector< Statistics > const &modules)
 
bool anyTableFull_ () const
 

Private Attributes

tbb::concurrent_unordered_map< ConcurrentKey, PerScheduleData, ConcurrentKeyHasher > data_
 
bool const printSummary_
 
unique_ptr< cet::sqlite::Connection > const db_
 
bool const overwriteContents_
 
string sourceType_ {}
 
name_array< 5u > const timeSourceColumnNames_
 
name_array< 4u > const timeEventColumnNames_
 
name_array< 7u > const timeModuleColumnNames_
 
timeSource_t timeSourceTable_
 
timeEvent_t timeEventTable_
 
timeModule_t timeModuleTable_
 

Detailed Description

Definition at line 124 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 146 of file TimeTracker_service.cc.

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

Definition at line 150 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 152 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 148 of file TimeTracker_service.cc.

Constructor & Destructor Documentation

art::TimeTracker::TimeTracker ( Parameters const &  config,
ActivityRegistry areg 
)
explicit

Definition at line 182 of file TimeTracker_service.cc.

References db_, overwriteContents_, postEndJob(), postEventProcessing(), postEventReading(), postSourceConstruction(), preEventProcessing(), preEventReading(), recordTime(), startTime(), timeEventColumnNames_, timeEventTable_, timeModuleColumnNames_, timeModuleTable_, timeSourceColumnNames_, and timeSourceTable_.

183  : printSummary_{config().printSummary()}
184  , db_{ServiceHandle<DatabaseConnection>{}
185  -> get(config().dbOutput().filename())}
186  , overwriteContents_{config().dbOutput().overwrite()}
187  , timeSourceColumnNames_{{"Run", "SubRun", "Event", "Source", "Time"}}
188  , timeEventColumnNames_{{"Run", "SubRun", "Event", "Time"}}
189  , timeModuleColumnNames_{{"Run",
190  "SubRun",
191  "Event",
192  "Path",
193  "ModuleLabel",
194  "ModuleType",
195  "Time"}}
197  "TimeSource",
200  , timeEventTable_{*db_,
201  "TimeEvent",
203  overwriteContents_}
205  "TimeModule",
207  overwriteContents_}
208  {
209  areg.sPostSourceConstruction.watch(this,
211  areg.sPostEndJob.watch(this, &TimeTracker::postEndJob);
212  // Event reading
213  areg.sPreSourceEvent.watch(this, &TimeTracker::preEventReading);
214  areg.sPostSourceEvent.watch(this, &TimeTracker::postEventReading);
215  // Event execution
216  areg.sPreProcessEvent.watch(this, &TimeTracker::preEventProcessing);
217  areg.sPostProcessEvent.watch(this, &TimeTracker::postEventProcessing);
218  // Module execution
219  areg.sPreModule.watch(this, &TimeTracker::startTime);
220  areg.sPostModule.watch(
221  [this](auto const& mc) { this->recordTime(mc, ""s); });
222  areg.sPreWriteEvent.watch(this, &TimeTracker::startTime);
223  areg.sPostWriteEvent.watch(
224  [this](auto const& mc) { this->recordTime(mc, "(write)"s); });
225  }
void preEventReading(ScheduleContext)
void preEventProcessing(Event const &, ScheduleContext)
name_array< 4u > const timeEventColumnNames_
void postEventProcessing(Event const &, ScheduleContext)
void postSourceConstruction(ModuleDescription const &)
void postEventReading(Event const &, ScheduleContext)
timeModule_t timeModuleTable_
unique_ptr< cet::sqlite::Connection > const db_
name_array< 7u > const timeModuleColumnNames_
timeSource_t timeSourceTable_
void recordTime(ModuleContext const &mc, string const &suffix)
name_array< 5u > const timeSourceColumnNames_
void startTime(ModuleContext const &mc)

Member Function Documentation

bool art::TimeTracker::anyTableFull_ ( ) const
private

Definition at line 412 of file TimeTracker_service.cc.

References DECLARE_ART_SERVICE, DEFINE_ART_SERVICE, art::SHARED, timeEventTable_, timeModuleTable_, and timeSourceTable_.

Referenced by postEndJob().

413  {
414  return timeSourceTable_.full() || timeEventTable_.full() ||
415  timeModuleTable_.full();
416  }
timeModule_t timeModuleTable_
timeSource_t timeSourceTable_
void art::TimeTracker::logToDestination_ ( Statistics const &  evt,
vector< Statistics > const &  modules 
)
private

Definition at line 374 of file TimeTracker_service.cc.

References art::left().

Referenced by postEndJob().

376  {
377  size_t width{30};
378  auto identifier_size = [](Statistics const& s) {
379  return s.path.size() + s.mod_label.size() + s.mod_type.size() +
380  2; // Don't forget the two ':'s.
381  };
382  cet::for_all(modules, [&identifier_size, &width](auto const& mod) {
383  width = max(width, identifier_size(mod));
384  });
385  ostringstream msgOss;
386  HorizontalRule const rule{width + 4 + 5 * 14 + 12};
387  msgOss << '\n'
388  << rule('=') << '\n'
389  << std::setw(width + 2) << std::left << "TimeTracker printout (sec)"
390  << boost::format(" %=12s ") % "Min"
391  << boost::format(" %=12s ") % "Avg"
392  << boost::format(" %=12s ") % "Max"
393  << boost::format(" %=12s ") % "Median"
394  << boost::format(" %=12s ") % "RMS"
395  << boost::format(" %=10s ") % "nEvts" << '\n';
396  msgOss << rule('=') << '\n';
397  if (evt.n == 0u) {
398  msgOss << "[ No processed events ]\n";
399  } else {
400  // N.B. setw(width) applies to the first field in
401  // ostream& operator<<(ostream&, Statistics const&).
402  msgOss << setw(width) << evt << '\n' << rule('-') << '\n';
403  for (auto const& mod : modules) {
404  msgOss << setw(width) << mod << '\n';
405  }
406  }
407  msgOss << rule('=');
408  mf::LogAbsolute("TimeTracker") << msgOss.str();
409  }
constexpr auto const & left(const_AssnsIter< L, R, D, Dir > const &a, const_AssnsIter< L, R, D, Dir > const &b)
Definition: AssnsIter.h:94
TCEvent evt
Definition: DataStructs.cxx:8
MaybeLogger_< ELseverityLevel::ELsev_severe, true > LogAbsolute
void art::TimeTracker::postEndJob ( )
private

Definition at line 228 of file TimeTracker_service.cc.

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

Referenced by TimeTracker().

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

Definition at line 344 of file TimeTracker_service.cc.

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

Referenced by TimeTracker().

345  {
346  auto const& d = data_[key(sc.id())];
347  auto const t = chrono::duration<double>{now() - d.eventStart}.count();
348  timeEventTable_.insert(
349  d.eventID.run(), d.eventID.subRun(), d.eventID.event(), t);
350  }
tbb::concurrent_unordered_map< ConcurrentKey, PerScheduleData, ConcurrentKeyHasher > data_
Float_t d
Definition: plot.C:235
Float_t sc
Definition: plot.C:23
void art::TimeTracker::postEventReading ( Event const &  e,
ScheduleContext  sc 
)
private

Definition at line 325 of file TimeTracker_service.cc.

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

Referenced by TimeTracker().

326  {
327  auto& d = data_[key(sc.id())];
328  d.eventID = e.id();
329  auto const t = chrono::duration<double>{now() - d.eventStart}.count();
330  timeSourceTable_.insert(
331  d.eventID.run(), d.eventID.subRun(), d.eventID.event(), sourceType_, t);
332  }
tbb::concurrent_unordered_map< ConcurrentKey, PerScheduleData, ConcurrentKeyHasher > data_
Float_t d
Definition: plot.C:235
timeSource_t timeSourceTable_
Float_t sc
Definition: plot.C:23
Float_t e
Definition: plot.C:35
void art::TimeTracker::postSourceConstruction ( ModuleDescription const &  md)
private

Definition at line 311 of file TimeTracker_service.cc.

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

Referenced by TimeTracker().

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

Definition at line 335 of file TimeTracker_service.cc.

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

Referenced by TimeTracker().

337  {
338  auto& d = data_[key(sc.id())];
339  assert(d.eventID == e.id());
340  d.eventStart = now();
341  }
tbb::concurrent_unordered_map< ConcurrentKey, PerScheduleData, ConcurrentKeyHasher > data_
Float_t d
Definition: plot.C:235
Float_t sc
Definition: plot.C:23
Float_t e
Definition: plot.C:35
void art::TimeTracker::preEventReading ( ScheduleContext  sc)
private

Definition at line 317 of file TimeTracker_service.cc.

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

Referenced by TimeTracker().

318  {
319  auto& d = data_[key(sc.id())];
320  d.eventID = EventID::invalidEvent();
321  d.eventStart = now();
322  }
tbb::concurrent_unordered_map< ConcurrentKey, PerScheduleData, ConcurrentKeyHasher > data_
Float_t d
Definition: plot.C:235
Float_t sc
Definition: plot.C:23
static constexpr EventID invalidEvent() noexcept
Definition: EventID.h:202
void art::TimeTracker::recordTime ( ModuleContext const &  mc,
string const &  suffix 
)
private

Definition at line 360 of file TimeTracker_service.cc.

References d, data_, art::ModuleContext::moduleLabel(), art::ModuleContext::moduleName(), art::ModuleContext::pathName(), and timeModuleTable_.

Referenced by TimeTracker().

361  {
362  auto const& d = data_[key(mc)];
363  auto const t = chrono::duration<double>{now() - d.moduleStart}.count();
364  timeModuleTable_.insert(d.eventID.run(),
365  d.eventID.subRun(),
366  d.eventID.event(),
367  mc.pathName(),
368  mc.moduleLabel(),
369  mc.moduleName() + suffix,
370  t);
371  }
tbb::concurrent_unordered_map< ConcurrentKey, PerScheduleData, ConcurrentKeyHasher > data_
timeModule_t timeModuleTable_
Float_t d
Definition: plot.C:235
void art::TimeTracker::startTime ( ModuleContext const &  mc)
private

Definition at line 353 of file TimeTracker_service.cc.

References data_, and art::ModuleContext::scheduleID().

Referenced by TimeTracker().

354  {
355  data_[key(mc)].eventID = data_[key(mc.scheduleID())].eventID;
356  data_[key(mc)].moduleStart = now();
357  }
tbb::concurrent_unordered_map< ConcurrentKey, PerScheduleData, ConcurrentKeyHasher > data_

Member Data Documentation

tbb::concurrent_unordered_map<ConcurrentKey, PerScheduleData, ConcurrentKeyHasher> art::TimeTracker::data_
private
unique_ptr<cet::sqlite::Connection> const art::TimeTracker::db_
private

Definition at line 171 of file TimeTracker_service.cc.

Referenced by postEndJob(), and TimeTracker().

bool const art::TimeTracker::overwriteContents_
private

Definition at line 172 of file TimeTracker_service.cc.

Referenced by TimeTracker().

bool const art::TimeTracker::printSummary_
private

Definition at line 170 of file TimeTracker_service.cc.

Referenced by postEndJob().

constexpr bool art::TimeTracker::service_handle_allowed {false}
static

Definition at line 126 of file TimeTracker_service.cc.

string art::TimeTracker::sourceType_ {}
private

Definition at line 173 of file TimeTracker_service.cc.

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

name_array<4u> const art::TimeTracker::timeEventColumnNames_
private

Definition at line 175 of file TimeTracker_service.cc.

Referenced by TimeTracker().

timeEvent_t art::TimeTracker::timeEventTable_
private
name_array<7u> const art::TimeTracker::timeModuleColumnNames_
private

Definition at line 176 of file TimeTracker_service.cc.

Referenced by TimeTracker().

timeModule_t art::TimeTracker::timeModuleTable_
private

Definition at line 179 of file TimeTracker_service.cc.

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

name_array<5u> const art::TimeTracker::timeSourceColumnNames_
private

Definition at line 174 of file TimeTracker_service.cc.

Referenced by TimeTracker().

timeSource_t art::TimeTracker::timeSourceTable_
private

Definition at line 177 of file TimeTracker_service.cc.

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


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