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

Classes

struct  Config
 
struct  PerScheduleData
 

Public Types

using Parameters = ServiceTable< Config >
 

Public Member Functions

 MemoryTracker (fhicl::ParameterSet const &)
 
 MemoryTracker (ServiceTable< Config > const &, ActivityRegistry &)
 

Private Types

template<unsigned N>
using name_array = cet::sqlite::name_array< N >
 
using peakUsage_t = cet::sqlite::Ntuple< std::string, double, std::string >
 
using otherInfo_t = cet::sqlite::Ntuple< std::string, std::string, std::string, double, double >
 
using memEvent_t = cet::sqlite::Ntuple< std::string, uint32_t, uint32_t, uint32_t, double, double >
 
using memModule_t = cet::sqlite::Ntuple< std::string, uint32_t, uint32_t, uint32_t, std::string, std::string, std::string, double, double >
 
using memEventHeap_t = cet::sqlite::Ntuple< std::string, uint32_t, uint32_t, uint32_t, int, int, int, int, int, int, int >
 
using memModuleHeap_t = cet::sqlite::Ntuple< std::string, uint32_t, uint32_t, uint32_t, std::string, std::string, std::string, int, int, int, int, int, int, int >
 

Private Member Functions

void prePathProcessing (std::string const &)
 
void recordOtherData (ModuleDescription const &md, std::string const &step)
 
void recordEventData (Event const &e, std::string const &step)
 
void recordModuleData (ModuleDescription const &md, std::string const &step)
 
void postEndJob ()
 
bool checkMallocConfig_ (std::string const &, bool)
 
void recordPeakUsages_ ()
 
void flushTables_ ()
 
void summary_ ()
 

Private Attributes

LinuxProcMgr procInfo_
 
std::string fileName_
 
cet::sqlite::Connection db_
 
bool overwriteContents_
 
bool includeMallocInfo_
 
std::vector< PerScheduleDatadata_
 
name_array< 3u > peakUsageColumns_ {{"Name", "Value", "Description"}}
 
name_array< 5u > otherInfoColumns_
 
name_array< 6u > eventColumns_
 
name_array< 9u > moduleColumns_
 
name_array< 11u > eventHeapColumns_
 
name_array< 14u > moduleHeapColumns_
 
peakUsage_t peakUsageTable_
 
otherInfo_t otherInfoTable_
 
memEvent_t eventTable_
 
memModule_t moduleTable_
 
std::unique_ptr< memEventHeap_teventHeapTable_
 
std::unique_ptr< memModuleHeap_tmoduleHeapTable_
 

Detailed Description

Definition at line 16 of file MemoryTrackerDarwin_service.cc.

Member Typedef Documentation

using art::MemoryTracker::memEvent_t = cet::sqlite:: Ntuple<std::string, uint32_t, uint32_t, uint32_t, double, double>
private

Definition at line 147 of file MemoryTrackerLinux_service.cc.

using art::MemoryTracker::memEventHeap_t = cet::sqlite::Ntuple<std::string, uint32_t, uint32_t, uint32_t, int, int, int, int, int, int, int>
private

Definition at line 167 of file MemoryTrackerLinux_service.cc.

using art::MemoryTracker::memModule_t = cet::sqlite::Ntuple<std::string, uint32_t, uint32_t, uint32_t, std::string, std::string, std::string, double, double>
private

Definition at line 156 of file MemoryTrackerLinux_service.cc.

using art::MemoryTracker::memModuleHeap_t = cet::sqlite::Ntuple<std::string, uint32_t, uint32_t, uint32_t, std::string, std::string, std::string, int, int, int, int, int, int, int>
private

Definition at line 181 of file MemoryTrackerLinux_service.cc.

template<unsigned N>
using art::MemoryTracker::name_array = cet::sqlite::name_array<N>
private

Definition at line 101 of file MemoryTrackerLinux_service.cc.

