| # Gaudi Framework, version v21r7 |

Home |  | Generated: 22 Jan 2010

# MemStatAuditor.cpp

Go to the documentation of this file.

    00001
    00002 #include "GaudiKernel/MsgStream.h"
    00003 #include "GaudiKernel/AudFactory.h"
    00004 #include "GaudiKernel/IChronoStatSvc.h"
    00005
    00006 #include "GaudiKernel/Stat.h"
    00007
    00009 #include "ProcStats.h"
    00010 #include "MemStatAuditor.h"
    00011
    00012 DECLARE_AUDITOR_FACTORY(MemStatAuditor);
    00013
    00014 MemStatAuditor::MemStatAuditor(const std::string& name, ISvcLocator* pSvcLocator) :
    00015   Auditor(name, pSvcLocator), m_vSize(-1.)
    00016 {
    00017   declareProperty("CustomEventTypes",m_types);
    00018
    00019   m_stat = serviceLocator()->service("ChronoStatSvc");
    00020 }
    00021
    00022 MemStatAuditor::~MemStatAuditor(){
    00023 }
    00024
    00025 void MemStatAuditor::beforeInitialize(INamedInterface*) {
    00026   //DR not useful
    00027   //   std::string theString = "Memory usage before ";
    00028   //   theString += alg->name() ;
    00029   //   theString += " \tInitialization Method";
    00030   //   printinfo(theString, alg->name() );
    00031 }
    00032 void MemStatAuditor:: afterInitialize(INamedInterface* ini){
    00033   std::string theString = "Memory usage has changed after  ";
    00034   theString += ini->name() ;
    00035   theString += " \tInitialization Method";
    00036   printinfo(theString, ini->name() );
    00037 }
    00038 void MemStatAuditor::beforeReinitialize(INamedInterface*) {
    00039   //DR not useful
    00040   //   std::string theString = "Memory usage before ";
    00041   //   theString += alg->name() ;
    00042   //   theString += " \tReinitialization Method";
    00043   //   printinfo(theString, alg->name() );
    00044 }
    00045 void MemStatAuditor:: afterReinitialize(INamedInterface* ini){
    00046   std::string theString = "Memory usage has changed after  ";
    00047   theString += ini->name() ;
    00048   theString += " \tReinitialization Method";
    00049   printinfo(theString, ini->name() );
    00050 }
    00051 void MemStatAuditor:: beforeExecute(INamedInterface*){
    00052   //DR not useful
    00053   //   std::string theString = "Memory usage has changed before ";
    00054   //   theString += alg->name() ;
    00055   //   theString += " \tBefExecute Method";
    00056   //   printinfo(theString, alg->name() );
    00057 }
    00058 void MemStatAuditor:: afterExecute(INamedInterface* alg, const StatusCode& ) {
    00059   std::string theString = "Memory usage has changed after  ";
    00060   theString += alg->name() ;
    00061   theString += " \tExecute Method";
    00062   printinfo(theString, alg->name() );
    00063
    00064 }
    00065 void MemStatAuditor::beforeBeginRun(INamedInterface*) {
    00066   //DR not useful
    00067   //   std::string theString = "Memory usage before ";
    00068   //   theString += alg->name() ;
    00069   //   theString += " \tBeginRun Method";
    00070   //   printinfo(theString, alg->name() );
    00071 }
    00072 void MemStatAuditor:: afterBeginRun(INamedInterface* ini){
    00073   std::string theString = "Memory usage has changed after  ";
    00074   theString += ini->name() ;
    00075   theString += " \tBeginRun Method";
    00076   printinfo(theString, ini->name() );
    00077 }
    00078 void MemStatAuditor::beforeEndRun(INamedInterface*) {
    00079   //DR not useful
    00080   //   std::string theString = "Memory usage before ";
    00081   //   theString += alg->name() ;
    00082   //   theString += " \tEndRun Method";
    00083   //   printinfo(theString, alg->name() );
    00084 }
    00085 void MemStatAuditor:: afterEndRun(INamedInterface* ini){
    00086   std::string theString = "Memory usage has changed after  ";
    00087   theString += ini->name() ;
    00088   theString += " \tEndRun Method";
    00089   printinfo(theString, ini->name() );
    00090 }
    00091 void MemStatAuditor:: beforeFinalize(INamedInterface*) {
    00092   //DR not useful
    00093   //   std::string theString = "Memory usage has changed before ";
    00094   //   theString += alg->name() ;
    00095   //   theString += " \tFinalize Method";
    00096   //   printinfo(theString, alg->name() );
    00097 }
    00098 void MemStatAuditor:: afterFinalize(INamedInterface*){
    00099   //DR not useful
    00100   //   std::string theString = "Memory usage has changed after  ";
    00101   //   theString += alg->name() ;
    00102   //   theString += " \tFinalize Method";
    00103   //   printinfo(theString, alg->name() );
    00104
    00105 }
    00106
    00107 void
    00108 MemStatAuditor::before(CustomEventTypeRef evt, const std::string& caller) {
    00109
    00110   if (m_types.value().size() != 0) {
    00111     if ( (m_types.value())[0] == "none") {
    00112       return;
    00113     }
    00114
    00115     if ( find(m_types.value().begin(), m_types.value().end(), evt) ==
    00116          m_types.value().end() ) {
    00117       return;
    00118     }
    00119   }
    00120
    00121   std::string theString = "Memory usage before ";
    00122   theString += caller + " with auditor trigger " + evt;
    00123   printinfo(theString, caller);
    00124
    00125 }
    00126
    00127 void
    00128 MemStatAuditor::after(CustomEventTypeRef evt, const std::string& caller, const StatusCode&) {
    00129
    00130   if (m_types.value().size() != 0) {
    00131     if ( (m_types.value())[0] == "none") {
    00132       return;
    00133     }
    00134
    00135     if ( find(m_types.value().begin(), m_types.value().end(), evt) ==
    00136          m_types.value().end() ) {
    00137       return;
    00138     }
    00139   }
    00140
    00141   std::string theString = "Memory usage has changed after ";
    00142   theString += caller + " with auditor trigger " + evt;
    00143   printinfo(theString, caller);
    00144
    00145 }
    00146
    00147 StatusCode MemStatAuditor::sysFinalize( )
    00148 {
    00149   return StatusCode::SUCCESS;
    00150 }
    00151
    00152 bool MemStatAuditor::printinfo(const std::string& theString, const std::string& tag )
    00153 {
    00154   bool status(false);
    00155   ProcStats* p = ProcStats::instance();
    00156   procInfo info;
    00158   double deltaVSize =0.00001;
    00159
    00160
    00161   if( p->fetch(info) == true)
    00162     {
    00163       MsgStream log(msgSvc(), name());
    00164
    00165       if (m_vSize>0 && info.vsize >0 ){
    00166          deltaVSize=info.vsize-m_vSize;
    00167       }
    00168
    00169       // store the current VSize to be able to monitor the increment
    00170       if (info.vsize>0) {
    00171          m_vSize=info.vsize;
    00172       }
    00173
    00174       log << MSG::INFO << theString <<
    00175         " \tvirtual size = " << info.vsize << " MB"  <<
    00176         " \tresident set size = " << info.rss << " MB" <<
    00177         " deltaVsize = " << deltaVSize << "  MB " << endmsg;
    00179
    00180       //      Stat stv( statSvc() , tag+":VMemUsage" , info.vsize );
    00181       //   Stat str( statSvc() , tag+":RMemUsage" , info.rss   );
    00183       status=true;
    00184     }
    00185   // fill the stat for every call, not just when there is a change
    00186   // only monitor the increment in VSize
    00187   Stat sts( statSvc() , tag+":VMem" , deltaVSize );
    00188
    00189
    00191   return status; //FIXME
    00192 };
    00193
    00194
    00195
    00196
    00197
    00198
    00199
    00200