56 #include <boost/lexical_cast.hpp>
107 void postFork(
unsigned int,
unsigned int);
181 friend std::ostream &
operator<< (std::ostream & os,
233 std::map<std::string, std::string> &
m)
const;
250 void set (
double deltaV,
bool early);
253 friend std::ostream &
operator<< (std::ostream & os,
294 std::ostringstream
t;
300 std::ostringstream
t;
335 ret.
pss_ +=
static_cast<double>(
value)/1024.;
344 return(current-past)/(double)count;
353 , pg_size_(sysconf(_SC_PAGESIZE))
354 , num_to_skip_(iPS.getUntrackedParameter<int>(
"ignoreTotal"))
355 , showMallocInfo_(iPS.getUntrackedParameter<bool>(
"showMallocInfo"))
356 , oncePerEventMode_(iPS.getUntrackedParameter<bool>(
"oncePerEventMode"))
357 , jobReportOutputOnly_(iPS.getUntrackedParameter<bool>(
"jobReportOutputOnly"))
358 , monitorPssAndPrivate_(iPS.getUntrackedParameter<bool>(
"monitorPssAndPrivate"))
362 , smapsLineBufferLen_(0)
365 , moduleSummaryRequested_(iPS.getUntrackedParameter<bool>(
"moduleMemorySummary"))
366 , measurementUnderway_(
false){
369 std::ostringstream ost;
404 #ifndef __SANITIZE_ADDRESS__
423 <<
"ERROR: Problem with setting malloc options\n"
430 <<
"Malloc options: " << mo <<
"\n";
460 descriptions.
add(
"SimpleMemoryCheck", desc);
466 std::ostringstream smapsNameOst;
467 smapsNameOst <<
"/proc/"<<getpid()<<
"/smaps";
468 if((
smapsFile_ =fopen(smapsNameOst.str().c_str(),
"r"))==0) {
481 bool expected =
false;
483 std::shared_ptr<void> guard(
nullptr,[
this](
void const*) {
492 bool expected =
false;
494 std::shared_ptr<void> guard(
nullptr,[
this](
void const*) {
502 bool expected =
false;
504 std::shared_ptr<void> guard(
nullptr,[
this](
void const*) {
512 bool expected =
false;
514 std::shared_ptr<void> guard(
nullptr,[
this](
void const*) {
522 bool expected =
false;
524 std::shared_ptr<void> guard(
nullptr,[
this](
void const*) {
534 <<
"MemoryReport> Peak virtual size " <<
eventT1_.
vsize <<
" Mbytes"
536 <<
" Key events increasing vsize: \n"
550 mmr <<
"ModuleMemoryReport> Each line has module label and: \n";
551 mmr <<
" (after early ignored events) \n";
553 " count of times module executed; average increase in vsize \n";
555 " maximum increase in vsize; event on which maximum occurred \n";
556 mmr <<
" (during early ignored events) \n";
557 mmr <<
" total and maximum vsize increases \n \n";
558 for(SignificantModulesMap::iterator im =
modules_.begin();
562 mmr << im->first <<
": ";
578 #define SIMPLE_MEMORY_CHECK_ORIGINAL_XML_OUTPUT
579 #ifdef SIMPLE_MEMORY_CHECK_ORIGINAL_XML_OUTPUT
581 std::map<std::string, std::string> reportData;
614 struct mallinfo minfo = mallinfo();
616 std::make_pair(
"HEAP_ARENA_SIZE_BYTES",
i2str(minfo.arena)));
618 std::make_pair(
"HEAP_ARENA_N_UNUSED_CHUNKS",
i2str(minfo.ordblks)));
620 std::make_pair(
"HEAP_TOP_FREE_BYTES",
i2str(minfo.keepcost)));
622 std::make_pair(
"HEAP_MAPPED_SIZE_BYTES",
i2str(minfo.hblkhd)));
624 std::make_pair(
"HEAP_MAPPED_N_CHUNKS",
i2str(minfo.hblks)));
626 std::make_pair(
"HEAP_USED_BYTES",
i2str(minfo.uordblks)));
628 std::make_pair(
"HEAP_UNUSED_BYTES",
i2str(minfo.fordblks)));
642 for(SignificantModulesMap::iterator im =
modules_.begin();
649 reportData.insert(std::make_pair(label+
"AverageDeltaVsize",
655 reportData.insert(std::make_pair(label+
"MaxEarlyDeltaVsize",
d2str(m.
maxEarlyVsize)));
660 std::map<std::string, std::string> reportMemoryProperties;
662 if(FILE* fmeminfo = fopen(
"/proc/meminfo",
"r")) {
667 while(fgets(buf,
sizeof(buf), fmeminfo)) {
668 char*
token =
nullptr;
669 token = strtok(buf, space);
670 if(token !=
nullptr) {
671 value = atol(strtok(
nullptr, space));
673 reportMemoryProperties.insert(std::make_pair(category.substr(0, strlen(token)-1),
i2str(value)));
681 reportSvc->reportPerformanceSummary(
"ApplicationMemory", reportData);
682 reportSvc->reportPerformanceSummary(
"SystemMemory", reportMemoryProperties);
685 #ifdef SIMPLE_MEMORY_CHECK_DIFFERENT_XML_OUTPUT
686 std::vector<std::string> reportData;
718 struct mallinfo minfo = mallinfo();
719 reportData.push_back(
720 mallOutput(
"HEAP_ARENA_SIZE_BYTES", minfo.arena));
721 reportData.push_back(
722 mallOutput(
"HEAP_ARENA_N_UNUSED_CHUNKS", minfo.ordblks));
723 reportData.push_back(
724 mallOutput(
"HEAP_TOP_FREE_BYTES", minfo.keepcost));
725 reportData.push_back(
726 mallOutput(
"HEAP_MAPPED_SIZE_BYTES", minfo.hblkhd));
727 reportData.push_back(
728 mallOutput(
"HEAP_MAPPED_N_CHUNKS", minfo.hblks));
729 reportData.push_back(
730 mallOutput(
"HEAP_USED_BYTES", minfo.uordblks));
731 reportData.push_back(
732 mallOutput(
"HEAP_UNUSED_BYTES", minfo.fordblks));
744 reportSvc->reportMemoryInfo(reportData);
751 bool expected =
false;
753 std::shared_ptr<void> guard(
nullptr,[
this](
void const*) {
770 bool expected =
false;
772 std::shared_ptr<void> guard(
nullptr,[
this](
void const*) {
775 bool expected =
false;
788 bool expected =
false;
790 std::shared_ptr<void> guard(
nullptr,[
this](
void const*) {
804 std::shared_ptr<void> guard(
nullptr,[
this](
void const*) {
807 bool expected =
false;
809 std::shared_ptr<void> guard(
nullptr,[
this](
void const*) {
927 <<
"MemoryCheck: " << type <<
" "
928 << mdname <<
":" << mdlabel
929 <<
" VSIZE " <<
current_->vsize <<
" " << deltaVSIZE
930 <<
" RSS " <<
current_->rss <<
" " << deltaRSS;
933 struct mallinfo minfo = mallinfo();
936 <<
"MemoryCheck: " << type <<
" "
937 << mdname <<
":" << mdlabel
938 <<
" VSIZE " <<
current_->vsize <<
" " << deltaVSIZE
939 <<
" RSS " <<
current_->rss <<
" " << deltaRSS
941 <<
" HEAP-ARENA [ SIZE-BYTES " << minfo.arena
942 <<
" N-UNUSED-CHUNKS " << minfo.ordblks
943 <<
" TOP-FREE-BYTES " << minfo.keepcost <<
" ]"
944 <<
" HEAP-MAPPED [ SIZE-BYTES " << minfo.hblkhd
945 <<
" N-CHUNKS " << minfo.hblks <<
" ]"
946 <<
" HEAP-USED-BYTES " << minfo.uordblks
947 <<
" HEAP-UNUSED-BYTES " << minfo.fordblks
962 #ifdef SIMPLE_MEMORY_CHECK_ORIGINAL_XML_OUTPUT
966 std::map<std::string, std::string>&
m)
const {
967 { std::ostringstream os;
968 os << title <<
"-a-COUNT";
969 m.insert(std::make_pair(os.str(),
i2str(e.
count))); }
970 { std::ostringstream os;
971 os << title <<
"-b-RUN";
972 m.insert(std::make_pair(os.str(),
d2str(static_cast<double>(e.
event.
run())))); }
973 { std::ostringstream os;
974 os << title <<
"-c-EVENT";
975 m.insert(std::make_pair(os.str(),
d2str(static_cast<double>(e.
event.
event())))); }
976 { std::ostringstream os;
977 os << title <<
"-d-VSIZE";
978 m.insert(std::make_pair(os.str(),
d2str(e.
vsize))); }
979 { std::ostringstream os;
980 os << title <<
"-e-DELTV";
982 { std::ostringstream os;
983 os << title <<
"-f-RSS";
984 m.insert(std::make_pair(os.str(),
d2str(e.
rss))); }
986 { std::ostringstream os;
987 os << title <<
"-g-PRIVATE";
989 { std::ostringstream os;
990 os << title <<
"-h-PSS";
991 m.insert(std::make_pair(os.str(),
d2str(e.
pss))); }
996 #ifdef SIMPLE_MEMORY_CHECK_DIFFERENT_XML_OUTPUT
999 SignificantEvent
const&
e)
const {
1000 std::ostringstream os;
1001 os <<
" <" << title <<
">\n";
1002 os <<
" " << e.count <<
": " << e.event;
1003 os <<
" vsize " << e.vsize-e.deltaVsize <<
" + " << e.deltaVsize
1004 <<
" = " << e.vsize;
1005 os <<
" rss: " << e.rss <<
"\n";
1006 os <<
" </" << title <<
">\n";
1012 std::ostringstream os;
1013 os <<
" <" << title <<
">\n";
1014 os <<
" " << n <<
"\n";
1015 os <<
" </" << title <<
">\n";
1039 os <<
"[" << se.
count <<
"] "
1042 <<
" rss = " << se.
rss <<
" delta = " << se.
deltaRss;
1071 #if defined(__linux__)
void watchPostModuleConstruction(PostModuleConstruction::slot_type const &iSlot)
std::map< std::string, SignificantModule > SignificantModulesMap
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
tuple ret
prodAgent to be discontinued
void postFork(unsigned int, unsigned int)
SignificantEvent eventDeltaRssT1_
void preSourceConstruction(const ModuleDescription &)
void set_mmap_max(opt_type mmap_max)
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_
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 set(double deltaV, bool early)
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_
char *& smapsLineBuffer()
SignificantEvent eventRssT3_
edm::propagate_const< FILE * > smapsFile_
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
ModuleDescription const * moduleDescription() const
char const * smapsLineBuffer() const
std::shared_ptr< T > & get_underlying_safe(propagate_const< std::shared_ptr< T >> &iP)
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_
double deltaR(double eta1, double eta2, double phi1, double phi2)
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_
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
edm::propagate_const< char * > smapsLineBuffer_
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 operator>(const smapsInfo &p) const
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_