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

Classes

struct  Config
 

Public Types

using Parameters = ServiceTable< Config >
 

Public Member Functions

 MemoryTracker (fhicl::ParameterSet const &)
 
 MemoryTracker (Parameters const &, ActivityRegistry &)
 

Static Public Attributes

static constexpr bool service_handle_allowed {false}
 

Private Types

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

Private Member Functions

void prePathProcessing (PathContext const &pc)
 
void recordOtherData (ModuleDescription const &md, string const &step)
 
void recordOtherData (ModuleContext const &mc, string const &step)
 
void recordEventData (Event const &e, string const &step)
 
void recordModuleData (ModuleContext const &mc, string const &step)
 
void postEndJob ()
 
bool checkMallocConfig_ (string const &, bool)
 
void recordPeakUsages_ ()
 
void flushTables_ ()
 
bool using_file_database_ () const
 
void summary_ ()
 
bool anyTableFull_ () const
 

Private Attributes

LinuxProcMgr procInfo_ {}
 
string const fileName_
 
unique_ptr< cet::sqlite::Connection > const db_
 
bool const overwriteContents_
 
bool const includeMallocInfo_
 
EventID currentEventID_ {EventID::invalidEvent()}
 
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_
 
unique_ptr< memEventHeap_teventHeapTable_
 
unique_ptr< memModuleHeap_tmoduleHeapTable_
 

Detailed Description

Definition at line 17 of file MemoryTrackerDarwin_service.cc.

Member Typedef Documentation

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

Definition at line 72 of file MemoryTrackerLinux_service.cc.

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

Definition at line 92 of file MemoryTrackerLinux_service.cc.

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

Definition at line 81 of file MemoryTrackerLinux_service.cc.

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

Definition at line 106 of file MemoryTrackerLinux_service.cc.

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

Definition at line 67 of file MemoryTrackerLinux_service.cc.

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

Definition at line 70 of file MemoryTrackerLinux_service.cc.

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

Definition at line 68 of file MemoryTrackerLinux_service.cc.

Constructor & Destructor Documentation

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

Definition at line 21 of file MemoryTrackerDarwin_service.cc.

References DECLARE_ART_SERVICE, DEFINE_ART_SERVICE, and art::SHARED.

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

Member Function Documentation

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

Definition at line 457 of file MemoryTrackerLinux_service.cc.

References DECLARE_ART_SERVICE, DEFINE_ART_SERVICE, eventHeapTable_, eventTable_, moduleHeapTable_, moduleTable_, otherInfoTable_, peakUsageTable_, and art::SHARED.

Referenced by summary_().

458  {
459  return peakUsageTable_.full() || otherInfoTable_.full() ||
460  eventTable_.full() || moduleTable_.full() ||
461  (eventHeapTable_ && eventHeapTable_->full()) ||
462  (moduleHeapTable_ && moduleHeapTable_->full());
463  }
unique_ptr< memEventHeap_t > eventHeapTable_
unique_ptr< memModuleHeap_t > moduleHeapTable_
bool art::MemoryTracker::checkMallocConfig_ ( string const &  dbfilename,
bool  include 
)
private

Definition at line 373 of file MemoryTrackerLinux_service.cc.

References art::errors::Configuration.

375  {
376  if (include && dbfilename.empty()) {
377  string const errmsg =
378  "\n'includeMallocInfo : true' is valid only if a nonempty db filename is specified:\n\n"s +
379  " MemoryTracker: {\n"
380  " includeMallocInfo: true\n"
381  " dbOutput: {\n"
382  " filename: \"your_filename.db\"\n"
383  " }\n"
384  " }\n\n";
385  throw Exception{errors::Configuration} << errmsg;
386  }
387  return include;
388  }
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
void art::MemoryTracker::flushTables_ ( )
private

Definition at line 400 of file MemoryTrackerLinux_service.cc.

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

Referenced by postEndJob().

401  {
402  otherInfoTable_.flush();
403  eventTable_.flush();
404  moduleTable_.flush();
405  peakUsageTable_.flush();
406  if (eventHeapTable_) {
407  eventHeapTable_->flush();
408  }
409  if (moduleHeapTable_) {
410  moduleHeapTable_->flush();
411  }
412  }
unique_ptr< memEventHeap_t > eventHeapTable_
unique_ptr< memModuleHeap_t > moduleHeapTable_
void art::MemoryTracker::postEndJob ( )
private
void art::MemoryTracker::prePathProcessing ( PathContext const &  pc)
private
void art::MemoryTracker::recordEventData ( Event const &  e,
string const &  step 
)
private

