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  typedef MallocOpts::opt_type opt_type;
172 
173  opt_type
174  p_mmap_max = iPS.getUntrackedParameter<int>("M_MMAP_MAX"),
175  p_trim_thr = iPS.getUntrackedParameter<int>("M_TRIM_THRESHOLD"),
176  p_top_pad = iPS.getUntrackedParameter<int>("M_TOP_PAD"),
177  p_mmap_thr = iPS.getUntrackedParameter<int>("M_MMAP_THRESHOLD");
178 
179  if(p_mmap_max >= 0) mopts.set_mmap_max(p_mmap_max);
180  if(p_trim_thr >= 0) mopts.set_trim_thr(p_trim_thr);
181  if(p_top_pad >= 0) mopts.set_top_pad(p_top_pad);
182  if(p_mmap_thr >= 0) mopts.set_mmap_thr(p_mmap_thr);
183 
184  mopts.adjustMallocParams();
185 
186  if(mopts.hasErrors()) {
187  LogWarning("MemoryCheck")
188  << "ERROR: Problem with setting malloc options\n"
189  << mopts.error_message();
190  }
191 
192  if(iPS.getUntrackedParameter<bool>("dump") == true) {
193  MallocOpts mo = mopts.get();
194  LogWarning("MemoryCheck")
195  << "Malloc options: " << mo << "\n";
196  }
197  }
198 
200 #ifdef LINUX
201  if(0 != smapsFile_) {
202  fclose(smapsFile_);
203  }
204 #endif
205  if (smapsLineBuffer_) {
206  //getline will create the memory using malloc
207  free(smapsLineBuffer_);
208  }
209  }
210 
213  desc.addUntracked<int>("ignoreTotal", 1);
214  desc.addUntracked<bool>("showMallocInfo", false);
215  desc.addUntracked<bool>("oncePerEventMode", false);
216  desc.addUntracked<bool>("jobReportOutputOnly", false);
217  desc.addUntracked<bool>("monitorPssAndPrivate", false);
218  desc.addUntracked<bool>("moduleMemorySummary", false);
219  desc.addUntracked<int>("M_MMAP_MAX", -1);
220  desc.addUntracked<int>("M_TRIM_THRESHOLD", -1);
221  desc.addUntracked<int>("M_TOP_PAD", -1);
222  desc.addUntracked<int>("M_MMAP_THRESHOLD", -1);
223  desc.addUntracked<bool>("dump", false);
224  descriptions.add("SimpleMemoryCheck", desc);
225  }
226 
228 #ifdef LINUX
229  if (monitorPssAndPrivate_) {
230  std::ostringstream smapsNameOst;
231  smapsNameOst <<"/proc/"<<getpid()<<"/smaps";
232  if((smapsFile_ =fopen(smapsNameOst.str().c_str(), "r"))==0) {
233  throw Exception(errors::Configuration) <<"Failed to open smaps file "<<smapsNameOst.str()<<std::endl;
234  }
235  }
236 #endif
237  }
238 
242  }
243 
245  updateAndPrint("pre-ctor", md.moduleLabel(), md.moduleName());
246  }
247 
248 
250  updateAndPrint("ctor", md.moduleLabel(), md.moduleName());
251  }
252 
254  updateAndPrint("module", "source", "source");
255  }
256 
258  updateAndPrint("ctor", md.moduleLabel(), md.moduleName());
259  }
260 
262  updateAndPrint("beginJob", md.moduleLabel(), md.moduleName());
263  }
264 
266  if(not jobReportOutputOnly_) {
267  LogAbsolute("MemoryReport") // changelog 1
268  << "MemoryReport> Peak virtual size " << eventT1_.vsize << " Mbytes"
269  << "\n"
270  << " Key events increasing vsize: \n"
271  << eventL2_ << "\n"
272  << eventL1_ << "\n"
273  << eventM_ << "\n"
274  << eventR1_ << "\n"
275  << eventR2_ << "\n"
276  << eventT3_ << "\n"
277  << eventT2_ << "\n"
278  << eventT1_ ;
279  }
280  if(moduleSummaryRequested_ and not jobReportOutputOnly_) { // changelog 1
281  LogAbsolute mmr("ModuleMemoryReport"); // at end of if block, mmr
282  // is destructed, causing
283  // message to be logged
284  mmr << "ModuleMemoryReport> Each line has module label and: \n";
285  mmr << " (after early ignored events) \n";
286  mmr <<
287  " count of times module executed; average increase in vsize \n";
288  mmr <<
289  " maximum increase in vsize; event on which maximum occurred \n";
290  mmr << " (during early ignored events) \n";
291  mmr << " total and maximum vsize increases \n \n";
292  for(SignificantModulesMap::iterator im = modules_.begin();
293  im != modules_.end(); ++im) {
294  SignificantModule const& m = im->second;
295  if(m.totalDeltaVsize == 0 && m.totalEarlyVsize == 0) continue;
296  mmr << im->first << ": ";
297  mmr << "n = " << m.postEarlyCount;
298  if(m.postEarlyCount > 0) {
299  mmr << " avg = " << m.totalDeltaVsize/m.postEarlyCount;
300  }
301  mmr << " max = " << m.maxDeltaVsize << " " << m.eventMaxDeltaV;
302  if(m.totalEarlyVsize > 0) {
303  mmr << " early total: " << m.totalEarlyVsize;
304  mmr << " max: " << m.maxEarlyVsize;
305  }
306  mmr << "\n";
307  }
308  } // end of if; mmr goes out of scope; log message is queued
309 
310  Service<JobReport> reportSvc;
311  // changelog 1
312 #define SIMPLE_MEMORY_CHECK_ORIGINAL_XML_OUTPUT
313 #ifdef SIMPLE_MEMORY_CHECK_ORIGINAL_XML_OUTPUT
314 // std::map<std::string, double> reportData;
315  std::map<std::string, std::string> reportData;
316 
317  if(eventL2_.vsize > 0)
318  eventStatOutput("LargeVsizeIncreaseEventL2", eventL2_, reportData);
319  if(eventL1_.vsize > 0)
320  eventStatOutput("LargeVsizeIncreaseEventL1", eventL1_, reportData);
321  if(eventM_.vsize > 0)
322  eventStatOutput("LargestVsizeIncreaseEvent", eventM_, reportData);
323  if(eventR1_.vsize > 0)
324  eventStatOutput("LargeVsizeIncreaseEventR1", eventR1_, reportData);
325  if(eventR2_.vsize > 0)
326  eventStatOutput("LargeVsizeIncreaseEventR2", eventR2_, reportData);
327  if(eventT3_.vsize > 0)
328  eventStatOutput("ThirdLargestVsizeEventT3", eventT3_, reportData);
329  if(eventT2_.vsize > 0)
330  eventStatOutput("SecondLargestVsizeEventT2", eventT2_, reportData);
331  if(eventT1_.vsize > 0)
332  eventStatOutput("LargestVsizeEventT1", eventT1_, reportData);
333 
334  if(eventRssT3_.rss > 0)
335  eventStatOutput("ThirdLargestRssEvent", eventRssT3_, reportData);
336  if(eventRssT2_.rss > 0)
337  eventStatOutput("SecondLargestRssEvent", eventRssT2_, reportData);
338  if(eventRssT1_.rss > 0)
339  eventStatOutput("LargestRssEvent", eventRssT1_, reportData);
340  if(eventDeltaRssT3_.deltaRss > 0)
341  eventStatOutput("ThirdLargestIncreaseRssEvent", eventDeltaRssT3_, reportData);
342  if(eventDeltaRssT2_.deltaRss > 0)
343  eventStatOutput("SecondLargestIncreaseRssEvent", eventDeltaRssT2_, reportData);
344  if(eventDeltaRssT1_.deltaRss > 0)
345  eventStatOutput("LargestIncreaseRssEvent", eventDeltaRssT1_, reportData);
346 
347 #ifdef __linux__
348  struct mallinfo minfo = mallinfo();
349  reportData.insert(
350  std::make_pair("HEAP_ARENA_SIZE_BYTES", i2str(minfo.arena)));
351  reportData.insert(
352  std::make_pair("HEAP_ARENA_N_UNUSED_CHUNKS", i2str(minfo.ordblks)));
353  reportData.insert(
354  std::make_pair("HEAP_TOP_FREE_BYTES", i2str(minfo.keepcost)));
355  reportData.insert(
356  std::make_pair("HEAP_MAPPED_SIZE_BYTES", i2str(minfo.hblkhd)));
357  reportData.insert(
358  std::make_pair("HEAP_MAPPED_N_CHUNKS", i2str(minfo.hblks)));
359  reportData.insert(
360  std::make_pair("HEAP_USED_BYTES", i2str(minfo.uordblks)));
361  reportData.insert(
362  std::make_pair("HEAP_UNUSED_BYTES", i2str(minfo.fordblks)));
363 #endif
364 
365  // Report Growth rates for VSize and Rss
366  reportData.insert(
367  std::make_pair("AverageGrowthRateVsize", d2str(averageGrowthRate(current_->vsize, growthRateVsize_, count_))));
368  reportData.insert(
369  std::make_pair("PeakValueVsize", d2str(eventT1_.vsize)));
370  reportData.insert(
371  std::make_pair("AverageGrowthRateRss", d2str(averageGrowthRate(current_->rss, growthRateRss_, count_))));
372  reportData.insert(
373  std::make_pair("PeakValueRss", d2str(eventRssT1_.rss)));
374 
375  if(moduleSummaryRequested_) { // changelog 2
376  for(SignificantModulesMap::iterator im = modules_.begin();
377  im != modules_.end(); ++im) {
378  SignificantModule const& m = im->second;
379  if(m.totalDeltaVsize == 0 && m.totalEarlyVsize == 0) continue;
380  std::string label = im->first+":";
381  reportData.insert(std::make_pair(label+"PostEarlyCount", i2str(m.postEarlyCount)));
382  if(m.postEarlyCount > 0) {
383  reportData.insert(std::make_pair(label+"AverageDeltaVsize",
385  }
386  reportData.insert(std::make_pair(label+"MaxDeltaVsize", d2str(m.maxDeltaVsize)));
387  if(m.totalEarlyVsize > 0) {
388  reportData.insert(std::make_pair(label+"TotalEarlyVsize", d2str(m.totalEarlyVsize)));
389  reportData.insert(std::make_pair(label+"MaxEarlyDeltaVsize", d2str(m.maxEarlyVsize)));
390  }
391  }
392  }
393 
394  std::map<std::string, std::string> reportMemoryProperties;
395 
396  if(FILE* fmeminfo = fopen("/proc/meminfo", "r")) {
397  char buf[128];
398  char space[] = " ";
399  size_t value;
400 
401  while(fgets(buf, sizeof(buf), fmeminfo)) {
402  char* token = NULL;
403  token = strtok(buf, space);
404  if(token != NULL) {
405  value = atol(strtok(NULL, space));
406  std::string category = token;
407  reportMemoryProperties.insert(std::make_pair(category.substr(0, strlen(token)-1), i2str(value)));
408  }
409  }
410 
411  fclose(fmeminfo);
412  }
413 
414 // reportSvc->reportMemoryInfo(reportData, reportMemoryProperties);
415  reportSvc->reportPerformanceSummary("ApplicationMemory", reportData);
416  reportSvc->reportPerformanceSummary("SystemMemory", reportMemoryProperties);
417 #endif
418 
419 #ifdef SIMPLE_MEMORY_CHECK_DIFFERENT_XML_OUTPUT
420  std::vector<std::string> reportData;
421 
422  if(eventL2_.vsize > 0) reportData.push_back(
423  eventStatOutput("LargeVsizeIncreaseEventL2", eventL2_));
424  if(eventL1_.vsize > 0) reportData.push_back(
425  eventStatOutput("LargeVsizeIncreaseEventL1", eventL1_));
426  if(eventM_.vsize > 0) reportData.push_back(
427  eventStatOutput("LargestVsizeIncreaseEvent", eventM_));
428  if(eventR1_.vsize > 0) reportData.push_back(
429  eventStatOutput("LargeVsizeIncreaseEventR1", eventR1_));
430  if(eventR2_.vsize > 0) reportData.push_back(
431  eventStatOutput("LargeVsizeIncreaseEventR2", eventR2_));
432  if(eventT3_.vsize > 0) reportData.push_back(
433  eventStatOutput("ThirdLargestVsizeEventT3", eventT3_));
434  if(eventT2_.vsize > 0) reportData.push_back(
435  eventStatOutput("SecondLargestVsizeEventT2", eventT2_));
436  if(eventT1_.vsize > 0) reportData.push_back(
437  eventStatOutput("LargestVsizeEventT1", eventT1_));
438 
439  if(eventRssT3_.rss > 0)
440  eventStatOutput("ThirdLargestRssEvent", eventRssT3_, reportData);
441  if(eventRssT2_.rss > 0)
442  eventStatOutput("SecondLargestRssEvent", eventRssT2_, reportData);
443  if(eventRssT1_.rss > 0)
444  eventStatOutput("LargestRssEvent", eventRssT1_, reportData);
445  if(eventDeltaRssT3_.deltaRss > 0)
446  eventStatOutput("ThirdLargestIncreaseRssEvent", eventDeltaRssT3_, reportData);
447  if(eventDeltaRssT2_.deltaRss > 0)
448  eventStatOutput("SecondLargestIncreaseRssEvent", eventDeltaRssT2_, reportData);
449  if(eventDeltaRssT1_.deltaRss > 0)
450  eventStatOutput("LargestIncreaseRssEvent", eventDeltaRssT1_, reportData);
451 
452  struct mallinfo minfo = mallinfo();
453  reportData.push_back(
454  mallOutput("HEAP_ARENA_SIZE_BYTES", minfo.arena));
455  reportData.push_back(
456  mallOutput("HEAP_ARENA_N_UNUSED_CHUNKS", minfo.ordblks));
457  reportData.push_back(
458  mallOutput("HEAP_TOP_FREE_BYTES", minfo.keepcost));
459  reportData.push_back(
460  mallOutput("HEAP_MAPPED_SIZE_BYTES", minfo.hblkhd));
461  reportData.push_back(
462  mallOutput("HEAP_MAPPED_N_CHUNKS", minfo.hblks));
463  reportData.push_back(
464  mallOutput("HEAP_USED_BYTES", minfo.uordblks));
465  reportData.push_back(
466  mallOutput("HEAP_UNUSED_BYTES", minfo.fordblks));
467 
468  // Report Growth rates for VSize and Rss
469  reportData.insert(
470  std::make_pair("AverageGrowthRateVsize", d2str(averageGrowthRate(current_->vsize, growthRateVsize_, count_))));
471  reportData.insert(
472  std::make_pair("PeakValueVsize", d2str(eventT1_.vsize)));
473  reportData.insert(
474  std::make_pair("AverageGrowthRateRss", d2str(averageGrowthRate(current_->rss, growthRateRss_, count_))));
475  reportData.insert(
476  std::make_pair("PeakValueRss", d2str(eventRssT1_.rss)));
477 
478  reportSvc->reportMemoryInfo(reportData);
479  // This is a form of reportMemoryInfo taking s vector, not a map
480 #endif
481  } // postEndJob
482 
484  currentEventID_ = iID; // changelog 2
485  }
486 
488  ++count_;
489  update();
490  if (monitorPssAndPrivate_) {
492  }
493  updateEventStats(e.id());
494  if(oncePerEventMode_) {
495  // should probably use be Run:Event or count_ for the label and name
496  updateMax();
497  andPrint("event", "", "");
498  }
499  }
500 
502  update(); // changelog 2
504  }
505 
507  if(!oncePerEventMode_) {
508  updateAndPrint("module", md.moduleLabel(), md.moduleName());
509  } else if(moduleSummaryRequested_) { // changelog 2
510  update();
511  }
512  if(moduleSummaryRequested_) { // changelog 2
513  double dv = current_->vsize - moduleEntryVsize_;
514  std::string label = md.moduleLabel();
515  updateModuleMemoryStats (modules_[label], dv);
516  }
517  }
518 
519  void SimpleMemoryCheck::postFork(unsigned int, unsigned int) {
520 #ifdef LINUX
521  if(0 != smapsFile_) {
522  fclose(smapsFile_);
523  }
524  openFiles();
525 #endif
526  }
527 
530  *current_ = fetch();
531  }
532 
534  if((*current_ > max_) || oncePerEventMode_) {
535  if(count_ >= num_to_skip_) {
536  }
537  max_ = *current_;
538  }
539  }
540 
542  if(count_ < num_to_skip_) return;
543  if(count_ == num_to_skip_) {
544  eventT1_.set(0, 0, e, this);
545  eventM_.set (0, 0, e, this);
546  eventRssT1_.set(0, 0, e, this);
547  eventDeltaRssT1_.set(0, 0, e, this);
548  return;
549  }
550  double vsize = current_->vsize;
551  double deltaVsize = vsize - eventT1_.vsize;
552 
553  // Update significative events for Vsize
554  if(vsize > eventT1_.vsize) {
555  double deltaRss = current_->rss - eventT1_.rss;
556  eventT3_ = eventT2_;
557  eventT2_ = eventT1_;
558  eventT1_.set(deltaVsize, deltaRss, e, this);
559  } else if(vsize > eventT2_.vsize) {
560  double deltaRss = current_->rss - eventT1_.rss;
561  eventT3_ = eventT2_;
562  eventT2_.set(deltaVsize, deltaRss, e, this);
563  } else if(vsize > eventT3_.vsize) {
564  double deltaRss = current_->rss - eventT1_.rss;
565  eventT3_.set(deltaVsize, deltaRss, e, this);
566  }
567 
568  if(deltaVsize > eventM_.deltaVsize) {
569  double deltaRss = current_->rss - eventM_.rss;
571  eventL2_ = eventL1_;
572  } else {
573  eventL2_ = eventR1_;
574  }
575  eventL1_ = eventM_;
576  eventM_.set(deltaVsize, deltaRss, e, this);
579  } else if(deltaVsize > eventR1_.deltaVsize) {
580  double deltaRss = current_->rss - eventM_.rss;
581  eventR2_ = eventR1_;
582  eventR1_.set(deltaVsize, deltaRss, e, this);
583  } else if(deltaVsize > eventR2_.deltaVsize) {
584  double deltaRss = current_->rss - eventR1_.rss;
585  eventR2_.set(deltaVsize, deltaRss, e, this);
586  }
587 
588  // Update significative events for Rss
589  double rss = current_->rss;
590  double deltaRss = rss - eventRssT1_.rss;
591 
592  if(rss > eventRssT1_.rss) {
595  eventRssT1_.set(deltaVsize, deltaRss, e, this);
596  } else if(rss > eventRssT2_.rss) {
598  eventRssT2_.set(deltaVsize, deltaRss, e, this);
599  } else if(rss > eventRssT3_.rss) {
600  eventRssT3_.set(deltaVsize, deltaRss, e, this);
601  }
602  if(deltaRss > eventDeltaRssT1_.deltaRss) {
605  eventDeltaRssT1_.set(deltaVsize, deltaRss, e, this);
606  } else if(deltaRss > eventDeltaRssT2_.deltaRss) {
608  eventDeltaRssT2_.set(deltaVsize, deltaRss, e, this);
609  } else if(deltaRss > eventDeltaRssT3_.deltaRss) {
610  eventDeltaRssT3_.set(deltaVsize, deltaRss, e, this);
611  }
612  } // updateEventStats
613 
614  void SimpleMemoryCheck::andPrint(std::string const& type,
615  std::string const& mdlabel, std::string const& mdname) const {
616  if(not jobReportOutputOnly_ && ((*current_ > max_) || oncePerEventMode_)) {
617  if(count_ >= num_to_skip_) {
618  double deltaVSIZE = current_->vsize - max_.vsize;
619  double deltaRSS = current_->rss - max_.rss;
620  if(!showMallocInfo_) { // default
621  LogWarning("MemoryCheck")
622  << "MemoryCheck: " << type << " "
623  << mdname << ":" << mdlabel
624  << " VSIZE " << current_->vsize << " " << deltaVSIZE
625  << " RSS " << current_->rss << " " << deltaRSS
626  << "\n";
627  } else {
628 #ifdef __linux__
629  struct mallinfo minfo = mallinfo();
630 #endif
631  LogWarning("MemoryCheck")
632  << "MemoryCheck: " << type << " "
633  << mdname << ":" << mdlabel
634  << " VSIZE " << current_->vsize << " " << deltaVSIZE
635  << " RSS " << current_->rss << " " << deltaRSS
636 #ifdef __linux__
637  << " HEAP-ARENA [ SIZE-BYTES " << minfo.arena
638  << " N-UNUSED-CHUNKS " << minfo.ordblks
639  << " TOP-FREE-BYTES " << minfo.keepcost << " ]"
640  << " HEAP-MAPPED [ SIZE-BYTES " << minfo.hblkhd
641  << " N-CHUNKS " << minfo.hblks << " ]"
642  << " HEAP-USED-BYTES " << minfo.uordblks
643  << " HEAP-UNUSED-BYTES " << minfo.fordblks
644 #endif
645  << "\n";
646  }
647  }
648  }
649  }
650 
651  void SimpleMemoryCheck::updateAndPrint(std::string const& type,
652  std::string const& mdlabel, std::string const& mdname) {
653  update();
654  andPrint(type, mdlabel, mdname);
655  updateMax();
656  }
657 
658 #ifdef SIMPLE_MEMORY_CHECK_ORIGINAL_XML_OUTPUT
659  void
661  SignificantEvent const& e,
662  std::map<std::string, std::string>& m) const {
663  { std::ostringstream os;
664  os << title << "-a-COUNT";
665  m.insert(std::make_pair(os.str(), i2str(e.count))); }
666  { std::ostringstream os;
667  os << title << "-b-RUN";
668  m.insert(std::make_pair(os.str(), d2str(static_cast<double>(e.event.run())))); }
669  { std::ostringstream os;
670  os << title << "-c-EVENT";
671  m.insert(std::make_pair(os.str(), d2str(static_cast<double>(e.event.event())))); }
672  { std::ostringstream os;
673  os << title << "-d-VSIZE";
674  m.insert(std::make_pair(os.str(), d2str(e.vsize))); }
675  { std::ostringstream os;
676  os << title << "-e-DELTV";
677  m.insert(std::make_pair(os.str(), d2str(e.deltaVsize))); }
678  { std::ostringstream os;
679  os << title << "-f-RSS";
680  m.insert(std::make_pair(os.str(), d2str(e.rss))); }
681  if (monitorPssAndPrivate_) {
682  { std::ostringstream os;
683  os << title << "-g-PRIVATE";
684  m.insert(std::make_pair(os.str(), d2str(e.privateSize))); }
685  { std::ostringstream os;
686  os << title << "-h-PSS";
687  m.insert(std::make_pair(os.str(), d2str(e.pss))); }
688  }
689  } // eventStatOutput
690 #endif
691 
692 #ifdef SIMPLE_MEMORY_CHECK_DIFFERENT_XML_OUTPUT
693  std::string
695  SignificantEvent const& e) const {
696  std::ostringstream os;
697  os << " <" << title << ">\n";
698  os << " " << e.count << ": " << e.event;
699  os << " vsize " << e.vsize-e.deltaVsize << " + " << e.deltaVsize
700  << " = " << e.vsize;
701  os << " rss: " << e.rss << "\n";
702  os << " </" << title << ">\n";
703  return os.str();
704  } // eventStatOutput
705 
706  std::string
707  SimpleMemoryCheck::mallOutput(std::string title, size_t const& n) const {
708  std::ostringstream os;
709  os << " <" << title << ">\n";
710  os << " " << n << "\n";
711  os << " </" << title << ">\n";
712  return os.str();
713  }
714 #endif
715  // changelog 2
716  void
718  double dv) {
719  if(count_ < num_to_skip_) {
720  m.totalEarlyVsize += dv;
721  if(dv > m.maxEarlyVsize) m.maxEarlyVsize = dv;
722  } else {
723  ++m.postEarlyCount;
724  m.totalDeltaVsize += dv;
725  if(dv > m.maxDeltaVsize) {
726  m.maxDeltaVsize = dv;
728  }
729  }
730  } //updateModuleMemoryStats
731 
732  std::ostream&
733  operator<< (std::ostream& os,
735  os << "[" << se.count << "] "
736  << se.event << " vsize = " << se.vsize
737  << " deltaVsize = " << se.deltaVsize
738  << " rss = " << se.rss << " delta = " << se.deltaRss;
739 
740  if (se.monitorPssAndPrivate) {
741  os <<" private = "<<se.privateSize<<" pss = "<<se.pss;
742  }
743  return os;
744  }
745 
746  std::ostream&
747  operator<< (std::ostream& os,
749  if(sm.postEarlyCount > 0) {
750  os << "\nPost Early Events: TotalDeltaVsize: " << sm.totalDeltaVsize
751  << " (avg: " << sm.totalDeltaVsize/sm.postEarlyCount
752  << "; max: " << sm.maxDeltaVsize
753  << " during " << sm.eventMaxDeltaV << ")";
754  }
755  if(sm.totalEarlyVsize > 0) {
756  os << "\n Early Events: TotalDeltaVsize: " << sm.totalEarlyVsize
757  << " (max: " << sm.maxEarlyVsize << ")";
758  }
759 
760  return os;
761  }
762 
763  } // end namespace service
764 } // end namespace edm
765 
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:22
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:519
SignificantEvent eventDeltaRssT1_
Definition: Memory.h:193
void preSourceConstruction(const ModuleDescription &)
Definition: Memory.cc:244
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:541
ProcInfoFetcher piFetcher_
Definition: Memory.h:102
void postModule(const ModuleDescription &)
Definition: Memory.cc:506
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:614
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:501
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:487
void updateModuleMemoryStats(SignificantModule &m, double dv)
Definition: Memory.cc:717
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:651
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:249
SignificantEvent eventT2_
Definition: Memory.h:175
void postModuleBeginJob(const ModuleDescription &)
Definition: Memory.cc:261
double averageGrowthRate(double current, double past, int count)
Definition: Memory.cc:109
void preEventProcessing(const edm::EventID &, const edm::Timestamp &)
Definition: Memory.cc:483
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:257
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: Memory.cc:211
MallocOptionSetter & getGlobalOptionSetter()
Definition: MallocOpts.cc:217
void watchPostBeginJob(PostBeginJob::slot_type const &iSlot)
convenience function for attaching to signal