![]() |
|
|
Generated: 18 Jul 2008 |
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 } 00017 00018 MemoryAuditor::~MemoryAuditor(){ 00019 } 00020 00021 void MemoryAuditor::beforeInitialize(INamedInterface* alg) { 00022 std::string theString = "Memory usage before "; 00023 theString += alg->name() ; 00024 theString += " Initialization Method"; 00025 printinfo(theString); 00026 } 00027 void MemoryAuditor:: afterInitialize(INamedInterface* alg){ 00028 std::string theString = "Memory usage has changed after "; 00029 theString += alg->name() ; 00030 theString += " Initialization Method"; 00031 printinfo(theString); 00032 } 00033 void MemoryAuditor::beforeReinitialize(INamedInterface* alg) { 00034 std::string theString = "Memory usage before "; 00035 theString += alg->name() ; 00036 theString += " Reinitialization Method"; 00037 printinfo(theString); 00038 } 00039 void MemoryAuditor:: afterReinitialize(INamedInterface* alg){ 00040 std::string theString = "Memory usage has changed after "; 00041 theString += alg->name() ; 00042 theString += " Reinitialization Method"; 00043 printinfo(theString); 00044 } 00045 void MemoryAuditor:: beforeExecute(INamedInterface* alg){ 00046 std::string theString = "Memory usage has changed before "; 00047 theString += alg->name() ; 00048 theString += " Execute Method"; 00049 printinfo(theString); 00050 } 00051 void MemoryAuditor:: afterExecute(INamedInterface* alg, const StatusCode& ) { 00052 std::string theString = "Memory usage has changed after "; 00053 theString += alg->name() ; 00054 theString += " Execute Method"; 00055 printinfo(theString); 00056 } 00057 void MemoryAuditor::beforeBeginRun(INamedInterface* ini) { 00058 std::string theString = "Memory usage before "; 00059 theString += ini->name() ; 00060 theString += " BeginRun Method"; 00061 printinfo(theString); 00062 } 00063 void MemoryAuditor:: afterBeginRun(INamedInterface* ini){ 00064 std::string theString = "Memory usage has changed after "; 00065 theString += ini->name() ; 00066 theString += " BeginRun Method"; 00067 printinfo(theString); 00068 } 00069 void MemoryAuditor::beforeEndRun(INamedInterface* ini) { 00070 std::string theString = "Memory usage before "; 00071 theString += ini->name() ; 00072 theString += " EndRun Method"; 00073 printinfo(theString); 00074 } 00075 void MemoryAuditor:: afterEndRun(INamedInterface* ini){ 00076 std::string theString = "Memory usage has changed after "; 00077 theString += ini->name() ; 00078 theString += " EndRun Method"; 00079 printinfo(theString); 00080 } 00081 void MemoryAuditor:: beforeFinalize(INamedInterface* alg) { 00082 std::string theString = "Memory usage has changed before "; 00083 theString += alg->name() ; 00084 theString += " Finalize Method"; 00085 printinfo(theString); 00086 } 00087 void MemoryAuditor:: afterFinalize(INamedInterface* alg){ 00088 std::string theString = "Memory usage has changed after "; 00089 theString += alg->name() ; 00090 theString += " Finalize Method"; 00091 printinfo(theString); 00092 } 00093 00094 StatusCode MemoryAuditor::sysFinalize( ) 00095 { 00096 return StatusCode::SUCCESS; 00097 } 00098 00099 bool MemoryAuditor::printinfo(std::string theString) 00100 { 00101 ProcStats* p = ProcStats::instance(); 00102 procInfo info; 00103 00104 // The fetch method returns true if memory usage has changed... 00105 if( p->fetch(info) == true) { 00106 MsgStream log(msgSvc(), name()); 00107 log << MSG::INFO << theString << 00108 " virtual size = " << info.vsize << " MB" << 00109 " resident set size = " << info.rss << " MB" << endreq; 00110 return true; 00111 } 00112 else { 00113 return false; 00114 } 00115 }