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 
36 
37 #ifdef __linux__
38 #include <malloc.h>
39 #endif
40 #include <sstream>
41 #include <iostream>
42 #include <string>
43 #include <stdio.h>
44 #include <string.h>
45 #include <cstring>
46 
47 #ifdef __linux__
48 #define LINUX 1
49 #endif
50 
51 #include <unistd.h>
52 #include <fcntl.h>
53 
54 namespace edm {
55  namespace service {
56 
57  static std::string d2str(double d){
58  std::ostringstream t;
59  t << d;
60  return t.str();
61  }
62 
63  static std::string i2str(int i){
64  std::ostringstream t;
65  t << i;
66  return t.str();
67  }
68 
69  struct linux_proc {
70  int pid; // %d
71  char comm[400]; // %s
72  char state; // %c
73  int ppid; // %d
74  int pgrp; // %d
75  int session; // %d
76  int tty; // %d
77  int tpgid; // %d
78  unsigned int flags; // %u
79  unsigned int minflt; // %u
80  unsigned int cminflt; // %u
81  unsigned int majflt; // %u
82  unsigned int cmajflt; // %u
83  int utime; // %d
84  int stime; // %d
85  int cutime; // %d
86  int cstime; // %d
87  int counter; // %d
88  int priority; // %d
89  unsigned int timeout; // %u
90  unsigned int itrealvalue; // %u
91  int starttime; // %d
92  unsigned int vsize; // %u
93  unsigned int rss; // %u
94  unsigned int rlim; // %u
95  unsigned int startcode; // %u
96  unsigned int endcode; // %u
97  unsigned int startstack; // %u
98  unsigned int kstkesp; // %u
99  unsigned int kstkeip; // %u
100  int signal; // %d
101  int blocked; // %d
102  int sigignore; // %d
103  int sigcatch; // %d
104  unsigned int wchan; // %u
105  };
106 
108  {
109  procInfo ret;
110  double pr_size=0.0, pr_rssize=0.0;
111 
112 #ifdef LINUX
113  linux_proc pinfo;
114  int cnt;
115 
116  lseek(fd_,0,SEEK_SET);
117 
118  if((cnt=read(fd_,buf_,sizeof(buf_)))<0)
119  {
120  perror("Read of Proc file failed:");
121  return procInfo();
122  }
123 
124  if(cnt>0)
125  {
126  buf_[cnt]='\0';
127 
128  sscanf(buf_,
129  "%d %s %c %d %d %d %d %d %u %u %u %u %u %d %d %d %d %d %d %u %u %d %u %u %u %u %u %u %u %u %d %d %d %d %u",
130  &pinfo.pid, // %d
131  pinfo.comm, // %s
132  &pinfo.state, // %c
133  &pinfo.ppid, // %d
134  &pinfo.pgrp, // %d
135  &pinfo.session, // %d
136  &pinfo.tty, // %d
137  &pinfo.tpgid, // %d
138  &pinfo.flags, // %u
139  &pinfo.minflt, // %u
140  &pinfo.cminflt, // %u
141  &pinfo.majflt, // %u
142  &pinfo.cmajflt, // %u
143  &pinfo.utime, // %d
144  &pinfo.stime, // %d
145  &pinfo.cutime, // %d
146  &pinfo.cstime, // %d
147  &pinfo.counter, // %d
148  &pinfo.priority, // %d
149  &pinfo.timeout, // %u
150  &pinfo.itrealvalue, // %u
151  &pinfo.starttime, // %d
152  &pinfo.vsize, // %u
153  &pinfo.rss, // %u
154  &pinfo.rlim, // %u
155  &pinfo.startcode, // %u
156  &pinfo.endcode, // %u
157  &pinfo.startstack, // %u
158  &pinfo.kstkesp, // %u
159  &pinfo.kstkeip, // %u
160  &pinfo.signal, // %d
161  &pinfo.blocked, // %d
162  &pinfo.sigignore, // %d
163  &pinfo.sigcatch, // %d
164  &pinfo.wchan // %u
165  );
166 
167  // resident set size in pages
168  pr_size = (double)pinfo.vsize;
169  pr_rssize = (double)pinfo.rss;
170 
171  ret.vsize = pr_size / (1024.0*1024.0);
172  ret.rss = (pr_rssize * pg_size_) / (1024.0*1024.0);
173  }
174 #else
175  ret.vsize=0;
176  ret.rss=0;
177 #endif
178  return ret;
179  }
180 
181 
182  double SimpleMemoryCheck::averageGrowthRate(double current, double past, int count) {
183  return (current-past)/(double)count;
184  }
185 
187  ActivityRegistry&iReg)
188  : a_()
189  , b_()
190  , current_(&a_)
191  , previous_(&b_)
192  , pg_size_(sysconf(_SC_PAGESIZE)) // getpagesize()
193  , num_to_skip_(iPS.getUntrackedParameter<int>("ignoreTotal"))
194  , showMallocInfo_(iPS.getUntrackedParameter<bool>("showMallocInfo"))
195  , oncePerEventMode_
196  (iPS.getUntrackedParameter<bool>("oncePerEventMode"))
197  , jobReportOutputOnly_(iPS.getUntrackedParameter<bool>("jobReportOutputOnly"))
198  , count_()
199  , growthRateVsize_()
200  , growthRateRss_()
201  , moduleSummaryRequested_
202  (iPS.getUntrackedParameter<bool>("moduleMemorySummary"))
203  // changelog 2
204  {
205  // pg_size = (double)getpagesize();
206  std::ostringstream ost;
207 
208 #ifdef LINUX
209  ost << "/proc/" << getpid() << "/stat";
210  fname_ = ost.str();
211 
212  if((fd_=open(ost.str().c_str(),O_RDONLY))<0)
213  {
215  << "Memory checker server: Failed to open " << ost.str() << std::endl;
216  }
217 #endif
218  if (!oncePerEventMode_) { // default, prints on increases
219  iReg.watchPreSourceConstruction(this,
221  iReg.watchPostSourceConstruction(this,
223  iReg.watchPostSource(this,
225  iReg.watchPostModuleConstruction(this,
227  iReg.watchPostModuleBeginJob(this,
229  iReg.watchPostProcessEvent(this,
231  iReg.watchPostModule(this,
233  iReg.watchPostBeginJob(this,
235  iReg.watchPostEndJob(this,
237  } else {
238  iReg.watchPostProcessEvent(this,
240  iReg.watchPostEndJob(this,
242  }
243  if (moduleSummaryRequested_) { // changelog 2
244  iReg.watchPreProcessEvent(this,
246  iReg.watchPreModule(this,
248  if (oncePerEventMode_) {
249  iReg.watchPostModule(this,
251  }
252  }
253 
254  // The following are not currenty used/implemented below for either
255  // of the print modes (but are left here for reference)
256  // iReg.watchPostBeginJob(this,
257  // &SimpleMemoryCheck::postBeginJob);
258  // iReg.watchPreProcessEvent(this,
259  // &SimpleMemoryCheck::preEventProcessing);
260  // iReg.watchPreModule(this,
261  // &SimpleMemoryCheck::preModule);
262 
263  typedef edm::MallocOpts::opt_type opt_type;
265 
266  opt_type
267  p_mmap_max=iPS.getUntrackedParameter<int>("M_MMAP_MAX"),
268  p_trim_thr=iPS.getUntrackedParameter<int>("M_TRIM_THRESHOLD"),
269  p_top_pad=iPS.getUntrackedParameter<int>("M_TOP_PAD"),
270  p_mmap_thr=iPS.getUntrackedParameter<int>("M_MMAP_THRESHOLD");
271 
272  if(p_mmap_max>=0) mopts.set_mmap_max(p_mmap_max);
273  if(p_trim_thr>=0) mopts.set_trim_thr(p_trim_thr);
274  if(p_top_pad>=0) mopts.set_top_pad(p_top_pad);
275  if(p_mmap_thr>=0) mopts.set_mmap_thr(p_mmap_thr);
276 
277  mopts.adjustMallocParams();
278 
279  if(mopts.hasErrors())
280  {
281  LogWarning("MemoryCheck")
282  << "ERROR: Problem with setting malloc options\n"
283  << mopts.error_message();
284  }
285 
286  if(iPS.getUntrackedParameter<bool>("dump")==true)
287  {
288  edm::MallocOpts mo = mopts.get();
289  LogWarning("MemoryCheck")
290  << "Malloc options: " << mo << "\n";
291  }
292  }
293 
295  {
296 #ifdef LINUX
297  close(fd_);
298 #endif
299  }
300 
303  desc.addUntracked<int>("ignoreTotal",1);
304  desc.addUntracked<bool>("showMallocInfo",false);
305  desc.addUntracked<bool>("oncePerEventMode",false);
306  desc.addUntracked<bool>("jobReportOutputOnly",false);
307  desc.addUntracked<bool>("moduleMemorySummary",false);
308  desc.addUntracked<int>("M_MMAP_MAX",-1);
309  desc.addUntracked<int>("M_TRIM_THRESHOLD",-1);
310  desc.addUntracked<int>("M_TOP_PAD",-1);
311  desc.addUntracked<int>("M_MMAP_THRESHOLD",-1);
312  desc.addUntracked<bool>("dump",false);
313  descriptions.add("SimpleMemoryCheck", desc);
314  }
315 
317  {
320  }
321 
323  {
324  updateAndPrint("pre-ctor", md.moduleLabel(), md.moduleName());
325  }
326 
327 
329  {
330  updateAndPrint("ctor", md.moduleLabel(), md.moduleName());
331  }
332 
334  {
335  updateAndPrint("module", "source", "source");
336  }
337 
339  {
340  updateAndPrint("ctor", md.moduleLabel(), md.moduleName());
341  }
342 
344  {
345  updateAndPrint("beginJob", md.moduleLabel(), md.moduleName());
346  }
347 
349  {
350  if(not jobReportOutputOnly_) {
351  edm::LogAbsolute("MemoryReport") // changelog 1
352  << "MemoryReport> Peak virtual size " << eventT1_.vsize << " Mbytes"
353  << "\n"
354  << " Key events increasing vsize: \n"
355  << eventL2_ << "\n"
356  << eventL1_ << "\n"
357  << eventM_ << "\n"
358  << eventR1_ << "\n"
359  << eventR2_ << "\n"
360  << eventT3_ << "\n"
361  << eventT2_ << "\n"
362  << eventT1_ ;
363  }
364  if (moduleSummaryRequested_ and not jobReportOutputOnly_) { // changelog 1
365  edm::LogAbsolute mmr("ModuleMemoryReport"); // at end of if block, mmr
366  // is destructed, causing
367  // message to be logged
368  mmr << "ModuleMemoryReport> Each line has module label and: \n";
369  mmr << " (after early ignored events) \n";
370  mmr <<
371  " count of times module executed; average increase in vsize \n";
372  mmr <<
373  " maximum increase in vsize; event on which maximum occurred \n";
374  mmr << " (during early ignored events) \n";
375  mmr << " total and maximum vsize increases \n \n";
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  mmr << im->first << ": ";
381  mmr << "n = " << m.postEarlyCount;
382  if ( m.postEarlyCount > 0 ) mmr << " avg = "
384  mmr << " max = " << m.maxDeltaVsize << " " << m.eventMaxDeltaV;
385  if ( m.totalEarlyVsize > 0 ) {
386  mmr << " early total: " << m.totalEarlyVsize;
387  mmr << " max: " << m.maxEarlyVsize;
388  }
389  mmr << "\n";
390  }
391  } // end of if; mmr goes out of scope; log message is queued
392 
393  Service<JobReport> reportSvc;
394  // changelog 1
395 #define SIMPLE_MEMORY_CHECK_ORIGINAL_XML_OUTPUT
396 #ifdef SIMPLE_MEMORY_CHECK_ORIGINAL_XML_OUTPUT
397 // std::map<std::string, double> reportData;
398  std::map<std::string, std::string> reportData;
399 
400  if (eventL2_.vsize > 0)
401  eventStatOutput("LargeVsizeIncreaseEventL2", eventL2_, reportData);
402  if (eventL1_.vsize > 0)
403  eventStatOutput("LargeVsizeIncreaseEventL1", eventL1_, reportData);
404  if (eventM_.vsize > 0)
405  eventStatOutput("LargestVsizeIncreaseEvent", eventM_, reportData);
406  if (eventR1_.vsize > 0)
407  eventStatOutput("LargeVsizeIncreaseEventR1", eventR1_, reportData);
408  if (eventR2_.vsize > 0)
409  eventStatOutput("LargeVsizeIncreaseEventR2", eventR2_, reportData);
410  if (eventT3_.vsize > 0)
411  eventStatOutput("ThirdLargestVsizeEventT3", eventT3_, reportData);
412  if (eventT2_.vsize > 0)
413  eventStatOutput("SecondLargestVsizeEventT2", eventT2_, reportData);
414  if (eventT1_.vsize > 0)
415  eventStatOutput("LargestVsizeEventT1", eventT1_, reportData);
416 
417  if (eventRssT3_.rss > 0)
418  eventStatOutput("ThirdLargestRssEvent", eventRssT3_, reportData);
419  if (eventRssT2_.rss > 0)
420  eventStatOutput("SecondLargestRssEvent", eventRssT2_, reportData);
421  if (eventRssT1_.rss > 0)
422  eventStatOutput("LargestRssEvent", eventRssT1_, reportData);
423  if (eventDeltaRssT3_.deltaRss > 0)
424  eventStatOutput("ThirdLargestIncreaseRssEvent", eventDeltaRssT3_, reportData);
425  if (eventDeltaRssT2_.deltaRss > 0)
426  eventStatOutput("SecondLargestIncreaseRssEvent", eventDeltaRssT2_, reportData);
427  if (eventDeltaRssT1_.deltaRss > 0)
428  eventStatOutput("LargestIncreaseRssEvent", eventDeltaRssT1_, reportData);
429 
430 #ifdef __linux__
431  struct mallinfo minfo = mallinfo();
432  reportData.insert(
433  std::make_pair("HEAP_ARENA_SIZE_BYTES", i2str(minfo.arena)));
434  reportData.insert(
435  std::make_pair("HEAP_ARENA_N_UNUSED_CHUNKS", i2str(minfo.ordblks)));
436  reportData.insert(
437  std::make_pair("HEAP_TOP_FREE_BYTES", i2str(minfo.keepcost)));
438  reportData.insert(
439  std::make_pair("HEAP_MAPPED_SIZE_BYTES", i2str(minfo.hblkhd)));
440  reportData.insert(
441  std::make_pair("HEAP_MAPPED_N_CHUNKS", i2str(minfo.hblks)));
442  reportData.insert(
443  std::make_pair("HEAP_USED_BYTES", i2str(minfo.uordblks)));
444  reportData.insert(
445  std::make_pair("HEAP_UNUSED_BYTES", i2str(minfo.fordblks)));
446 #endif
447 
448  // Report Growth rates for VSize and Rss
449  reportData.insert(
450  std::make_pair("AverageGrowthRateVsize", d2str(averageGrowthRate(current_->vsize, growthRateVsize_, count_))));
451  reportData.insert(
452  std::make_pair("PeakValueVsize", d2str(eventT1_.vsize)));
453  reportData.insert(
454  std::make_pair("AverageGrowthRateRss", d2str(averageGrowthRate(current_->rss, growthRateRss_, count_))));
455  reportData.insert(
456  std::make_pair("PeakValueRss", d2str(eventRssT1_.rss)));
457 
458  if (moduleSummaryRequested_) { // changelog 2
459  for (SignificantModulesMap::iterator im=modules_.begin();
460  im != modules_.end(); ++im) {
461  SignificantModule const& m = im->second;
462  if ( m.totalDeltaVsize == 0 && m.totalEarlyVsize == 0 ) continue;
463  std::string label = im->first+":";
464  reportData.insert(
465  std::make_pair(label+"PostEarlyCount", i2str(m.postEarlyCount)));
466  if ( m.postEarlyCount > 0 ) {
467  reportData.insert(
468  std::make_pair(label+"AverageDeltaVsize",
470  }
471  reportData.insert(
472  std::make_pair(label+"MaxDeltaVsize", d2str(m.maxDeltaVsize)));
473  if ( m.totalEarlyVsize > 0 ) {
474  reportData.insert(
475  std::make_pair(label+"TotalEarlyVsize", d2str(m.totalEarlyVsize)));
476  reportData.insert(
477  std::make_pair(label+"MaxEarlyDeltaVsize", d2str(m.maxEarlyVsize)));
478  }
479  }
480  }
481 
482  std::map<std::string, std::string> reportMemoryProperties;
483 
484  if (FILE *fmeminfo = fopen("/proc/meminfo", "r")){
485  char buf[128];
486  char space[] = " ";
487  size_t value;
488 
489  while (fgets(buf, sizeof(buf), fmeminfo)){
490  char *token = NULL;
491  token = strtok(buf, space);
492  if (token != NULL){
493  value = atol(strtok(NULL, space));
494  std::string category = token;
495  reportMemoryProperties.insert(std::make_pair(category.substr(0,strlen(token)-1), i2str(value)));
496  }
497  }
498 
499  fclose(fmeminfo);
500  }
501 
502 // reportSvc->reportMemoryInfo(reportData, reportMemoryProperties);
503  reportSvc->reportPerformanceSummary("ApplicationMemory", reportData);
504  reportSvc->reportPerformanceSummary("SystemMemory", reportMemoryProperties);
505 #endif
506 
507 #ifdef SIMPLE_MEMORY_CHECK_DIFFERENT_XML_OUTPUT
508  std::vector<std::string> reportData;
509 
510  if (eventL2_.vsize > 0) reportData.push_back(
511  eventStatOutput("LargeVsizeIncreaseEventL2", eventL2_));
512  if (eventL1_.vsize > 0) reportData.push_back(
513  eventStatOutput("LargeVsizeIncreaseEventL1", eventL1_));
514  if (eventM_.vsize > 0) reportData.push_back(
515  eventStatOutput("LargestVsizeIncreaseEvent", eventM_));
516  if (eventR1_.vsize > 0) reportData.push_back(
517  eventStatOutput("LargeVsizeIncreaseEventR1", eventR1_));
518  if (eventR2_.vsize > 0) reportData.push_back(
519  eventStatOutput("LargeVsizeIncreaseEventR2", eventR2_));
520  if (eventT3_.vsize > 0) reportData.push_back(
521  eventStatOutput("ThirdLargestVsizeEventT3", eventT3_));
522  if (eventT2_.vsize > 0) reportData.push_back(
523  eventStatOutput("SecondLargestVsizeEventT2", eventT2_));
524  if (eventT1_.vsize > 0) reportData.push_back(
525  eventStatOutput("LargestVsizeEventT1", eventT1_));
526 
527  if (eventRssT3_.rss > 0)
528  eventStatOutput("ThirdLargestRssEvent", eventRssT3_, reportData);
529  if (eventRssT2_.rss > 0)
530  eventStatOutput("SecondLargestRssEvent", eventRssT2_, reportData);
531  if (eventRssT1_.rss > 0)
532  eventStatOutput("LargestRssEvent", eventRssT1_, reportData);
533  if (eventDeltaRssT3_.deltaRss > 0)
534  eventStatOutput("ThirdLargestIncreaseRssEvent", eventDeltaRssT3_, reportData);
535  if (eventDeltaRssT2_.deltaRss > 0)
536  eventStatOutput("SecondLargestIncreaseRssEvent", eventDeltaRssT2_, reportData);
537  if (eventDeltaRssT1_.deltaRss > 0)
538  eventStatOutput("LargestIncreaseRssEvent", eventDeltaRssT1_, reportData);
539 
540  struct mallinfo minfo = mallinfo();
541  reportData.push_back(
542  mallOutput("HEAP_ARENA_SIZE_BYTES", minfo.arena));
543  reportData.push_back(
544  mallOutput("HEAP_ARENA_N_UNUSED_CHUNKS", minfo.ordblks));
545  reportData.push_back(
546  mallOutput("HEAP_TOP_FREE_BYTES", minfo.keepcost));
547  reportData.push_back(
548  mallOutput("HEAP_MAPPED_SIZE_BYTES", minfo.hblkhd));
549  reportData.push_back(
550  mallOutput("HEAP_MAPPED_N_CHUNKS", minfo.hblks));
551  reportData.push_back(
552  mallOutput("HEAP_USED_BYTES", minfo.uordblks));
553  reportData.push_back(
554  mallOutput("HEAP_UNUSED_BYTES", minfo.fordblks));
555 
556  // Report Growth rates for VSize and Rss
557  reportData.insert(
558  std::make_pair("AverageGrowthRateVsize", d2str(averageGrowthRate(current_->vsize, growthRateVsize_, count_))));
559  reportData.insert(
560  std::make_pair("PeakValueVsize", d2str(eventT1_.vsize)));
561  reportData.insert(
562  std::make_pair("AverageGrowthRateRss", d2str(averageGrowthRate(current_->rss, growthRateRss_, count_))));
563  reportData.insert(
564  std::make_pair("PeakValueRss", d2str(eventRssT1_.rss)));
565 
566  reportSvc->reportMemoryInfo(reportData);
567  // This is a form of reportMemoryInfo taking s vector, not a map
568 #endif
569  } // postEndJob
570 
572  const edm::Timestamp& iTime)
573  {
574  currentEventID_ = iID; // changelog 2
575  }
576 
578  const EventSetup&)
579  {
580  ++count_;
581  update();
582  updateEventStats( e.id() );
583  if (oncePerEventMode_) {
584  // should probably use be Run:Event or count_ for the label and name
585  updateMax();
586  andPrint("event", "", "");
587  }
588  }
589 
591  update(); // changelog 2
593  }
594 
596  if (!oncePerEventMode_) {
597  updateAndPrint("module", md.moduleLabel(), md.moduleName());
598  } else if (moduleSummaryRequested_) { // changelog 2
599  update();
600  }
601  if (moduleSummaryRequested_) { // changelog 2
602  double dv = current_->vsize - moduleEntryVsize_;
603  std::string label = md.moduleLabel();
604  updateModuleMemoryStats (modules_[label],dv);
605  }
606  }
607 
608 
610  {
612  *current_ = fetch();
613  }
614 
616  {
617  if ((*current_ > max_) || oncePerEventMode_)
618  {
619  if(count_ >= num_to_skip_) {
620  }
621  max_ = *current_;
622  }
623  }
624 
626  if (count_ < num_to_skip_) return;
627  if (count_ == num_to_skip_) {
628  eventT1_.set(0, 0, e, this);
629  eventM_.set (0, 0, e, this);
630  eventRssT1_.set(0, 0, e, this);
631  eventDeltaRssT1_.set(0, 0, e, this);
632  return;
633  }
634  double vsize = current_->vsize;
635  double deltaVsize = vsize - eventT1_.vsize;
636 
637  // Update significative events for Vsize
638  if (vsize > eventT1_.vsize) {
639  double deltaRss = current_->rss - eventT1_.rss;
640  eventT3_ = eventT2_;
641  eventT2_ = eventT1_;
642  eventT1_.set(deltaVsize, deltaRss, e, this);
643  } else if(vsize > eventT2_.vsize) {
644  double deltaRss = current_->rss - eventT1_.rss;
645  eventT3_ = eventT2_;
646  eventT2_.set(deltaVsize, deltaRss, e, this);
647  } else if(vsize > eventT3_.vsize) {
648  double deltaRss = current_->rss - eventT1_.rss;
649  eventT3_.set(deltaVsize, deltaRss, e, this);
650  }
651 
652  if (deltaVsize > eventM_.deltaVsize) {
653  double deltaRss = current_->rss - eventM_.rss;
655  eventL2_ = eventL1_;
656  } else {
657  eventL2_ = eventR1_;
658  }
659  eventL1_ = eventM_;
660  eventM_.set(deltaVsize, deltaRss, e, this);
663  } else if (deltaVsize > eventR1_.deltaVsize) {
664  double deltaRss = current_->rss - eventM_.rss;
665  eventR2_ = eventR1_;
666  eventR1_.set(deltaVsize, deltaRss, e, this);
667  } else if (deltaVsize > eventR2_.deltaVsize) {
668  double deltaRss = current_->rss - eventR1_.rss;
669  eventR2_.set(deltaVsize, deltaRss, e, this);
670  }
671 
672  // Update significative events for Rss
673  double rss = current_->rss;
674  double deltaRss = rss - eventRssT1_.rss;
675 
676  if(rss > eventRssT1_.rss){
679  eventRssT1_.set(deltaVsize, deltaRss, e, this);
680  } else if(rss > eventRssT2_.rss) {
682  eventRssT2_.set(deltaVsize, deltaRss, e, this);
683  } else if(rss > eventRssT3_.rss) {
684  eventRssT3_.set(deltaVsize, deltaRss, e, this);
685  }
686  if(deltaRss > eventDeltaRssT1_.deltaRss) {
689  eventDeltaRssT1_.set(deltaVsize, deltaRss, e, this);
690  } else if(deltaRss > eventDeltaRssT2_.deltaRss) {
692  eventDeltaRssT2_.set(deltaVsize, deltaRss, e, this);
693  } else if(deltaRss > eventDeltaRssT3_.deltaRss) {
694  eventDeltaRssT3_.set(deltaVsize, deltaRss, e, this);
695  }
696  } // updateEventStats
697 
698  void SimpleMemoryCheck::andPrint(const std::string& type,
699  const std::string& mdlabel, const std::string& mdname) const
700  {
701  if (not jobReportOutputOnly_ && ((*current_ > max_) || oncePerEventMode_)) {
702  if(count_ >= num_to_skip_) {
703  double deltaVSIZE = current_->vsize - max_.vsize;
704  double deltaRSS = current_->rss - max_.rss;
705  if (!showMallocInfo_) { // default
706  LogWarning("MemoryCheck")
707  << "MemoryCheck: " << type << " "
708  << mdname << ":" << mdlabel
709  << " VSIZE " << current_->vsize << " " << deltaVSIZE
710  << " RSS " << current_->rss << " " << deltaRSS
711  << "\n";
712  } else {
713 #ifdef __linux__
714  struct mallinfo minfo = mallinfo();
715 #endif
716  LogWarning("MemoryCheck")
717  << "MemoryCheck: " << type << " "
718  << mdname << ":" << mdlabel
719  << " VSIZE " << current_->vsize << " " << deltaVSIZE
720  << " RSS " << current_->rss << " " << deltaRSS
721 #ifdef __linux__
722  << " HEAP-ARENA [ SIZE-BYTES " << minfo.arena
723  << " N-UNUSED-CHUNKS " << minfo.ordblks
724  << " TOP-FREE-BYTES " << minfo.keepcost << " ]"
725  << " HEAP-MAPPED [ SIZE-BYTES " << minfo.hblkhd
726  << " N-CHUNKS " << minfo.hblks << " ]"
727  << " HEAP-USED-BYTES " << minfo.uordblks
728  << " HEAP-UNUSED-BYTES " << minfo.fordblks
729 #endif
730  << "\n";
731  }
732  }
733  }
734  }
735 
736  void SimpleMemoryCheck::updateAndPrint(const std::string& type,
737  const std::string& mdlabel, const std::string& mdname)
738  {
739  update();
740  andPrint(type, mdlabel, mdname);
741  updateMax();
742  }
743 
744 #ifdef SIMPLE_MEMORY_CHECK_ORIGINAL_XML_OUTPUT
745  void
747  SignificantEvent const& e,
748  std::map<std::string, std::string> &m) const
749  {
750  { std::ostringstream os;
751  os << title << "-a-COUNT";
752  m.insert(std::make_pair(os.str(), i2str(e.count))); }
753  { std::ostringstream os;
754  os << title << "-b-RUN";
755  m.insert(std::make_pair(os.str(), d2str(static_cast<double>(e.event.run())) )); }
756  { std::ostringstream os;
757  os << title << "-c-EVENT";
758  m.insert(std::make_pair(os.str(), d2str(static_cast<double>(e.event.event())) )); }
759  { std::ostringstream os;
760  os << title << "-d-VSIZE";
761  m.insert(std::make_pair(os.str(), d2str(e.vsize))); }
762  { std::ostringstream os;
763  os << title << "-e-DELTV";
764  m.insert(std::make_pair(os.str(), d2str(e.deltaVsize))); }
765  { std::ostringstream os;
766  os << title << "-f-RSS";
767  m.insert(std::make_pair(os.str(), d2str(e.rss))); }
768  } // eventStatOutput
769 #endif
770 
771 
772 #ifdef SIMPLE_MEMORY_CHECK_DIFFERENT_XML_OUTPUT
773  std::string
775  SignificantEvent const& e) const
776  {
777  std::ostringstream os;
778  os << " <" << title << ">\n";
779  os << " " << e.count << ": " << e.event;
780  os << " vsize " << e.vsize-e.deltaVsize << " + " << e.deltaVsize
781  << " = " << e.vsize;
782  os << " rss: " << e.rss << "\n";
783  os << " </" << title << ">\n";
784  return os.str();
785  } // eventStatOutput
786 
787  std::string
788  SimpleMemoryCheck::mallOutput(std::string title, size_t const& n) const {
789  std::ostringstream os;
790  os << " <" << title << ">\n";
791  os << " " << n << "\n";
792  os << " </" << title << ">\n";
793  return os.str();
794  }
795 #endif
796  // changelog 2
797  void
799  double dv) {
800  if(count_ < num_to_skip_) {
801  m.totalEarlyVsize += dv;
802  if (dv > m.maxEarlyVsize) m.maxEarlyVsize = dv;
803  } else {
804  ++m.postEarlyCount;
805  m.totalDeltaVsize += dv;
806  if (dv > m.maxDeltaVsize) {
807  m.maxDeltaVsize = dv;
809  }
810  }
811  } //updateModuleMemoryStats
812 
813 
814 
815  std::ostream &
816  operator<< (std::ostream & os,
818  os << "[" << se.count << "] "
819  << se.event << " vsize = " << se.vsize
820  << " deltaVsize = " << se.deltaVsize
821  << " rss = " << se.rss << " delta " << se.deltaRss;
822  return os;
823  }
824 
825  std::ostream &
826  operator<< (std::ostream & os,
828  if ( sm.postEarlyCount > 0 ) {
829  os << "\nPost Early Events: TotalDeltaVsize: " << sm.totalDeltaVsize
830  << " (avg: " << sm.totalDeltaVsize/sm.postEarlyCount
831  << "; max: " << sm.maxDeltaVsize
832  << " during " << sm.eventMaxDeltaV << ")";
833  }
834  if ( sm.totalEarlyVsize > 0 ) {
835  os << "\n Early Events: TotalDeltaVsize: " << sm.totalEarlyVsize
836  << " (max: " << sm.maxEarlyVsize << ")";
837  }
838 
839  return os;
840  }
841 
842  } // end namespace service
843 } // end namespace edm
844 
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:63
int i
Definition: DBlmapReader.cc:9
std::string eventStatOutput(std::string title, SignificantEvent const &e) const
SignificantEvent eventDeltaRssT1_
Definition: Memory.h:172
void preSourceConstruction(const ModuleDescription &)
Definition: Memory.cc:322
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:208
ParameterDescriptionBase * addUntracked(U const &iLabel, T const &value)
const std::string & label
Definition: MVAComputer.cc:186
void watchPostEndJob(PostEndJob::slot_type const &iSlot)
SignificantEvent eventM_
Definition: Memory.h:148
SignificantEvent eventT1_
Definition: Memory.h:153
void set_mmap_thr(opt_type mmap_thr)
Definition: MallocOpts.h:82
void updateEventStats(edm::EventID const &e)
Definition: Memory.cc:625
void postModule(const ModuleDescription &)
Definition: Memory.cc:595
unsigned int vsize
Definition: Memory.cc:92
unsigned int startstack
Definition: Memory.cc:97
unsigned int kstkesp
Definition: Memory.cc:98
void watchPostModule(PostModule::slot_type const &iSlot)
void watchPreProcessEvent(PreProcessEvent::slot_type const &iSlot)
unsigned int cmajflt
Definition: Memory.cc:82
void watchPreSourceConstruction(PreSourceConstruction::slot_type const &iSlot)
void watchPostSourceConstruction(PostSourceConstruction::slot_type const &iSlot)
SignificantEvent eventRssT2_
Definition: Memory.h:170
SignificantEvent eventL1_
Definition: Memory.h:149
std::string const & moduleName() const
#define NULL
Definition: scimark2.h:8
SignificantEvent eventT3_
Definition: Memory.h:155
unsigned int startcode
Definition: Memory.cc:95
unsigned int endcode
Definition: Memory.cc:96
std::string const & moduleLabel() const
void andPrint(const std::string &type, const std::string &mdlabel, const std::string &mdname) const
Definition: Memory.cc:698
void watchPreModule(PreModule::slot_type const &iSlot)
unsigned int timeout
Definition: Memory.cc:89
unsigned int cminflt
Definition: Memory.cc:80
SignificantEvent eventRssT3_
Definition: Memory.h:171
void watchPostProcessEvent(PostProcessEvent::slot_type const &iSlot)
void preModule(const ModuleDescription &)
Definition: Memory.cc:590
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
unsigned int flags
Definition: Memory.cc:78
unsigned int rss
Definition: Memory.cc:93
friend struct SignificantEvent
Definition: Memory.h:129
void set(double deltaV, double deltaR, edm::EventID const &e, SimpleMemoryCheck *t)
Definition: Memory.h:119
void postEventProcessing(const Event &, const EventSetup &)
Definition: Memory.cc:577
void updateModuleMemoryStats(SignificantModule &m, double dv)
Definition: Memory.cc:798
ErrorLog & operator<<(ErrorLog &e, const T &t)
unsigned int majflt
Definition: Memory.cc:81
unsigned int kstkeip
Definition: Memory.cc:99
SignificantEvent eventR1_
Definition: Memory.h:151
SignificantEvent eventDeltaRssT3_
Definition: Memory.h:174
unsigned int itrealvalue
Definition: Memory.cc:90
void updateAndPrint(const std::string &type, const std::string &mdlabel, const std::string &mdname)
Definition: Memory.cc:736
unsigned int wchan
Definition: Memory.cc:104
SignificantEvent eventR2_
Definition: Memory.h:152
static std::string d2str(double d)
Definition: Memory.cc:57
void add(std::string const &label, ParameterSetDescription const &psetDescription)
void watchPostSource(PostSource::slot_type const &iSlot)
std::string error_message() const
Definition: MallocOpts.h:74
SignificantEvent eventL2_
Definition: Memory.h:150
edm::EventID id() const
Definition: EventBase.h:56
SignificantEvent eventDeltaRssT2_
Definition: Memory.h:173
std::string mallOutput(std::string title, size_t const &n) const
static const std::string category("Muon|RecoMuon|L3MuonCandidateProducerFromMuons")
void watchPostModuleBeginJob(PostModuleBeginJob::slot_type const &iSlot)
unsigned int minflt
Definition: Memory.cc:79
void postSourceConstruction(const ModuleDescription &)
Definition: Memory.cc:328
SignificantEvent eventT2_
Definition: Memory.h:154
void postModuleBeginJob(const ModuleDescription &)
Definition: Memory.cc:343
double averageGrowthRate(double current, double past, int count)
Definition: Memory.cc:182
void preEventProcessing(const edm::EventID &, const edm::Timestamp &)
Definition: Memory.cc:571
void set_top_pad(opt_type top_pad)
Definition: MallocOpts.h:80
SimpleMemoryCheck(const ParameterSet &, ActivityRegistry &)
Definition: Memory.cc:186
SignificantModulesMap modules_
Definition: Memory.h:206
SignificantEvent eventRssT1_
Definition: Memory.h:169
void postModuleConstruction(const ModuleDescription &)
Definition: Memory.cc:338
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: Memory.cc:301
MallocOptionSetter & getGlobalOptionSetter()
Definition: MallocOpts.cc:217
unsigned int rlim
Definition: Memory.cc:94
void watchPostBeginJob(PostBeginJob::slot_type const &iSlot)
convenience function for attaching to signal