using art::MemoryTracker::otherInfo_t = cet::sqlite:: Ntuple<std::string, std::string, std::string, double, double>
private

Definition at line 145 of file MemoryTrackerLinux_service.cc.

using art::MemoryTracker::peakUsage_t = cet::sqlite::Ntuple<std::string, double, std::string>
private

Definition at line 143 of file MemoryTrackerLinux_service.cc.

Constructor & Destructor Documentation

art::MemoryTracker::MemoryTracker ( fhicl::ParameterSet const &  )
inline

Definition at line 18 of file MemoryTrackerDarwin_service.cc.

References DECLARE_ART_SERVICE, DEFINE_ART_SERVICE, and art::LEGACY.

19  {
20  mf::LogAbsolute("MemoryTracker")
21  << "\n"
22  << "The MemoryTracker service is not supported for this operating "
23  "system.\n"
24  << "If desired, please log an issue with:\n\n"
25  << "https://cdcvs.fnal.gov/redmine/projects/cet-is/issues/new\n\n";
26  }
MaybeLogger_< ELseverityLevel::ELsev_severe, true > LogAbsolute
art::MemoryTracker::MemoryTracker ( ServiceTable< Config > const &  config,
ActivityRegistry iReg 
)

Definition at line 209 of file MemoryTrackerLinux_service.cc.

References checkMallocConfig_(), data_, db_, e, eventColumns_, eventHeapColumns_, eventHeapTable_, eventTable_, fileName_, art::ServiceHandle< T, SCOPE >::get(), includeMallocInfo_, moduleColumns_, moduleHeapColumns_, moduleHeapTable_, moduleTable_, otherInfoColumns_, otherInfoTable_, overwriteContents_, peakUsageColumns_, peakUsageTable_, postEndJob(), prePathProcessing(), recordEventData(), recordModuleData(), and recordOtherData().

