]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/AliMemoryWatcher.h
Bug fix in copy constructor and assignment operator.
[u/mrichter/AliRoot.git] / STEER / AliMemoryWatcher.h
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     */
5
6 /* $Id$ */
7
8 //_________________________________________________________________________
9 //Basic Memory Leak utility.
10 //  
11 //  You can use this tiny class to *see* if your program is leaking.
12 //  Usage:
13 //  AliMemoryWatcher memwatcher;
14 //  some program loop on events here {
15 //    if ( nevents % x == 0 ) 
16 //    {
17 //    // take a sample every x events
18 //      memwatcher.watch(nevents);
19 //    }
20 //  }
21 //  TFile f("out.root","RECREATE");
22 //  memwatcher.write();
23 //  f.Close();
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.
35 //  
36 //  But by fitting the VSIZE by a pol1 under ROOT, you'll see right away
37 //  by how much your program is leaking.
38 //
39 //*-- Author: Laurent Aphecetche(SUBATECH)
40
41 // --- ROOT system ---
42
43 #include "TObject.h" 
44 class TH2;
45 class TGraph;
46 class TStopwatch;
47 class AliMemoryWatcher : public TObject 
48 {
49 public:
50   AliMemoryWatcher(UInt_t maxsize=10000);
51   AliMemoryWatcher(const AliMemoryWatcher& mw);
52   ~AliMemoryWatcher() ;
53   void Watch(Int_t x);
54   
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 ;
64   Int_t       WriteToFile();
65   AliMemoryWatcher & operator = (const AliMemoryWatcher &) { return *this; } 
66 private:
67   UInt_t fMAXSIZE;     // maximum size of arrays where the informationis stored
68   UInt_t fSize;        // the requested size of information to be retrieved
69   Int_t* fX;           //[fMAXSIZE] array that contains the step numbers
70   Int_t* fVSIZE;       //[fMAXSIZE] array that contains the virtual memory at each step
71   Int_t* fRSSIZE;      //[fMAXSIZE] array that contains the real memory at each step
72   Double_t* fTIME;     //[fMAXSIZE] array that contains the CPU time at each step
73   TStopwatch* fTimer;  // the chronometer
74   Bool_t fDisabled;    // to switch on/off the monitoring
75
76   ClassDef(AliMemoryWatcher,2) // General purpose memory watcher
77
78 } ;
79 #endif