Go to the documentation of this file.00001 #ifndef FWCore_Services_Memory_h
00002 #define FWCore_Services_Memory_h
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00023 #include "FWCore/ServiceRegistry/interface/ActivityRegistry.h"
00024 #include "DataFormats/Provenance/interface/EventID.h"
00025 #include <cstdio>
00026
00027 namespace edm {
00028 class EventID;
00029 class Timestamp;
00030 class Event;
00031 class EventSetup;
00032 class ModuleDescription;
00033 class ConfigurationDescriptions;
00034
00035 namespace service {
00036 struct procInfo
00037 {
00038 procInfo():vsize(),rss() {}
00039 procInfo(double sz, double rss_sz): vsize(sz),rss(rss_sz) {}
00040
00041 bool operator==(const procInfo& p) const
00042 { return vsize==p.vsize && rss==p.rss; }
00043
00044 bool operator>(const procInfo& p) const
00045 { return vsize>p.vsize || rss>p.rss; }
00046
00047
00048 double vsize;
00049 double rss;
00050 };
00051
00052 struct smapsInfo
00053 {
00054 smapsInfo():private_(),pss_() {}
00055 smapsInfo(double private_sz, double pss_sz): private_(private_sz),pss_(pss_sz) {}
00056
00057 bool operator==(const smapsInfo& p) const
00058 { return private_==p.private_ && pss_==p.pss_; }
00059
00060 bool operator>(const smapsInfo& p) const
00061 { return private_>p.private_ || pss_>p.pss_; }
00062
00063 double private_;
00064 double pss_;
00065 };
00066
00067
00068 class SimpleMemoryCheck
00069 {
00070 public:
00071
00072 SimpleMemoryCheck(const ParameterSet&,ActivityRegistry&);
00073 ~SimpleMemoryCheck();
00074
00075 static void fillDescriptions(edm::ConfigurationDescriptions & descriptions);
00076
00077 void preSourceConstruction(const ModuleDescription&);
00078 void postSourceConstruction(const ModuleDescription&);
00079 void postSource();
00080
00081 void postBeginJob();
00082
00083 void preEventProcessing(const edm::EventID&, const edm::Timestamp&);
00084 void postEventProcessing(const Event&, const EventSetup&);
00085
00086 void postModuleBeginJob(const ModuleDescription&);
00087 void postModuleConstruction(const ModuleDescription&);
00088
00089 void preModule(const ModuleDescription&);
00090 void postModule(const ModuleDescription&);
00091
00092 void postEndJob();
00093
00094 void postFork(unsigned int, unsigned int);
00095 private:
00096 procInfo fetch();
00097 smapsInfo fetchSmaps();
00098 double pageSize() const { return pg_size_; }
00099 double averageGrowthRate(double current, double past, int count);
00100 void update();
00101 void updateMax();
00102 void andPrint(const std::string& type,
00103 const std::string& mdlabel, const std::string& mdname) const;
00104 void updateAndPrint(const std::string& type,
00105 const std::string& mdlabel, const std::string& mdname);
00106 void openFiles();
00107
00108 procInfo a_;
00109 procInfo b_;
00110 procInfo max_;
00111 procInfo* current_;
00112 procInfo* previous_;
00113
00114 smapsInfo currentSmaps_;
00115
00116 char buf_[500];
00117 int fd_;
00118 std::string fname_;
00119 double pg_size_;
00120 int num_to_skip_;
00121
00122 bool showMallocInfo_;
00123 bool oncePerEventMode_;
00124 bool jobReportOutputOnly_;
00125 bool monitorPssAndPrivate_;
00126 int count_;
00127
00128
00129 FILE* smapsFile_;
00130 char* smapsLineBuffer_;
00131 size_t smapsLineBufferLen_;
00132
00133
00134
00135 double growthRateVsize_;
00136 double growthRateRss_;
00137
00138
00139 struct SignificantEvent {
00140 int count;
00141 double vsize;
00142 double deltaVsize;
00143 double rss;
00144 double deltaRss;
00145 bool monitorPssAndPrivate;
00146 double privateSize;
00147 double pss;
00148 edm::EventID event;
00149 SignificantEvent() : count(0), vsize(0), deltaVsize(0),
00150 rss(0), deltaRss(0), monitorPssAndPrivate(false), privateSize(0), pss(0),event() {}
00151 void set (double deltaV, double deltaR,
00152 edm::EventID const & e, SimpleMemoryCheck *t)
00153 { count = t->count_;
00154 vsize = t->current_->vsize;
00155 deltaVsize = deltaV;
00156 rss = t->current_->rss;
00157 deltaRss = deltaR;
00158 monitorPssAndPrivate = t->monitorPssAndPrivate_;
00159 if (monitorPssAndPrivate) {
00160 privateSize = t->currentSmaps_.private_;
00161 pss = t->currentSmaps_.pss_;
00162 }
00163 event = e;
00164 }
00165 };
00166 friend struct SignificantEvent;
00167 friend std::ostream & operator<< (std::ostream & os,
00168 SimpleMemoryCheck::SignificantEvent const & se);
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185 SignificantEvent eventM_;
00186 SignificantEvent eventL1_;
00187 SignificantEvent eventL2_;
00188 SignificantEvent eventR1_;
00189 SignificantEvent eventR2_;
00190 SignificantEvent eventT1_;
00191 SignificantEvent eventT2_;
00192 SignificantEvent eventT3_;
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206 SignificantEvent eventRssT1_;
00207 SignificantEvent eventRssT2_;
00208 SignificantEvent eventRssT3_;
00209 SignificantEvent eventDeltaRssT1_;
00210 SignificantEvent eventDeltaRssT2_;
00211 SignificantEvent eventDeltaRssT3_;
00212
00213
00214 void updateEventStats(edm::EventID const & e);
00215 std::string eventStatOutput(std::string title,
00216 SignificantEvent const& e) const;
00217 void eventStatOutput(std::string title,
00218 SignificantEvent const& e,
00219 std::map<std::string, std::string> &m) const;
00220 std::string mallOutput(std::string title, size_t const& n) const;
00221
00222
00223 struct SignificantModule {
00224 int postEarlyCount;
00225 double totalDeltaVsize;
00226 double maxDeltaVsize;
00227 edm::EventID eventMaxDeltaV;
00228 double totalEarlyVsize;
00229 double maxEarlyVsize;
00230 SignificantModule() : postEarlyCount (0)
00231 , totalDeltaVsize (0)
00232 , maxDeltaVsize (0)
00233 , eventMaxDeltaV ()
00234 , totalEarlyVsize (0)
00235 , maxEarlyVsize (0) {}
00236 void set (double deltaV, bool early);
00237 };
00238 friend struct SignificantModule;
00239 friend std::ostream & operator<< (std::ostream & os,
00240 SimpleMemoryCheck::SignificantModule const & se);
00241 bool moduleSummaryRequested_;
00242 typedef std::map<std::string,SignificantModule> SignificantModulesMap;
00243 SignificantModulesMap modules_;
00244 double moduleEntryVsize_;
00245 edm::EventID currentEventID_;
00246 void updateModuleMemoryStats(SignificantModule & m, double dv);
00247
00248 };
00249
00250 std::ostream &
00251 operator<< (std::ostream & os,
00252 SimpleMemoryCheck::SignificantEvent const & se);
00253
00254 std::ostream &
00255 operator<< (std::ostream & os,
00256 SimpleMemoryCheck::SignificantModule const & se);
00257
00258 }
00259 }
00260
00261
00262
00263 #endif