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
00032
00033
00034
00035
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
00045
00046
00047
00048
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
00058
00059
00060
00061
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
00072
00073
00074
00075
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
00085
00086
00087
00088
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
00098
00099
00100
00101
00102 }
00103 void MemStatAuditor:: afterFinalize(INamedInterface*){
00104
00105
00106
00107
00108
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
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
00186
00188 status=true;
00189 }
00190
00191
00192 Stat sts( statSvc() , tag+":VMem" , deltaVSize );
00193
00194
00196 return status;
00197 };
00198
00199
00200
00201
00202
00203
00204
00205