50 #include <boost/lexical_cast.hpp>
104 ret.
pss_ +=
static_cast<double>(
value)/1024.;
113 return(current-past)/(double)count;
122 , pg_size_(sysconf(_SC_PAGESIZE))
123 , num_to_skip_(iPS.getUntrackedParameter<int>(
"ignoreTotal"))
124 , showMallocInfo_(iPS.getUntrackedParameter<bool>(
"showMallocInfo"))
125 , oncePerEventMode_(iPS.getUntrackedParameter<bool>(
"oncePerEventMode"))
126 , jobReportOutputOnly_(iPS.getUntrackedParameter<bool>(
"jobReportOutputOnly"))
127 , monitorPssAndPrivate_(iPS.getUntrackedParameter<bool>(
"monitorPssAndPrivate"))
130 , smapsLineBuffer_(
NULL)
131 , smapsLineBufferLen_(0)
134 , moduleSummaryRequested_(iPS.getUntrackedParameter<bool>(
"moduleMemorySummary"))
135 , measurementUnderway_(
false){
138 std::ostringstream ost;
173 #ifndef __SANITIZE_ADDRESS__
192 <<
"ERROR: Problem with setting malloc options\n"
199 <<
"Malloc options: " << mo <<
"\n";
229 descriptions.
add(
"SimpleMemoryCheck", desc);
235 std::ostringstream smapsNameOst;
236 smapsNameOst <<
"/proc/"<<getpid()<<
"/smaps";
237 if((
smapsFile_ =fopen(smapsNameOst.str().c_str(),
"r"))==0) {
250 bool expected =
false;
252 std::shared_ptr<void> guard(
nullptr,[
this](
void const*) {
261 bool expected =
false;
263 std::shared_ptr<void> guard(
nullptr,[
this](
void const*) {
271 bool expected =
false;
273 std::shared_ptr<void> guard(
nullptr,[
this](
void const*) {
281 bool expected =
false;
283 std::shared_ptr<void> guard(
nullptr,[
this](
void const*) {
291 bool expected =
false;
293 std::shared_ptr<void> guard(
nullptr,[
this](
void const*) {
303 <<
"MemoryReport> Peak virtual size " <<
eventT1_.
vsize <<
" Mbytes"
305 <<
" Key events increasing vsize: \n"
319 mmr <<
"ModuleMemoryReport> Each line has module label and: \n";
320 mmr <<
" (after early ignored events) \n";
322 " count of times module executed; average increase in vsize \n";
324 " maximum increase in vsize; event on which maximum occurred \n";
325 mmr <<
" (during early ignored events) \n";
326 mmr <<
" total and maximum vsize increases \n \n";
327 for(SignificantModulesMap::iterator im =
modules_.begin();
331 mmr << im->first <<
": ";
347 #define SIMPLE_MEMORY_CHECK_ORIGINAL_XML_OUTPUT
348 #ifdef SIMPLE_MEMORY_CHECK_ORIGINAL_XML_OUTPUT
350 std::map<std::string, std::string> reportData;
383 struct mallinfo minfo = mallinfo();
385 std::make_pair(
"HEAP_ARENA_SIZE_BYTES",
i2str(minfo.arena)));
387 std::make_pair(
"HEAP_ARENA_N_UNUSED_CHUNKS",
i2str(minfo.ordblks)));
389 std::make_pair(
"HEAP_TOP_FREE_BYTES",
i2str(minfo.keepcost)));
391 std::make_pair(
"HEAP_MAPPED_SIZE_BYTES",
i2str(minfo.hblkhd)));
393 std::make_pair(
"HEAP_MAPPED_N_CHUNKS",
i2str(minfo.hblks)));
395 std::make_pair(
"HEAP_USED_BYTES",
i2str(minfo.uordblks)));
397 std::make_pair(
"HEAP_UNUSED_BYTES",
i2str(minfo.fordblks)));
411 for(SignificantModulesMap::iterator im =
modules_.begin();
418 reportData.insert(std::make_pair(label+
"AverageDeltaVsize",
424 reportData.insert(std::make_pair(label+
"MaxEarlyDeltaVsize",
d2str(m.
maxEarlyVsize)));
429 std::map<std::string, std::string> reportMemoryProperties;
431 if(FILE* fmeminfo = fopen(
"/proc/meminfo",
"r")) {
436 while(fgets(buf,
sizeof(buf), fmeminfo)) {
438 token = strtok(buf, space);
440 value = atol(strtok(
NULL, space));
442 reportMemoryProperties.insert(std::make_pair(category.substr(0, strlen(token)-1),
i2str(value)));
450 reportSvc->reportPerformanceSummary(
"ApplicationMemory", reportData);
451 reportSvc->reportPerformanceSummary(
"SystemMemory", reportMemoryProperties);
454 #ifdef SIMPLE_MEMORY_CHECK_DIFFERENT_XML_OUTPUT
455 std::vector<std::string> reportData;
487 struct mallinfo minfo = mallinfo();
488 reportData.push_back(
489 mallOutput(
"HEAP_ARENA_SIZE_BYTES", minfo.arena));
490 reportData.push_back(
491 mallOutput(
"HEAP_ARENA_N_UNUSED_CHUNKS", minfo.ordblks));
492 reportData.push_back(
493 mallOutput(
"HEAP_TOP_FREE_BYTES", minfo.keepcost));
494 reportData.push_back(
495 mallOutput(
"HEAP_MAPPED_SIZE_BYTES", minfo.hblkhd));
496 reportData.push_back(
497 mallOutput(
"HEAP_MAPPED_N_CHUNKS", minfo.hblks));
498 reportData.push_back(
499 mallOutput(
"HEAP_USED_BYTES", minfo.uordblks));
500 reportData.push_back(
501 mallOutput(
"HEAP_UNUSED_BYTES", minfo.fordblks));
513 reportSvc->reportMemoryInfo(reportData);
520 bool expected =
false;
522 std::shared_ptr<void> guard(
nullptr,[
this](
void const*) {
539 bool expected =
false;
541 std::shared_ptr<void> guard(
nullptr,[
this](
void const*) {
544 bool expected =
false;
557 bool expected =
false;
559 std::shared_ptr<void> guard(
nullptr,[
this](
void const*) {
573 std::shared_ptr<void> guard(
nullptr,[
this](
void const*) {
576 bool expected =
false;
578 std::shared_ptr<void> guard(
nullptr,[
this](
void const*) {
696 <<
"MemoryCheck: " << type <<
" "
697 << mdname <<
":" << mdlabel
703 struct mallinfo minfo = mallinfo();
706 <<
"MemoryCheck: " << type <<
" "
707 << mdname <<
":" << mdlabel
711 <<
" HEAP-ARENA [ SIZE-BYTES " << minfo.arena
712 <<
" N-UNUSED-CHUNKS " << minfo.ordblks
713 <<
" TOP-FREE-BYTES " << minfo.keepcost <<
" ]"
714 <<
" HEAP-MAPPED [ SIZE-BYTES " << minfo.hblkhd
715 <<
" N-CHUNKS " << minfo.hblks <<
" ]"
716 <<
" HEAP-USED-BYTES " << minfo.uordblks
717 <<
" HEAP-UNUSED-BYTES " << minfo.fordblks
732 #ifdef SIMPLE_MEMORY_CHECK_ORIGINAL_XML_OUTPUT
736 std::map<std::string, std::string>&
m)
const {
737 { std::ostringstream os;
738 os << title <<
"-a-COUNT";
739 m.insert(std::make_pair(os.str(),
i2str(e.
count))); }
740 { std::ostringstream os;
741 os << title <<
"-b-RUN";
742 m.insert(std::make_pair(os.str(),
d2str(static_cast<double>(e.
event.
run())))); }
743 { std::ostringstream os;
744 os << title <<
"-c-EVENT";
745 m.insert(std::make_pair(os.str(),
d2str(static_cast<double>(e.
event.
event())))); }
746 { std::ostringstream os;
747 os << title <<
"-d-VSIZE";
748 m.insert(std::make_pair(os.str(),
d2str(e.
vsize))); }
749 { std::ostringstream os;
750 os << title <<
"-e-DELTV";
752 { std::ostringstream os;
753 os << title <<
"-f-RSS";
754 m.insert(std::make_pair(os.str(),
d2str(e.
rss))); }
756 { std::ostringstream os;
757 os << title <<
"-g-PRIVATE";
759 { std::ostringstream os;
760 os << title <<
"-h-PSS";
761 m.insert(std::make_pair(os.str(),
d2str(e.
pss))); }
766 #ifdef SIMPLE_MEMORY_CHECK_DIFFERENT_XML_OUTPUT
769 SignificantEvent
const&
e)
const {
770 std::ostringstream os;
771 os <<
" <" << title <<
">\n";
772 os <<
" " << e.count <<
": " << e.event;
773 os <<
" vsize " << e.vsize-e.deltaVsize <<
" + " << e.deltaVsize
775 os <<
" rss: " << e.rss <<
"\n";
776 os <<
" </" << title <<
">\n";
782 std::ostringstream os;
783 os <<
" <" << title <<
">\n";
784 os <<
" " << n <<
"\n";
785 os <<
" </" << title <<
">\n";
809 os <<
"[" << se.
count <<
"] "
812 <<
" 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)
ParameterDescriptionBase * addUntracked(U const &iLabel, T const &value)
size_t smapsLineBufferLen_
void watchPostEndJob(PostEndJob::slot_type const &iSlot)
std::atomic< bool > measurementUnderway_
SignificantEvent eventT1_
void set_mmap_thr(opt_type mmap_thr)
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 watchPostModuleEvent(PostModuleEvent::slot_type const &iSlot)
void watchPostSourceEvent(PostSourceEvent::slot_type const &iSlot)
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
std::atomic< unsigned int > moduleStreamID_
SignificantEvent eventRssT3_
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
ModuleDescription const * moduleDescription() 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)
bool monitorPssAndPrivate_
SignificantEvent eventR1_
SignificantEvent eventDeltaRssT3_
StreamID const & streamID() const
bool moduleSummaryRequested_
bool jobReportOutputOnly_
void updateAndPrint(const std::string &type, const std::string &mdlabel, const std::string &mdname)
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_
void watchPostForkReacquireResources(PostForkReacquireResources::slot_type const &iSlot)
std::string error_message() const
SignificantEvent eventL2_
SignificantEvent eventDeltaRssT2_
void postEvent(StreamContext const &)
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 postSourceEvent(StreamID)
EventID const & eventID() const
void postModuleBeginJob(const ModuleDescription &)
volatile std::atomic< bool > shutdown_flag false
double averageGrowthRate(double current, double past, int count)
void set_top_pad(opt_type top_pad)
SimpleMemoryCheck(const ParameterSet &, ActivityRegistry &)
SignificantModulesMap modules_
SignificantEvent eventRssT1_
void postModule(StreamContext const &, ModuleCallingContext const &)
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
std::atomic< unsigned int > moduleID_