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 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00020 #include "FWCore/ServiceRegistry/interface/ActivityRegistry.h"
00021 #include "DataFormats/Provenance/interface/EventID.h"
00022
00023 namespace edm {
00024 class EventID;
00025 class Timestamp;
00026 class Event;
00027 class EventSetup;
00028 class ModuleDescription;
00029
00030 namespace service {
00031 struct procInfo
00032 {
00033 procInfo():vsize(),rss() {}
00034 procInfo(double sz, double rss_sz): vsize(sz),rss(rss_sz) {}
00035
00036 bool operator==(const procInfo& p) const
00037 { return vsize==p.vsize && rss==p.rss; }
00038
00039 bool operator>(const procInfo& p) const
00040 { return vsize>p.vsize || rss>p.rss; }
00041
00042
00043 double vsize;
00044 double rss;
00045 };
00046
00047 class SimpleMemoryCheck
00048 {
00049 public:
00050
00051 SimpleMemoryCheck(const ParameterSet&,ActivityRegistry&);
00052 ~SimpleMemoryCheck();
00053
00054 void preSourceConstruction(const ModuleDescription&);
00055 void postSourceConstruction(const ModuleDescription&);
00056 void postSource();
00057
00058 void postBeginJob();
00059
00060 void preEventProcessing(const edm::EventID&, const edm::Timestamp&);
00061 void postEventProcessing(const Event&, const EventSetup&);
00062
00063 void postModuleBeginJob(const ModuleDescription&);
00064 void postModuleConstruction(const ModuleDescription&);
00065
00066 void preModule(const ModuleDescription&);
00067 void postModule(const ModuleDescription&);
00068
00069 void postEndJob();
00070
00071 private:
00072 procInfo fetch();
00073 double pageSize() const { return pg_size_; }
00074 void update();
00075 void updateMax();
00076 void andPrint(const std::string& type,
00077 const std::string& mdlabel, const std::string& mdname) const;
00078 void updateAndPrint(const std::string& type,
00079 const std::string& mdlabel, const std::string& mdname);
00080
00081 procInfo a_;
00082 procInfo b_;
00083 procInfo max_;
00084 procInfo* current_;
00085 procInfo* previous_;
00086
00087 char buf_[500];
00088 int fd_;
00089 std::string fname_;
00090 double pg_size_;
00091 int num_to_skip_;
00092
00093 bool showMallocInfo;
00094 bool oncePerEventMode;
00095 int count_;
00096
00097
00098 struct SignificantEvent {
00099 int count;
00100 double vsize;
00101 double deltaVsize;
00102 double rss;
00103 double deltaRss;
00104 edm::EventID event;
00105 SignificantEvent() : count(0), vsize(0), deltaVsize(0),
00106 rss(0), deltaRss(0), event() {}
00107 void set (double deltaV, double deltaR,
00108 edm::EventID const & e, SimpleMemoryCheck *t)
00109 { count = t->count_;
00110 vsize = t->current_->vsize;
00111 deltaVsize = deltaV;
00112 rss = t->current_->rss;
00113 deltaRss = deltaR;
00114 event = e;
00115 }
00116 };
00117 friend class SignificantEvent;
00118 friend std::ostream & operator<< (std::ostream & os,
00119 SimpleMemoryCheck::SignificantEvent const & se);
00120 SignificantEvent eventM_;
00121 SignificantEvent eventL1_;
00122 SignificantEvent eventL2_;
00123 SignificantEvent eventR1_;
00124 SignificantEvent eventR2_;
00125 SignificantEvent eventT1_;
00126 SignificantEvent eventT2_;
00127 SignificantEvent eventT3_;
00128 void updateEventStats(edm::EventID const & e);
00129 std::string eventStatOutput(std::string title,
00130 SignificantEvent const& e) const;
00131 void eventStatOutput(std::string title,
00132 SignificantEvent const& e,
00133 std::map<std::string, double> &m) const;
00134 std::string mallOutput(std::string title, size_t const& n) const;
00135
00136
00137 struct SignificantModule {
00138 int postEarlyCount;
00139 double totalDeltaVsize;
00140 double maxDeltaVsize;
00141 edm::EventID eventMaxDeltaV;
00142 double totalEarlyVsize;
00143 double maxEarlyVsize;
00144 SignificantModule() : postEarlyCount (0)
00145 , totalDeltaVsize (0)
00146 , maxDeltaVsize (0)
00147 , eventMaxDeltaV ()
00148 , totalEarlyVsize (0)
00149 , maxEarlyVsize (0) {}
00150 void set (double deltaV, bool early);
00151 };
00152 friend class SignificantModule;
00153 friend std::ostream & operator<< (std::ostream & os,
00154 SimpleMemoryCheck::SignificantModule const & se);
00155 bool moduleSummaryRequested;
00156 typedef std::map<std::string,SignificantModule> SignificantModulesMap;
00157 SignificantModulesMap modules_;
00158 double moduleEntryVsize_;
00159 edm::EventID currentEventID_;
00160 void updateModuleMemoryStats(SignificantModule & m, double dv);
00161
00162 };
00163
00164 std::ostream &
00165 operator<< (std::ostream & os,
00166 SimpleMemoryCheck::SignificantEvent const & se);
00167
00168 std::ostream &
00169 operator<< (std::ostream & os,
00170 SimpleMemoryCheck::SignificantModule const & se);
00171
00172 }
00173 }
00174
00175
00176
00177 #endif