]>
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 */ | |
0742d588 | 5 | |
d60522e4 | 6 | /* $Id$ */ |
0742d588 | 7 | |
d60522e4 | 8 | //_________________________________________________________________________ |
0742d588 | 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 | // | |
d60522e4 | 39 | //*-- Author: Laurent Aphecetche(SUBATECH) |
0742d588 | 40 | |
d60522e4 | 41 | // --- ROOT system --- |
0742d588 | 42 | |
d60522e4 | 43 | #include "TObject.h" |
44 | class TH2; | |
45 | class TGraph; | |
46 | class TStopwatch; | |
ac8cd48d | 47 | class AliMemoryWatcher : public TObject |
d60522e4 | 48 | { |
49 | public: | |
ac8cd48d | 50 | AliMemoryWatcher(UInt_t maxsize=10000); |
d1898505 | 51 | AliMemoryWatcher(const AliMemoryWatcher& mw); |
ac8cd48d | 52 | ~AliMemoryWatcher() ; |
7406fd3c | 53 | void SetUseMallinfo(Bool_t use) { fUseMallinfo = use; } |
b01af8c2 | 54 | void Watch(Int_t x); |
d60522e4 | 55 | |
00399209 | 56 | UInt_t Size(void) const { return fSize; } |
b01af8c2 | 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 ; | |
c4cb6153 | 65 | Int_t WriteToFile(); |
ac8cd48d | 66 | AliMemoryWatcher & operator = (const AliMemoryWatcher &) { return *this; } |
d60522e4 | 67 | private: |
7406fd3c | 68 | Bool_t fUseMallinfo; // use mallinfo function instead of ps command |
00399209 | 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 | |
9f50efc4 | 73 | Int_t* fX; //[fMAXSIZE] array that contains the step numbers |
74 | Int_t* fVSIZE; //[fMAXSIZE] array that contains the virtual memory at each step | |
75 | Int_t* fRSSIZE; //[fMAXSIZE] array that contains the real memory at each step | |
76 | Double_t* fTIME; //[fMAXSIZE] array that contains the CPU time at each step | |
00399209 | 77 | TStopwatch* fTimer; // the chronometer |
78 | Bool_t fDisabled; // to switch on/off the monitoring | |
dfe7f75b | 79 | |
ac8cd48d | 80 | ClassDef(AliMemoryWatcher,1) // General purpose memory watcher |
dfe7f75b | 81 | |
d60522e4 | 82 | } ; |
4ed9ed00 | 83 | #endif |