]>
Commit | Line | Data |
---|---|---|
ac8cd48d | 1 | #ifndef ALIMEMORYWATCHER_H |
2 | #define ALIMEMORYWATCHER_H | |
d60522e4 | 3 | /* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. * |
4 | * See cxx source for full Copyright notice */ | |
5 | /* $Id$ */ | |
d60522e4 | 6 | //_________________________________________________________________________ |
7 | /*Basic Memory Leak utility. | |
8 | ||
9 | You can use this tiny class to *see* if your program is leaking. | |
d60522e4 | 10 | Usage: |
ac8cd48d | 11 | AliMemoryWatcher memwatcher; |
d60522e4 | 12 | some program loop on events here { |
13 | if ( nevents % x == 0 ) | |
14 | { | |
15 | // take a sample every x events | |
16 | memwatcher.watch(nevents); | |
17 | } | |
18 | } | |
d60522e4 | 19 | TFile f("out.root","RECREATE"); |
20 | memwatcher.write(); | |
21 | f.Close(); | |
d60522e4 | 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 | |
25 | the total memory used | |
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) | |
d60522e4 | 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. | |
33 | ||
34 | But by fitting the VSIZE by a pol1 under ROOT, you'll see right away | |
35 | by how much your program is leaking. | |
36 | */ | |
37 | //*-- Author: Laurent Aphecetche(SUBATECH) | |
d60522e4 | 38 | // --- ROOT system --- |
39 | #include "TObject.h" | |
40 | class TH2; | |
41 | class TGraph; | |
42 | class TStopwatch; | |
ac8cd48d | 43 | class AliMemoryWatcher : public TObject |
d60522e4 | 44 | { |
45 | public: | |
ac8cd48d | 46 | AliMemoryWatcher(UInt_t maxsize=10000); |
d1898505 | 47 | AliMemoryWatcher(const AliMemoryWatcher& mw); |
ac8cd48d | 48 | ~AliMemoryWatcher() ; |
b01af8c2 | 49 | void Watch(Int_t x); |
d60522e4 | 50 | |
00399209 | 51 | UInt_t Size(void) const { return fSize; } |
b01af8c2 | 52 | Int_t X(Int_t n) const { return fX[n]; } |
53 | Int_t VSIZE(Int_t n) const { return fVSIZE[n]; } | |
54 | Int_t RSSIZE(Int_t n) const { return fRSSIZE[n]; } | |
55 | Double_t TIME(Int_t n) const { return fTIME[n]; } | |
56 | TGraph* GraphVSIZE(void); | |
57 | TGraph* GraphRSSIZE(void); | |
58 | TGraph* GraphTIME(void); | |
59 | TH2* Frame(void) const ; | |
6c4904c2 | 60 | Int_t Write(const char *name=0, Int_t option=0, Int_t bufsize=0); |
ac8cd48d | 61 | AliMemoryWatcher & operator = (const AliMemoryWatcher &) { return *this; } |
d60522e4 | 62 | private: |
00399209 | 63 | Int_t fPID; // PID of the process to watch |
64 | char fCmd[1024]; // the command sent to the system to retrieve things ("ps .....") | |
65 | UInt_t fMAXSIZE; // maximum size of arrays where the informationis stored | |
66 | UInt_t fSize; // the requested size of information to be retrieved | |
67 | Int_t* fX; // array that contains the step numbers | |
68 | Int_t* fVSIZE; // array that contains the virtual memory at each step | |
69 | Int_t* fRSSIZE; // array that contains the real memory at each step | |
70 | Double_t* fTIME; // array that contains the CPU time at each step | |
71 | TStopwatch* fTimer; // the chronometer | |
72 | Bool_t fDisabled; // to switch on/off the monitoring | |
dfe7f75b | 73 | |
ac8cd48d | 74 | ClassDef(AliMemoryWatcher,1) // General purpose memory watcher |
dfe7f75b | 75 | |
d60522e4 | 76 | } ; |
4ed9ed00 | 77 | #endif |