| # Gaudi Framework, version v21r11 |

Home |  | Generated: 30 Sep 2010

# MemoryAuditor.cpp

Go to the documentation of this file.

    00001 // MemoryAuditor:
    00002 //  An auditor that monitors memory usage
    00003
    00004 #ifdef __ICC
    00005 // disable icc warning #654: overloaded virtual function "B::Y" is only partially overridden in class "C"
    00006 //   TODO: there is only a partial overload of IAuditor::before and IAuditor::after
    00007 #pragma warning(disable:654)
    00008 #endif
    00009
    00010 #include "MemoryAuditor.h"
    00011 #include "ProcStats.h"
    00012 #include "GaudiKernel/MsgStream.h"
    00013 #include "GaudiKernel/AudFactory.h"
    00014
    00015 DECLARE_AUDITOR_FACTORY(MemoryAuditor)
    00016
    00017 MemoryAuditor::MemoryAuditor(const std::string& name, ISvcLocator* pSvcLocator) :
    00018   Auditor(name, pSvcLocator)
    00019 {
    00020   declareProperty("CustomEventTypes",m_types);
    00021
    00022 }
    00023
    00024 MemoryAuditor::~MemoryAuditor(){
    00025 }
    00026
    00027 void MemoryAuditor::beforeInitialize(INamedInterface* alg) {
    00028   std::string theString = "Memory usage before ";
    00029   theString += alg->name() ;
    00030   theString += " Initialization Method";
    00031   printinfo(theString);
    00032 }
    00033 void MemoryAuditor:: afterInitialize(INamedInterface* alg){
    00034   std::string theString = "Memory usage has changed after ";
    00035   theString += alg->name() ;
    00036   theString += " Initialization Method";
    00037   printinfo(theString);
    00038 }
    00039 void MemoryAuditor::beforeReinitialize(INamedInterface* alg) {
    00040   std::string theString = "Memory usage before ";
    00041   theString += alg->name() ;
    00042   theString += " Reinitialization Method";
    00043   printinfo(theString);
    00044 }
    00045 void MemoryAuditor:: afterReinitialize(INamedInterface* alg){
    00046   std::string theString = "Memory usage has changed after ";
    00047   theString += alg->name() ;
    00048   theString += " Reinitialization Method";
    00049   printinfo(theString);
    00050 }
    00051 void MemoryAuditor:: beforeExecute(INamedInterface* alg){
    00052   std::string theString = "Memory usage has changed before ";
    00053   theString += alg->name() ;
    00054   theString += " Execute Method";
    00055   printinfo(theString);
    00056 }
    00057 void MemoryAuditor:: afterExecute(INamedInterface* alg, const StatusCode& ) {
    00058   std::string theString = "Memory usage has changed after ";
    00059   theString += alg->name() ;
    00060   theString += " Execute Method";
    00061   printinfo(theString);
    00062 }
    00063 void MemoryAuditor::beforeBeginRun(INamedInterface* ini) {
    00064   std::string theString = "Memory usage before ";
    00065   theString += ini->name() ;
    00066   theString += " BeginRun Method";
    00067   printinfo(theString);
    00068 }
    00069 void MemoryAuditor:: afterBeginRun(INamedInterface* ini){
    00070   std::string theString = "Memory usage has changed after ";
    00071   theString += ini->name() ;
    00072   theString += " BeginRun Method";
    00073   printinfo(theString);
    00074 }
    00075 void MemoryAuditor::beforeEndRun(INamedInterface* ini) {
    00076   std::string theString = "Memory usage before ";
    00077   theString += ini->name() ;
    00078   theString += " EndRun Method";
    00079   printinfo(theString);
    00080 }
    00081 void MemoryAuditor:: afterEndRun(INamedInterface* ini){
    00082   std::string theString = "Memory usage has changed after ";
    00083   theString += ini->name() ;
    00084   theString += " EndRun Method";
    00085   printinfo(theString);
    00086 }
    00087 void MemoryAuditor:: beforeFinalize(INamedInterface* alg) {
    00088   std::string theString = "Memory usage has changed before ";
    00089   theString += alg->name() ;
    00090   theString += " Finalize Method";
    00091   printinfo(theString);
    00092 }
    00093 void MemoryAuditor:: afterFinalize(INamedInterface* alg){
    00094   std::string theString = "Memory usage has changed after ";
    00095   theString += alg->name() ;
    00096   theString += " Finalize Method";
    00097   printinfo(theString);
    00098 }
    00099
    00100 void
    00101 MemoryAuditor::before(CustomEventTypeRef evt, const std::string& caller) {
    00102   if (m_types.value().size() != 0) {
    00103     if ( (m_types.value())[0] == "none") {
    00104       return;
    00105     }
    00106
    00107     if ( find(m_types.value().begin(), m_types.value().end(), evt) ==
    00108          m_types.value().end() ) {
    00109       return;
    00110     }
    00111   }
    00112
    00113   std::string theString = "Memory usage before ";
    00114   theString += caller + " with auditor trigger " + evt;
    00115   printinfo(theString);
    00116
    00117 }
    00118
    00119 void
    00120 MemoryAuditor::after(CustomEventTypeRef evt, const std::string& caller, const StatusCode&) {
    00121
    00122   if (m_types.value().size() != 0) {
    00123     if ( (m_types.value())[0] == "none") {
    00124       return;
    00125     }
    00126
    00127     if ( find(m_types.value().begin(), m_types.value().end(), evt) ==
    00128          m_types.value().end() ) {
    00129       return;
    00130     }
    00131   }
    00132
    00133   std::string theString = "Memory usage has changed after ";
    00134   theString += caller + " with auditor trigger " + evt;
    00135   printinfo(theString);
    00136
    00137 }
    00138
    00139
    00140 StatusCode MemoryAuditor::sysFinalize( )
    00141 {
    00142   return StatusCode::SUCCESS;
    00143 }
    00144
    00145 bool MemoryAuditor::printinfo(std::string theString)
    00146 {
    00147    ProcStats* p = ProcStats::instance();
    00148    procInfo info;
    00149
    00150    // The fetch method returns true if memory usage has changed...
    00151    if( p->fetch(info) == true) {
    00152      MsgStream log(msgSvc(), name());
    00153      log << MSG::INFO << theString <<
    00154        " virtual size = " << info.vsize << " MB"  <<
    00155        " resident set size = " << info.rss << " MB" << endmsg;
    00156      return true;
    00157     }
    00158    else {
    00159       return false;
    00160    }
    00161 }