Definition at line 306 of file MemoryTrackerLinux_service.cc.

References currentEventID_, art::EventID::event(), eventHeapTable_, eventTable_, art::Event::id(), includeMallocInfo_, procInfo_, art::EventID::run(), and art::EventID::subRun().

307  {
308  currentEventID_ = e.id();
309  auto const currentMemory = procInfo_.getCurrentData();
310  eventTable_.insert(step,
314  LinuxProcData::getValueInMB<vsize_t>(currentMemory),
315  LinuxProcData::getValueInMB<rss_t>(currentMemory));
316  if (includeMallocInfo_) {
317  auto minfo = LinuxMallInfo{}.get();
318  eventHeapTable_->insert(step,
322  minfo.arena,
323  minfo.ordblks,
324  minfo.keepcost,
325  minfo.hblkhd,
326  minfo.hblks,
327  minfo.uordblks,
328  minfo.fordblks);
329  }
330  }
unique_ptr< memEventHeap_t > eventHeapTable_
RunNumber_t run() const
Definition: EventID.h:98
EventNumber_t event() const
Definition: EventID.h:116
Float_t e
Definition: plot.C:35
SubRunNumber_t subRun() const
Definition: EventID.h:110
void art::MemoryTracker::recordModuleData ( ModuleContext const &  mc,
string const &  step 
)
private

Definition at line 333 of file MemoryTrackerLinux_service.cc.

References currentEventID_, art::EventID::event(), includeMallocInfo_, moduleHeapTable_, art::ModuleContext::moduleLabel(), art::ModuleContext::moduleName(), moduleTable_, art::ModuleContext::pathName(), procInfo_, art::EventID::run(), and art::EventID::subRun().

334  {
335  auto const currentMemory = procInfo_.getCurrentData();
336  moduleTable_.insert(step,
340  mc.pathName(),
341  mc.moduleLabel(),
342  mc.moduleName(),
343  LinuxProcData::getValueInMB<vsize_t>(currentMemory),
344  LinuxProcData::getValueInMB<rss_t>(currentMemory));
345  if (includeMallocInfo_) {
346  auto minfo = LinuxMallInfo{}.get();
347  moduleHeapTable_->insert(step,
351  mc.pathName(),
352  mc.moduleLabel(),
353  mc.moduleName(),
354  minfo.arena,
355  minfo.ordblks,
356  minfo.keepcost,
357  minfo.hblkhd,
358  minfo.hblks,
359  minfo.uordblks,
360  minfo.fordblks);
361  }
362  }
RunNumber_t run() const
Definition: EventID.h:98
EventNumber_t event() const
Definition: EventID.h:116
unique_ptr< memModuleHeap_t > moduleHeapTable_
SubRunNumber_t subRun() const
Definition: EventID.h:110
void art::MemoryTracker::recordOtherData ( ModuleDescription const &  md,
string const &  step 
)
private

Definition at line 294 of file MemoryTrackerLinux_service.cc.

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

Referenced by recordOtherData().

296  {
297  auto const data = procInfo_.getCurrentData();
298  otherInfoTable_.insert(step,
299  md.moduleLabel(),
300  md.moduleName(),
301  LinuxProcData::getValueInMB<vsize_t>(data),
302  LinuxProcData::getValueInMB<rss_t>(data));
303  }
void art::MemoryTracker::recordOtherData ( ModuleContext const &  mc,
string const &  step 
)
private

Definition at line 288 of file MemoryTrackerLinux_service.cc.

References art::ModuleContext::moduleDescription(), and recordOtherData().

289  {
290  recordOtherData(mc.moduleDescription(), step);
291  }
void recordOtherData(ModuleDescription const &md, string const &step)
void art::MemoryTracker::recordPeakUsages_ ( )
private

Definition at line 391 of file MemoryTrackerLinux_service.cc.

References peakUsageTable_, and procInfo_.

Referenced by postEndJob().

392  {
393  peakUsageTable_.insert(
394  "VmPeak", procInfo_.getVmPeak(), "Peak virtual memory (MB)");
395  peakUsageTable_.insert(
396  "VmHWM", procInfo_.getVmHWM(), "Peak resident set size (MB)");
397  }
void art::MemoryTracker::summary_ ( )
private

