Gaudi Framework, version v20r2

Generated: 18 Jul 2008

MemStatAuditor.cpp

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

Generated at Fri Jul 18 11:59:19 2008 for Gaudi Framework, version v20r2 by Doxygen version 1.5.1 written by Dimitri van Heesch, © 1997-2004