211  : procInfo_{nSchedules}
212  , fileName_{config().dbOutput().filename()}
213  , db_{ServiceHandle<DatabaseConnection>{}->get(fileName_)}
214  , overwriteContents_{config().dbOutput().overwrite()}
215  // Fix so that a value of 'false' is an error if filename => in-memory db.
216  , includeMallocInfo_{checkMallocConfig_(config().dbOutput().filename(),
217  config().includeMallocInfo())}
218  // tables
219  , peakUsageTable_{db_, "PeakUsage", peakUsageColumns_, true}
220  // always recompute the peak usage
222  , eventTable_{db_, "EventInfo", eventColumns_, overwriteContents_}
223  , moduleTable_{db_, "ModuleInfo", moduleColumns_, overwriteContents_}
225  std::make_unique<memEventHeap_t>(db_,
226  "EventMallocInfo",
228  nullptr}
230  std::make_unique<memModuleHeap_t>(db_,
231  "ModuleMallocInfo",
233  nullptr}
234 {
235  data_.resize(nSchedules);
236 
237  iReg.sPostEndJob.watch(this, &MemoryTracker::postEndJob);
238 
239  if (!fileName_.empty()) {
240  iReg.sPreModuleConstruction.watch([this](auto const& md) {
241  this->recordOtherData(md, "PreModuleConstruction");
242  });
243  iReg.sPostModuleConstruction.watch([this](auto const& md) {
244  this->recordOtherData(md, "PostModuleConstruction");
245  });
246  iReg.sPreModuleBeginJob.watch(
247  [this](auto const& md) { this->recordOtherData(md, "PreBeginJob"); });
248  iReg.sPostModuleBeginJob.watch(
249  [this](auto const& md) { this->recordOtherData(md, "PostBeginJob"); });
250  iReg.sPreModuleBeginRun.watch(
251  [this](auto const& md) { this->recordOtherData(md, "PreBeginRun"); });
252  iReg.sPostModuleBeginRun.watch(
253  [this](auto const& md) { this->recordOtherData(md, "PostBeginRun"); });
254  iReg.sPreModuleBeginSubRun.watch(
255  [this](auto const& md) { this->recordOtherData(md, "PreBeginSubRun"); });
256  iReg.sPostModuleBeginSubRun.watch(
257  [this](auto const& md) { this->recordOtherData(md, "PostBeginSubRun"); });
258  iReg.sPreProcessPath.watch(this, &MemoryTracker::prePathProcessing);
259  iReg.sPreProcessEvent.watch(
260  [this](auto const& e) { this->recordEventData(e, "PreProcessEvent"); });
261  iReg.sPostProcessEvent.watch(
262  [this](auto const& e) { this->recordEventData(e, "PostProcessEvent"); });
263  iReg.sPreModule.watch([this](auto const& md) {
264  this->recordModuleData(md, "PreProcessModule");
265  });
266  iReg.sPostModule.watch([this](auto const& md) {
267  this->recordModuleData(md, "PostProcessModule");
268  });
269  iReg.sPreWriteEvent.watch(
270  [this](auto const& md) { this->recordModuleData(md, "PreWriteEvent"); });
271  iReg.sPostWriteEvent.watch(
272  [this](auto const& md) { this->recordModuleData(md, "PostWriteEvent"); });
273  iReg.sPreModuleEndSubRun.watch(
274  [this](auto const& md) { this->recordOtherData(md, "PreEndSubRun"); });
275  iReg.sPreModuleEndRun.watch(
276  [this](auto const& md) { this->recordOtherData(md, "PreEndRun"); });
277  iReg.sPreModuleEndJob.watch(
278  [this](auto const& md) { this->recordOtherData(md, "PreEndJob"); });
279  iReg.sPostModuleEndSubRun.watch(
280  [this](auto const& md) { this->recordOtherData(md, "PostEndSubRun"); });
281  iReg.sPostModuleEndRun.watch(
282  [this](auto const& md) { this->recordOtherData(md, "PostEndRun"); });
283  iReg.sPostModuleEndJob.watch(
284  [this](auto const& md) { this->recordOtherData(md, "PostEndJob"); });
285  }
286 }
void recordOtherData(ModuleDescription const &md, std::string const &step)
name_array< 11u > eventHeapColumns_
void prePathProcessing(std::string const &)
std::vector< PerScheduleData > data_
std::unique_ptr< memEventHeap_t > eventHeapTable_
bool checkMallocConfig_(std::string const &, bool)
void recordModuleData(ModuleDescription const &md, std::string const &step)
std::unique_ptr< memModuleHeap_t > moduleHeapTable_
void recordEventData(Event const &e, std::string const &step)
name_array< 14u > moduleHeapColumns_
Float_t e
Definition: plot.C:34
cet::sqlite::Connection db_

Member Function Documentation

bool art::MemoryTracker::checkMallocConfig_ ( std::string const &  dbfilename,
bool  include 
)
private

Definition at line 397 of file MemoryTrackerLinux_service.cc.

References art::errors::Configuration, and s.

Referenced by MemoryTracker().

399 {
400  if (include && dbfilename.empty()) {
401  std::string const errmsg =
402  "\n'includeMallocInfo : true' is valid only if a nonempty db filename is specified:\n\n"s +
403  " MemoryTracker: {\n"
404  " includeMallocInfo: true\n"
405  " dbOutput: {\n"
406  " filename: \"your_filename.db\"\n"
407  " }\n"
408  " }\n\n";
409  throw Exception{errors::Configuration} << errmsg;
410  }
411  return include;
412 }
Float_t s
Definition: plot.C:23
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
void art::MemoryTracker::flushTables_ ( )
private

Definition at line 426 of file MemoryTrackerLinux_service.cc.

References eventHeapTable_, eventTable_, moduleHeapTable_, moduleTable_, otherInfoTable_, and peakUsageTable_.

Referenced by postEndJob().

