Classes | Public Types | Public Member Functions | Static Public Attributes | Private Types | Private Member Functions | Private Attributes | List of all members
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)
 

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.

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

183  , db_{ServiceHandle<DatabaseConnection>{}->get(
184  config().dbOutput().filename())}
185  , overwriteContents_{config().dbOutput().overwrite()}
186  , timeSourceColumnNames_{{"Run", "SubRun", "Event", "Source", "Time"}}
187  , timeEventColumnNames_{{"Run", "SubRun", "Event", "Time"}}
188  , timeModuleColumnNames_{{"Run",
189  "SubRun",
190  "Event",
191  "Path",
192  "ModuleLabel",
193  "ModuleType",
194  "Time"}}
196  "TimeSource",
199  , timeEventTable_{*db_,
200  "TimeEvent",
202  overwriteContents_}
204  "TimeModule",
206  overwriteContents_}
207  {
208  areg.sPostSourceConstruction.watch(this,
210  areg.sPostEndJob.watch(this, &TimeTracker::postEndJob);
211  // Event reading
212  areg.sPreSourceEvent.watch(this, &TimeTracker::preEventReading);
213  areg.sPostSourceEvent.watch(this, &TimeTracker::postEventReading);
214  // Event execution
215  areg.sPreProcessEvent.watch(this, &TimeTracker::preEventProcessing);
216  areg.sPostProcessEvent.watch(this, &TimeTracker::postEventProcessing);
217  // Module execution
218  areg.sPreModule.watch(this, &TimeTracker::startTime);
219  areg.sPostModule.watch(
220  [this](auto const& mc) { this->recordTime(mc, ""s); });
221  areg.sPreWriteEvent.watch(this, &TimeTracker::startTime);
222  areg.sPostWriteEvent.watch(
223  [this](auto const& mc) { this->recordTime(mc, "(write)"s); });
224  }
void preEventReading(ScheduleContext)
void preEventProcessing(Event const &, ScheduleContext)
name_array< 4u > const timeEventColumnNames_
string filename
Definition: train.py:213
void postEventProcessing(Event const &, ScheduleContext)
void postSourceConstruction(ModuleDescription const &)
fhicl::Atom< bool > printSummary
void postEventReading(Event const &, ScheduleContext)
timeModule_t timeModuleTable_
static Config * config
Definition: config.cpp:1054
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)
static QCString * s
Definition: config.cpp:1042
fhicl::Table< DBoutput > dbOutput

Member Function Documentation

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

Definition at line 359 of file TimeTracker_service.cc.

361  {
362  size_t width{30};
363  auto identifier_size = [](Statistics const& s) {
364  return s.path.size() + s.mod_label.size() + s.mod_type.size() +
365  2; // Don't forget the two ':'s.
366  };
367  cet::for_all(modules, [&identifier_size, &width](auto const& mod) {
368  width = max(width, identifier_size(mod));
369  });
370  ostringstream msgOss;
371  HorizontalRule const rule{width + 4 + 5 * 14 + 12};
372  msgOss << '\n'
373  << rule('=') << '\n'
374  << std::setw(width + 2) << std::left << "TimeTracker printout (sec)"
375  << boost::format(" %=12s ") % "Min"
376  << boost::format(" %=12s ") % "Avg"
377  << boost::format(" %=12s ") % "Max"
378  << boost::format(" %=12s ") % "Median"
379  << boost::format(" %=12s ") % "RMS"
380  << boost::format(" %=10s ") % "nEvts"
381  << "\n";
382  msgOss << rule('=') << '\n';
383  if (evt.n == 0u) {
384  msgOss << "[ No processed events ]\n";
385  } else {
386  // N.B. setw(width) applies to the first field in
387  // ostream& operator<<(ostream&, Statistics const&).
388  msgOss << setw(width) << evt << '\n' << rule('-') << '\n';
389  for (auto const& mod : modules) {
390  msgOss << setw(width) << mod << '\n';
391  }
392  }
393  msgOss << rule('=');
394  mf::LogAbsolute("TimeTracker") << msgOss.str();
395  }
static bool format(QChar::Decomposition tag, QString &str, int index, int len)
Definition: qstring.cpp:11496
uint size() const
Definition: qcstring.h:201
static int max(int a, int b)
Q_EXPORT QTSManip setw(int w)
Definition: qtextstream.h:331
auto for_all(FwdCont &, Func)
TCEvent evt
Definition: DataStructs.cxx:7
MaybeLogger_< ELseverityLevel::ELsev_severe, true > LogAbsolute
static QCString * s
Definition: config.cpp:1042
void art::TimeTracker::postEndJob ( )
private

Definition at line 227 of file TimeTracker_service.cc.

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

Definition at line 329 of file TimeTracker_service.cc.

