CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Memory.h
Go to the documentation of this file.
1 #ifndef FWCore_Services_Memory_h
2 #define FWCore_Services_Memory_h
3 // -*- C++ -*-
4 //
5 // Package: Services
6 // Class : SimpleMemoryCheck
7 //
8 //
9 // Original Author: Jim Kowalkowski
10 //
11 // Change Log
12 //
13 // 1 - Apr 25, 2008 M. Fischler
14 // Data structures for Event summary statistics,
15 //
16 // 2 - Jan 14, 2009 Natalia Garcia Nebot
17 // Added: - Average rate of growth in RSS and peak value attained.
18 // - Average rate of growth in VSize over time, Peak VSize
19 
20 
25 
26 #include <cstdio>
27 #include <atomic>
28 
29 namespace edm {
30  class EventID;
31  class Timestamp;
32  class Event;
33  class EventSetup;
34  class ModuleDescription;
36 
37  namespace service {
38  struct smapsInfo
39  {
41  smapsInfo(double private_sz, double pss_sz): private_(private_sz),pss_(pss_sz) {}
42 
43  bool operator==(const smapsInfo& p) const
44  { return private_==p.private_ && pss_==p.pss_; }
45 
46  bool operator>(const smapsInfo& p) const
47  { return private_>p.private_ || pss_>p.pss_; }
48 
49  double private_; // in MB
50  double pss_; // in MB
51  };
52 
53 
55  {
56  public:
57 
60 
61  static void fillDescriptions(edm::ConfigurationDescriptions & descriptions);
62 
66 
67  void postBeginJob();
68 
69  void postEvent(StreamContext const&);
70 
73 
74  void preModule(StreamContext const&, ModuleCallingContext const&);
75  void postModule(StreamContext const&, ModuleCallingContext const&);
76 
77  void postEndJob();
78 
79  void postFork(unsigned int, unsigned int);
80  private:
81  ProcInfo fetch();
83  double pageSize() const { return pg_size_; }
84  double averageGrowthRate(double current, double past, int count);
85  void update();
86  void updateMax();
87  void andPrint(const std::string& type,
88  const std::string& mdlabel, const std::string& mdname) const;
89  void updateAndPrint(const std::string& type,
90  const std::string& mdlabel, const std::string& mdname);
91  void openFiles();
92 
98 
100 
102  double pg_size_;
104  //options
109  std::atomic<int> count_;
110 
111  //smaps
112  FILE* smapsFile_;
115 
116 
117  //Rates of growth
120 
121  // Event summary statistics changeLog 1
123  int count;
124  double vsize;
125  double deltaVsize;
126  double rss;
127  double deltaRss;
129  double privateSize;
130  double pss;
134  void set (double deltaV, double deltaR,
135  edm::EventID const & e, SimpleMemoryCheck *t)
136  { count = t->count_;
137  vsize = t->current_->vsize;
138  deltaVsize = deltaV;
139  rss = t->current_->rss;
140  deltaRss = deltaR;
142  if (monitorPssAndPrivate) {
144  pss = t->currentSmaps_.pss_;
145  }
146  event = e;
147  }
148  }; // SignificantEvent
149  friend struct SignificantEvent;
150  friend std::ostream & operator<< (std::ostream & os,
152 
153  /*
154  Significative events for deltaVsize:
155  - eventM_: Event which makes the biggest value for deltaVsize
156  - eventL1_: Event which makes the second biggest value for deltaVsize
157  - eventL2_: Event which makes the third biggest value for deltaVsize
158  - eventR1_: Event which makes the second biggest value for deltaVsize
159  - eventR2_: Event which makes the third biggest value for deltaVsize
160  M>L1>L2 and M>R1>R2
161  Unknown relation between Ls and Rs events ???????
162  Significative events for vsize:
163  - eventT1_: Event whith the biggest value for vsize
164  - eventT2_: Event whith the second biggest value for vsize
165  - eventT3_: Event whith the third biggest value for vsize
166  T1>T2>T3
167  */
176 
177  /*
178  Significative event for deltaRss:
179  - eventRssT1_: Event whith the biggest value for rss
180  - eventRssT2_: Event whith the second biggest value for rss
181  - eventRssT3_: Event whith the third biggest value for rss
182  T1>T2>T3
183  Significative events for deltaRss:
184  - eventDeltaRssT1_: Event whith the biggest value for deltaRss
185  - eventDeltaRssT2_: Event whith the second biggest value for deltaRss
186  - eventDeltaRssT3_: Event whith the third biggest value for deltaRss
187  T1>T2>T3
188  */
195 
196 
197  void updateEventStats(edm::EventID const & e);
199  SignificantEvent const& e) const;
201  SignificantEvent const& e,
202  std::map<std::string, std::string> &m) const;
203  std::string mallOutput(std::string title, size_t const& n) const;
204 
205  // Module summary statistices
214  , totalDeltaVsize (0)
215  , maxDeltaVsize (0)
216  , eventMaxDeltaV ()
217  , totalEarlyVsize (0)
218  , maxEarlyVsize (0) {}
219  void set (double deltaV, bool early);
220  }; // SignificantModule
221  friend struct SignificantModule;
222  friend std::ostream & operator<< (std::ostream & os,
225  typedef std::map<std::string,SignificantModule> SignificantModulesMap;
228  void updateModuleMemoryStats(SignificantModule & m, double dv, edm::EventID const&);
229 
230  //Used to guarantee we only do one measurement at a time
231  std::atomic<bool> measurementUnderway_;
232  std::atomic<bool> moduleMeasurementUnderway_;
233  std::atomic<unsigned int> moduleStreamID_;
234  std::atomic<unsigned int> moduleID_;
235 
236  }; // SimpleMemoryCheck
237 
238  std::ostream &
239  operator<< (std::ostream & os,
241 
242  std::ostream &
243  operator<< (std::ostream & os,
245 
246  }
247 }
248 
249 
250 
251 #endif
std::map< std::string, SignificantModule > SignificantModulesMap
Definition: Memory.h:225
type
Definition: HCALResponse.h:21
std::string eventStatOutput(std::string title, SignificantEvent const &e) const
void postFork(unsigned int, unsigned int)
Definition: Memory.cc:593
SignificantEvent eventDeltaRssT1_
Definition: Memory.h:192
void preSourceConstruction(const ModuleDescription &)
Definition: Memory.cc:249
std::pair< ALIstring, ALIstring > pss
Definition: Fit.h:27
friend std::ostream & operator<<(std::ostream &os, SimpleMemoryCheck::SignificantEvent const &se)
Definition: Memory.cc:806
SignificantEvent eventM_
Definition: Memory.h:168
std::atomic< bool > measurementUnderway_
Definition: Memory.h:231
SignificantEvent eventT1_
Definition: Memory.h:173
void updateEventStats(edm::EventID const &e)
Definition: Memory.cc:615
ProcInfoFetcher piFetcher_
Definition: Memory.h:101
std::atomic< bool > moduleMeasurementUnderway_
Definition: Memory.h:232
SignificantEvent eventRssT2_
Definition: Memory.h:190
SignificantEvent eventL1_
Definition: Memory.h:169
SignificantEvent eventT3_
Definition: Memory.h:175
void andPrint(const std::string &type, const std::string &mdlabel, const std::string &mdname) const
Definition: Memory.cc:688
std::atomic< unsigned int > moduleStreamID_
Definition: Memory.h:233
SignificantEvent eventRssT3_
Definition: Memory.h:191
std::ostream & operator<<(std::ostream &os, SimpleMemoryCheck::SignificantEvent const &se)
Definition: Memory.cc:806
void set(double deltaV, double deltaR, edm::EventID const &e, SimpleMemoryCheck *t)
Definition: Memory.h:134
SignificantEvent eventR1_
Definition: Memory.h:171
SignificantEvent eventDeltaRssT3_
Definition: Memory.h:194
double deltaR(double eta1, double eta2, double phi1, double phi2)
Definition: TreeUtility.cc:17
smapsInfo(double private_sz, double pss_sz)
Definition: Memory.h:41
void updateAndPrint(const std::string &type, const std::string &mdlabel, const std::string &mdname)
Definition: Memory.cc:724
bool operator==(const smapsInfo &p) const
Definition: Memory.h:43
SignificantEvent eventR2_
Definition: Memory.h:172
void preModule(StreamContext const &, ModuleCallingContext const &)
Definition: Memory.cc:538
void updateModuleMemoryStats(SignificantModule &m, double dv, edm::EventID const &)
Definition: Memory.cc:790
std::atomic< int > count_
Definition: Memory.h:109
SignificantEvent eventL2_
Definition: Memory.h:170
SignificantEvent eventDeltaRssT2_
Definition: Memory.h:193
void postEvent(StreamContext const &)
Definition: Memory.cc:518
std::string mallOutput(std::string title, size_t const &n) const
void postSourceConstruction(const ModuleDescription &)
Definition: Memory.cc:260
SignificantEvent eventT2_
Definition: Memory.h:174
void postSourceEvent(StreamID)
Definition: Memory.cc:270
void postModuleBeginJob(const ModuleDescription &)
Definition: Memory.cc:290
volatile std::atomic< bool > shutdown_flag false
double averageGrowthRate(double current, double past, int count)
Definition: Memory.cc:112
SimpleMemoryCheck(const ParameterSet &, ActivityRegistry &)
Definition: Memory.cc:116
SignificantModulesMap modules_
Definition: Memory.h:226
SignificantEvent eventRssT1_
Definition: Memory.h:189
void postModule(StreamContext const &, ModuleCallingContext const &)
Definition: Memory.cc:555
void postModuleConstruction(const ModuleDescription &)
Definition: Memory.cc:280
bool operator>(const smapsInfo &p) const
Definition: Memory.h:46
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: Memory.cc:216
double pageSize() const
Definition: Memory.h:83
std::atomic< unsigned int > moduleID_
Definition: Memory.h:234