1 #ifndef ALIMEMORYWATCHER_H
2 #define ALIMEMORYWATCHER_H
3 /* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * See cxx source for full Copyright notice */
8 //_________________________________________________________________________
9 //Basic Memory Leak utility.
11 // You can use this tiny class to *see* if your program is leaking.
13 // AliMemoryWatcher memwatcher;
14 // some program loop on events here {
15 // if ( nevents % x == 0 )
17 // // take a sample every x events
18 // memwatcher.watch(nevents);
21 // TFile f("out.root","RECREATE");
22 // memwatcher.write();
24 // In the output root file you'll get 3 graphs representing
25 // the evolAliPHOSon, as a function of the number of events, of :
26 // - VSIZE is the virtual size (in KBytes) of your program, that is sort of
27 // the total memory used
28 // - RSSIZE is the resident size (in KBytes), that is, the part of your
29 // program which is really in physical memory.
30 // - TIME is an estimate of time per event (really it's the time elasped
31 // between two calls to watch method)
32 // WARNING: this is far from a bulletproof memory report (it's basically
33 // using UNIX command ps -h -p [PID] -o vsize,rssize to do its job).
34 // It has only been tested on Linux so far.
36 // But by fitting the VSIZE by a pol1 under ROOT, you'll see right away
37 // by how much your program is leaking.
39 //*-- Author: Laurent Aphecetche(SUBATECH)
41 // --- ROOT system ---
47 class AliMemoryWatcher : public TObject
50 AliMemoryWatcher(UInt_t maxsize=10000);
51 AliMemoryWatcher(const AliMemoryWatcher& mw);
53 void SetUseMallinfo(Bool_t use) { fUseMallinfo = use; }
56 UInt_t Size(void) const { return fSize; }
57 Int_t X(Int_t n) const { return fX[n]; }
58 Int_t VSIZE(Int_t n) const { return fVSIZE[n]; }
59 Int_t RSSIZE(Int_t n) const { return fRSSIZE[n]; }
60 Double_t TIME(Int_t n) const { return fTIME[n]; }
61 TGraph* GraphVSIZE(void);
62 TGraph* GraphRSSIZE(void);
63 TGraph* GraphTIME(void);
64 TH2* Frame(void) const ;
66 AliMemoryWatcher & operator = (const AliMemoryWatcher &) { return *this; }
68 Bool_t fUseMallinfo; // use mallinfo function instead of ps command
69 Int_t fPID; // PID of the process to watch
70 char fCmd[1024]; // the command sent to the system to retrieve things ("ps .....")
71 UInt_t fMAXSIZE; // maximum size of arrays where the informationis stored
72 UInt_t fSize; // the requested size of information to be retrieved
73 Int_t* fX; // array that contains the step numbers
74 Int_t* fVSIZE; // array that contains the virtual memory at each step
75 Int_t* fRSSIZE; // array that contains the real memory at each step
76 Double_t* fTIME; // array that contains the CPU time at each step
77 TStopwatch* fTimer; // the chronometer
78 Bool_t fDisabled; // to switch on/off the monitoring
80 ClassDef(AliMemoryWatcher,1) // General purpose memory watcher