CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Memory.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: Services
4 // Class : Memory
5 //
6 // Implementation:
7 //
8 // Original Author: Jim Kowalkowski
9 //
10 // Change Log
11 //
12 // 1 - Apr 25, 2008 M. Fischler
13 // Collect event summary information and output to XML file and logger
14 // at the end of the job. Involves split-up of updateAndPrint method.
15 //
16 // 2 - May 7, 2008 M. Fischler
17 // Collect module summary information and output to XML file and logger
18 // at the end of the job.
19 //
20 // 3 - Jan 14, 2009 Natalia Garcia Nebot
21 // Added: - Average rate of growth in RSS and peak value attained.
22 // - Average rate of growth in VSize over time, Peak VSize
23 //
24 //
25 
27 
37 
38 #include <cstring>
39 #include <iostream>
40 #ifdef __linux__
41 #include <malloc.h>
42 #endif
43 #include <sstream>
44 //#include <stdio.h>
45 #include <string>
46 //#include <string.h>
47 #include <boost/lexical_cast.hpp>
48 
49 #ifdef __linux__
50 #define LINUX 1
51 #endif
52 
53 #include <fcntl.h>
54 #include <unistd.h>
55 
56 namespace edm {
57  namespace service {
58 
59  static std::string d2str(double d) {
60  std::ostringstream t;
61  t << d;
62  return t.str();
63  }
64 
65  static std::string i2str(int i) {
66  std::ostringstream t;
67  t << i;
68  return t.str();
69  }
70 
72  return piFetcher_.fetch();
73  }
74 
76  smapsInfo ret;
77  ret.private_ = 0;
78  ret.pss_ = 0;
79 #ifdef LINUX
80  fseek(smapsFile_, 0, SEEK_SET);
81  ssize_t read;
82 
83  /*
84  The format of the report is
85  Private_Clean: 0 kB
86  Private_Dirty: 72 kB
87  Swap: 0 kB
88  Pss: 72 kB
89  */
90 
91  while ((read = getline(&smapsLineBuffer_, &smapsLineBufferLen_, smapsFile_)) != -1) {
92  if(read > 14) {
93  //Private
94  if(0==strncmp("Private_",smapsLineBuffer_,8)) {
95  unsigned int value = atoi(smapsLineBuffer_+14);
96  //Convert from kB to MB
97  ret.private_ += static_cast<double>(value)/1024.;
98  } else if(0==strncmp("Pss:",smapsLineBuffer_,4)) {
99  unsigned int value = atoi(smapsLineBuffer_+4);
100  //Convert from kB to MB
101  ret.pss_ += static_cast<double>(value)/1024.;
102  }
103  }
104  }
105 #endif
106  return ret;
107  }
108 
109  double SimpleMemoryCheck::averageGrowthRate(double current, double past, int count) {
110  return(current-past)/(double)count;
111  }
112 
114  ActivityRegistry&iReg)
115  : a_()
116  , b_()
117  , current_(&a_)
118  , previous_(&b_)
119  , pg_size_(sysconf(_SC_PAGESIZE)) // getpagesize()
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"))
125  , count_()
126  , smapsFile_(0)
127  , smapsLineBuffer_(NULL)
128  , smapsLineBufferLen_(0)
129  , growthRateVsize_()
130  , growthRateRss_()
131  , moduleSummaryRequested_(iPS.getUntrackedParameter<bool>("moduleMemorySummary")) {
132  // changelog 2
133  // pg_size = (double)getpagesize();
134  std::ostringstream ost;
135 
136  openFiles();
138 
139  if(!oncePerEventMode_) { // default, prints on increases
149  } else {
152  }
153  if(moduleSummaryRequested_) { // changelog 2
156  if(oncePerEventMode_) {
158  }
159  }
160 
161  // The following are not currenty used/implemented below for either
162  // of the print modes (but are left here for reference)
163  // iReg.watchPostBeginJob(this,
164  // &SimpleMemoryCheck::postBeginJob);
165  // iReg.watchPreProcessEvent(this,
166  // &SimpleMemoryCheck::preEventProcessing);
167  // iReg.watchPreModule(this,
168  // &SimpleMemoryCheck::preModule);
169 
170 #ifndef __SANITIZE_ADDRESS__
171  typedef MallocOpts::opt_type opt_type;
173 
174  opt_type
175  p_mmap_max = iPS.getUntrackedParameter<int>("M_MMAP_MAX"),
176  p_trim_thr = iPS.getUntrackedParameter<int>("M_TRIM_THRESHOLD"),
177  p_top_pad = iPS.getUntrackedParameter<int>("M_TOP_PAD"),
178  p_mmap_thr = iPS.getUntrackedParameter<int>("M_MMAP_THRESHOLD");
179 
180  if(p_mmap_max >= 0) mopts.set_mmap_max(p_mmap_max);
181  if(p_trim_thr >= 0) mopts.set_trim_thr(p_trim_thr);
182  if(p_top_pad >= 0) mopts.set_top_pad(p_top_pad);
183  if(p_mmap_thr >= 0) mopts.set_mmap_thr(p_mmap_thr);
184 
185  mopts.adjustMallocParams();
186 
187  if(mopts.hasErrors()) {
188  LogWarning("MemoryCheck")
189  << "ERROR: Problem with setting malloc options\n"
190  << mopts.error_message();
191  }
192 
193  if(iPS.getUntrackedParameter<bool>("dump") == true) {
194  MallocOpts mo = mopts.get();
195  LogWarning("MemoryCheck")
196  << "Malloc options: " << mo << "\n";
197  }
198 #endif
199  }
200 
202 #ifdef LINUX
203  if(0 != smapsFile_) {
204  fclose(smapsFile_);
205  }
206 #endif
207  if (smapsLineBuffer_) {
208  //getline will create the memory using malloc
209  free(smapsLineBuffer_);
210  }
211  }
212 
215  desc.addUntracked<int>("ignoreTotal", 1);
216  desc.addUntracked<bool>("showMallocInfo", false);
217  desc.addUntracked<bool>("oncePerEventMode", false);
218  desc.addUntracked<bool>("jobReportOutputOnly", false);
219  desc.addUntracked<bool>("monitorPssAndPrivate", false);
220  desc.addUntracked<bool>("moduleMemorySummary", false);
221  desc.addUntracked<int>("M_MMAP_MAX", -1);
222  desc.addUntracked<int>("M_TRIM_THRESHOLD", -1);
223  desc.addUntracked<int>("M_TOP_PAD", -1);
224  desc.addUntracked<int>("M_MMAP_THRESHOLD", -1);
225  desc.addUntracked<bool>("dump", false);
226  descriptions.add("SimpleMemoryCheck", desc);
227  }
228 
230 #ifdef LINUX
231  if (monitorPssAndPrivate_) {
232  std::ostringstream smapsNameOst;
233  smapsNameOst <<"/proc/"<<getpid()<<"/smaps";
234  if((smapsFile_ =fopen(smapsNameOst.str().c_str(), "r"))==0) {
235  throw Exception(errors::Configuration) <<"Failed to open smaps file "<<smapsNameOst.str()<<std::endl;
236  }
237  }
238 #endif
239  }
240 
244  }
245 
247  updateAndPrint("pre-ctor", md.moduleLabel(), md.moduleName());
248  }
249 
250 
252  updateAndPrint("ctor", md.moduleLabel(), md.moduleName());
253  }
254 
256  updateAndPrint("module", "source", "source");
257  }
258 
260  updateAndPrint("ctor", md.moduleLabel(), md.moduleName());
261  }
262 
264  updateAndPrint("beginJob", md.moduleLabel(), md.moduleName());
265  }
266 
268  if(not jobReportOutputOnly_) {
269  LogAbsolute("MemoryReport") // changelog 1
270  << "MemoryReport> Peak virtual size " << eventT1_.vsize << " Mbytes"
271  << "\n"
272  << " Key events increasing vsize: \n"
273  << eventL2_ << "\n"
274  << eventL1_ << "\n"
275  << eventM_ << "\n"
276  << eventR1_ << "\n"
277  << eventR2_ << "\n"
278  << eventT3_ << "\n"
279  << eventT2_ << "\n"
280  << eventT1_ ;
281  }
282  if(moduleSummaryRequested_ and not jobReportOutputOnly_) { // changelog 1
283  LogAbsolute mmr("ModuleMemoryReport"); // at end of if block, mmr
284  // is destructed, causing
285  // message to be logged
286  mmr << "ModuleMemoryReport> Each line has module label and: \n";
287  mmr << " (after early ignored events) \n";
288  mmr <<
289  " count of times module executed; average increase in vsize \n";
290  mmr <<
291  " maximum increase in vsize; event on which maximum occurred \n";
292  mmr << " (during early ignored events) \n";
293  mmr << " total and maximum vsize increases \n \n";
294  for(SignificantModulesMap::iterator im = modules_.begin();
295  im != modules_.end(); ++im) {
296  SignificantModule const& m = im->second;
297  if(m.totalDeltaVsize == 0 && m.totalEarlyVsize == 0) continue;
298  mmr << im->first << ": ";
299  mmr << "n = " << m.postEarlyCount;
300  if(m.postEarlyCount > 0) {
301  mmr << " avg = " << m.totalDeltaVsize/m.postEarlyCount;
302  }
303  mmr << " max = " << m.maxDeltaVsize << " " << m.eventMaxDeltaV;
304  if(m.totalEarlyVsize > 0) {
305  mmr << " early total: " << m.totalEarlyVsize;
306  mmr << " max: " << m.maxEarlyVsize;
307  }
308  mmr << "\n";
309  }
310  } // end of if; mmr goes out of scope; log message is queued
311 
312  Service<JobReport> reportSvc;
313  // changelog 1
314 #define SIMPLE_MEMORY_CHECK_ORIGINAL_XML_OUTPUT
315 #ifdef SIMPLE_MEMORY_CHECK_ORIGINAL_XML_OUTPUT
316 // std::map<std::string, double> reportData;
317  std::map<std::string, std::string> reportData;
318 
319  if(eventL2_.vsize > 0)
320  eventStatOutput("LargeVsizeIncreaseEventL2", eventL2_, reportData);
321  if(eventL1_.vsize > 0)
322  eventStatOutput("LargeVsizeIncreaseEventL1", eventL1_, reportData);
323  if(eventM_.vsize > 0)
324  eventStatOutput("LargestVsizeIncreaseEvent", eventM_, reportData);
325  if(eventR1_.vsize > 0)
326  eventStatOutput("LargeVsizeIncreaseEventR1", eventR1_, reportData);
327  if(eventR2_.vsize > 0)
328  eventStatOutput("LargeVsizeIncreaseEventR2", eventR2_, reportData);
329  if(eventT3_.vsize > 0)
330  eventStatOutput("ThirdLargestVsizeEventT3", eventT3_, reportData);
331  if(eventT2_.vsize > 0)
332  eventStatOutput("SecondLargestVsizeEventT2", eventT2_, reportData);
333  if(eventT1_.vsize > 0)
334  eventStatOutput("LargestVsizeEventT1", eventT1_, reportData);
335 
336  if(eventRssT3_.rss > 0)
337  eventStatOutput("ThirdLargestRssEvent", eventRssT3_, reportData);
338  if(eventRssT2_.rss > 0)
339  eventStatOutput("SecondLargestRssEvent", eventRssT2_, reportData);
340  if(eventRssT1_.rss > 0)
341  eventStatOutput("LargestRssEvent", eventRssT1_, reportData);
342  if(eventDeltaRssT3_.deltaRss > 0)
343  eventStatOutput("ThirdLargestIncreaseRssEvent", eventDeltaRssT3_, reportData);
344  if(eventDeltaRssT2_.deltaRss > 0)
345  eventStatOutput("SecondLargestIncreaseRssEvent", eventDeltaRssT2_, reportData);
346  if(eventDeltaRssT1_.deltaRss > 0)
347  eventStatOutput("LargestIncreaseRssEvent", eventDeltaRssT1_, reportData);
348 
349 #ifdef __linux__
350  struct mallinfo minfo = mallinfo();
351  reportData.insert(
352  std::make_pair("HEAP_ARENA_SIZE_BYTES", i2str(minfo.arena)));
353  reportData.insert(
354  std::make_pair("HEAP_ARENA_N_UNUSED_CHUNKS", i2str(minfo.ordblks)));
355  reportData.insert(
356  std::make_pair("HEAP_TOP_FREE_BYTES", i2str(minfo.keepcost)));
357  reportData.insert(
358  std::make_pair("HEAP_MAPPED_SIZE_BYTES", i2str(minfo.hblkhd)));
359  reportData.insert(
360  std::make_pair("HEAP_MAPPED_N_CHUNKS", i2str(minfo.hblks)));
361  reportData.insert(
362  std::make_pair("HEAP_USED_BYTES", i2str(minfo.uordblks)));
363  reportData.insert(
364  std::make_pair("HEAP_UNUSED_BYTES", i2str(minfo.fordblks)));
365 #endif
366 
367  // Report Growth rates for VSize and Rss
368  reportData.insert(
369  std::make_pair("AverageGrowthRateVsize", d2str(averageGrowthRate(current_->vsize, growthRateVsize_, count_))));
370  reportData.insert(
371  std::make_pair("PeakValueVsize", d2str(eventT1_.vsize)));
372  reportData.insert(
373  std::make_pair("AverageGrowthRateRss", d2str(averageGrowthRate(current_->rss, growthRateRss_, count_))));
374  reportData.insert(
375  std::make_pair("PeakValueRss", d2str(eventRssT1_.rss)));
376 
377  if(moduleSummaryRequested_) { // changelog 2
378  for(SignificantModulesMap::iterator im = modules_.begin();
379  im != modules_.end(); ++im) {
380  SignificantModule const& m = im->second;
381  if(m.totalDeltaVsize == 0 && m.totalEarlyVsize == 0) continue;
382  std::string label = im->first+":";
383  reportData.insert(std::make_pair(label+"PostEarlyCount", i2str(m.postEarlyCount)));
384  if(m.postEarlyCount > 0) {
385  reportData.insert(std::make_pair(label+"AverageDeltaVsize",
387  }
388  reportData.insert(std::make_pair(label+"MaxDeltaVsize", d2str(m.maxDeltaVsize)));
389  if(m.totalEarlyVsize > 0) {
390  reportData.insert(std::make_pair(label+"TotalEarlyVsize", d2str(m.totalEarlyVsize)));
391  reportData.insert(std::make_pair(label+"MaxEarlyDeltaVsize", d2str(m.maxEarlyVsize)));
392  }
393  }
394  }
395 
396  std::map<std::string, std::string> reportMemoryProperties;
397 
398  if(FILE* fmeminfo = fopen("/proc/meminfo", "r")) {
399  char buf[128];
400  char space[] = " ";
401  size_t value;
402 
403  while(fgets(buf, sizeof(buf), fmeminfo)) {
404  char* token = NULL;
405  token = strtok(buf, space);
406  if(token != NULL) {
407  value = atol(strtok(NULL, space));
408  std::string category = token;
409  reportMemoryProperties.insert(std::make_pair(category.substr(0, strlen(token)-1), i2str(value)));
410  }
411  }
412 
413  fclose(fmeminfo);
414  }
415 
416 // reportSvc->reportMemoryInfo(reportData, reportMemoryProperties);
417  reportSvc->reportPerformanceSummary("ApplicationMemory", reportData);
418  reportSvc->reportPerformanceSummary("SystemMemory", reportMemoryProperties);
419 #endif
420 
421 #ifdef SIMPLE_MEMORY_CHECK_DIFFERENT_XML_OUTPUT
422  std::vector<std::string> reportData;
423 
424  if(eventL2_.vsize > 0) reportData.push_back(
425  eventStatOutput("LargeVsizeIncreaseEventL2", eventL2_));
426  if(eventL1_.vsize > 0) reportData.push_back(
427  eventStatOutput("LargeVsizeIncreaseEventL1", eventL1_));
428  if(eventM_.vsize > 0) reportData.push_back(
429  eventStatOutput("LargestVsizeIncreaseEvent", eventM_));
430  if(eventR1_.vsize > 0) reportData.push_back(
431  eventStatOutput("LargeVsizeIncreaseEventR1", eventR1_));
432  if(eventR2_.vsize > 0) reportData.push_back(
433  eventStatOutput("LargeVsizeIncreaseEventR2", eventR2_));
434  if(eventT3_.vsize > 0) reportData.push_back(
435  eventStatOutput("ThirdLargestVsizeEventT3", eventT3_));
436  if(eventT2_.vsize > 0) reportData.push_back(
437  eventStatOutput("SecondLargestVsizeEventT2", eventT2_));
438  if(eventT1_.vsize > 0) reportData.push_back(
439  eventStatOutput("LargestVsizeEventT1", eventT1_));
440 
441  if(eventRssT3_.rss > 0)
442  eventStatOutput("ThirdLargestRssEvent", eventRssT3_, reportData);
443  if(eventRssT2_.rss > 0)
444  eventStatOutput("SecondLargestRssEvent", eventRssT2_, reportData);
445  if(eventRssT1_.rss > 0)
446  eventStatOutput("LargestRssEvent", eventRssT1_, reportData);
447  if(eventDeltaRssT3_.deltaRss > 0)
448  eventStatOutput("ThirdLargestIncreaseRssEvent", eventDeltaRssT3_, reportData);
449  if(eventDeltaRssT2_.deltaRss > 0)
450  eventStatOutput("SecondLargestIncreaseRssEvent", eventDeltaRssT2_, reportData);
451  if(eventDeltaRssT1_.deltaRss > 0)
452  eventStatOutput("LargestIncreaseRssEvent", eventDeltaRssT1_, reportData);
453 
454  struct mallinfo minfo = mallinfo();
455  reportData.push_back(
456  mallOutput("HEAP_ARENA_SIZE_BYTES", minfo.arena));
457  reportData.push_back(
458  mallOutput("HEAP_ARENA_N_UNUSED_CHUNKS", minfo.ordblks));
459  reportData.push_back(
460  mallOutput("HEAP_TOP_FREE_BYTES", minfo.keepcost));
461  reportData.push_back(
462  mallOutput("HEAP_MAPPED_SIZE_BYTES", minfo.hblkhd));
463  reportData.push_back(
464  mallOutput("HEAP_MAPPED_N_CHUNKS", minfo.hblks));
465  reportData.push_back(
466  mallOutput("HEAP_USED_BYTES", minfo.uordblks));
467  reportData.push_back(
468  mallOutput("HEAP_UNUSED_BYTES", minfo.fordblks));
469 
470  // Report Growth rates for VSize and Rss
471  reportData.insert(
472  std::make_pair("AverageGrowthRateVsize", d2str(averageGrowthRate(current_->vsize, growthRateVsize_, count_))));
473  reportData.insert(
474  std::make_pair("PeakValueVsize", d2str(eventT1_.vsize)));
475  reportData.insert(
476  std::make_pair("AverageGrowthRateRss", d2str(averageGrowthRate(current_->rss, growthRateRss_, count_))));
477  reportData.insert(
478  std::make_pair("PeakValueRss", d2str(eventRssT1_.rss)));
479 
480  reportSvc->reportMemoryInfo(reportData);
481  // This is a form of reportMemoryInfo taking s vector, not a map
482 #endif
483  } // postEndJob
484 
486  currentEventID_ = iID; // changelog 2
487  }
488 
490  ++count_;
491  update();
492  if (monitorPssAndPrivate_) {
494  }
495  updateEventStats(e.id());
496  if(oncePerEventMode_) {
497  // should probably use be Run:Event or count_ for the label and name
498  updateMax();
499  andPrint("event", "", "");
500  }
501  }
502 
504  update(); // changelog 2
506  }
507 
509  if(!oncePerEventMode_) {
510  updateAndPrint("module", md.moduleLabel(), md.moduleName());
511  } else if(moduleSummaryRequested_) { // changelog 2
512  update();
513  }
514  if(moduleSummaryRequested_) { // changelog 2
515  double dv = current_->vsize - moduleEntryVsize_;
517  updateModuleMemoryStats (modules_[label], dv);
518  }
519  }
520 
521  void SimpleMemoryCheck::postFork(unsigned int, unsigned int) {
522 #ifdef LINUX
523  if(0 != smapsFile_) {
524  fclose(smapsFile_);
525  }
526  openFiles();
527 #endif
528  }
529 
532  *current_ = fetch();
533  }
534 
536  if((*current_ > max_) || oncePerEventMode_) {
537  if(count_ >= num_to_skip_) {
538  }
539  max_ = *current_;
540  }
541  }
542 
544  if(count_ < num_to_skip_) return;
545  if(count_ == num_to_skip_) {
546  eventT1_.set(0, 0, e, this);
547  eventM_.set (0, 0, e, this);
548  eventRssT1_.set(0, 0, e, this);
549  eventDeltaRssT1_.set(0, 0, e, this);
550  return;
551  }
552  double vsize = current_->vsize;
553  double deltaVsize = vsize - eventT1_.vsize;
554 
555  // Update significative events for Vsize
556  if(vsize > eventT1_.vsize) {
557  double deltaRss = current_->rss - eventT1_.rss;
558  eventT3_ = eventT2_;
559  eventT2_ = eventT1_;
560  eventT1_.set(deltaVsize, deltaRss, e, this);
561  } else if(vsize > eventT2_.vsize) {
562  double deltaRss = current_->rss - eventT1_.rss;
563  eventT3_ = eventT2_;
564  eventT2_.set(deltaVsize, deltaRss, e, this);
565  } else if(vsize > eventT3_.vsize) {
566  double deltaRss = current_->rss - eventT1_.rss;
567  eventT3_.set(deltaVsize, deltaRss, e, this);
568  }
569 
570  if(deltaVsize > eventM_.deltaVsize) {
571  double deltaRss = current_->rss - eventM_.rss;
573  eventL2_ = eventL1_;
574  } else {
575  eventL2_ = eventR1_;
576  }
577  eventL1_ = eventM_;
578  eventM_.set(deltaVsize, deltaRss, e, this);
581  } else if(deltaVsize > eventR1_.deltaVsize) {
582  double deltaRss = current_->rss - eventM_.rss;
583  eventR2_ = eventR1_;
584  eventR1_.set(deltaVsize, deltaRss, e, this);
585  } else if(deltaVsize > eventR2_.deltaVsize) {
586  double deltaRss = current_->rss - eventR1_.rss;
587  eventR2_.set(deltaVsize, deltaRss, e, this);
588  }
589 
590  // Update significative events for Rss
591  double rss = current_->rss;
592  double deltaRss = rss - eventRssT1_.rss;
593 
594  if(rss > eventRssT1_.rss) {
597  eventRssT1_.set(deltaVsize, deltaRss, e, this);
598  } else if(rss > eventRssT2_.rss) {
600  eventRssT2_.set(deltaVsize, deltaRss, e, this);
601  } else if(rss > eventRssT3_.rss) {
602  eventRssT3_.set(deltaVsize, deltaRss, e, this);
603  }
604  if(deltaRss > eventDeltaRssT1_.deltaRss) {
607  eventDeltaRssT1_.set(deltaVsize, deltaRss, e, this);
608  } else if(deltaRss > eventDeltaRssT2_.deltaRss) {
610  eventDeltaRssT2_.set(deltaVsize, deltaRss, e, this);
611  } else if(deltaRss > eventDeltaRssT3_.deltaRss) {
612  eventDeltaRssT3_.set(deltaVsize, deltaRss, e, this);
613  }
614  } // updateEventStats
615 
617  std::string const& mdlabel, std::string const& mdname) const {
618  if(not jobReportOutputOnly_ && ((*current_ > max_) || oncePerEventMode_)) {
619  if(count_ >= num_to_skip_) {
620  double deltaVSIZE = current_->vsize - max_.vsize;
621  double deltaRSS = current_->rss - max_.rss;
622  if(!showMallocInfo_) { // default
623  LogWarning("MemoryCheck")
624  << "MemoryCheck: " << type << " "
625  << mdname << ":" << mdlabel
626  << " VSIZE " << current_->vsize << " " << deltaVSIZE
627  << " RSS " << current_->rss << " " << deltaRSS
628  << "\n";
629  } else {
630 #ifdef __linux__
631  struct mallinfo minfo = mallinfo();
632 #endif
633  LogWarning("MemoryCheck")
634  << "MemoryCheck: " << type << " "
635  << mdname << ":" << mdlabel
636  << " VSIZE " << current_->vsize << " " << deltaVSIZE
637  << " RSS " << current_->rss << " " << deltaRSS
638 #ifdef __linux__
639  << " HEAP-ARENA [ SIZE-BYTES " << minfo.arena
640  << " N-UNUSED-CHUNKS " << minfo.ordblks
641  << " TOP-FREE-BYTES " << minfo.keepcost << " ]"
642  << " HEAP-MAPPED [ SIZE-BYTES " << minfo.hblkhd
643  << " N-CHUNKS " << minfo.hblks << " ]"
644  << " HEAP-USED-BYTES " << minfo.uordblks
645  << " HEAP-UNUSED-BYTES " << minfo.fordblks
646 #endif
647  << "\n";
648  }
649  }
650  }
651  }
652 
654  std::string const& mdlabel, std::string const& mdname) {
655  update();
656  andPrint(type, mdlabel, mdname);
657  updateMax();
658  }
659 
660 #ifdef SIMPLE_MEMORY_CHECK_ORIGINAL_XML_OUTPUT
661  void
663  SignificantEvent const& e,
664  std::map<std::string, std::string>& m) const {
665  { std::ostringstream os;
666  os << title << "-a-COUNT";
667  m.insert(std::make_pair(os.str(), i2str(e.count))); }
668  { std::ostringstream os;
669  os << title << "-b-RUN";
670  m.insert(std::make_pair(os.str(), d2str(static_cast<double>(e.event.run())))); }
671  { std::ostringstream os;
672  os << title << "-c-EVENT";
673  m.insert(std::make_pair(os.str(), d2str(static_cast<double>(e.event.event())))); }
674  { std::ostringstream os;
675  os << title << "-d-VSIZE";
676  m.insert(std::make_pair(os.str(), d2str(e.vsize))); }
677  { std::ostringstream os;
678  os << title << "-e-DELTV";
679  m.insert(std::make_pair(os.str(), d2str(e.deltaVsize))); }
680  { std::ostringstream os;
681  os << title << "-f-RSS";
682  m.insert(std::make_pair(os.str(), d2str(e.rss))); }
683  if (monitorPssAndPrivate_) {
684  { std::ostringstream os;
685  os << title << "-g-PRIVATE";
686  m.insert(std::make_pair(os.str(), d2str(e.privateSize))); }
687  { std::ostringstream os;
688  os << title << "-h-PSS";
689  m.insert(std::make_pair(os.str(), d2str(e.pss))); }
690  }
691  } // eventStatOutput
692 #endif
693 
694 #ifdef SIMPLE_MEMORY_CHECK_DIFFERENT_XML_OUTPUT
697  SignificantEvent const& e) const {
698  std::ostringstream os;
699  os << " <" << title << ">\n";
700  os << " " << e.count << ": " << e.event;
701  os << " vsize " << e.vsize-e.deltaVsize << " + " << e.deltaVsize
702  << " = " << e.vsize;
703  os << " rss: " << e.rss << "\n";
704  os << " </" << title << ">\n";
705  return os.str();
706  } // eventStatOutput
707 
709  SimpleMemoryCheck::mallOutput(std::string title, size_t const& n) const {
710  std::ostringstream os;
711  os << " <" << title << ">\n";
712  os << " " << n << "\n";
713  os << " </" << title << ">\n";
714  return os.str();
715  }
716 #endif
717  // changelog 2
718  void
720  double dv) {
721  if(count_ < num_to_skip_) {
722  m.totalEarlyVsize += dv;
723  if(dv > m.maxEarlyVsize) m.maxEarlyVsize = dv;
724  } else {
725  ++m.postEarlyCount;
726  m.totalDeltaVsize += dv;
727  if(dv > m.maxDeltaVsize) {
728  m.maxDeltaVsize = dv;
730  }
731  }
732  } //updateModuleMemoryStats
733 
734  std::ostream&
735  operator<< (std::ostream& os,
737  os << "[" << se.count << "] "
738  << se.event << " vsize = " << se.vsize
739  << " deltaVsize = " << se.deltaVsize
740  << " rss = " << se.rss << " delta = " << se.deltaRss;
741 
742  if (se.monitorPssAndPrivate) {
743  os <<" private = "<<se.privateSize<<" pss = "<<se.pss;
744  }
745  return os;
746  }
747 
748  std::ostream&
749  operator<< (std::ostream& os,
751  if(sm.postEarlyCount > 0) {
752  os << "\nPost Early Events: TotalDeltaVsize: " << sm.totalDeltaVsize
753  << " (avg: " << sm.totalDeltaVsize/sm.postEarlyCount
754  << "; max: " << sm.maxDeltaVsize
755  << " during " << sm.eventMaxDeltaV << ")";
756  }
757  if(sm.totalEarlyVsize > 0) {
758  os << "\n Early Events: TotalDeltaVsize: " << sm.totalEarlyVsize
759  << " (max: " << sm.maxEarlyVsize << ")";
760  }
761 
762  return os;
763  }
764 
765  } // end namespace service
766 } // end namespace edm
767 
RunNumber_t run() const
Definition: EventID.h:42
void watchPostModuleConstruction(PostModuleConstruction::slot_type const &iSlot)
MallocOpts get() const
Definition: MallocOpts.h:85
type
Definition: HCALResponse.h:21
EventNumber_t event() const
Definition: EventID.h:44
T getUntrackedParameter(std::string const &, T const &) const
void set_trim_thr(opt_type trim_thr)
Definition: MallocOpts.h:78
static std::string i2str(int i)
Definition: Memory.cc:65
int i
Definition: DBlmapReader.cc:9
std::string eventStatOutput(std::string title, SignificantEvent const &e) const
void postFork(unsigned int, unsigned int)
Definition: Memory.cc:521
SignificantEvent eventDeltaRssT1_
Definition: Memory.h:193
void preSourceConstruction(const ModuleDescription &)
Definition: Memory.cc:246
void set_mmap_max(opt_type mmap_max)
Definition: MallocOpts.h:76
bool hasErrors() const
Definition: MallocOpts.h:73
edm::EventID currentEventID_
Definition: Memory.h:229
ParameterDescriptionBase * addUntracked(U const &iLabel, T const &value)
void watchPostEndJob(PostEndJob::slot_type const &iSlot)
SignificantEvent eventM_
Definition: Memory.h:169
SignificantEvent eventT1_
Definition: Memory.h:174
void set_mmap_thr(opt_type mmap_thr)
Definition: MallocOpts.h:82
void updateEventStats(edm::EventID const &e)
Definition: Memory.cc:543
ProcInfoFetcher piFetcher_
Definition: Memory.h:102
void postModule(const ModuleDescription &)
Definition: Memory.cc:508
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_
Definition: Memory.h:191
SignificantEvent eventL1_
Definition: Memory.h:170
std::string const & moduleName() const
#define NULL
Definition: scimark2.h:8
SignificantEvent eventT3_
Definition: Memory.h:176
std::string const & moduleLabel() const
void andPrint(const std::string &type, const std::string &mdlabel, const std::string &mdname) const
Definition: Memory.cc:616
void watchPreModule(PreModule::slot_type const &iSlot)
SignificantEvent eventRssT3_
Definition: Memory.h:192
void watchPostProcessEvent(PostProcessEvent::slot_type const &iSlot)
void preModule(const ModuleDescription &)
Definition: Memory.cc:503
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
friend struct SignificantEvent
Definition: Memory.h:150
void set(double deltaV, double deltaR, edm::EventID const &e, SimpleMemoryCheck *t)
Definition: Memory.h:135
void postEventProcessing(const Event &, const EventSetup &)
Definition: Memory.cc:489
void updateModuleMemoryStats(SignificantModule &m, double dv)
Definition: Memory.cc:719
ErrorLog & operator<<(ErrorLog &e, const T &t)
SignificantEvent eventR1_
Definition: Memory.h:172
SignificantEvent eventDeltaRssT3_
Definition: Memory.h:195
void updateAndPrint(const std::string &type, const std::string &mdlabel, const std::string &mdname)
Definition: Memory.cc:653
SignificantEvent eventR2_
Definition: Memory.h:173
static std::string d2str(double d)
Definition: Memory.cc:59
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
Definition: MallocOpts.h:74
SignificantEvent eventL2_
Definition: Memory.h:171
edm::EventID id() const
Definition: EventBase.h:56
SignificantEvent eventDeltaRssT2_
Definition: Memory.h:194
std::string mallOutput(std::string title, size_t const &n) const
void watchPostModuleBeginJob(PostModuleBeginJob::slot_type const &iSlot)
void postSourceConstruction(const ModuleDescription &)
Definition: Memory.cc:251
SignificantEvent eventT2_
Definition: Memory.h:175
void postModuleBeginJob(const ModuleDescription &)
Definition: Memory.cc:263
double averageGrowthRate(double current, double past, int count)
Definition: Memory.cc:109
void preEventProcessing(const edm::EventID &, const edm::Timestamp &)
Definition: Memory.cc:485
void set_top_pad(opt_type top_pad)
Definition: MallocOpts.h:80
SimpleMemoryCheck(const ParameterSet &, ActivityRegistry &)
Definition: Memory.cc:113
SignificantModulesMap modules_
Definition: Memory.h:227
SignificantEvent eventRssT1_
Definition: Memory.h:190
void postModuleConstruction(const ModuleDescription &)
Definition: Memory.cc:259
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: Memory.cc:213
MallocOptionSetter & getGlobalOptionSetter()
Definition: MallocOpts.cc:219
void watchPostBeginJob(PostBeginJob::slot_type const &iSlot)
convenience function for attaching to signal