Commit 13bf3436 authored by cvs2svn's avatar cvs2svn
Browse files

This commit was manufactured by cvs2svn to create tag

'GAUDI_v19r3-pre'.

git-svn-id: svn+ssh://svn.cern.ch/reps/gaudi/distribution/tags/GAUDI/GAUDI_v19r3-pre@3722 53ecefc3-a64d-0410-9bdf-b8581fa3287e
parent ddddb07b
include $(CMTROOT)/src/Makefile.header
include $(CMTROOT)/src/constituents.make
!include $(CMTROOT)\src\NMakefile.header
!include $(CMTROOT)\src\constituents.nmake
package GaudiAud
version v8r1
branches doc src cmt
use GaudiKernel v*
# component library
library GaudiAud ../src/*.cpp
apply_pattern component_library library=GaudiAud
Package: GaudiAud
Package manager : David Quarrie
!==============v8r1==========================================================
! 2007-01-18 - Charles Leggett
patch #972.
- add messageCount to IMessageSvc
- extend Auditor::(sys)afterExecute to pass a const StatusCode&,
which is the return code of the algorithm
- new auditor to monitor algorithms, issue message if algorithm
writes out an ERROR or FATAL, but returns SUCCESS
!==============v8r0==========================================================
! 2007-01-12 - Hubert Degaudenzi
- bug #22799. changed the return value of chronoStart, chronoStop,
chronoPrint, stat and statPrint method of the IChronoStatSvc from
StatusCode to void.
! 2006-12-13 - Charles Leggett
- instrmented auditors for reinitialize, beginRun, endRun
! 2006-11-30 - Pere Mato
Adpated package to the new PluginSvc
- Removed protected from constructor/destructors and fiendship of
Factory class
!==============v7r2==========================================================
! 2006-09-21 Hubert Degaudenzi
- use of the DECLARE macros for the auditor factories.
! 2006-09-13 Charles Leggett and Hubert Degaudenzi
- added AlgContextAuditor (remove from GaudiSvc)
!==============v7r1==========================================================
! 2006-04-13 Charles Leggett and Hubert Degaudenzi
- inserted ATLAS feature INamedInterface.
!==============v7r0==========================================================
! 2006-03-15 - Hubert Degaudenzi
- replaced the returned StatusCode with void for before*/after*
methods of auditors. Interface changed.
!==============v6r6==========================================================
! 2006-01-27 - Pere Mato
- Use the compoment_library pattern
!==============v6r5==========================================================
! 2004-06-08 - Pere Mato
- ProcStats.h(.cpp) Fixed [bugs #3667] bytes to Mbytes conversion in ProcStats.cpp
!==============v6r4==========================================================
! 2004-01-15 - Pere Mato
- Added changes from ATLAS (Paolo et al.)
!==============v6r3==========================================================
! 2004-01-07 - David Rousseau
- MemStatAuditor::printinfo: don't return when p->fetch(info) is false
! 2003-11-06 - David Rousseau
- radically change the philosophy of MemStatAuditor: MemStatAuditor
now accumulate the incremental change of memory usage during the job.
Only VSize is monitored (RSS is less reproducible).
This allows to spot in which algorithm memory leak happen
! 2003-11-26 - Pere Mato
- Small changes for Mac OSX (Guy Barrand)
!==============v6r2==========================================================
! 2003-01-06 - Sebastien Ponce
- better support for gcc 3.2
!==============v6r1==========================================================
! 2002-09-24 - Pere Mato
- Changes to clean the reference counting and memory deallocation
detected by the "valgrind" tool. Changed failes: ChronoAuditor.cpp (.h)
- requirements: use v*
!==============v6r0p1=========================================================
! 2002-09-23 - Flr
- requirements - use GaudiKernel v*
!=============================================================================
!20010508 - Pere Mato
- Using GaudiKernel v10
!=============================================================================
!20010206 - Pere Mato
- New Auditor MemStatAuditor made by I. Belyaev added to the package
!=============================================================================
!20001025 - GaudiAud v1 -David Quarrie
- This package contains concrete Auditors. An Auditor monitors some resource
on a per-Algorithm basis. It performs this monitoring by calls immediately
before and after the appropriate initialize, execute and finalize calls.
Initial implementations are:
NameAuditor This is a diagnostic tool that just displays the name of
each Algorithm.
ChronoAuditor This displays at the end of job the total and per event
cpu time taken by each Algorithm.
MemoryAuditor This warns of possible memory leaks. However, Algorithms
that register objects with the transient event store will
cause this warning to be triggered. It is designed to
warn of memory leaks from Algorithms that retrieve objects
from the transient event store.
// AlgContextAuditor:
// An auditor that prints the name of each algorithm method before
// and after it is called///
#include "AlgContextAuditor.h"
#include "GaudiKernel/AudFactory.h"
#include <cassert>
#include "GaudiKernel/IAlgContextSvc.h"
#include "GaudiKernel/IAlgorithm.h"
DECLARE_AUDITOR_FACTORY(AlgContextAuditor)
AlgContextAuditor::AlgContextAuditor(const std::string& name, ISvcLocator* pSvcLocator) :
Auditor(name, pSvcLocator)
{}
AlgContextAuditor::~AlgContextAuditor()
{}
StatusCode
AlgContextAuditor::sysInitialize()
{
return service("AlgContextSvc", p_algContextSvc, true);
}
void
AlgContextAuditor::setContext(INamedInterface* ini)
{
IAlgorithm* pAlg = dynamic_cast<IAlgorithm*>(ini);
if (pAlg == 0) {
return;
}
assert(p_algContextSvc);
p_algContextSvc->setCurrentAlg(pAlg);
return;
}
#ifndef GAUDISVC_ALGCONTEXTAUDITOR_H
#define GAUDISVC_ALGCONTEXTAUDITOR_H
// ClassName: AlgContextAuditor
//
// Description: Prints the AlgContext of each algorithm before entering
// the algorithm and after leaving it
//
// Author: M. Shapiro, LBNL
//
#ifndef GAUDIKERNEL_AUDITOR_H
#include "GaudiKernel/Auditor.h"
#endif
class INamedInterface;
class IAlgContextSvc;
class AlgContextAuditor: public Auditor {
public:
//structors
AlgContextAuditor(const std::string& name, ISvcLocator* pSvcLocator);
virtual ~AlgContextAuditor();
//initialization
StatusCode sysInitialize();
//IAuditor implementation
void beforeInitialize(INamedInterface* pAlg)
{ setContext(pAlg); }
void afterInitialize(INamedInterface*)
{ setContext(0); }
void beforeExecute(INamedInterface* pAlg)
{ setContext(pAlg); }
void afterExecute(INamedInterface*, const StatusCode& )
{ setContext(0); }
void beforeFinalize(INamedInterface* pAlg)
{ setContext(pAlg); }
void afterFinalize(INamedInterface*)
{ setContext(0); }
private:
void setContext(INamedInterface* pAlg);
IAlgContextSvc* p_algContextSvc;
};
#endif
// AlgErrorAuditor:
// An auditor that monitors memory usage
#include "AlgErrorAuditor.h"
#include "GaudiKernel/MsgStream.h"
#include "GaudiKernel/IMessageSvc.h"
#include "GaudiKernel/INamedInterface.h"
#include "GaudiKernel/AudFactory.h"
#include "GaudiKernel/GaudiException.h"
DECLARE_AUDITOR_FACTORY(AlgErrorAuditor);
AlgErrorAuditor::AlgErrorAuditor(const std::string& name, ISvcLocator* pSvcLocator)
: Auditor(name, pSvcLocator), m_errorCount(0), m_fatalCount(0) {
}
AlgErrorAuditor::~AlgErrorAuditor(){
}
void
AlgErrorAuditor:: beforeExecute(INamedInterface* ){
m_error = msgSvc()->messageCount(MSG::ERROR);
m_fatal = msgSvc()->messageCount(MSG::FATAL);
}
void
AlgErrorAuditor:: afterExecute(INamedInterface* alg, const StatusCode& sc) {
if (! sc.isSuccess()) { return; }
if (msgSvc()->messageCount(MSG::ERROR) != m_error) {
MsgStream log(msgSvc(), name());
log << MSG::ERROR
<< "Algorithm " << alg->name()
<< " reported an ERROR, but returned a StatusCode::SUCCESS"
<< endreq;
m_errorCount ++;
}
if (msgSvc()->messageCount(MSG::FATAL) != m_fatal) {
MsgStream log(msgSvc(), name());
log << MSG::ERROR
<< "Algorithm " << alg->name()
<< " reported a FATAL, but returned a StatusCode::SUCCESS"
<< endreq;
m_fatalCount ++;
}
}
StatusCode
AlgErrorAuditor::finalize() {
if (m_error != 0 ) {
MsgStream log(msgSvc(), name());
log << MSG::INFO << "Found " << m_errorCount
<< " instances where an Algorithm::execute() produced an ERROR but returned a SUCCESS"
<< endreq;
}
if (m_fatal != 0 ) {
MsgStream log(msgSvc(), name());
log << MSG::INFO << "Found " << m_fatalCount
<< " instances where an Algorithm::execute() produced a FATAL but returned a SUCCESS"
<< endreq;
}
return StatusCode::SUCCESS;
}
#ifndef GAUDIAUD_ALGERRORAUDITOR_H
#define GAUDIAUD_ALGERRORAUDITOR_H
#include "GaudiKernel/Auditor.h"
class INamedInterface;
class IMessageSvc;
/** @class AlgErrorAuditor
Monitors the cpu time usage of each algorithm
@author David Quarrie
*/
class AlgErrorAuditor : virtual public Auditor {
public:
AlgErrorAuditor(const std::string& name, ISvcLocator* pSvcLocator);
virtual ~AlgErrorAuditor();
virtual StatusCode finalize();
virtual void beforeExecute(INamedInterface* alg);
virtual void afterExecute(INamedInterface* alg, const StatusCode&);
private:
int m_error;
int m_fatal;
int m_errorCount;
int m_fatalCount;
};
#endif
// ChronoAuditor:
// An auditor that monitors memory usage
#include "ChronoAuditor.h"
#include "GaudiKernel/MsgStream.h"
#include "GaudiKernel/INamedInterface.h"
#include "GaudiKernel/AudFactory.h"
#include "GaudiKernel/Chrono.h"
DECLARE_AUDITOR_FACTORY(ChronoAuditor);
ChronoAuditor::ChronoAuditor(const std::string& name, ISvcLocator* pSvcLocator)
: Auditor(name, pSvcLocator) {
service( "ChronoStatSvc", m_chronoSvc, true).ignore();
}
ChronoAuditor::~ChronoAuditor(){
m_chronoSvc->release();
}
void ChronoAuditor::beforeInitialize(INamedInterface* alg) {
chronoSvc( )->chronoStart( alg->name() + ":initialize" ) ;
}
void ChronoAuditor:: afterInitialize(INamedInterface* alg){
chronoSvc( )->chronoStop( alg->name() + ":initialize" ) ;
}
void ChronoAuditor::beforeReinitialize(INamedInterface* alg) {
chronoSvc( )->chronoStart( alg->name() + ":reinitialize" ) ;
}
void ChronoAuditor:: afterReinitialize(INamedInterface* alg){
chronoSvc( )->chronoStop( alg->name() + ":reinitialize" ) ;
}
void ChronoAuditor:: beforeExecute(INamedInterface* alg){
chronoSvc( )->chronoStart( alg->name() + ":execute" ) ;
}
void ChronoAuditor:: afterExecute(INamedInterface* alg, const StatusCode& ) {
chronoSvc( )->chronoStop( alg->name() + ":execute" ) ;
}
void ChronoAuditor::beforeBeginRun(INamedInterface* alg) {
chronoSvc( )->chronoStart( alg->name() + ":beginRun" ) ;
}
void ChronoAuditor:: afterBeginRun(INamedInterface* alg){
chronoSvc( )->chronoStop( alg->name() + ":beginRun" ) ;
}
void ChronoAuditor::beforeEndRun(INamedInterface* alg) {
chronoSvc( )->chronoStart( alg->name() + ":endRun" ) ;
}
void ChronoAuditor:: afterEndRun(INamedInterface* alg){
chronoSvc( )->chronoStop( alg->name() + ":endRun" ) ;
}
void ChronoAuditor:: beforeFinalize(INamedInterface* alg) {
chronoSvc( )->chronoStart( alg->name() + ":finalize" ) ;
}
void ChronoAuditor:: afterFinalize(INamedInterface* alg){
chronoSvc( )->chronoStop( alg->name() + ":finalize" ) ;
}
#ifndef GAUDIAUD_CHRONOAUDITOR_H
#define GAUDIAUD_CHRONOAUDITOR_H
#include "GaudiKernel/Auditor.h"
class INamedInterface;
class IChronoStatSvc;
/** @class ChronoAuditor
Monitors the cpu time usage of each algorithm
@author David Quarrie
*/
class ChronoAuditor : virtual public Auditor {
public:
ChronoAuditor(const std::string& name, ISvcLocator* pSvcLocator);
virtual ~ChronoAuditor();
virtual void beforeInitialize(INamedInterface* alg);
virtual void afterInitialize(INamedInterface* alg);
virtual void beforeReinitialize(INamedInterface* alg);
virtual void afterReinitialize(INamedInterface* alg);
virtual void beforeExecute(INamedInterface* alg);
virtual void afterExecute(INamedInterface* alg, const StatusCode&);
virtual void beforeBeginRun(INamedInterface* alg);
virtual void afterBeginRun(INamedInterface *alg);
virtual void beforeEndRun(INamedInterface* alg);
virtual void afterEndRun(INamedInterface *alg);
virtual void beforeFinalize(INamedInterface* alg);
virtual void afterFinalize(INamedInterface* alg);
IChronoStatSvc* chronoSvc( ) { return m_chronoSvc; }
private:
IChronoStatSvc* m_chronoSvc;
};
#endif
#include "GaudiKernel/LoadFactoryEntries.h"
LOAD_FACTORY_ENTRIES(GaudiAud)
#include "GaudiKernel/MsgStream.h"
#include "GaudiKernel/INamedInterface.h"
#include "GaudiKernel/AudFactory.h"
#include "GaudiKernel/Stat.h"
/// local
#include "ProcStats.h"
#include "MemStatAuditor.h"
DECLARE_AUDITOR_FACTORY(MemStatAuditor);
MemStatAuditor::MemStatAuditor(const std::string& name, ISvcLocator* pSvcLocator) :
Auditor(name, pSvcLocator)
{
StatusCode sc = serviceLocator()->service("ChronoStatSvc" , m_stat );
if( sc.isSuccess() && 0 != statSvc() ) { statSvc()->addRef(); }
m_vSize=-1.;
}
MemStatAuditor::~MemStatAuditor(){
}
void MemStatAuditor::beforeInitialize(INamedInterface*) {
//DR not useful
// std::string theString = "Memory usage before ";
// theString += alg->name() ;
// theString += " \tInitialization Method";
// printinfo(theString, alg->name() );
}
void MemStatAuditor:: afterInitialize(INamedInterface*){
//DR not useful
// std::string theString = "Memory usage has changed after ";
// theString += alg->name() ;
// theString += " \tInitialization Method";
// printinfo(theString, alg->name() );
}
void MemStatAuditor::beforeReinitialize(INamedInterface*) {
//DR not useful
// std::string theString = "Memory usage before ";
// theString += alg->name() ;
// theString += " \tReinitialization Method";
// printinfo(theString, alg->name() );
}
void MemStatAuditor:: afterReinitialize(INamedInterface* ini){
std::string theString = "Memory usage has changed after ";
theString += ini->name() ;
theString += " \tReinitialization Method";
printinfo(theString, ini->name() );
}
void MemStatAuditor:: beforeExecute(INamedInterface*){
//DR not useful
// std::string theString = "Memory usage has changed before ";
// theString += alg->name() ;
// theString += " \tBefExecute Method";
// printinfo(theString, alg->name() );
}
void MemStatAuditor:: afterExecute(INamedInterface* alg, const StatusCode& ) {
std::string theString = "Memory usage has changed after ";
theString += alg->name() ;
theString += " \tExecute Method";
printinfo(theString, alg->name() );
}
void MemStatAuditor::beforeBeginRun(INamedInterface*) {
//DR not useful
// std::string theString = "Memory usage before ";
// theString += alg->name() ;
// theString += " \tBeginRun Method";
// printinfo(theString, alg->name() );
}
void MemStatAuditor:: afterBeginRun(INamedInterface* ini){
std::string theString = "Memory usage has changed after ";
theString += ini->name() ;
theString += " \tBeginRun Method";
printinfo(theString, ini->name() );
}
void MemStatAuditor::beforeEndRun(INamedInterface*) {
//DR not useful
// std::string theString = "Memory usage before ";
// theString += alg->name() ;
// theString += " \tEndRun Method";
// printinfo(theString, alg->name() );
}
void MemStatAuditor:: afterEndRun(INamedInterface* ini){
std::string theString = "Memory usage has changed after ";
theString += ini->name() ;
theString += " \tEndRun Method";
printinfo(theString, ini->name() );
}
void MemStatAuditor:: beforeFinalize(INamedInterface*) {
//DR not useful
// std::string theString = "Memory usage has changed before ";
// theString += alg->name() ;
// theString += " \tFinalize Method";
// printinfo(theString, alg->name() );
}
void MemStatAuditor:: afterFinalize(INamedInterface*){
//DR not useful
// std::string theString = "Memory usage has changed after ";
// theString += alg->name() ;
// theString += " \tFinalize Method";
// printinfo(theString, alg->name() );
}
StatusCode MemStatAuditor::sysFinalize( )
{
return StatusCode::SUCCESS;
}
bool MemStatAuditor::printinfo(const std::string& theString, const std::string& tag )
{
bool status(false);
ProcStats* p = ProcStats::instance();
procInfo info;
///cannot be eaxactly 0
double deltaVSize =0.00001;
if( p->fetch(info) == true)
{
MsgStream log(msgSvc(), name());
if (m_vSize>0 && info.vsize >0 ){
deltaVSize=info.vsize-m_vSize;
}
// store the current VSize to be able to monitor the increment
if (info.vsize>0) {
m_vSize=info.vsize;
}
log << MSG::INFO << theString <<
" \tvirtual size = " << info.vsize << " MB" <<
" \tresident set size = " << info.rss << " MB" <<
" deltaVsize = " << deltaVSize << " MB " << endreq;
///
// Stat stv( statSvc() , tag+":VMemUsage" , info.vsize );
// Stat str( statSvc() , tag+":RMemUsage" , info.rss );
///
status=true;
}
// fill the stat for every call, not just when there is a change
// only monitor the increment in VSize
Stat sts( statSvc() , tag+":VMem" , deltaVSize );
///
return status; //FIXME
};
#ifndef GAUDIAUDITOR_MemStatAuditor_H
#define GAUDIAUDITOR_MemStatAuditor_H 1
/** @class MemStatAuditor MemStatAuditor.h GaudiAud/MemStatAudit.h
Just a minor modification of MemoryAuditor to allow
the ouput memory statistics table to be printed
@author Vanya Belyaev
@date 04/02/2001
*/
#include "GaudiKernel/Auditor.h"
class INamedInterface;