427 {
428  otherInfoTable_.flush();
429  eventTable_.flush();
430  moduleTable_.flush();
431  peakUsageTable_.flush();
432  if (eventHeapTable_)
433  eventHeapTable_->flush();
434  if (moduleHeapTable_)
435  moduleHeapTable_->flush();
436 }
std::unique_ptr< memEventHeap_t > eventHeapTable_
std::unique_ptr< memModuleHeap_t > moduleHeapTable_
void art::MemoryTracker::postEndJob ( )
private
void art::MemoryTracker::prePathProcessing ( std::string const &  pathname)
private

Definition at line 290 of file MemoryTrackerLinux_service.cc.

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

Referenced by MemoryTracker().

291 {
292  // MT-TODO: Placeholder until we're multi-threaded
293  auto const sid = ScheduleID::first().id();
294  data_[sid].pathName = pathname;
295 }
constexpr id_type id() const
Definition: ScheduleID.h:70
std::vector< PerScheduleData > data_
static ScheduleID first()
Definition: ScheduleID.h:82
void art::MemoryTracker::recordEventData ( Event const &  e,
std::string const &  step 
)
private

Definition at line 314 of file MemoryTrackerLinux_service.cc.

References d, data_, eventHeapTable_, eventTable_, art::ScheduleID::first(), art::ScheduleID::id(), art::Event::id(), includeMallocInfo_, and procInfo_.

Referenced by MemoryTracker().

315 {
316  // MT-TODO: Placeholder until we're multi-threaded
317  auto const sid = ScheduleID::first().id();
318  auto& d = data_[sid];
319  d.eventID = e.id();
320 
321  auto const currentMemory = procInfo_.getCurrentData(sid);
322 
323  eventTable_.insert(step,
324  d.eventID.run(),
325  d.eventID.subRun(),
326  d.eventID.event(),
327  LinuxProcData::getValueInMB<vsize_t>(currentMemory),
328  LinuxProcData::getValueInMB<rss_t>(currentMemory));
329 
330  if (includeMallocInfo_) {
331  auto minfo = LinuxMallInfo{}.get();
332  eventHeapTable_->insert(step,
333  d.eventID.run(),
334  d.eventID.subRun(),
335  d.eventID.event(),
336  minfo.arena,
337  minfo.ordblks,
338  minfo.keepcost,
339  minfo.hblkhd,
340  minfo.hblks,
341  minfo.uordblks,
342  minfo.fordblks);
343  }
344 }
constexpr id_type id() const
Definition: ScheduleID.h:70
std::vector< PerScheduleData > data_
static ScheduleID first()
Definition: ScheduleID.h:82
std::unique_ptr< memEventHeap_t > eventHeapTable_
Float_t d
Definition: plot.C:237
Float_t e
Definition: plot.C:34
void art::MemoryTracker::recordModuleData ( ModuleDescription const &  md,
std::string const &  step 
)
private

Definition at line 348 of file MemoryTrackerLinux_service.cc.

References d, data_, art::ScheduleID::first(), art::ScheduleID::id(), includeMallocInfo_, moduleHeapTable_, art::ModuleDescription::moduleLabel(), art::ModuleDescription::moduleName(), moduleTable_, and procInfo_.

Referenced by MemoryTracker().

