240 void set(
double deltaV,
bool early);
276 std::ostringstream
t;
282 std::ostringstream
t;
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;
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) {
499 mmr << im->first <<
": ";
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 struct mallinfo minfo = mallinfo();
552 reportData.insert(std::make_pair(
"HEAP_ARENA_SIZE_BYTES",
i2str(minfo.arena)));
553 reportData.insert(std::make_pair(
"HEAP_ARENA_N_UNUSED_CHUNKS",
i2str(minfo.ordblks)));
554 reportData.insert(std::make_pair(
"HEAP_TOP_FREE_BYTES",
i2str(minfo.keepcost)));
555 reportData.insert(std::make_pair(
"HEAP_MAPPED_SIZE_BYTES",
i2str(minfo.hblkhd)));
556 reportData.insert(std::make_pair(
"HEAP_MAPPED_N_CHUNKS",
i2str(minfo.hblks)));
557 reportData.insert(std::make_pair(
"HEAP_USED_BYTES",
i2str(minfo.uordblks)));
558 reportData.insert(std::make_pair(
"HEAP_UNUSED_BYTES",
i2str(minfo.fordblks)));
562 reportData.insert(std::make_pair(
"AverageGrowthRateVsize",
570 for (SignificantModulesMap::iterator im =
modules_.begin(); im !=
modules_.end(); ++im) {
582 reportData.insert(std::make_pair(label +
"MaxEarlyDeltaVsize",
d2str(m.
maxEarlyVsize)));
587 std::map<std::string, std::string> reportMemoryProperties;
589 if (FILE* fmeminfo = fopen(
"/proc/meminfo",
"r")) {
593 while (fgets(buf,
sizeof(buf), fmeminfo)) {
595 char*
token =
nullptr;
596 token = strtok_r(buf, space, &saveptr);
597 if (token !=
nullptr) {
598 value = atol(strtok_r(
nullptr, space, &saveptr));
600 reportMemoryProperties.insert(std::make_pair(category.substr(0, strlen(token) - 1),
i2str(value)));
608 reportSvc->reportPerformanceSummary(
"ApplicationMemory", reportData);
609 reportSvc->reportPerformanceSummary(
"SystemMemory", reportMemoryProperties);
612 #ifdef SIMPLE_MEMORY_CHECK_DIFFERENT_XML_OUTPUT
613 std::vector<std::string> reportData;
645 struct mallinfo minfo = mallinfo();
646 reportData.push_back(
mallOutput(
"HEAP_ARENA_SIZE_BYTES", minfo.arena));
647 reportData.push_back(
mallOutput(
"HEAP_ARENA_N_UNUSED_CHUNKS", minfo.ordblks));
648 reportData.push_back(
mallOutput(
"HEAP_TOP_FREE_BYTES", minfo.keepcost));
649 reportData.push_back(
mallOutput(
"HEAP_MAPPED_SIZE_BYTES", minfo.hblkhd));
650 reportData.push_back(
mallOutput(
"HEAP_MAPPED_N_CHUNKS", minfo.hblks));
651 reportData.push_back(
mallOutput(
"HEAP_USED_BYTES", minfo.uordblks));
652 reportData.push_back(
mallOutput(
"HEAP_UNUSED_BYTES", minfo.fordblks));
655 reportData.insert(std::make_pair(
"AverageGrowthRateVsize",
662 reportSvc->reportMemoryInfo(reportData);
669 bool expected =
false;
671 std::shared_ptr<void> guard(
672 nullptr, [
this](
void const*) {
measurementUnderway_.store(
false, std::memory_order_release); });
687 bool expectedMeasurementUnderway =
false;
688 if (
measurementUnderway_.compare_exchange_strong(expectedMeasurementUnderway,
true, std::memory_order_acq_rel)) {
689 std::shared_ptr<void> guard(
690 nullptr, [
this](
void const*) {
measurementUnderway_.store(
false, std::memory_order_release); });
691 bool expectedModuleMeasurementUnderway =
false;
705 bool expected =
false;
707 std::shared_ptr<void> guard(
708 nullptr, [
this](
void const*) {
measurementUnderway_.store(
false, std::memory_order_release); });
720 std::shared_ptr<void> guardModuleMeasurementUnderway(
722 bool expected =
false;
724 std::shared_ptr<void> guardMeasurementUnderway(
725 nullptr, [
this](
void const*) {
measurementUnderway_.store(
false, std::memory_order_release); });
833 LogWarning(
"MemoryCheck") <<
"MemoryCheck: " << type <<
" " << mdname <<
":" << mdlabel <<
" VSIZE "
838 struct mallinfo minfo = mallinfo();
840 LogWarning(
"MemoryCheck") <<
"MemoryCheck: " << type <<
" " << mdname <<
":" << mdlabel <<
" VSIZE "
844 <<
" HEAP-ARENA [ SIZE-BYTES " << minfo.arena <<
" N-UNUSED-CHUNKS "
845 << minfo.ordblks <<
" TOP-FREE-BYTES " << minfo.keepcost <<
" ]"
846 <<
" HEAP-MAPPED [ SIZE-BYTES " << minfo.hblkhd <<
" N-CHUNKS " << minfo.hblks
848 <<
" HEAP-USED-BYTES " << minfo.uordblks <<
" HEAP-UNUSED-BYTES "
865 #ifdef SIMPLE_MEMORY_CHECK_ORIGINAL_XML_OUTPUT
868 std::map<std::string, std::string>&
m)
const {
870 std::ostringstream os;
871 os << title <<
"-a-COUNT";
872 m.insert(std::make_pair(os.str(),
i2str(e.
count)));
875 std::ostringstream os;
876 os << title <<
"-b-RUN";
877 m.insert(std::make_pair(os.str(),
d2str(static_cast<double>(e.
event.
run()))));
880 std::ostringstream os;
881 os << title <<
"-c-EVENT";
882 m.insert(std::make_pair(os.str(),
d2str(static_cast<double>(e.
event.
event()))));
885 std::ostringstream os;
886 os << title <<
"-d-VSIZE";
887 m.insert(std::make_pair(os.str(),
d2str(e.
vsize)));
890 std::ostringstream os;
891 os << title <<
"-e-DELTV";
895 std::ostringstream os;
896 os << title <<
"-f-RSS";
897 m.insert(std::make_pair(os.str(),
d2str(e.
rss)));
901 std::ostringstream os;
902 os << title <<
"-g-PRIVATE";
906 std::ostringstream os;
907 os << title <<
"-h-PSS";
908 m.insert(std::make_pair(os.str(),
d2str(e.
pss)));
914 #ifdef SIMPLE_MEMORY_CHECK_DIFFERENT_XML_OUTPUT
916 std::ostringstream os;
917 os <<
" <" << title <<
">\n";
918 os <<
" " << e.count <<
": " << e.event;
919 os <<
" vsize " << e.vsize - e.deltaVsize <<
" + " << e.deltaVsize <<
" = " << e.vsize;
920 os <<
" rss: " << e.rss <<
"\n";
921 os <<
" </" << title <<
">\n";
926 std::ostringstream os;
927 os <<
" <" << title <<
">\n";
928 os <<
" " << n <<
"\n";
929 os <<
" </" << title <<
">\n";
953 <<
" rss = " << se.
rss <<
" delta = " << se.
deltaRss;
977 #if defined(__linux__)
void watchPostModuleConstruction(PostModuleConstruction::slot_type const &iSlot)
EventNumber_t event() const
static std::string i2str(int i)
std::string eventStatOutput(std::string title, SignificantEvent const &e) const
tuple ret
prodAgent to be discontinued
SignificantEvent eventDeltaRssT1_
void preSourceConstruction(const ModuleDescription &)
std::pair< ALIstring, ALIstring > pss
friend std::ostream & operator<<(std::ostream &os, SimpleMemoryCheck::SignificantEvent const &se)
ParameterDescriptionBase * addUntracked(U const &iLabel, T const &value)
size_t smapsLineBufferLen_
void watchPostEndJob(PostEndJob::slot_type const &iSlot)
edm::propagate_const< ProcInfo * > current_
static const char category[]
std::atomic< bool > measurementUnderway_
SignificantEvent eventT1_
void watchPreModuleEvent(PreModuleEvent::slot_type const &iSlot)
void updateEventStats(edm::EventID const &e)
ProcInfoFetcher piFetcher_
void watchPostEvent(PostEvent::slot_type const &iSlot)
std::atomic< bool > moduleMeasurementUnderway_
void watchPreSourceConstruction(PreSourceConstruction::slot_type const &iSlot)
void watchPostSourceConstruction(PostSourceConstruction::slot_type const &iSlot)
SignificantEvent eventRssT2_
SignificantEvent eventL1_
std::string const & moduleName() const
void set(double deltaV, bool early)
void watchPostModuleEvent(PostModuleEvent::slot_type const &iSlot)
void watchPostSourceEvent(PostSourceEvent::slot_type const &iSlot)
SignificantEvent eventT3_
constexpr std::shared_ptr< T > & get_underlying_safe(propagate_const< std::shared_ptr< T >> &iP)
std::string const & moduleLabel() const
edm::EventID eventMaxDeltaV
void andPrint(const std::string &type, const std::string &mdlabel, const std::string &mdname) const
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)
ModuleDescription const * moduleDescription() const
char const * smapsLineBuffer() 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_
StreamID const & streamID() const
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)
bool operator==(const smapsInfo &p) const
unsigned int value() const
SignificantEvent eventR2_
void preModule(StreamContext const &, ModuleCallingContext 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 &)
std::string mallOutput(std::string title, size_t const &n) const
edm::propagate_const< char * > smapsLineBuffer_
void watchPostModuleBeginJob(PostModuleBeginJob::slot_type const &iSlot)
void postSourceConstruction(const ModuleDescription &)
Log< level::System, true > LogAbsolute
SignificantEvent eventT2_
void postSourceEvent(StreamID)
EventID const & eventID() const
void postModuleBeginJob(const ModuleDescription &)
double averageGrowthRate(double current, double past, int count)
Log< level::Warning, false > LogWarning
SimpleMemoryCheck(const ParameterSet &, ActivityRegistry &)
SignificantModulesMap modules_
SignificantEvent eventRssT1_
void postModule(StreamContext const &, ModuleCallingContext const &)
void postModuleConstruction(const ModuleDescription &)
bool operator>(const smapsInfo &p) const
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_