162 vsize =
t->current_->vsize;
164 rss =
t->current_->rss;
169 pss =
t->currentSmaps_.pss_;
240 void set(
double deltaV,
bool early);
276 std::ostringstream
t;
282 std::ostringstream
t;
311 ret.private_ +=
static_cast<double>(
value) / 1024.;
315 ret.pss_ +=
static_cast<double>(
value) / 1024.;
324 return (current - past) / (double)
count;
332 pg_size_(sysconf(_SC_PAGESIZE))
334 num_to_skip_(iPS.getUntrackedParameter<
int>(
"ignoreTotal")),
335 showMallocInfo_(iPS.getUntrackedParameter<
bool>(
"showMallocInfo")),
336 oncePerEventMode_(iPS.getUntrackedParameter<
bool>(
"oncePerEventMode")),
337 jobReportOutputOnly_(iPS.getUntrackedParameter<
bool>(
"jobReportOutputOnly")),
338 monitorPssAndPrivate_(iPS.getUntrackedParameter<
bool>(
"monitorPssAndPrivate")),
341 smapsLineBuffer_(nullptr),
342 smapsLineBufferLen_(0),
345 moduleSummaryRequested_(iPS.getUntrackedParameter<
bool>(
"moduleMemorySummary")),
346 measurementUnderway_(
false) {
349 std::ostringstream ost;
398 desc.addUntracked<
int>(
"ignoreTotal", 1);
399 desc.addUntracked<
bool>(
"showMallocInfo",
false);
400 desc.addUntracked<
bool>(
"oncePerEventMode",
false);
401 desc.addUntracked<
bool>(
"jobReportOutputOnly",
false);
402 desc.addUntracked<
bool>(
"monitorPssAndPrivate",
false);
403 desc.addUntracked<
bool>(
"moduleMemorySummary",
false);
404 desc.addUntracked<
bool>(
"dump",
false);
405 descriptions.
add(
"SimpleMemoryCheck",
desc);
411 std::ostringstream smapsNameOst;
412 smapsNameOst <<
"/proc/" << getpid() <<
"/smaps";
413 if ((
smapsFile_ = fopen(smapsNameOst.str().c_str(),
"r")) ==
nullptr) {
426 bool expected =
false;
428 std::shared_ptr<void> guard(
429 nullptr, [
this](
void const*) {
measurementUnderway_.store(
false, std::memory_order_release); });
435 bool expected =
false;
437 std::shared_ptr<void> guard(
438 nullptr, [
this](
void const*) {
measurementUnderway_.store(
false, std::memory_order_release); });
444 bool expected =
false;
446 std::shared_ptr<void> guard(
447 nullptr, [
this](
void const*) {
measurementUnderway_.store(
false, std::memory_order_release); });
453 bool expected =
false;
455 std::shared_ptr<void> guard(
456 nullptr, [
this](
void const*) {
measurementUnderway_.store(
false, std::memory_order_release); });
462 bool expected =
false;
464 std::shared_ptr<void> guard(
465 nullptr, [
this](
void const*) {
measurementUnderway_.store(
false, std::memory_order_release); });
473 <<
"MemoryReport> Peak virtual size " <<
eventT1_.
vsize <<
" Mbytes" 475 <<
" Key events increasing vsize: \n" 489 mmr <<
"ModuleMemoryReport> Each line has module label and: \n";
490 mmr <<
" (after early ignored events) \n";
491 mmr <<
" count of times module executed; average increase in vsize \n";
492 mmr <<
" maximum increase in vsize; event on which maximum occurred \n";
493 mmr <<
" (during early ignored events) \n";
494 mmr <<
" total and maximum vsize increases \n \n";
495 for (SignificantModulesMap::iterator im =
modules_.begin(); im !=
modules_.end(); ++im) {
497 if (
m.totalDeltaVsize == 0 &&
m.totalEarlyVsize == 0)
499 mmr << im->first <<
": ";
500 mmr <<
"n = " <<
m.postEarlyCount;
501 if (
m.postEarlyCount > 0) {
502 mmr <<
" avg = " <<
m.totalDeltaVsize /
m.postEarlyCount;
504 mmr <<
" max = " <<
m.maxDeltaVsize <<
" " <<
m.eventMaxDeltaV;
505 if (
m.totalEarlyVsize > 0) {
506 mmr <<
" early total: " <<
m.totalEarlyVsize;
507 mmr <<
" max: " <<
m.maxEarlyVsize;
515 #define SIMPLE_MEMORY_CHECK_ORIGINAL_XML_OUTPUT 516 #ifdef SIMPLE_MEMORY_CHECK_ORIGINAL_XML_OUTPUT 518 std::map<std::string, std::string> reportData;
551 #if (__GLIBC__ > 2) || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 33) 552 struct mallinfo2 minfo = mallinfo2();
554 struct mallinfo minfo = mallinfo();
556 reportData.insert(std::make_pair(
"HEAP_ARENA_SIZE_BYTES",
std::to_string(minfo.arena)));
557 reportData.insert(std::make_pair(
"HEAP_ARENA_N_UNUSED_CHUNKS",
std::to_string(minfo.ordblks)));
558 reportData.insert(std::make_pair(
"HEAP_TOP_FREE_BYTES",
std::to_string(minfo.keepcost)));
559 reportData.insert(std::make_pair(
"HEAP_MAPPED_SIZE_BYTES",
std::to_string(minfo.hblkhd)));
560 reportData.insert(std::make_pair(
"HEAP_MAPPED_N_CHUNKS",
std::to_string(minfo.hblks)));
561 reportData.insert(std::make_pair(
"HEAP_USED_BYTES",
std::to_string(minfo.uordblks)));
562 reportData.insert(std::make_pair(
"HEAP_UNUSED_BYTES",
std::to_string(minfo.fordblks)));
566 reportData.insert(std::make_pair(
"AverageGrowthRateVsize",
574 for (SignificantModulesMap::iterator im =
modules_.begin(); im !=
modules_.end(); ++im) {
576 if (
m.totalDeltaVsize == 0 &&
m.totalEarlyVsize == 0)
579 reportData.insert(std::make_pair(
label +
"PostEarlyCount",
i2str(
m.postEarlyCount)));
580 if (
m.postEarlyCount > 0) {
581 reportData.insert(std::make_pair(
label +
"AverageDeltaVsize",
d2str(
m.totalDeltaVsize /
m.postEarlyCount)));
583 reportData.insert(std::make_pair(
label +
"MaxDeltaVsize",
d2str(
m.maxDeltaVsize)));
584 if (
m.totalEarlyVsize > 0) {
585 reportData.insert(std::make_pair(
label +
"TotalEarlyVsize",
d2str(
m.totalEarlyVsize)));
586 reportData.insert(std::make_pair(
label +
"MaxEarlyDeltaVsize",
d2str(
m.maxEarlyVsize)));
591 std::map<std::string, std::string> reportMemoryProperties;
593 if (FILE* fmeminfo = fopen(
"/proc/meminfo",
"r")) {
597 while (fgets(
buf,
sizeof(
buf), fmeminfo)) {
599 char*
token =
nullptr;
600 token = strtok_r(
buf, space, &saveptr);
601 if (
token !=
nullptr) {
602 value = atol(strtok_r(
nullptr, space, &saveptr));
612 reportSvc->reportPerformanceSummary(
"ApplicationMemory", reportData);
613 reportSvc->reportPerformanceSummary(
"SystemMemory", reportMemoryProperties);
616 #ifdef SIMPLE_MEMORY_CHECK_DIFFERENT_XML_OUTPUT 617 std::vector<std::string> reportData;
649 #if (__GLIBC__ > 2) || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 33) 650 struct mallinfo2 minfo = mallinfo2();
652 struct mallinfo minfo = mallinfo();
654 reportData.push_back(
mallOutput(
"HEAP_ARENA_SIZE_BYTES", minfo.arena));
655 reportData.push_back(
mallOutput(
"HEAP_ARENA_N_UNUSED_CHUNKS", minfo.ordblks));
656 reportData.push_back(
mallOutput(
"HEAP_TOP_FREE_BYTES", minfo.keepcost));
657 reportData.push_back(
mallOutput(
"HEAP_MAPPED_SIZE_BYTES", minfo.hblkhd));
658 reportData.push_back(
mallOutput(
"HEAP_MAPPED_N_CHUNKS", minfo.hblks));
659 reportData.push_back(
mallOutput(
"HEAP_USED_BYTES", minfo.uordblks));
660 reportData.push_back(
mallOutput(
"HEAP_UNUSED_BYTES", minfo.fordblks));
663 reportData.insert(std::make_pair(
"AverageGrowthRateVsize",
670 reportSvc->reportMemoryInfo(reportData);
677 bool expected =
false;
679 std::shared_ptr<void> guard(
680 nullptr, [
this](
void const*) {
measurementUnderway_.store(
false, std::memory_order_release); });
695 bool expectedMeasurementUnderway =
false;
696 if (
measurementUnderway_.compare_exchange_strong(expectedMeasurementUnderway,
true, std::memory_order_acq_rel)) {
697 std::shared_ptr<void> guard(
698 nullptr, [
this](
void const*) {
measurementUnderway_.store(
false, std::memory_order_release); });
699 bool expectedModuleMeasurementUnderway =
false;
713 bool expected =
false;
715 std::shared_ptr<void> guard(
716 nullptr, [
this](
void const*) {
measurementUnderway_.store(
false, std::memory_order_release); });
728 std::shared_ptr<void> guardModuleMeasurementUnderway(
730 bool expected =
false;
732 std::shared_ptr<void> guardMeasurementUnderway(
733 nullptr, [
this](
void const*) {
measurementUnderway_.store(
false, std::memory_order_release); });
841 LogWarning(
"MemoryCheck") <<
"MemoryCheck: " <<
type <<
" " << mdname <<
":" << mdlabel <<
" VSIZE " 846 #if (__GLIBC__ > 2) || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 33) 847 struct mallinfo2 minfo = mallinfo2();
849 struct mallinfo minfo = mallinfo();
852 LogWarning(
"MemoryCheck") <<
"MemoryCheck: " <<
type <<
" " << mdname <<
":" << mdlabel <<
" VSIZE " 856 <<
" HEAP-ARENA [ SIZE-BYTES " << minfo.arena <<
" N-UNUSED-CHUNKS " 857 << minfo.ordblks <<
" TOP-FREE-BYTES " << minfo.keepcost <<
" ]" 858 <<
" HEAP-MAPPED [ SIZE-BYTES " << minfo.hblkhd <<
" N-CHUNKS " << minfo.hblks
860 <<
" HEAP-USED-BYTES " << minfo.uordblks <<
" HEAP-UNUSED-BYTES " 877 #ifdef SIMPLE_MEMORY_CHECK_ORIGINAL_XML_OUTPUT 880 std::map<std::string, std::string>&
m)
const {
882 std::ostringstream os;
883 os <<
title <<
"-a-COUNT";
884 m.insert(std::make_pair(os.str(),
i2str(
e.count)));
887 std::ostringstream os;
888 os <<
title <<
"-b-RUN";
889 m.insert(std::make_pair(os.str(),
d2str(static_cast<double>(
e.event.run()))));
892 std::ostringstream os;
893 os <<
title <<
"-c-EVENT";
894 m.insert(std::make_pair(os.str(),
d2str(static_cast<double>(
e.event.event()))));
897 std::ostringstream os;
898 os <<
title <<
"-d-VSIZE";
899 m.insert(std::make_pair(os.str(),
d2str(
e.vsize)));
902 std::ostringstream os;
903 os <<
title <<
"-e-DELTV";
904 m.insert(std::make_pair(os.str(),
d2str(
e.deltaVsize)));
907 std::ostringstream os;
908 os <<
title <<
"-f-RSS";
909 m.insert(std::make_pair(os.str(),
d2str(
e.rss)));
913 std::ostringstream os;
914 os <<
title <<
"-g-PRIVATE";
915 m.insert(std::make_pair(os.str(),
d2str(
e.privateSize)));
918 std::ostringstream os;
919 os <<
title <<
"-h-PSS";
920 m.insert(std::make_pair(os.str(),
d2str(
e.pss)));
926 #ifdef SIMPLE_MEMORY_CHECK_DIFFERENT_XML_OUTPUT 928 std::ostringstream os;
929 os <<
" <" <<
title <<
">\n";
930 os <<
" " <<
e.count <<
": " <<
e.event;
931 os <<
" vsize " <<
e.vsize -
e.deltaVsize <<
" + " <<
e.deltaVsize <<
" = " <<
e.vsize;
932 os <<
" rss: " <<
e.rss <<
"\n";
933 os <<
" </" <<
title <<
">\n";
938 std::ostringstream os;
939 os <<
" <" <<
title <<
">\n";
940 os <<
" " <<
n <<
"\n";
941 os <<
" </" <<
title <<
">\n";
950 m.totalEarlyVsize += dv;
951 if (dv >
m.maxEarlyVsize)
952 m.maxEarlyVsize = dv;
955 m.totalDeltaVsize += dv;
956 if (dv >
m.maxDeltaVsize) {
957 m.maxDeltaVsize = dv;
958 m.eventMaxDeltaV = currentEventID;
965 <<
" rss = " << se.
rss <<
" delta = " << se.
deltaRss;
989 #if defined(__linux__)
void watchPostModuleConstruction(PostModuleConstruction::slot_type const &iSlot)
static std::string i2str(int i)
ModuleDescription const * moduleDescription() const
SignificantEvent eventDeltaRssT1_
void preSourceConstruction(const ModuleDescription &)
std::pair< ALIstring, ALIstring > pss
friend std::ostream & operator<<(std::ostream &os, SimpleMemoryCheck::SignificantEvent const &se)
size_t smapsLineBufferLen_
void watchPostEndJob(PostEndJob::slot_type const &iSlot)
edm::propagate_const< ProcInfo * > current_
std::atomic< bool > measurementUnderway_
SignificantEvent eventT1_
void watchPreModuleEvent(PreModuleEvent::slot_type const &iSlot)
void updateEventStats(edm::EventID const &e)
ProcInfoFetcher piFetcher_
ret
prodAgent to be discontinued
void watchPostEvent(PostEvent::slot_type const &iSlot)
std::atomic< bool > moduleMeasurementUnderway_
std::string eventStatOutput(std::string title, SignificantEvent const &e) const
void watchPreSourceConstruction(PreSourceConstruction::slot_type const &iSlot)
void watchPostSourceConstruction(PostSourceConstruction::slot_type const &iSlot)
SignificantEvent eventRssT2_
SignificantEvent eventL1_
void watchPostModuleEvent(PostModuleEvent::slot_type const &iSlot)
std::string to_string(const V &value)
void watchPostSourceEvent(PostSourceEvent::slot_type const &iSlot)
std::string const & moduleName() const
SignificantEvent eventT3_
constexpr std::shared_ptr< T > & get_underlying_safe(propagate_const< std::shared_ptr< T >> &iP)
edm::EventID eventMaxDeltaV
std::atomic< unsigned int > moduleStreamID_
char *& smapsLineBuffer()
SignificantEvent eventRssT3_
edm::propagate_const< FILE * > smapsFile_
std::map< std::string, SignificantModule > SignificantModulesMap
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
StreamID const & streamID() const
bool operator==(const smapsInfo &p) const
friend struct SignificantEvent
std::ostream & operator<<(std::ostream &os, SimpleMemoryCheck::SignificantEvent const &se)
void set(double deltaV, double deltaR, edm::EventID const &e, SimpleMemoryCheck *t)
edm::propagate_const< ProcInfo * > previous_
bool monitorPssAndPrivate_
SignificantEvent eventR1_
SignificantEvent eventDeltaRssT3_
bool moduleSummaryRequested_
smapsInfo(double private_sz, double pss_sz)
bool jobReportOutputOnly_
#define DEFINE_FWK_SERVICE(type)
void updateAndPrint(const std::string &type, const std::string &mdlabel, const std::string &mdname)
void andPrint(const std::string &type, const std::string &mdlabel, const std::string &mdname) const
SignificantEvent eventR2_
void preModule(StreamContext const &, ModuleCallingContext const &)
char const * smapsLineBuffer() const
static std::string d2str(double d)
void add(std::string const &label, ParameterSetDescription const &psetDescription)
void updateModuleMemoryStats(SignificantModule &m, double dv, edm::EventID const &)
std::atomic< int > count_
SignificantEvent eventL2_
SignificantEvent eventDeltaRssT2_
void postEvent(StreamContext const &)
edm::propagate_const< char * > smapsLineBuffer_
EventID const & eventID() const
void watchPostModuleBeginJob(PostModuleBeginJob::slot_type const &iSlot)
void postSourceConstruction(const ModuleDescription &)
Log< level::System, true > LogAbsolute
SignificantEvent eventT2_
void postSourceEvent(StreamID)
void postModuleBeginJob(const ModuleDescription &)
unsigned int value() const
std::string mallOutput(std::string title, size_t const &n) const
double averageGrowthRate(double current, double past, int count)
Log< level::Warning, false > LogWarning
SimpleMemoryCheck(const ParameterSet &, ActivityRegistry &)
bool operator>(const smapsInfo &p) const
SignificantModulesMap modules_
SignificantEvent eventRssT1_
void postModule(StreamContext const &, ModuleCallingContext const &)
std::string const & moduleLabel() const
void postModuleConstruction(const ModuleDescription &)
bool monitorPssAndPrivate
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
void watchPostBeginJob(PostBeginJob::slot_type const &iSlot)
convenience function for attaching to signal
std::atomic< unsigned int > moduleID_