47 #include <boost/lexical_cast.hpp>
101 ret.
pss_ +=
static_cast<double>(
value)/1024.;
110 return(current-past)/(double)count;
119 , pg_size_(sysconf(_SC_PAGESIZE))
120 , num_to_skip_(iPS.getUntrackedParameter<int>(
"ignoreTotal"))
121 , showMallocInfo_(iPS.getUntrackedParameter<bool>(
"showMallocInfo"))
122 , oncePerEventMode_(iPS.getUntrackedParameter<bool>(
"oncePerEventMode"))
123 , jobReportOutputOnly_(iPS.getUntrackedParameter<bool>(
"jobReportOutputOnly"))
124 , monitorPssAndPrivate_(iPS.getUntrackedParameter<bool>(
"monitorPssAndPrivate"))
127 , smapsLineBuffer_(
NULL)
128 , smapsLineBufferLen_(0)
131 , moduleSummaryRequested_(iPS.getUntrackedParameter<bool>(
"moduleMemorySummary")) {
134 std::ostringstream ost;
170 #ifndef __SANITIZE_ADDRESS__
189 <<
"ERROR: Problem with setting malloc options\n"
196 <<
"Malloc options: " << mo <<
"\n";
226 descriptions.
add(
"SimpleMemoryCheck", desc);
232 std::ostringstream smapsNameOst;
233 smapsNameOst <<
"/proc/"<<getpid()<<
"/smaps";
234 if((
smapsFile_ =fopen(smapsNameOst.str().c_str(),
"r"))==0) {
270 <<
"MemoryReport> Peak virtual size " <<
eventT1_.
vsize <<
" Mbytes"
272 <<
" Key events increasing vsize: \n"
286 mmr <<
"ModuleMemoryReport> Each line has module label and: \n";
287 mmr <<
" (after early ignored events) \n";
289 " count of times module executed; average increase in vsize \n";
291 " maximum increase in vsize; event on which maximum occurred \n";
292 mmr <<
" (during early ignored events) \n";
293 mmr <<
" total and maximum vsize increases \n \n";
294 for(SignificantModulesMap::iterator im =
modules_.begin();
298 mmr << im->first <<
": ";
314 #define SIMPLE_MEMORY_CHECK_ORIGINAL_XML_OUTPUT
315 #ifdef SIMPLE_MEMORY_CHECK_ORIGINAL_XML_OUTPUT
317 std::map<std::string, std::string> reportData;
350 struct mallinfo minfo = mallinfo();
352 std::make_pair(
"HEAP_ARENA_SIZE_BYTES",
i2str(minfo.arena)));
354 std::make_pair(
"HEAP_ARENA_N_UNUSED_CHUNKS",
i2str(minfo.ordblks)));
356 std::make_pair(
"HEAP_TOP_FREE_BYTES",
i2str(minfo.keepcost)));
358 std::make_pair(
"HEAP_MAPPED_SIZE_BYTES",
i2str(minfo.hblkhd)));
360 std::make_pair(
"HEAP_MAPPED_N_CHUNKS",
i2str(minfo.hblks)));
362 std::make_pair(
"HEAP_USED_BYTES",
i2str(minfo.uordblks)));
364 std::make_pair(
"HEAP_UNUSED_BYTES",
i2str(minfo.fordblks)));
378 for(SignificantModulesMap::iterator im =
modules_.begin();
385 reportData.insert(std::make_pair(label+
"AverageDeltaVsize",
391 reportData.insert(std::make_pair(label+
"MaxEarlyDeltaVsize",
d2str(m.
maxEarlyVsize)));
396 std::map<std::string, std::string> reportMemoryProperties;
398 if(FILE* fmeminfo = fopen(
"/proc/meminfo",
"r")) {
403 while(fgets(buf,
sizeof(buf), fmeminfo)) {
405 token = strtok(buf, space);
407 value = atol(strtok(
NULL, space));
409 reportMemoryProperties.insert(std::make_pair(category.substr(0, strlen(token)-1),
i2str(value)));
417 reportSvc->reportPerformanceSummary(
"ApplicationMemory", reportData);
418 reportSvc->reportPerformanceSummary(
"SystemMemory", reportMemoryProperties);
421 #ifdef SIMPLE_MEMORY_CHECK_DIFFERENT_XML_OUTPUT
422 std::vector<std::string> reportData;
454 struct mallinfo minfo = mallinfo();
455 reportData.push_back(
456 mallOutput(
"HEAP_ARENA_SIZE_BYTES", minfo.arena));
457 reportData.push_back(
458 mallOutput(
"HEAP_ARENA_N_UNUSED_CHUNKS", minfo.ordblks));
459 reportData.push_back(
460 mallOutput(
"HEAP_TOP_FREE_BYTES", minfo.keepcost));
461 reportData.push_back(
462 mallOutput(
"HEAP_MAPPED_SIZE_BYTES", minfo.hblkhd));
463 reportData.push_back(
464 mallOutput(
"HEAP_MAPPED_N_CHUNKS", minfo.hblks));
465 reportData.push_back(
466 mallOutput(
"HEAP_USED_BYTES", minfo.uordblks));
467 reportData.push_back(
468 mallOutput(
"HEAP_UNUSED_BYTES", minfo.fordblks));
480 reportSvc->reportMemoryInfo(reportData);
624 <<
"MemoryCheck: " << type <<
" "
625 << mdname <<
":" << mdlabel
631 struct mallinfo minfo = mallinfo();
634 <<
"MemoryCheck: " << type <<
" "
635 << mdname <<
":" << mdlabel
639 <<
" HEAP-ARENA [ SIZE-BYTES " << minfo.arena
640 <<
" N-UNUSED-CHUNKS " << minfo.ordblks
641 <<
" TOP-FREE-BYTES " << minfo.keepcost <<
" ]"
642 <<
" HEAP-MAPPED [ SIZE-BYTES " << minfo.hblkhd
643 <<
" N-CHUNKS " << minfo.hblks <<
" ]"
644 <<
" HEAP-USED-BYTES " << minfo.uordblks
645 <<
" HEAP-UNUSED-BYTES " << minfo.fordblks
660 #ifdef SIMPLE_MEMORY_CHECK_ORIGINAL_XML_OUTPUT
664 std::map<std::string, std::string>&
m)
const {
665 { std::ostringstream os;
666 os << title <<
"-a-COUNT";
667 m.insert(std::make_pair(os.str(),
i2str(e.
count))); }
668 { std::ostringstream os;
669 os << title <<
"-b-RUN";
670 m.insert(std::make_pair(os.str(),
d2str(static_cast<double>(e.
event.
run())))); }
671 { std::ostringstream os;
672 os << title <<
"-c-EVENT";
673 m.insert(std::make_pair(os.str(),
d2str(static_cast<double>(e.
event.
event())))); }
674 { std::ostringstream os;
675 os << title <<
"-d-VSIZE";
676 m.insert(std::make_pair(os.str(),
d2str(e.
vsize))); }
677 { std::ostringstream os;
678 os << title <<
"-e-DELTV";
680 { std::ostringstream os;
681 os << title <<
"-f-RSS";
682 m.insert(std::make_pair(os.str(),
d2str(e.
rss))); }
684 { std::ostringstream os;
685 os << title <<
"-g-PRIVATE";
687 { std::ostringstream os;
688 os << title <<
"-h-PSS";
689 m.insert(std::make_pair(os.str(),
d2str(e.
pss))); }
694 #ifdef SIMPLE_MEMORY_CHECK_DIFFERENT_XML_OUTPUT
697 SignificantEvent
const&
e)
const {
698 std::ostringstream os;
699 os <<
" <" << title <<
">\n";
700 os <<
" " << e.count <<
": " << e.event;
701 os <<
" vsize " << e.vsize-e.deltaVsize <<
" + " << e.deltaVsize
703 os <<
" rss: " << e.rss <<
"\n";
704 os <<
" </" << title <<
">\n";
710 std::ostringstream os;
711 os <<
" <" << title <<
">\n";
712 os <<
" " << n <<
"\n";
713 os <<
" </" << title <<
">\n";
737 os <<
"[" << se.
count <<
"] "
740 <<
" rss = " << se.
rss <<
" delta = " << se.
deltaRss;
void watchPostModuleConstruction(PostModuleConstruction::slot_type const &iSlot)
EventNumber_t event() const
T getUntrackedParameter(std::string const &, T const &) const
void set_trim_thr(opt_type trim_thr)
static std::string i2str(int i)
std::string eventStatOutput(std::string title, SignificantEvent const &e) const
void postFork(unsigned int, unsigned int)
SignificantEvent eventDeltaRssT1_
void preSourceConstruction(const ModuleDescription &)
void set_mmap_max(opt_type mmap_max)
edm::EventID currentEventID_
ParameterDescriptionBase * addUntracked(U const &iLabel, T const &value)
size_t smapsLineBufferLen_
void watchPostEndJob(PostEndJob::slot_type const &iSlot)
SignificantEvent eventT1_
void set_mmap_thr(opt_type mmap_thr)
void updateEventStats(edm::EventID const &e)
ProcInfoFetcher piFetcher_
void postModule(const ModuleDescription &)
void watchPostModule(PostModule::slot_type const &iSlot)
void watchPreProcessEvent(PreProcessEvent::slot_type const &iSlot)
void watchPreSourceConstruction(PreSourceConstruction::slot_type const &iSlot)
void watchPostSourceConstruction(PostSourceConstruction::slot_type const &iSlot)
SignificantEvent eventRssT2_
SignificantEvent eventL1_
std::string const & moduleName() const
SignificantEvent eventT3_
std::string const & moduleLabel() const
edm::EventID eventMaxDeltaV
void andPrint(const std::string &type, const std::string &mdlabel, const std::string &mdname) const
void watchPreModule(PreModule::slot_type const &iSlot)
SignificantEvent eventRssT3_
void watchPostProcessEvent(PostProcessEvent::slot_type const &iSlot)
void preModule(const ModuleDescription &)
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
friend struct SignificantEvent
void set(double deltaV, double deltaR, edm::EventID const &e, SimpleMemoryCheck *t)
void postEventProcessing(const Event &, const EventSetup &)
void updateModuleMemoryStats(SignificantModule &m, double dv)
bool monitorPssAndPrivate_
ErrorLog & operator<<(ErrorLog &e, const T &t)
SignificantEvent eventR1_
SignificantEvent eventDeltaRssT3_
bool moduleSummaryRequested_
bool jobReportOutputOnly_
void updateAndPrint(const std::string &type, const std::string &mdlabel, const std::string &mdname)
SignificantEvent eventR2_
static std::string d2str(double d)
void add(std::string const &label, ParameterSetDescription const &psetDescription)
void watchPostForkReacquireResources(PostForkReacquireResources::slot_type const &iSlot)
void watchPostSource(PostSource::slot_type const &iSlot)
std::string error_message() const
SignificantEvent eventL2_
SignificantEvent eventDeltaRssT2_
std::string mallOutput(std::string title, size_t const &n) const
void watchPostModuleBeginJob(PostModuleBeginJob::slot_type const &iSlot)
void adjustMallocParams()
void postSourceConstruction(const ModuleDescription &)
SignificantEvent eventT2_
void postModuleBeginJob(const ModuleDescription &)
double averageGrowthRate(double current, double past, int count)
void preEventProcessing(const edm::EventID &, const edm::Timestamp &)
void set_top_pad(opt_type top_pad)
SimpleMemoryCheck(const ParameterSet &, ActivityRegistry &)
SignificantModulesMap modules_
SignificantEvent eventRssT1_
void postModuleConstruction(const ModuleDescription &)
bool monitorPssAndPrivate
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
MallocOptionSetter & getGlobalOptionSetter()
void watchPostBeginJob(PostBeginJob::slot_type const &iSlot)
convenience function for attaching to signal