47 #include <boost/lexical_cast.hpp>
59 static std::string
d2str(
double d) {
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;
188 <<
"ERROR: Problem with setting malloc options\n"
195 <<
"Malloc options: " << mo <<
"\n";
224 descriptions.
add(
"SimpleMemoryCheck", desc);
230 std::ostringstream smapsNameOst;
231 smapsNameOst <<
"/proc/"<<getpid()<<
"/smaps";
232 if((
smapsFile_ =fopen(smapsNameOst.str().c_str(),
"r"))==0) {
268 <<
"MemoryReport> Peak virtual size " <<
eventT1_.
vsize <<
" Mbytes"
270 <<
" Key events increasing vsize: \n"
284 mmr <<
"ModuleMemoryReport> Each line has module label and: \n";
285 mmr <<
" (after early ignored events) \n";
287 " count of times module executed; average increase in vsize \n";
289 " maximum increase in vsize; event on which maximum occurred \n";
290 mmr <<
" (during early ignored events) \n";
291 mmr <<
" total and maximum vsize increases \n \n";
292 for(SignificantModulesMap::iterator im =
modules_.begin();
296 mmr << im->first <<
": ";
312 #define SIMPLE_MEMORY_CHECK_ORIGINAL_XML_OUTPUT
313 #ifdef SIMPLE_MEMORY_CHECK_ORIGINAL_XML_OUTPUT
315 std::map<std::string, std::string> reportData;
348 struct mallinfo minfo = mallinfo();
350 std::make_pair(
"HEAP_ARENA_SIZE_BYTES",
i2str(minfo.arena)));
352 std::make_pair(
"HEAP_ARENA_N_UNUSED_CHUNKS",
i2str(minfo.ordblks)));
354 std::make_pair(
"HEAP_TOP_FREE_BYTES",
i2str(minfo.keepcost)));
356 std::make_pair(
"HEAP_MAPPED_SIZE_BYTES",
i2str(minfo.hblkhd)));
358 std::make_pair(
"HEAP_MAPPED_N_CHUNKS",
i2str(minfo.hblks)));
360 std::make_pair(
"HEAP_USED_BYTES",
i2str(minfo.uordblks)));
362 std::make_pair(
"HEAP_UNUSED_BYTES",
i2str(minfo.fordblks)));
376 for(SignificantModulesMap::iterator im =
modules_.begin();
380 std::string
label = im->first+
":";
383 reportData.insert(std::make_pair(label+
"AverageDeltaVsize",
389 reportData.insert(std::make_pair(label+
"MaxEarlyDeltaVsize",
d2str(m.
maxEarlyVsize)));
394 std::map<std::string, std::string> reportMemoryProperties;
396 if(FILE* fmeminfo = fopen(
"/proc/meminfo",
"r")) {
401 while(fgets(buf,
sizeof(buf), fmeminfo)) {
403 token = strtok(buf, space);
405 value = atol(strtok(
NULL, space));
407 reportMemoryProperties.insert(std::make_pair(category.substr(0, strlen(token)-1),
i2str(value)));
415 reportSvc->reportPerformanceSummary(
"ApplicationMemory", reportData);
416 reportSvc->reportPerformanceSummary(
"SystemMemory", reportMemoryProperties);
419 #ifdef SIMPLE_MEMORY_CHECK_DIFFERENT_XML_OUTPUT
420 std::vector<std::string> reportData;
452 struct mallinfo minfo = mallinfo();
453 reportData.push_back(
454 mallOutput(
"HEAP_ARENA_SIZE_BYTES", minfo.arena));
455 reportData.push_back(
456 mallOutput(
"HEAP_ARENA_N_UNUSED_CHUNKS", minfo.ordblks));
457 reportData.push_back(
458 mallOutput(
"HEAP_TOP_FREE_BYTES", minfo.keepcost));
459 reportData.push_back(
460 mallOutput(
"HEAP_MAPPED_SIZE_BYTES", minfo.hblkhd));
461 reportData.push_back(
462 mallOutput(
"HEAP_MAPPED_N_CHUNKS", minfo.hblks));
463 reportData.push_back(
464 mallOutput(
"HEAP_USED_BYTES", minfo.uordblks));
465 reportData.push_back(
466 mallOutput(
"HEAP_UNUSED_BYTES", minfo.fordblks));
478 reportSvc->reportMemoryInfo(reportData);
615 std::string
const& mdlabel, std::string
const& mdname)
const {
622 <<
"MemoryCheck: " << type <<
" "
623 << mdname <<
":" << mdlabel
629 struct mallinfo minfo = mallinfo();
632 <<
"MemoryCheck: " << type <<
" "
633 << mdname <<
":" << mdlabel
637 <<
" HEAP-ARENA [ SIZE-BYTES " << minfo.arena
638 <<
" N-UNUSED-CHUNKS " << minfo.ordblks
639 <<
" TOP-FREE-BYTES " << minfo.keepcost <<
" ]"
640 <<
" HEAP-MAPPED [ SIZE-BYTES " << minfo.hblkhd
641 <<
" N-CHUNKS " << minfo.hblks <<
" ]"
642 <<
" HEAP-USED-BYTES " << minfo.uordblks
643 <<
" HEAP-UNUSED-BYTES " << minfo.fordblks
652 std::string
const& mdlabel, std::string
const& mdname) {
658 #ifdef SIMPLE_MEMORY_CHECK_ORIGINAL_XML_OUTPUT
662 std::map<std::string, std::string>&
m)
const {
663 { std::ostringstream os;
664 os << title <<
"-a-COUNT";
665 m.insert(std::make_pair(os.str(),
i2str(e.
count))); }
666 { std::ostringstream os;
667 os << title <<
"-b-RUN";
668 m.insert(std::make_pair(os.str(),
d2str(static_cast<double>(e.
event.
run())))); }
669 { std::ostringstream os;
670 os << title <<
"-c-EVENT";
671 m.insert(std::make_pair(os.str(),
d2str(static_cast<double>(e.
event.
event())))); }
672 { std::ostringstream os;
673 os << title <<
"-d-VSIZE";
674 m.insert(std::make_pair(os.str(),
d2str(e.
vsize))); }
675 { std::ostringstream os;
676 os << title <<
"-e-DELTV";
678 { std::ostringstream os;
679 os << title <<
"-f-RSS";
680 m.insert(std::make_pair(os.str(),
d2str(e.
rss))); }
682 { std::ostringstream os;
683 os << title <<
"-g-PRIVATE";
685 { std::ostringstream os;
686 os << title <<
"-h-PSS";
687 m.insert(std::make_pair(os.str(),
d2str(e.
pss))); }
692 #ifdef SIMPLE_MEMORY_CHECK_DIFFERENT_XML_OUTPUT
695 SignificantEvent
const&
e)
const {
696 std::ostringstream os;
697 os <<
" <" << title <<
">\n";
698 os <<
" " << e.count <<
": " << e.event;
699 os <<
" vsize " << e.vsize-e.deltaVsize <<
" + " << e.deltaVsize
701 os <<
" rss: " << e.rss <<
"\n";
702 os <<
" </" << title <<
">\n";
708 std::ostringstream os;
709 os <<
" <" << title <<
">\n";
710 os <<
" " << n <<
"\n";
711 os <<
" </" << title <<
">\n";
735 os <<
"[" << se.
count <<
"] "
738 <<
" 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