57 static std::string
d2str(
double d){
110 double pr_size=0.0, pr_rssize=0.0;
116 lseek(
fd_,0,SEEK_SET);
120 perror(
"Read of Proc file failed:");
129 "%d %s %c %d %d %d %d %d %u %u %u %u %u %d %d %d %d %d %d %u %u %d %u %u %u %u %u %u %u %u %d %d %d %d %u",
168 pr_size = (double)pinfo.
vsize;
169 pr_rssize = (
double)pinfo.
rss;
171 ret.
vsize = pr_size / (1024.0*1024.0);
172 ret.
rss = (pr_rssize *
pg_size_) / (1024.0*1024.0);
183 return (current-past)/(double)count;
192 , pg_size_(sysconf(_SC_PAGESIZE))
193 , num_to_skip_(iPS.getUntrackedParameter<int>(
"ignoreTotal"))
194 , showMallocInfo_(iPS.getUntrackedParameter<bool>(
"showMallocInfo"))
196 (iPS.getUntrackedParameter<bool>(
"oncePerEventMode"))
197 , jobReportOutputOnly_(iPS.getUntrackedParameter<bool>(
"jobReportOutputOnly"))
201 , moduleSummaryRequested_
202 (iPS.getUntrackedParameter<bool>(
"moduleMemorySummary"))
206 std::ostringstream ost;
209 ost <<
"/proc/" << getpid() <<
"/stat";
212 if((
fd_=open(ost.str().c_str(),O_RDONLY))<0)
215 <<
"Memory checker server: Failed to open " << ost.str() << std::endl;
282 <<
"ERROR: Problem with setting malloc options\n"
290 <<
"Malloc options: " << mo <<
"\n";
313 descriptions.
add(
"SimpleMemoryCheck", desc);
352 <<
"MemoryReport> Peak virtual size " <<
eventT1_.
vsize <<
" Mbytes"
354 <<
" Key events increasing vsize: \n"
368 mmr <<
"ModuleMemoryReport> Each line has module label and: \n";
369 mmr <<
" (after early ignored events) \n";
371 " count of times module executed; average increase in vsize \n";
373 " maximum increase in vsize; event on which maximum occurred \n";
374 mmr <<
" (during early ignored events) \n";
375 mmr <<
" total and maximum vsize increases \n \n";
376 for (SignificantModulesMap::iterator im=
modules_.begin();
380 mmr << im->first <<
": ";
395 #define SIMPLE_MEMORY_CHECK_ORIGINAL_XML_OUTPUT
396 #ifdef SIMPLE_MEMORY_CHECK_ORIGINAL_XML_OUTPUT
398 std::map<std::string, std::string> reportData;
431 struct mallinfo minfo = mallinfo();
433 std::make_pair(
"HEAP_ARENA_SIZE_BYTES",
i2str(minfo.arena)));
435 std::make_pair(
"HEAP_ARENA_N_UNUSED_CHUNKS",
i2str(minfo.ordblks)));
437 std::make_pair(
"HEAP_TOP_FREE_BYTES",
i2str(minfo.keepcost)));
439 std::make_pair(
"HEAP_MAPPED_SIZE_BYTES",
i2str(minfo.hblkhd)));
441 std::make_pair(
"HEAP_MAPPED_N_CHUNKS",
i2str(minfo.hblks)));
443 std::make_pair(
"HEAP_USED_BYTES",
i2str(minfo.uordblks)));
445 std::make_pair(
"HEAP_UNUSED_BYTES",
i2str(minfo.fordblks)));
459 for (SignificantModulesMap::iterator im=
modules_.begin();
463 std::string
label = im->first+
":";
468 std::make_pair(label+
"AverageDeltaVsize",
482 std::map<std::string, std::string> reportMemoryProperties;
484 if (FILE *fmeminfo = fopen(
"/proc/meminfo",
"r")){
489 while (fgets(buf,
sizeof(buf), fmeminfo)){
491 token = strtok(buf, space);
493 value = atol(strtok(
NULL, space));
495 reportMemoryProperties.insert(std::make_pair(category.substr(0,strlen(token)-1),
i2str(value)));
503 reportSvc->reportPerformanceSummary(
"ApplicationMemory", reportData);
504 reportSvc->reportPerformanceSummary(
"SystemMemory", reportMemoryProperties);
507 #ifdef SIMPLE_MEMORY_CHECK_DIFFERENT_XML_OUTPUT
508 std::vector<std::string> reportData;
540 struct mallinfo minfo = mallinfo();
541 reportData.push_back(
542 mallOutput(
"HEAP_ARENA_SIZE_BYTES", minfo.arena));
543 reportData.push_back(
544 mallOutput(
"HEAP_ARENA_N_UNUSED_CHUNKS", minfo.ordblks));
545 reportData.push_back(
546 mallOutput(
"HEAP_TOP_FREE_BYTES", minfo.keepcost));
547 reportData.push_back(
548 mallOutput(
"HEAP_MAPPED_SIZE_BYTES", minfo.hblkhd));
549 reportData.push_back(
550 mallOutput(
"HEAP_MAPPED_N_CHUNKS", minfo.hblks));
551 reportData.push_back(
552 mallOutput(
"HEAP_USED_BYTES", minfo.uordblks));
553 reportData.push_back(
554 mallOutput(
"HEAP_UNUSED_BYTES", minfo.fordblks));
566 reportSvc->reportMemoryInfo(reportData);
699 const std::string& mdlabel,
const std::string& mdname)
const
707 <<
"MemoryCheck: " << type <<
" "
708 << mdname <<
":" << mdlabel
714 struct mallinfo minfo = mallinfo();
717 <<
"MemoryCheck: " << type <<
" "
718 << mdname <<
":" << mdlabel
722 <<
" HEAP-ARENA [ SIZE-BYTES " << minfo.arena
723 <<
" N-UNUSED-CHUNKS " << minfo.ordblks
724 <<
" TOP-FREE-BYTES " << minfo.keepcost <<
" ]"
725 <<
" HEAP-MAPPED [ SIZE-BYTES " << minfo.hblkhd
726 <<
" N-CHUNKS " << minfo.hblks <<
" ]"
727 <<
" HEAP-USED-BYTES " << minfo.uordblks
728 <<
" HEAP-UNUSED-BYTES " << minfo.fordblks
737 const std::string& mdlabel,
const std::string& mdname)
744 #ifdef SIMPLE_MEMORY_CHECK_ORIGINAL_XML_OUTPUT
748 std::map<std::string, std::string> &
m)
const
750 { std::ostringstream os;
751 os << title <<
"-a-COUNT";
752 m.insert(std::make_pair(os.str(),
i2str(e.
count))); }
753 { std::ostringstream os;
754 os << title <<
"-b-RUN";
755 m.insert(std::make_pair(os.str(),
d2str(static_cast<double>(e.
event.
run())) )); }
756 { std::ostringstream os;
757 os << title <<
"-c-EVENT";
758 m.insert(std::make_pair(os.str(),
d2str(static_cast<double>(e.
event.
event())) )); }
759 { std::ostringstream os;
760 os << title <<
"-d-VSIZE";
761 m.insert(std::make_pair(os.str(),
d2str(e.
vsize))); }
762 { std::ostringstream os;
763 os << title <<
"-e-DELTV";
765 { std::ostringstream os;
766 os << title <<
"-f-RSS";
767 m.insert(std::make_pair(os.str(),
d2str(e.
rss))); }
772 #ifdef SIMPLE_MEMORY_CHECK_DIFFERENT_XML_OUTPUT
775 SignificantEvent
const& e)
const
777 std::ostringstream os;
778 os <<
" <" << title <<
">\n";
779 os <<
" " << e.count <<
": " << e.event;
780 os <<
" vsize " << e.vsize-e.deltaVsize <<
" + " << e.deltaVsize
782 os <<
" rss: " << e.rss <<
"\n";
783 os <<
" </" << title <<
">\n";
789 std::ostringstream os;
790 os <<
" <" << title <<
">\n";
791 os <<
" " << n <<
"\n";
792 os <<
" </" << title <<
">\n";
818 os <<
"[" << se.
count <<
"] "
821 <<
" 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
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)
void watchPostEndJob(PostEndJob::slot_type const &iSlot)
SignificantEvent eventT1_
void set_mmap_thr(opt_type mmap_thr)
void updateEventStats(edm::EventID const &e)
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)
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 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
static const std::string category("Muon|RecoMuon|L3MuonCandidateProducerFromMuons")
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 &)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
MallocOptionSetter & getGlobalOptionSetter()
void watchPostBeginJob(PostBeginJob::slot_type const &iSlot)
convenience function for attaching to signal