350 {
351  // MT-TODO: Placeholder until we're multi-threaded
352  auto const sid = ScheduleID::first().id();
353  auto& d = data_[sid];
354 
355  auto const currentMemory = procInfo_.getCurrentData(sid);
356 
357  moduleTable_.insert(step,
358  d.eventID.run(),
359  d.eventID.subRun(),
360  d.eventID.event(),
361  d.pathName,
362  md.moduleLabel(),
363  md.moduleName(),
364  LinuxProcData::getValueInMB<vsize_t>(currentMemory),
365  LinuxProcData::getValueInMB<rss_t>(currentMemory));
366 
367  if (includeMallocInfo_) {
368  auto minfo = LinuxMallInfo{}.get();
369  moduleHeapTable_->insert(step,
370  d.eventID.run(),
371  d.eventID.subRun(),
372  d.eventID.event(),
373  d.pathName,
374  md.moduleLabel(),
375  md.moduleName(),
376  minfo.arena,
377  minfo.ordblks,
378  minfo.keepcost,
379  minfo.hblkhd,
380  minfo.hblks,
381  minfo.uordblks,
382  minfo.fordblks);
383  }
384 }
constexpr id_type id() const
Definition: ScheduleID.h:70
std::vector< PerScheduleData > data_
static ScheduleID first()
Definition: ScheduleID.h:82
std::unique_ptr< memModuleHeap_t > moduleHeapTable_
Float_t d
Definition: plot.C:237
void art::MemoryTracker::recordOtherData ( ModuleDescription const &  md,
std::string const &  step 
)
private

Definition at line 299 of file MemoryTrackerLinux_service.cc.

References art::ScheduleID::first(), art::ScheduleID::id(), art::ModuleDescription::moduleLabel(), art::ModuleDescription::moduleName(), otherInfoTable_, and procInfo_.

Referenced by MemoryTracker().

301 {
302  // MT-TODO: Placeholder until we're multi-threaded
303  auto const sid = ScheduleID::first().id();
304  auto const data = procInfo_.getCurrentData(sid);
305  otherInfoTable_.insert(step,
306  md.moduleLabel(),
307  md.moduleName(),
308  LinuxProcData::getValueInMB<vsize_t>(data),
309  LinuxProcData::getValueInMB<rss_t>(data));
310 }
constexpr id_type id() const
Definition: ScheduleID.h:70
static ScheduleID first()
Definition: ScheduleID.h:82
void art::MemoryTracker::recordPeakUsages_ ( )
private

Definition at line 416 of file MemoryTrackerLinux_service.cc.

References peakUsageTable_, and procInfo_.

Referenced by postEndJob().

417 {
418  peakUsageTable_.insert(
419  "VmPeak", procInfo_.getVmPeak(), "Peak virtual memory (MB)");
420  peakUsageTable_.insert(
421  "VmHWM", procInfo_.getVmHWM(), "Peak resident set size (MB)");
422 }
void art::MemoryTracker::summary_ ( )
private

Definition at line 440 of file MemoryTrackerLinux_service.cc.

References db_, DECLARE_ART_SERVICE, DEFINE_ART_SERVICE, fileName_, art::left(), art::LEGACY, and peakUsageTable_.

Referenced by postEndJob().

441 {
442  using namespace cet::sqlite;
443  using namespace std;
444  query_result<double> rVMax;
445  query_result<double> rRMax;
446  rVMax
447  << select("Value").from(db_, peakUsageTable_.name()).where("Name='VmPeak'");
448  rRMax
449  << select("Value").from(db_, peakUsageTable_.name()).where("Name='VmHWM'");
450 
451  mf::LogAbsolute log{"MemoryTracker"};
452  HorizontalRule const rule{100};
453  log << '\n' << rule('=') << '\n';
454  log << std::left << "MemoryTracker summary (base-10 MB units used)\n\n";
455  log << " Peak virtual memory usage (VmPeak) : " << unique_value(rVMax)
456  << " MB\n"
457  << " Peak resident set size usage (VmHWM): " << unique_value(rRMax)
458  << " MB\n";
459  if (!(fileName_.empty() || fileName_ == ":memory:")) {
460  log << " Details saved in: '" << fileName_ << "'\n";
461  }
462  log << rule('=');
463 }
STL namespace.
constexpr auto const & left(const_AssnsIter< L, R, D, Dir > const &a, const_AssnsIter< L, R, D, Dir > const &b)
Definition: AssnsIter.h:104
cet::sqlite::Connection db_

Member Data Documentation

std::vector<PerScheduleData> art::MemoryTracker::data_
private
cet::sqlite::Connection art::MemoryTracker::db_
private

