]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/AliMemoryWatcher.h
Coding conventions (Alberto)
[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 SetUseMallinfo(Bool_t use) { fUseMallinfo = use; }
54   void Watch(Int_t x);
55   
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 ;
65   Int_t       WriteToFile();
66   AliMemoryWatcher & operator = (const AliMemoryWatcher &) { return *this; } 
67 private:
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
79
80   ClassDef(AliMemoryWatcher,1) // General purpose memory watcher
81
82 } ;
83 #endif