| # Gaudi Framework, version v20r4
Generated: 8 Jan 2009

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