MemoryAuditor.cpp
Go to the documentation of this file.00001
00002
00003
00004 #include "MemoryAuditor.h"
00005 #include "ProcStats.h"
00006 #include "GaudiKernel/MsgStream.h"
00007 #include "GaudiKernel/AudFactory.h"
00008
00009 DECLARE_AUDITOR_FACTORY(MemoryAuditor)
00010
00011 MemoryAuditor::MemoryAuditor(const std::string& name, ISvcLocator* pSvcLocator) :
00012 Auditor(name, pSvcLocator)
00013 {
00014 declareProperty("CustomEventTypes",m_types);
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 void
00095 MemoryAuditor::before(CustomEventTypeRef evt, const std::string& caller) {
00096 if (m_types.value().size() != 0) {
00097 if ( (m_types.value())[0] == "none") {
00098 return;
00099 }
00100
00101 if ( find(m_types.value().begin(), m_types.value().end(), evt) ==
00102 m_types.value().end() ) {
00103 return;
00104 }
00105 }
00106
00107 std::string theString = "Memory usage before ";
00108 theString += caller + " with auditor trigger " + evt;
00109 printinfo(theString);
00110
00111 }
00112
00113 void
00114 MemoryAuditor::after(CustomEventTypeRef evt, const std::string& caller, const StatusCode&) {
00115
00116 if (m_types.value().size() != 0) {
00117 if ( (m_types.value())[0] == "none") {
00118 return;
00119 }
00120
00121 if ( find(m_types.value().begin(), m_types.value().end(), evt) ==
00122 m_types.value().end() ) {
00123 return;
00124 }
00125 }
00126
00127 std::string theString = "Memory usage has changed after ";
00128 theString += caller + " with auditor trigger " + evt;
00129 printinfo(theString);
00130
00131 }
00132
00133
00134 StatusCode MemoryAuditor::sysFinalize( )
00135 {
00136 return StatusCode::SUCCESS;
00137 }
00138
00139 bool MemoryAuditor::printinfo(std::string theString)
00140 {
00141 ProcStats* p = ProcStats::instance();
00142 procInfo info;
00143
00144
00145 if( p->fetch(info) == true) {
00146 MsgStream log(msgSvc(), name());
00147 log << MSG::INFO << theString <<
00148 " virtual size = " << info.vsize << " MB" <<
00149 " resident set size = " << info.rss << " MB" << endmsg;
00150 return true;
00151 }
00152 else {
00153 return false;
00154 }
00155 }