source: Sophya/trunk/SophyaLib/SysTools/resusage.h@ 2483

Last change on this file since 2483 was 2322, checked in by cmv, 23 years ago
  • passage xxstream.h en xxstream
  • compile avec gcc_3.2, gcc_2.96 et cxx En 3.2 le seek from ::end semble marcher (voir Eval/COS/pbseekios.cc)

rz+cmv 11/2/2003

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