MemStatAuditor.cpp
Go to the documentation of this file.00001
00002 #include "GaudiKernel/MsgStream.h"
00003 #include "GaudiKernel/AudFactory.h"
00004 #include "GaudiKernel/IChronoStatSvc.h"
00005
00006 #include "GaudiKernel/Stat.h"
00007
00009 #include "ProcStats.h"
00010 #include "MemStatAuditor.h"
00011
00012 DECLARE_AUDITOR_FACTORY(MemStatAuditor)
00013
00014 MemStatAuditor::MemStatAuditor(const std::string& name, ISvcLocator* pSvcLocator) :
00015 Auditor(name, pSvcLocator), m_vSize(-1.)
00016 {
00017 declareProperty("CustomEventTypes",m_types);
00018
00019 m_stat = serviceLocator()->service("ChronoStatSvc");
00020 }
00021
00022 MemStatAuditor::~MemStatAuditor(){
00023 }
00024
00025 void MemStatAuditor::beforeInitialize(INamedInterface*) {
00026
00027
00028
00029
00030
00031 }
00032 void MemStatAuditor:: afterInitialize(INamedInterface* ini){
00033 std::string theString = "Memory usage has changed after ";
00034 theString += ini->name() ;
00035 theString += " \tInitialization Method";
00036 printinfo(theString, ini->name() );
00037 }
00038 void MemStatAuditor::beforeReinitialize(INamedInterface*) {
00039
00040
00041
00042
00043
00044 }
00045 void MemStatAuditor:: afterReinitialize(INamedInterface* ini){
00046 std::string theString = "Memory usage has changed after ";
00047 theString += ini->name() ;
00048 theString += " \tReinitialization Method";
00049 printinfo(theString, ini->name() );
00050 }
00051 void MemStatAuditor:: beforeExecute(INamedInterface*){
00052
00053
00054
00055
00056
00057 }
00058 void MemStatAuditor:: afterExecute(INamedInterface* alg, const StatusCode& ) {
00059 std::string theString = "Memory usage has changed after ";
00060 theString += alg->name() ;
00061 theString += " \tExecute Method";
00062 printinfo(theString, alg->name() );
00063
00064 }
00065 void MemStatAuditor::beforeBeginRun(INamedInterface*) {
00066
00067
00068
00069
00070
00071 }
00072 void MemStatAuditor:: afterBeginRun(INamedInterface* ini){
00073 std::string theString = "Memory usage has changed after ";
00074 theString += ini->name() ;
00075 theString += " \tBeginRun Method";
00076 printinfo(theString, ini->name() );
00077 }
00078 void MemStatAuditor::beforeEndRun(INamedInterface*) {
00079
00080
00081
00082
00083
00084 }
00085 void MemStatAuditor:: afterEndRun(INamedInterface* ini){
00086 std::string theString = "Memory usage has changed after ";
00087 theString += ini->name() ;
00088 theString += " \tEndRun Method";
00089 printinfo(theString, ini->name() );
00090 }
00091 void MemStatAuditor:: beforeFinalize(INamedInterface*) {
00092
00093
00094
00095
00096
00097 }
00098 void MemStatAuditor:: afterFinalize(INamedInterface*){
00099
00100
00101
00102
00103
00104
00105 }
00106
00107 void
00108 MemStatAuditor::before(CustomEventTypeRef evt, const std::string& caller) {
00109
00110 if (m_types.value().size() != 0) {
00111 if ( (m_types.value())[0] == "none") {
00112 return;
00113 }
00114
00115 if ( find(m_types.value().begin(), m_types.value().end(), evt) ==
00116 m_types.value().end() ) {
00117 return;
00118 }
00119 }
00120
00121 std::string theString = "Memory usage before ";
00122 theString += caller + " with auditor trigger " + evt;
00123 printinfo(theString, caller);
00124
00125 }
00126
00127 void
00128 MemStatAuditor::after(CustomEventTypeRef evt, const std::string& caller, const StatusCode&) {
00129
00130 if (m_types.value().size() != 0) {
00131 if ( (m_types.value())[0] == "none") {
00132 return;
00133 }
00134
00135 if ( find(m_types.value().begin(), m_types.value().end(), evt) ==
00136 m_types.value().end() ) {
00137 return;
00138 }
00139 }
00140
00141 std::string theString = "Memory usage has changed after ";
00142 theString += caller + " with auditor trigger " + evt;
00143 printinfo(theString, caller);
00144
00145 }
00146
00147 StatusCode MemStatAuditor::sysFinalize( )
00148 {
00149 return StatusCode::SUCCESS;
00150 }
00151
00152 bool MemStatAuditor::printinfo(const std::string& theString, const std::string& tag )
00153 {
00154 bool status(false);
00155 ProcStats* p = ProcStats::instance();
00156 procInfo info;
00158 double deltaVSize =0.00001;
00159
00160
00161 if( p->fetch(info) == true)
00162 {
00163 MsgStream log(msgSvc(), name());
00164
00165 if (m_vSize>0 && info.vsize >0 ){
00166 deltaVSize=info.vsize-m_vSize;
00167 }
00168
00169
00170 if (info.vsize>0) {
00171 m_vSize=info.vsize;
00172 }
00173
00174 log << MSG::INFO << theString <<
00175 " \tvirtual size = " << info.vsize << " MB" <<
00176 " \tresident set size = " << info.rss << " MB" <<
00177 " deltaVsize = " << deltaVSize << " MB " << endmsg;
00179
00180
00181
00183 status=true;
00184 }
00185
00186
00187 Stat sts( statSvc() , tag+":VMem" , deltaVSize );
00188
00189
00191 return status;
00192 }
00193
00194
00195
00196
00197
00198
00199
00200