55 #include <boost/lexical_cast.hpp> 104 double averageGrowthRate(
double current,
double past,
int count);
158 monitorPssAndPrivate(
false),
164 vsize =
t->current_->vsize;
166 rss =
t->current_->rss;
168 monitorPssAndPrivate =
t->monitorPssAndPrivate_;
169 if (monitorPssAndPrivate) {
170 privateSize =
t->currentSmaps_.private_;
171 pss =
t->currentSmaps_.pss_;
242 void set(
double deltaV,
bool early);
278 std::ostringstream
t;
284 std::ostringstream
t;
296 fseek(smapsFile_, 0, SEEK_SET);
307 while ((read = getline(&smapsLineBuffer(), &smapsLineBufferLen_, smapsFile_)) != -1) {
310 if (0 == strncmp(
"Private_", smapsLineBuffer_, 8)) {
311 unsigned int value = atoi(smapsLineBuffer_ + 14);
314 }
else if (0 == strncmp(
"Pss:", smapsLineBuffer_, 4)) {
315 unsigned int value = atoi(smapsLineBuffer_ + 4);
317 ret.
pss_ +=
static_cast<double>(
value) / 1024.;
326 return (current - past) / (double)count;
334 pg_size_(sysconf(_SC_PAGESIZE))
336 num_to_skip_(iPS.getUntrackedParameter<
int>(
"ignoreTotal")),
337 showMallocInfo_(iPS.getUntrackedParameter<
bool>(
"showMallocInfo")),
338 oncePerEventMode_(iPS.getUntrackedParameter<
bool>(
"oncePerEventMode")),
339 jobReportOutputOnly_(iPS.getUntrackedParameter<
bool>(
"jobReportOutputOnly")),
340 monitorPssAndPrivate_(iPS.getUntrackedParameter<
bool>(
"monitorPssAndPrivate")),
344 smapsLineBufferLen_(0),
347 moduleSummaryRequested_(iPS.getUntrackedParameter<
bool>(
"moduleMemorySummary")),
348 measurementUnderway_(
false) {
351 std::ostringstream ost;
385 #ifndef __SANITIZE_ADDRESS__ 411 LogWarning(
"MemoryCheck") <<
"Malloc options: " << mo <<
"\n";
441 descriptions.
add(
"SimpleMemoryCheck", desc);
447 std::ostringstream smapsNameOst;
448 smapsNameOst <<
"/proc/" << getpid() <<
"/smaps";
449 if ((
smapsFile_ = fopen(smapsNameOst.str().c_str(),
"r")) ==
nullptr) {
462 bool expected =
false;
464 std::shared_ptr<void> guard(
465 nullptr, [
this](
void const*) {
measurementUnderway_.store(
false, std::memory_order_release); });
471 bool expected =
false;
473 std::shared_ptr<void> guard(
474 nullptr, [
this](
void const*) {
measurementUnderway_.store(
false, std::memory_order_release); });
480 bool expected =
false;
482 std::shared_ptr<void> guard(
483 nullptr, [
this](
void const*) {
measurementUnderway_.store(
false, std::memory_order_release); });
489 bool expected =
false;
491 std::shared_ptr<void> guard(
492 nullptr, [
this](
void const*) {
measurementUnderway_.store(
false, std::memory_order_release); });
498 bool expected =
false;
500 std::shared_ptr<void> guard(
501 nullptr, [
this](
void const*) {
measurementUnderway_.store(
false, std::memory_order_release); });
509 <<
"MemoryReport> Peak virtual size " <<
eventT1_.
vsize <<
" Mbytes" 511 <<
" Key events increasing vsize: \n" 525 mmr <<
"ModuleMemoryReport> Each line has module label and: \n";
526 mmr <<
" (after early ignored events) \n";
527 mmr <<
" count of times module executed; average increase in vsize \n";
528 mmr <<
" maximum increase in vsize; event on which maximum occurred \n";
529 mmr <<
" (during early ignored events) \n";
530 mmr <<
" total and maximum vsize increases \n \n";
531 for (SignificantModulesMap::iterator im =
modules_.begin(); im !=
modules_.end(); ++im) {
535 mmr << im->first <<
": ";
551 #define SIMPLE_MEMORY_CHECK_ORIGINAL_XML_OUTPUT 552 #ifdef SIMPLE_MEMORY_CHECK_ORIGINAL_XML_OUTPUT 554 std::map<std::string, std::string> reportData;
587 struct mallinfo minfo = mallinfo();
588 reportData.insert(std::make_pair(
"HEAP_ARENA_SIZE_BYTES",
i2str(minfo.arena)));
589 reportData.insert(std::make_pair(
"HEAP_ARENA_N_UNUSED_CHUNKS",
i2str(minfo.ordblks)));
590 reportData.insert(std::make_pair(
"HEAP_TOP_FREE_BYTES",
i2str(minfo.keepcost)));
591 reportData.insert(std::make_pair(
"HEAP_MAPPED_SIZE_BYTES",
i2str(minfo.hblkhd)));
592 reportData.insert(std::make_pair(
"HEAP_MAPPED_N_CHUNKS",
i2str(minfo.hblks)));
593 reportData.insert(std::make_pair(
"HEAP_USED_BYTES",
i2str(minfo.uordblks)));
594 reportData.insert(std::make_pair(
"HEAP_UNUSED_BYTES",
i2str(minfo.fordblks)));
598 reportData.insert(std::make_pair(
"AverageGrowthRateVsize",
606 for (SignificantModulesMap::iterator im =
modules_.begin(); im !=
modules_.end(); ++im) {
618 reportData.insert(std::make_pair(label +
"MaxEarlyDeltaVsize",
d2str(m.
maxEarlyVsize)));
623 std::map<std::string, std::string> reportMemoryProperties;
625 if (FILE* fmeminfo = fopen(
"/proc/meminfo",
"r")) {
629 while (fgets(buf,
sizeof(buf), fmeminfo)) {
631 char* token =
nullptr;
632 token = strtok_r(buf, space, &saveptr);
633 if (token !=
nullptr) {
634 value = atol(strtok_r(
nullptr, space, &saveptr));
636 reportMemoryProperties.insert(std::make_pair(category.substr(0, strlen(token) - 1),
i2str(value)));
644 reportSvc->reportPerformanceSummary(
"ApplicationMemory", reportData);
645 reportSvc->reportPerformanceSummary(
"SystemMemory", reportMemoryProperties);
648 #ifdef SIMPLE_MEMORY_CHECK_DIFFERENT_XML_OUTPUT 649 std::vector<std::string> reportData;
681 struct mallinfo minfo = mallinfo();
682 reportData.push_back(
mallOutput(
"HEAP_ARENA_SIZE_BYTES", minfo.arena));
683 reportData.push_back(
mallOutput(
"HEAP_ARENA_N_UNUSED_CHUNKS", minfo.ordblks));
684 reportData.push_back(
mallOutput(
"HEAP_TOP_FREE_BYTES", minfo.keepcost));
685 reportData.push_back(
mallOutput(
"HEAP_MAPPED_SIZE_BYTES", minfo.hblkhd));
686 reportData.push_back(
mallOutput(
"HEAP_MAPPED_N_CHUNKS", minfo.hblks));
687 reportData.push_back(
mallOutput(
"HEAP_USED_BYTES", minfo.uordblks));
688 reportData.push_back(
mallOutput(
"HEAP_UNUSED_BYTES", minfo.fordblks));
691 reportData.insert(std::make_pair(
"AverageGrowthRateVsize",
698 reportSvc->reportMemoryInfo(reportData);
705 bool expected =
false;
707 std::shared_ptr<void> guard(
708 nullptr, [
this](
void const*) {
measurementUnderway_.store(
false, std::memory_order_release); });
723 bool expected =
false;
725 std::shared_ptr<void> guard(
726 nullptr, [
this](
void const*) {
measurementUnderway_.store(
false, std::memory_order_release); });
727 bool expected =
false;
741 bool expected =
false;
743 std::shared_ptr<void> guard(
744 nullptr, [
this](
void const*) {
measurementUnderway_.store(
false, std::memory_order_release); });
756 std::shared_ptr<void> guard(
758 bool expected =
false;
760 std::shared_ptr<void> guard(
761 nullptr, [
this](
void const*) {
measurementUnderway_.store(
false, std::memory_order_release); });
869 LogWarning(
"MemoryCheck") <<
"MemoryCheck: " << type <<
" " << mdname <<
":" << mdlabel <<
" VSIZE " 874 struct mallinfo minfo = mallinfo();
876 LogWarning(
"MemoryCheck") <<
"MemoryCheck: " << type <<
" " << mdname <<
":" << mdlabel <<
" VSIZE " 880 <<
" HEAP-ARENA [ SIZE-BYTES " << minfo.arena <<
" N-UNUSED-CHUNKS " 881 << minfo.ordblks <<
" TOP-FREE-BYTES " << minfo.keepcost <<
" ]" 882 <<
" HEAP-MAPPED [ SIZE-BYTES " << minfo.hblkhd <<
" N-CHUNKS " << minfo.hblks
884 <<
" HEAP-USED-BYTES " << minfo.uordblks <<
" HEAP-UNUSED-BYTES " 901 #ifdef SIMPLE_MEMORY_CHECK_ORIGINAL_XML_OUTPUT 904 std::map<std::string, std::string>&
m)
const {
906 std::ostringstream os;
907 os << title <<
"-a-COUNT";
908 m.insert(std::make_pair(os.str(),
i2str(e.
count)));
911 std::ostringstream os;
912 os << title <<
"-b-RUN";
913 m.insert(std::make_pair(os.str(),
d2str(static_cast<double>(e.
event.
run()))));
916 std::ostringstream os;
917 os << title <<
"-c-EVENT";
918 m.insert(std::make_pair(os.str(),
d2str(static_cast<double>(e.
event.
event()))));
921 std::ostringstream os;
922 os << title <<
"-d-VSIZE";
923 m.insert(std::make_pair(os.str(),
d2str(e.
vsize)));
926 std::ostringstream os;
927 os << title <<
"-e-DELTV";
931 std::ostringstream os;
932 os << title <<
"-f-RSS";
933 m.insert(std::make_pair(os.str(),
d2str(e.
rss)));
937 std::ostringstream os;
938 os << title <<
"-g-PRIVATE";
942 std::ostringstream os;
943 os << title <<
"-h-PSS";
944 m.insert(std::make_pair(os.str(),
d2str(e.
pss)));
950 #ifdef SIMPLE_MEMORY_CHECK_DIFFERENT_XML_OUTPUT 952 std::ostringstream os;
953 os <<
" <" << title <<
">\n";
956 os <<
" rss: " << e.
rss <<
"\n";
957 os <<
" </" << title <<
">\n";
962 std::ostringstream os;
963 os <<
" <" << title <<
">\n";
964 os <<
" " << n <<
"\n";
965 os <<
" </" << title <<
">\n";
989 <<
" rss = " << se.
rss <<
" delta = " << se.
deltaRss;
1013 #if defined(__linux__)
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)
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 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_
std::map< std::string, SignificantModule > SignificantModulesMap
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)
#define DEFINE_FWK_SERVICE(type)
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_
smapsInfo(double private_sz, double pss_sz)
bool jobReportOutputOnly_
void updateAndPrint(const std::string &type, const std::string &mdlabel, const std::string &mdname)
bool operator==(const smapsInfo &p) const
unsigned int value() const
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
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_
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 &)
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 &)
std::pair< std::string, std::shared_ptr< void > > fetch(const cond::Hash &payloadId, Session &session)
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_