CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch9/src/FWCore/Services/src/Memory.h

Go to the documentation of this file.
00001 #ifndef FWCore_Services_Memory_h
00002 #define FWCore_Services_Memory_h
00003 // -*- C++ -*-
00004 //
00005 // Package:     Services
00006 // Class  :     SimpleMemoryCheck
00007 // 
00008 //
00009 // Original Author:  Jim Kowalkowski
00010 // $Id: Memory.h,v 1.9 2011/04/13 20:45:17 chrjones Exp $
00011 //
00012 // Change Log
00013 //
00014 // 1 - Apr 25, 2008 M. Fischler
00015 //      Data structures for Event summary statistics, 
00016 //
00017 // 2 - Jan 14, 2009 Natalia Garcia Nebot
00018 //      Added:  - Average rate of growth in RSS and peak value attained.
00019 //              - Average rate of growth in VSize over time, Peak VSize
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       // see proc(4) man pages for units and a description
00047       double vsize;   // in MB (used to be in pages?)
00048       double rss;     // in MB (used to be in pages?)
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       //options
00100       bool showMallocInfo_;
00101       bool oncePerEventMode_;
00102       bool jobReportOutputOnly_;
00103       int count_;
00104 
00105       //Rates of growth
00106       double growthRateVsize_;
00107       double growthRateRss_;
00108 
00109       // Event summary statistics                               changeLog 1
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       }; // SignificantEvent
00129       friend struct SignificantEvent;
00130       friend std::ostream & operator<< (std::ostream & os, 
00131                 SimpleMemoryCheck::SignificantEvent const & se); 
00132 
00133       /* 
00134         Significative events for deltaVsize:
00135         - eventM_: Event which makes the biggest value for deltaVsize
00136         - eventL1_: Event which makes the second biggest value for deltaVsize
00137         - eventL2_: Event which makes the third biggest value for deltaVsize
00138         - eventR1_: Event which makes the second biggest value for deltaVsize
00139         - eventR2_: Event which makes the third biggest value for deltaVsize
00140         M>L1>L2 and M>R1>R2
00141                 Unknown relation between Ls and Rs events ???????
00142         Significative events for vsize:
00143         - eventT1_: Event whith the biggest value for vsize
00144         - eventT2_: Event whith the second biggest value for vsize
00145         - eventT3_: Event whith the third biggest value for vsize
00146         T1>T2>T3
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         Significative event for deltaRss:
00159         - eventRssT1_: Event whith the biggest value for rss
00160         - eventRssT2_: Event whith the second biggest value for rss
00161         - eventRssT3_: Event whith the third biggest value for rss
00162         T1>T2>T3
00163         Significative events for deltaRss:
00164         - eventDeltaRssT1_: Event whith the biggest value for deltaRss
00165         - eventDeltaRssT2_: Event whith the second biggest value for deltaRss
00166         - eventDeltaRssT3_: Event whith the third biggest value for deltaRss
00167         T1>T2>T3
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       // Module summary statistices
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       }; // SignificantModule
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     }; // SimpleMemoryCheck
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