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 int count_;
00126
00127
00128 FILE* smapsFile_;
00129 char* smapsLineBuffer_;
00130 size_t smapsLineBufferLen_;
00131
00132
00133
00134 double growthRateVsize_;
00135 double growthRateRss_;
00136
00137
00138 struct SignificantEvent {
00139 int count;
00140 double vsize;
00141 double deltaVsize;
00142 double rss;
00143 double deltaRss;
00144 double privateSize;
00145 double pss;
00146 edm::EventID event;
00147 SignificantEvent() : count(0), vsize(0), deltaVsize(0),
00148 rss(0), deltaRss(0), privateSize(0), pss(0),event() {}
00149 void set (double deltaV, double deltaR,
00150 edm::EventID const & e, SimpleMemoryCheck *t)
00151 { count = t->count_;
00152 vsize = t->current_->vsize;
00153 deltaVsize = deltaV;
00154 rss = t->current_->rss;
00155 deltaRss = deltaR;
00156 privateSize = t->currentSmaps_.private_;
00157 pss = t->currentSmaps_.pss_;
00158 event = e;
00159 }
00160 };
00161 friend struct SignificantEvent;
00162 friend std::ostream & operator<< (std::ostream & os,
00163 SimpleMemoryCheck::SignificantEvent const & se);
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180 SignificantEvent eventM_;
00181 SignificantEvent eventL1_;
00182 SignificantEvent eventL2_;
00183 SignificantEvent eventR1_;
00184 SignificantEvent eventR2_;
00185 SignificantEvent eventT1_;
00186 SignificantEvent eventT2_;
00187 SignificantEvent eventT3_;
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201 SignificantEvent eventRssT1_;
00202 SignificantEvent eventRssT2_;
00203 SignificantEvent eventRssT3_;
00204 SignificantEvent eventDeltaRssT1_;
00205 SignificantEvent eventDeltaRssT2_;
00206 SignificantEvent eventDeltaRssT3_;
00207
00208
00209 void updateEventStats(edm::EventID const & e);
00210 std::string eventStatOutput(std::string title,
00211 SignificantEvent const& e) const;
00212 void eventStatOutput(std::string title,
00213 SignificantEvent const& e,
00214 std::map<std::string, std::string> &m) const;
00215 std::string mallOutput(std::string title, size_t const& n) const;
00216
00217
00218 struct SignificantModule {
00219 int postEarlyCount;
00220 double totalDeltaVsize;
00221 double maxDeltaVsize;
00222 edm::EventID eventMaxDeltaV;
00223 double totalEarlyVsize;
00224 double maxEarlyVsize;
00225 SignificantModule() : postEarlyCount (0)
00226 , totalDeltaVsize (0)
00227 , maxDeltaVsize (0)
00228 , eventMaxDeltaV ()
00229 , totalEarlyVsize (0)
00230 , maxEarlyVsize (0) {}
00231 void set (double deltaV, bool early);
00232 };
00233 friend struct SignificantModule;
00234 friend std::ostream & operator<< (std::ostream & os,
00235 SimpleMemoryCheck::SignificantModule const & se);
00236 bool moduleSummaryRequested_;
00237 typedef std::map<std::string,SignificantModule> SignificantModulesMap;
00238 SignificantModulesMap modules_;
00239 double moduleEntryVsize_;
00240 edm::EventID currentEventID_;
00241 void updateModuleMemoryStats(SignificantModule & m, double dv);
00242
00243 };
00244
00245 std::ostream &
00246 operator<< (std::ostream & os,
00247 SimpleMemoryCheck::SignificantEvent const & se);
00248
00249 std::ostream &
00250 operator<< (std::ostream & os,
00251 SimpleMemoryCheck::SignificantModule const & se);
00252
00253 }
00254 }
00255
00256
00257
00258 #endif