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((max_rss<max_datasz) ? max_rss : max_datasz); }
|
---|
29 | inline uint_8 getDeltaMemorySize() { return delta_rss; }
|
---|
30 |
|
---|
31 | inline uint_8 getMaxDataSize() { return max_datasz; }
|
---|
32 | inline uint_8 getDataSize() { return cur_datasz; }
|
---|
33 | inline uint_8 getMaxResidentSize() { return max_rss; }
|
---|
34 | inline uint_8 getResidentSize() { return cur_rss; }
|
---|
35 | inline uint_8 getMaxStackSize() { return max_stack; }
|
---|
36 | inline uint_8 getStackSize() { return cur_stack; }
|
---|
37 |
|
---|
38 |
|
---|
39 | // Time in milli-second
|
---|
40 | inline uint_8 getCPUTime() { return cur_tottm; }
|
---|
41 | inline uint_8 getElapsedTime() { return elapsed_time; }
|
---|
42 | inline float getAverageCPULoad()
|
---|
43 | { return ((elapsed_time>1) ? (float)cur_tottm/(float)elapsed_time: 1.);}
|
---|
44 |
|
---|
45 | inline uint_8 getDeltaCPUTime() { return delta_tottm; }
|
---|
46 | inline uint_8 getDeltaElapsedTime() { return elapsed_time; }
|
---|
47 |
|
---|
48 |
|
---|
49 | inline uint_8 getTotalCPUTime() { return cur_tottm; }
|
---|
50 | inline uint_8 getUserCPUTime() { return cur_usrtm; }
|
---|
51 | inline uint_8 getSysCPUTime() { return cur_systm; }
|
---|
52 |
|
---|
53 |
|
---|
54 | void Print(ostream& os, int lp=0, bool upd=true);
|
---|
55 | inline void print(ostream& os, int lp=0, bool upd=true){ Print(os,lp,upd); }
|
---|
56 |
|
---|
57 | protected:
|
---|
58 | uint_8 max_datasz; // Max data segment size (KBytes)
|
---|
59 | uint_8 max_rss; // Max resident size
|
---|
60 | uint_8 max_stack; // Max stack size
|
---|
61 |
|
---|
62 | uint_8 cur_datasz; // Current data segment size
|
---|
63 | uint_8 cur_rss; // Current resident size
|
---|
64 | uint_8 cur_stack; // Current stack size
|
---|
65 |
|
---|
66 | uint_8 cur_tottm; // Current total CPU-Time - in milli-second
|
---|
67 | uint_8 cur_usrtm; // Current user CPU-Time - in milli-second
|
---|
68 | uint_8 cur_systm; // Current system CPU-Time - in milli-second
|
---|
69 | uint_8 elapsed_time; // Elapsed time - in milli-second
|
---|
70 | uint_8 t0_time; // time T0 in seconds
|
---|
71 |
|
---|
72 | // Delta_values : difference since last call to Update()
|
---|
73 | uint_8 delta_rss; // Max resident size
|
---|
74 | uint_8 delta_tottm; // Delta total CPU-Time - in milli-second
|
---|
75 |
|
---|
76 | uint_8 delta_elapsed_time; // Elapsed time - in milli-second
|
---|
77 |
|
---|
78 | };
|
---|
79 |
|
---|
80 | inline ostream& operator << (ostream& os, ResourceUsage& ru)
|
---|
81 | { ru.Print(os,0,true); return(os); }
|
---|
82 |
|
---|
83 | } // namespace SOPHYA
|
---|
84 |
|
---|
85 | #endif
|
---|
86 |
|
---|