+++ /dev/null
-/**************************************************************************
- * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
- * *
- * Author: The ALICE Off-line Project. *
- * Contributors are mentioned in the code where appropriate. *
- * *
- * Permission to use, copy, modify and distribute this software and its *
- * documentation strictly for non-commercial purposes is hereby granted *
- * without fee, provided that the above copyright notice appears in all *
- * copies and that both the copyright notice and this permission notice *
- * appear in the supporting documentation. The authors make no claims *
- * about the suitability of this software for any purpose. It is *
- * provided "as is" without express or implied warranty. *
- **************************************************************************/
-/* $Id$ */
-
-//_________________________________________________________________________
-//Basic Memory Leak utility.
-// You can use this tiny class to *see* if your program is leaking.
-// Usage:
-// AliMemoryWatcher memwatcher;
-// some program loop on events here {
-// if ( nevents % x == 0 )
-// {
-// // take a sample every x events
-// memwatcher.Watch(nevents);
-// }
-// }
-// TFile f("out.root","RECREATE");
-// memwatcher.Write();
-// f.Close();
-// In the output root file you'll get 3 graphs representing
-// the evolAliPHOSon, as a function of the number of events, of :
-// - VSIZE is the virtual size (in KBytes) of your program, that is sort of
-// the total memory used
-// - RSSIZE is the resident size (in KBytes), that is, the part of your
-// program which is really in physical memory.
-// - TIME is an estimate of time per event (really it's the time elasped
-// between two calls to watch method)
-// WARNING: this is far from a bulletproof memory report (it's basically
-// using UNIX command ps -h -p [PID] -o vsize,rssize to do its job).
-// It has only been tested on Linux so far.
-// But by fitting the VSIZE by a pol1 under ROOT, you'll see right away
-// by how much your program is leaking.
-//*-- Author: Laurent Aphecetche(SUBATECH)
-
-// --- std system ---
-#include <cassert>
-#ifdef NEVER
-#include <stdlib.h>
-#endif
-// --- AliRoot header files ---
-#include "AliLog.h"
-#include "AliMemoryWatcher.h"
-// --- ROOT system ---
-#include "TSystem.h"
-#include "TGraph.h"
-#include "TH2.h"
-#include "TStopwatch.h"
-#include "TError.h"
-
-ClassImp(AliMemoryWatcher)
-
-//_____________________________________________________________________________
-AliMemoryWatcher::AliMemoryWatcher(UInt_t maxsize) :
- TObject(),
- fMAXSIZE(maxsize),
- fSize(0),
- fX(new Int_t[fMAXSIZE]),
- fVSIZE(new Int_t[fMAXSIZE]),
- fRSSIZE(new Int_t[fMAXSIZE]),
- fTIME(new Double_t[fMAXSIZE]),
- fTimer(0),
- fDisabled(kFALSE)
-{
- //
- //ctor
- //
-}
-
-//_____________________________________________________________________________
-AliMemoryWatcher::AliMemoryWatcher(const AliMemoryWatcher& mw):
- TObject(mw),
- fMAXSIZE(mw.fMAXSIZE),
- fSize(0),
- fX(new Int_t[fMAXSIZE]),
- fVSIZE(new Int_t[fMAXSIZE]),
- fRSSIZE(new Int_t[fMAXSIZE]),
- fTIME(new Double_t[fMAXSIZE]),
- fTimer(0),
- fDisabled(kFALSE)
-{
- //copy ctor
-}
-
-//_____________________________________________________________________________
-AliMemoryWatcher::~AliMemoryWatcher()
-{
- // dtor
- delete[] fVSIZE;
- delete[] fRSSIZE;
- delete[] fX;
- delete[] fTIME;
- delete fTimer;
-}
-//_____________________________________________________________________________
-void AliMemoryWatcher::Watch(Int_t x)
-{
- static ProcInfo_t meminfo;
-#ifdef NEVER
- static Char_t cmd[1024]="";
-#endif
- // Sets the point where CPU parameters have to be monitored
- if ( !fDisabled && fSize < fMAXSIZE ) {
- if ( fSize==0 ) {
- fTimer = new TStopwatch;
- fTimer->Start(true);
- fTimer->Stop();
-#ifdef NEVER
- if(!cmd[0])
- sprintf(cmd,"ps -h -p %d -o vsz,rss | grep -v VSZ",gSystem->GetPid());
-#endif
- }
- gSystem->GetProcInfo(&meminfo);
- fX[fSize] = x ;
- fVSIZE[fSize] = meminfo.fMemVirtual / 1024;
- fRSSIZE[fSize] = meminfo.fMemResident / 1024;
- fTIME[fSize] = fTimer->CpuTime();
- fSize++;
-#ifdef NEVER
- Int_t vsize, rssize;
- FILE* pipe = 0;
- pipe = popen(cmd,"r");
- if ( pipe ) {
-
- fscanf(pipe,"%d %d",&vsize,&rssize);
-
- fX[fSize] = x ;
- fVSIZE[fSize] = vsize ;
- fRSSIZE[fSize] = rssize ;
- fTIME[fSize] = fTimer->CpuTime();
- fSize++;
- }
- Int_t iclose=pclose(pipe);
- assert(iclose!=-1);
-#endif
- fTimer->Start(true);
- } else {
- fDisabled=true;
- AliError("I'm full !" ) ;
- }
-}
-//_____________________________________________________________________________
-TGraph*
-AliMemoryWatcher::GraphVSIZE(void)
-{
- // Fills the graph with the virtual memory sized used
- TGraph* g = 0;
- if ( Size() )
- {
- g = new TGraph(Size());
- Int_t i ;
- for (i=0; i < g->GetN(); i++ ) {
- g->SetPoint(i,X(i),VSIZE(i));
- }
- }
- return g;
-}
-//_____________________________________________________________________________
-TGraph*
-AliMemoryWatcher::GraphRSSIZE(void)
-{
- // Fills the graph with the real memory sized used
- TGraph* g = 0;
- if ( Size() )
- {
- g = new TGraph(Size());
- Int_t i ;
- for (i=0; i < g->GetN(); i++ ) {
- g->SetPoint(i,X(i),RSSIZE(i));
- }
- }
- return g;
-}
-//_____________________________________________________________________________
-TGraph*
-AliMemoryWatcher::GraphTIME(void)
-{
- // Fills the raph with the used CPU time
- TGraph* g = 0;
- if ( Size() )
- {
- g = new TGraph(Size());
- Int_t i ;
- for (i=0; i < g->GetN(); i++ ) {
- g->SetPoint(i,X(i),TIME(i));
- }
- }
- return g;
-}
-//_____________________________________________________________________________
-TH2*
-AliMemoryWatcher::Frame(void) const
-{
- //creates the frame histo in which the graphs will be plotted
- Double_t xmin=1E30;
- Double_t xmax=0;
- Double_t ymin=1;
- Double_t ymax=0;
- UInt_t i ;
- for (i=0; i < Size() ; i++ ) {
- if ( X(i) < xmin ) xmin = X(i);
- if ( X(i) > xmax ) xmax = X(i);
- Double_t y = VSIZE(i)+RSSIZE(i);
- if ( y > ymax ) ymax = y;
- if ( VSIZE(i) < ymin ) ymin = VSIZE(i);
- if ( RSSIZE(i) < ymin ) ymin = RSSIZE(i);
- }
- TH2F* h = new TH2F("frame","",10,xmin,xmax,10,ymin*0.8,ymax*1.2);
- return h;
-}
-//_____________________________________________________________________________
-Int_t
-AliMemoryWatcher::WriteToFile()
-{
- // Stores the graphs in a file
- if ( GraphVSIZE() ) GraphVSIZE()->Write("VSIZE",TObject::kOverwrite);
- if ( GraphRSSIZE() ) GraphRSSIZE() ->Write("RSSIZE",TObject::kOverwrite);
- if ( GraphTIME() ) GraphTIME()->Write("TIME",TObject::kOverwrite);
- return 0;
-}
+++ /dev/null
-#ifndef ALIMEMORYWATCHER_H
-#define ALIMEMORYWATCHER_H
-/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
- * See cxx source for full Copyright notice */
-
-/* $Id$ */
-
-//_________________________________________________________________________
-//Basic Memory Leak utility.
-//
-// You can use this tiny class to *see* if your program is leaking.
-// Usage:
-// AliMemoryWatcher memwatcher;
-// some program loop on events here {
-// if ( nevents % x == 0 )
-// {
-// // take a sample every x events
-// memwatcher.watch(nevents);
-// }
-// }
-// TFile f("out.root","RECREATE");
-// memwatcher.write();
-// f.Close();
-// In the output root file you'll get 3 graphs representing
-// the evolAliPHOSon, as a function of the number of events, of :
-// - VSIZE is the virtual size (in KBytes) of your program, that is sort of
-// the total memory used
-// - RSSIZE is the resident size (in KBytes), that is, the part of your
-// program which is really in physical memory.
-// - TIME is an estimate of time per event (really it's the time elasped
-// between two calls to watch method)
-// WARNING: this is far from a bulletproof memory report (it's basically
-// using UNIX command ps -h -p [PID] -o vsize,rssize to do its job).
-// It has only been tested on Linux so far.
-//
-// But by fitting the VSIZE by a pol1 under ROOT, you'll see right away
-// by how much your program is leaking.
-//
-//*-- Author: Laurent Aphecetche(SUBATECH)
-
-// --- ROOT system ---
-
-#include "TObject.h"
-class TH2;
-class TGraph;
-class TStopwatch;
-class AliMemoryWatcher : public TObject
-{
-public:
- AliMemoryWatcher(UInt_t maxsize=10000);
- AliMemoryWatcher(const AliMemoryWatcher& mw);
- ~AliMemoryWatcher() ;
- void Watch(Int_t x);
-
- UInt_t Size(void) const { return fSize; }
- Int_t X(Int_t n) const { return fX[n]; }
- Int_t VSIZE(Int_t n) const { return fVSIZE[n]; }
- Int_t RSSIZE(Int_t n) const { return fRSSIZE[n]; }
- Double_t TIME(Int_t n) const { return fTIME[n]; }
- TGraph* GraphVSIZE(void);
- TGraph* GraphRSSIZE(void);
- TGraph* GraphTIME(void);
- TH2* Frame(void) const ;
- Int_t WriteToFile();
- AliMemoryWatcher & operator = (const AliMemoryWatcher &) { return *this; }
-private:
- UInt_t fMAXSIZE; // maximum size of arrays where the informationis stored
- UInt_t fSize; // the requested size of information to be retrieved
- Int_t* fX; //[fMAXSIZE] array that contains the step numbers
- Int_t* fVSIZE; //[fMAXSIZE] array that contains the virtual memory at each step
- Int_t* fRSSIZE; //[fMAXSIZE] array that contains the real memory at each step
- Double_t* fTIME; //[fMAXSIZE] array that contains the CPU time at each step
- TStopwatch* fTimer; // the chronometer
- Bool_t fDisabled; // to switch on/off the monitoring
-
- ClassDef(AliMemoryWatcher,2) // General purpose memory watcher
-
-} ;
-#endif