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