Definition at line 90 of file MemoryTrackerLinux_service.cc.

Referenced by MemoryTracker(), and summary_().

name_array<6u> art::MemoryTracker::eventColumns_
private
Initial value:
{
{"Step", "Run", "SubRun", "Event", "Vsize", "RSS"}}

Definition at line 106 of file MemoryTrackerLinux_service.cc.

Referenced by MemoryTracker().

name_array<11u> art::MemoryTracker::eventHeapColumns_
private
Initial value:
{{"Step",
"Run",
"SubRun",
"Event",
"arena",
"ordblks",
"keepcost",
"hblkhd",
"hblks",
"uordblks",
"fordblks"}}

Definition at line 117 of file MemoryTrackerLinux_service.cc.

Referenced by MemoryTracker().

std::unique_ptr<memEventHeap_t> art::MemoryTracker::eventHeapTable_
private

Definition at line 187 of file MemoryTrackerLinux_service.cc.

Referenced by flushTables_(), MemoryTracker(), and recordEventData().

memEvent_t art::MemoryTracker::eventTable_
private

Definition at line 185 of file MemoryTrackerLinux_service.cc.

Referenced by flushTables_(), MemoryTracker(), and recordEventData().

std::string art::MemoryTracker::fileName_
private

Definition at line 87 of file MemoryTrackerLinux_service.cc.

Referenced by MemoryTracker(), and summary_().

bool art::MemoryTracker::includeMallocInfo_
private

Definition at line 92 of file MemoryTrackerLinux_service.cc.

Referenced by MemoryTracker(), recordEventData(), and recordModuleData().

name_array<9u> art::MemoryTracker::moduleColumns_
private
Initial value:
{{"Step",
"Run",
"SubRun",
"Event",
"Path",
"ModuleLabel",
"ModuleType",
"Vsize",
"RSS"}}

Definition at line 108 of file MemoryTrackerLinux_service.cc.

Referenced by MemoryTracker().

name_array<14u> art::MemoryTracker::moduleHeapColumns_
private
Initial value:
{{"Step",
"Run",
"SubRun",
"Event",
"Path",
"ModuleLabel",
"ModuleType",
"arena",
"ordblks",
"keepcost",
"hblkhd",
"hblks",
"uordblks",
"fordblks"}}

Definition at line 128 of file MemoryTrackerLinux_service.cc.

Referenced by MemoryTracker().

std::unique_ptr<memModuleHeap_t> art::MemoryTracker::moduleHeapTable_
private

Definition at line 188 of file MemoryTrackerLinux_service.cc.

Referenced by flushTables_(), MemoryTracker(), and recordModuleData().

memModule_t art::MemoryTracker::moduleTable_
private

Definition at line 186 of file MemoryTrackerLinux_service.cc.

Referenced by flushTables_(), MemoryTracker(), and recordModuleData().

name_array<5u> art::MemoryTracker::otherInfoColumns_
private
Initial value:
{
{"Step", "ModuleLabel", "ModuleType", "Vsize", "RSS"}}

Definition at line 104 of file MemoryTrackerLinux_service.cc.

Referenced by MemoryTracker().

otherInfo_t art::MemoryTracker::otherInfoTable_
private

Definition at line 184 of file MemoryTrackerLinux_service.cc.

Referenced by flushTables_(), MemoryTracker(), and recordOtherData().

bool art::MemoryTracker::overwriteContents_
private

Definition at line 91 of file MemoryTrackerLinux_service.cc.

Referenced by MemoryTracker().

name_array<3u> art::MemoryTracker::peakUsageColumns_ {{"Name", "Value", "Description"}}
private

Definition at line 103 of file MemoryTrackerLinux_service.cc.

Referenced by MemoryTracker().

peakUsage_t art::MemoryTracker::peakUsageTable_
private
LinuxProcMgr art::MemoryTracker::procInfo_
private

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