330  {
331  auto const& d = data_[key(sc.id())];
332  auto const t = chrono::duration<double>{now() - d.eventStart}.count();
334  d.eventID.run(), d.eventID.subRun(), d.eventID.event(), t);
335  }
void insert(Args const ...)
Definition: Ntuple.h:231
tbb::concurrent_unordered_map< ConcurrentKey, PerScheduleData, ConcurrentKeyHasher > data_
def key(type, name=None)
Definition: graph.py:13
void art::TimeTracker::postEventReading ( Event const &  e,
ScheduleContext  sc 
)
private

Definition at line 310 of file TimeTracker_service.cc.

311  {
312  auto& d = data_[key(sc.id())];
313  d.eventID = e.id();
314  auto const t = chrono::duration<double>{now() - d.eventStart}.count();
316  d.eventID.run(), d.eventID.subRun(), d.eventID.event(), sourceType_, t);
317  }
void insert(Args const ...)
Definition: Ntuple.h:231
tbb::concurrent_unordered_map< ConcurrentKey, PerScheduleData, ConcurrentKeyHasher > data_
const double e
def key(type, name=None)
Definition: graph.py:13
timeSource_t timeSourceTable_
void art::TimeTracker::postSourceConstruction ( ModuleDescription const &  md)
private

Definition at line 296 of file TimeTracker_service.cc.

297  {
298  sourceType_ = md.moduleName();
299  }
void art::TimeTracker::preEventProcessing ( Event const &  ,
ScheduleContext   
)
private

Definition at line 320 of file TimeTracker_service.cc.

322  {
323  auto& d = data_[key(sc.id())];
324  assert(d.eventID == e.id());
325  d.eventStart = now();
326  }
tbb::concurrent_unordered_map< ConcurrentKey, PerScheduleData, ConcurrentKeyHasher > data_
const double e
def key(type, name=None)
Definition: graph.py:13
void art::TimeTracker::preEventReading ( ScheduleContext  sc)
private

Definition at line 302 of file TimeTracker_service.cc.

303  {
304  auto& d = data_[key(sc.id())];
305  d.eventID = EventID::invalidEvent();
306  d.eventStart = now();
307  }
tbb::concurrent_unordered_map< ConcurrentKey, PerScheduleData, ConcurrentKeyHasher > data_
def key(type, name=None)
Definition: graph.py:13
static constexpr EventID invalidEvent() noexcept
Definition: EventID.h:202
void art::TimeTracker::recordTime ( ModuleContext const &  mc,
string const &  suffix 
)
private

Definition at line 345 of file TimeTracker_service.cc.

346  {
347  auto const& d = data_[key(mc)];
348  auto const t = chrono::duration<double>{now() - d.moduleStart}.count();
349  timeModuleTable_.insert(d.eventID.run(),
350  d.eventID.subRun(),
351  d.eventID.event(),
352  mc.pathName(),
353  mc.moduleLabel(),
354  mc.moduleName() + suffix,
355  t);
356  }
void insert(Args const ...)
Definition: Ntuple.h:231
tbb::concurrent_unordered_map< ConcurrentKey, PerScheduleData, ConcurrentKeyHasher > data_
def key(type, name=None)
Definition: graph.py:13
timeModule_t timeModuleTable_
void art::TimeTracker::startTime ( ModuleContext const &  mc)
private

Definition at line 338 of file TimeTracker_service.cc.

339  {
340  data_[key(mc)].eventID = data_[key(mc.scheduleID())].eventID;
341  data_[key(mc)].moduleStart = now();
342  }
tbb::concurrent_unordered_map< ConcurrentKey, PerScheduleData, ConcurrentKeyHasher > data_
def key(type, name=None)
Definition: graph.py:13

Member Data Documentation

tbb::concurrent_unordered_map<ConcurrentKey, PerScheduleData, ConcurrentKeyHasher> art::TimeTracker::data_
private

Definition at line 168 of file TimeTracker_service.cc.

unique_ptr<cet::sqlite::Connection> const art::TimeTracker::db_
private

Definition at line 170 of file TimeTracker_service.cc.

bool const art::TimeTracker::overwriteContents_
private

Definition at line 171 of file TimeTracker_service.cc.

bool const art::TimeTracker::printSummary_
private

Definition at line 169 of file TimeTracker_service.cc.

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 172 of file TimeTracker_service.cc.

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

Definition at line 174 of file TimeTracker_service.cc.

timeEvent_t art::TimeTracker::timeEventTable_
private

Definition at line 177 of file TimeTracker_service.cc.

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

Definition at line 175 of file TimeTracker_service.cc.

timeModule_t art::TimeTracker::timeModuleTable_
private

Definition at line 178 of file TimeTracker_service.cc.

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

Definition at line 173 of file TimeTracker_service.cc.

timeSource_t art::TimeTracker::timeSourceTable_
private

Definition at line 176 of file TimeTracker_service.cc.


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