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