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