1 | // This may look like C code, but it is really -*- C++ -*-
|
---|
2 | // permet d'obtenir des informations sur les ressources utilisees
|
---|
3 | // R. Ansari - Juillet 2002
|
---|
4 | // LAL (Orsay) / IN2P3-CNRS DAPNIA/SPP (Saclay) / CEA
|
---|
5 |
|
---|
6 | #ifndef RESUSAGE_H_SEEN
|
---|
7 | #define RESUSAGE_H_SEEN
|
---|
8 |
|
---|
9 | #include "machdefs.h"
|
---|
10 | #include <iostream.h>
|
---|
11 |
|
---|
12 | namespace SOPHYA {
|
---|
13 |
|
---|
14 | //! Acces to nformation about resource usage (memory, CPU, ...)
|
---|
15 |
|
---|
16 | class ResourceUsage
|
---|
17 | {
|
---|
18 | public:
|
---|
19 | ResourceUsage();
|
---|
20 | ~ResourceUsage();
|
---|
21 |
|
---|
22 | int Update();
|
---|
23 |
|
---|
24 | // Memory usage in kilo-bytes
|
---|
25 | // NOTE: getDataSize() getStackSize() retournent des valeurs bizarres
|
---|
26 | inline uint_8 getMemorySize() { return cur_rss; }
|
---|
27 | inline uint_8 getMaxMemorySize()
|
---|
28 | { return((getMaxResidentSize()<getMaxDataSize()) ?
|
---|
29 | getMaxResidentSize() :getMaxDataSize() ); }
|
---|
30 | inline uint_8 getDeltaMemorySize() { return delta_rss; }
|
---|
31 |
|
---|
32 | inline uint_8 getMaxDataSize() { return((max_datasz>0)?max_datasz:1024); }
|
---|
33 | inline uint_8 getDataSize() { return cur_datasz; }
|
---|
34 | inline uint_8 getMaxResidentSize() { return((max_rss>0)?max_rss:1024); }
|
---|
35 | inline uint_8 getResidentSize() { return cur_rss; }
|
---|
36 | inline uint_8 getMaxStackSize() { return max_stack; }
|
---|
37 | inline uint_8 getStackSize() { return cur_stack; }
|
---|
38 |
|
---|
39 |
|
---|
40 | // Time in milli-second
|
---|
41 | inline uint_8 getCPUTime() { return cur_tottm; }
|
---|
42 | inline uint_8 getElapsedTime() { return elapsed_time; }
|
---|
43 | inline double getAverageCPULoad()
|
---|
44 | { return ((elapsed_time>1) ? (double)cur_tottm/(double)elapsed_time: 1.);}
|
---|
45 |
|
---|
46 | inline uint_8 getDeltaCPUTime() { return delta_tottm; }
|
---|
47 | inline uint_8 getDeltaElapsedTime() { return delta_elapsed_time; }
|
---|
48 | inline double getCPULoad()
|
---|
49 | { return ((delta_elapsed_time>1) ? (double)delta_tottm/(double)delta_elapsed_time: 1.);}
|
---|
50 |
|
---|
51 |
|
---|
52 | inline uint_8 getTotalCPUTime() { return cur_tottm; }
|
---|
53 | inline uint_8 getUserCPUTime() { return cur_usrtm; }
|
---|
54 | inline uint_8 getSysCPUTime() { return cur_systm; }
|
---|
55 |
|
---|
56 |
|
---|
57 | void Print(ostream& os, int lp=0, bool upd=true);
|
---|
58 | inline void print(ostream& os, int lp=0, bool upd=true){ Print(os,lp,upd); }
|
---|
59 |
|
---|
60 | protected:
|
---|
61 | uint_8 max_datasz; // Max data segment size (KBytes)
|
---|
62 | uint_8 max_rss; // Max resident size
|
---|
63 | uint_8 max_stack; // Max stack size
|
---|
64 |
|
---|
65 | uint_8 cur_datasz; // Current data segment size
|
---|
66 | uint_8 cur_rss; // Current resident size
|
---|
67 | uint_8 cur_stack; // Current stack size
|
---|
68 |
|
---|
69 | uint_8 cur_tottm; // Current total CPU-Time - in milli-second
|
---|
70 | uint_8 cur_usrtm; // Current user CPU-Time - in milli-second
|
---|
71 | uint_8 cur_systm; // Current system CPU-Time - in milli-second
|
---|
72 | uint_8 elapsed_time; // Elapsed time - in milli-second
|
---|
73 | uint_8 t0_time; // time T0 in seconds
|
---|
74 |
|
---|
75 | // Delta_values : difference since last call to Update()
|
---|
76 | uint_8 delta_rss; // Max resident size
|
---|
77 | uint_8 delta_tottm; // Delta total CPU-Time - in milli-second
|
---|
78 |
|
---|
79 | uint_8 delta_elapsed_time; // Elapsed time - in milli-second
|
---|
80 |
|
---|
81 | };
|
---|
82 |
|
---|
83 | inline ostream& operator << (ostream& os, ResourceUsage& ru)
|
---|
84 | { ru.Print(os,0,true); return(os); }
|
---|
85 |
|
---|
86 | } // namespace SOPHYA
|
---|
87 |
|
---|
88 | #endif
|
---|
89 |
|
---|