[2101] | 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
|
---|
[2212] | 26 | //! Returns the current memory (Resident) size (in kilo-bytes)
|
---|
[2101] | 27 | inline uint_8 getMemorySize() { return cur_rss; }
|
---|
[2212] | 28 | //! Returns the maximum allowed memory size: Min( \c MaxResidentSize , \c MaxDataSize ))
|
---|
[2101] | 29 | inline uint_8 getMaxMemorySize()
|
---|
[2108] | 30 | { return((getMaxResidentSize()<getMaxDataSize()) ?
|
---|
| 31 | getMaxResidentSize() :getMaxDataSize() ); }
|
---|
[2212] | 32 | //! Returns the increase in memory usage since the previous call to \b Update()
|
---|
[2101] | 33 | inline uint_8 getDeltaMemorySize() { return delta_rss; }
|
---|
| 34 |
|
---|
[2212] | 35 | //! Returns the maximum allowd data segment size (in kilo-bytes)
|
---|
[2108] | 36 | inline uint_8 getMaxDataSize() { return((max_datasz>0)?max_datasz:1024); }
|
---|
[2212] | 37 | //! Returns the current data segment size (in kilo-bytes)
|
---|
[2101] | 38 | inline uint_8 getDataSize() { return cur_datasz; }
|
---|
[2212] | 39 | //! Returns the maximum allowed resident size (in kilo-bytes)
|
---|
[2108] | 40 | inline uint_8 getMaxResidentSize() { return((max_rss>0)?max_rss:1024); }
|
---|
[2212] | 41 | //! Returns the current resident memory size (in kilo-bytes)
|
---|
[2101] | 42 | inline uint_8 getResidentSize() { return cur_rss; }
|
---|
[2212] | 43 | //! Returns the maximum allowed stack size (in kilo-bytes)
|
---|
[2101] | 44 | inline uint_8 getMaxStackSize() { return max_stack; }
|
---|
[2212] | 45 | //! Returns the current stack size (in kilo-bytes)
|
---|
[2101] | 46 | inline uint_8 getStackSize() { return cur_stack; }
|
---|
| 47 |
|
---|
| 48 |
|
---|
| 49 | // Time in milli-second
|
---|
[2212] | 50 | //! Returns the total CPU time used (in milli-second)
|
---|
[2101] | 51 | inline uint_8 getCPUTime() { return cur_tottm; }
|
---|
[2212] | 52 | //! Returns the total elapsed time (in milli-second)
|
---|
[2101] | 53 | inline uint_8 getElapsedTime() { return elapsed_time; }
|
---|
[2212] | 54 | //! Returns the average load ( CPU time / elapsed time)
|
---|
[2108] | 55 | inline double getAverageCPULoad()
|
---|
| 56 | { return ((elapsed_time>1) ? (double)cur_tottm/(double)elapsed_time: 1.);}
|
---|
[2101] | 57 |
|
---|
[2212] | 58 | //! Returns the CPU time used since the previous call to \b Update() (in milli-second)
|
---|
[2101] | 59 | inline uint_8 getDeltaCPUTime() { return delta_tottm; }
|
---|
[2212] | 60 | //! Returns the elapsed time since the previous call to \b Update() (in milli-second)
|
---|
[2159] | 61 | inline uint_8 getDeltaElapsedTime() { return delta_elapsed_time; }
|
---|
[2212] | 62 | //! Returns the CPU load since the previous call to \b Update()
|
---|
[2159] | 63 | inline double getCPULoad()
|
---|
| 64 | { return ((delta_elapsed_time>1) ? (double)delta_tottm/(double)delta_elapsed_time: 1.);}
|
---|
[2101] | 65 |
|
---|
| 66 |
|
---|
[2212] | 67 | //! Returns the total CPU time (in milli-second)
|
---|
[2101] | 68 | inline uint_8 getTotalCPUTime() { return cur_tottm; }
|
---|
[2212] | 69 | //! Returns the CPU time in user mode (in milli-second)
|
---|
[2101] | 70 | inline uint_8 getUserCPUTime() { return cur_usrtm; }
|
---|
[2212] | 71 | //! Returns the CPU time in system mode (in milli-second)
|
---|
[2101] | 72 | inline uint_8 getSysCPUTime() { return cur_systm; }
|
---|
| 73 |
|
---|
| 74 |
|
---|
| 75 | void Print(ostream& os, int lp=0, bool upd=true);
|
---|
[2212] | 76 | //! Alias for the \b Print() method.
|
---|
[2101] | 77 | inline void print(ostream& os, int lp=0, bool upd=true){ Print(os,lp,upd); }
|
---|
| 78 |
|
---|
[2255] | 79 | void ReadLinuxMem(); // methode de lecture des infos memoire ss Linux - OPerdereau
|
---|
| 80 | void ReadLinuxTotMem(); // methode de lecture des infos memoire ss Linux - OPerdereau
|
---|
| 81 |
|
---|
[2101] | 82 | protected:
|
---|
| 83 | uint_8 max_datasz; // Max data segment size (KBytes)
|
---|
| 84 | uint_8 max_rss; // Max resident size
|
---|
| 85 | uint_8 max_stack; // Max stack size
|
---|
| 86 |
|
---|
| 87 | uint_8 cur_datasz; // Current data segment size
|
---|
| 88 | uint_8 cur_rss; // Current resident size
|
---|
| 89 | uint_8 cur_stack; // Current stack size
|
---|
| 90 |
|
---|
| 91 | uint_8 cur_tottm; // Current total CPU-Time - in milli-second
|
---|
| 92 | uint_8 cur_usrtm; // Current user CPU-Time - in milli-second
|
---|
| 93 | uint_8 cur_systm; // Current system CPU-Time - in milli-second
|
---|
| 94 | uint_8 elapsed_time; // Elapsed time - in milli-second
|
---|
| 95 | uint_8 t0_time; // time T0 in seconds
|
---|
| 96 |
|
---|
| 97 | // Delta_values : difference since last call to Update()
|
---|
| 98 | uint_8 delta_rss; // Max resident size
|
---|
| 99 | uint_8 delta_tottm; // Delta total CPU-Time - in milli-second
|
---|
| 100 |
|
---|
| 101 | uint_8 delta_elapsed_time; // Elapsed time - in milli-second
|
---|
[2255] | 102 | uint_8 cur_pid ; // process PID
|
---|
[2101] | 103 | };
|
---|
| 104 |
|
---|
[2212] | 105 | //! Prints the resource usage information on the output stream
|
---|
[2101] | 106 | inline ostream& operator << (ostream& os, ResourceUsage& ru)
|
---|
| 107 | { ru.Print(os,0,true); return(os); }
|
---|
| 108 |
|
---|
| 109 | } // namespace SOPHYA
|
---|
| 110 |
|
---|
| 111 | #endif
|
---|
| 112 |
|
---|