| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

In This Package:

MemoryAuditor.cpp

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

Generated on Mon Apr 11 19:59:12 2011 for GaudiAud by doxygen 1.4.7