CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_1/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.12 2012/05/06 19:11:56 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 #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_;   // in MB
00050       double pss_;     // in MB
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       //options
00106       bool showMallocInfo_;
00107       bool oncePerEventMode_;
00108       bool jobReportOutputOnly_;
00109       bool monitorPssAndPrivate_;
00110       int count_;
00111 
00112       //smaps
00113       FILE* smapsFile_;
00114       char* smapsLineBuffer_;
00115       size_t smapsLineBufferLen_;
00116 
00117       
00118       //Rates of growth
00119       double growthRateVsize_;
00120       double growthRateRss_;
00121 
00122       // Event summary statistics                               changeLog 1
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       }; // SignificantEvent
00150       friend struct SignificantEvent;
00151       friend std::ostream & operator<< (std::ostream & os, 
00152                 SimpleMemoryCheck::SignificantEvent const & se); 
00153 
00154       /* 
00155         Significative events for deltaVsize:
00156         - eventM_: Event which makes the biggest value for deltaVsize
00157         - eventL1_: Event which makes the second biggest value for deltaVsize
00158         - eventL2_: Event which makes the third biggest value for deltaVsize
00159         - eventR1_: Event which makes the second biggest value for deltaVsize
00160         - eventR2_: Event which makes the third biggest value for deltaVsize
00161         M>L1>L2 and M>R1>R2
00162                 Unknown relation between Ls and Rs events ???????
00163         Significative events for vsize:
00164         - eventT1_: Event whith the biggest value for vsize
00165         - eventT2_: Event whith the second biggest value for vsize
00166         - eventT3_: Event whith the third biggest value for vsize
00167         T1>T2>T3
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         Significative event for deltaRss:
00180         - eventRssT1_: Event whith the biggest value for rss
00181         - eventRssT2_: Event whith the second biggest value for rss
00182         - eventRssT3_: Event whith the third biggest value for rss
00183         T1>T2>T3
00184         Significative events for deltaRss:
00185         - eventDeltaRssT1_: Event whith the biggest value for deltaRss
00186         - eventDeltaRssT2_: Event whith the second biggest value for deltaRss
00187         - eventDeltaRssT3_: Event whith the third biggest value for deltaRss
00188         T1>T2>T3
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       // Module summary statistices
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       }; // SignificantModule
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     }; // SimpleMemoryCheck
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