Definition at line 421 of file MemoryTrackerLinux_service.cc.

References anyTableFull_(), db_, fileName_, art::left(), peakUsageTable_, and using_file_database_().

Referenced by postEndJob().

422  {
423  using namespace cet::sqlite;
424  using namespace std;
425  query_result<double> rVMax;
426  query_result<double> rRMax;
427  rVMax << select("Value")
428  .from(*db_, peakUsageTable_.name())
429  .where("Name='VmPeak'");
430  rRMax << select("Value")
431  .from(*db_, peakUsageTable_.name())
432  .where("Name='VmHWM'");
433  mf::LogAbsolute log{"MemoryTracker"};
434  HorizontalRule const rule{100};
435  log << '\n' << rule('=') << '\n';
436 
437  if (anyTableFull_() && using_file_database_()) {
438  log << "The SQLite database connected to the MemoryTracker exceeded the "
439  "available resources.\n";
440  log << "No memory usage summary is available.\n";
441  log << "The database at " << fileName_
442  << " will contain an incomplete record of this job's memory usage.\n";
443  } else {
444  log << std::left << "MemoryTracker summary (base-10 MB units used)\n\n";
445  log << " Peak virtual memory usage (VmPeak) : " << unique_value(rVMax)
446  << " MB\n"
447  << " Peak resident set size usage (VmHWM): " << unique_value(rRMax)
448  << " MB\n";
449  if (using_file_database_()) {
450  log << " Details saved in: '" << fileName_ << "'\n";
451  }
452  }
453  log << rule('=');
454  }
STL namespace.
unique_ptr< cet::sqlite::Connection > const db_
constexpr auto const & left(const_AssnsIter< L, R, D, Dir > const &a, const_AssnsIter< L, R, D, Dir > const &b)
Definition: AssnsIter.h:94
bool art::MemoryTracker::using_file_database_ ( ) const
private

Definition at line 415 of file MemoryTrackerLinux_service.cc.

References fileName_.

Referenced by summary_().

416  {
417  return !fileName_.empty() && fileName_ != ":memory:";
418  }

Member Data Documentation

EventID art::MemoryTracker::currentEventID_ {EventID::invalidEvent()}
private

Definition at line 152 of file MemoryTrackerLinux_service.cc.

Referenced by recordEventData(), and recordModuleData().

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

Definition at line 145 of file MemoryTrackerLinux_service.cc.

Referenced by summary_().

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

Definition at line 156 of file MemoryTrackerLinux_service.cc.

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

Definition at line 167 of file MemoryTrackerLinux_service.cc.

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

Definition at line 196 of file MemoryTrackerLinux_service.cc.

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

memEvent_t art::MemoryTracker::eventTable_
private

Definition at line 194 of file MemoryTrackerLinux_service.cc.

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

string const art::MemoryTracker::fileName_
private

Definition at line 144 of file MemoryTrackerLinux_service.cc.

Referenced by summary_(), and using_file_database_().

bool const art::MemoryTracker::includeMallocInfo_
private

Definition at line 147 of file MemoryTrackerLinux_service.cc.

Referenced by recordEventData(), and recordModuleData().

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

Definition at line 158 of file MemoryTrackerLinux_service.cc.

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 178 of file MemoryTrackerLinux_service.cc.

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

Definition at line 197 of file MemoryTrackerLinux_service.cc.

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

memModule_t art::MemoryTracker::moduleTable_
private

Definition at line 195 of file MemoryTrackerLinux_service.cc.

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

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

Definition at line 154 of file MemoryTrackerLinux_service.cc.

otherInfo_t art::MemoryTracker::otherInfoTable_
private

Definition at line 193 of file MemoryTrackerLinux_service.cc.

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

bool const art::MemoryTracker::overwriteContents_
private

Definition at line 146 of file MemoryTrackerLinux_service.cc.

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

Definition at line 153 of file MemoryTrackerLinux_service.cc.

peakUsage_t art::MemoryTracker::peakUsageTable_
private
LinuxProcMgr art::MemoryTracker::procInfo_ {}
private
static constexpr bool art::MemoryTracker::service_handle_allowed {false}
static

Definition at line 19 of file MemoryTrackerDarwin_service.cc.


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