]>
Commit | Line | Data |
---|---|---|
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 */ | |
5 | /* $Id$ */ | |
6 | ||
7 | //_________________________________________________________________________ | |
8 | /*Basic Memory Leak utility. | |
9 | ||
10 | You can use this tiny class to *see* if your program is leaking. | |
11 | ||
12 | Usage: | |
13 | ||
14 | AliPHOSMemoryWatcher memwatcher; | |
15 | ||
16 | some program loop on events here { | |
17 | if ( nevents % x == 0 ) | |
18 | { | |
19 | // take a sample every x events | |
20 | memwatcher.watch(nevents); | |
21 | } | |
22 | } | |
23 | ||
24 | TFile f("out.root","RECREATE"); | |
25 | memwatcher.write(); | |
26 | f.Close(); | |
27 | ||
28 | In the output root file you'll get 3 graphs representing | |
29 | the evolAliPHOSon, as a function of the number of events, of : | |
30 | - VSIZE is the virtual size (in KBytes) of your program, that is sort of | |
31 | the total memory used | |
32 | - RSSIZE is the resident size (in KBytes), that is, the part of your | |
33 | program which is really in physical memory. | |
34 | - TIME is an estimate of time per event (really it's the time elasped | |
35 | between two calls to watch method) | |
36 | ||
37 | WARNING: this is far from a bulletproof memory report (it's basically | |
38 | using UNIX command ps -h -p [PID] -o vsize,rssize to do its job). | |
39 | It has only been tested on Linux so far. | |
40 | ||
41 | But by fitting the VSIZE by a pol1 under ROOT, you'll see right away | |
42 | by how much your program is leaking. | |
43 | */ | |
44 | //*-- Author: Laurent Aphecetche(SUBATECH) | |
45 | ||
46 | ||
47 | // --- ROOT system --- | |
48 | #include "TObject.h" | |
49 | class TH2; | |
50 | class TGraph; | |
51 | class TStopwatch; | |
52 | ||
53 | ||
54 | class AliPHOSMemoryWatcher : public TObject | |
55 | { | |
56 | public: | |
57 | ||
58 | AliPHOSMemoryWatcher(unsigned int maxsize=10000); | |
59 | ~AliPHOSMemoryWatcher(); | |
60 | ||
61 | void watch(int x); | |
62 | ||
63 | unsigned int size(void) const { return fSize; } | |
64 | ||
65 | int X(int n) const { return fX[n]; } | |
66 | int VSIZE(int n) const { return fVSIZE[n]; } | |
67 | int RSSIZE(int n) const { return fRSSIZE[n]; } | |
68 | double TIME(int n) const { return fTIME[n]; } | |
69 | ||
70 | TGraph* graphVSIZE(void); | |
71 | TGraph* graphRSSIZE(void); | |
72 | TGraph* graphTIME(void); | |
73 | ||
74 | TH2* frame(void); | |
75 | ||
76 | void write(void); | |
77 | ||
78 | private: | |
79 | int fPID; | |
80 | char fCmd[1024]; | |
81 | unsigned int fMAXSIZE; | |
82 | unsigned int fSize; | |
83 | int* fX; | |
84 | int* fVSIZE; | |
85 | int* fRSSIZE; | |
86 | double* fTIME; | |
87 | TStopwatch* fTimer; | |
88 | bool fDisabled; | |
89 | } ; | |
90 | ||
91 | #endif | |
92 |