Utility class to read cpu time information from /proc/stat and /cpu/pid/stat Allows accurate timing measures for both cpu and process (at least at OS timing accuracy) Call peekMeasures() once in a while (once a second, for instance, to avoid to much load) then call each getCPU. More...
#include <cpu_time_stat.h>
Classes | |
| struct | CTickStat |
Public Member Functions | |
| CCPUTimeStat () | |
Detailed measures | |
| float | getCPUUserLoad (TMeasureType type=Instant) const |
| Get User Load. | |
| float | getCPUSystemLoad (TMeasureType type=Instant) const |
| Get System Load. | |
| float | getCPUNiceLoad (TMeasureType type=Instant) const |
| Get Nice Load. | |
| float | getCPUIOWaitLoad (TMeasureType type=Instant) const |
| Get Nice Load. | |
| float | getProcessUserLoad (TMeasureType type=Instant) const |
| Get User load for this process (children excluded). | |
| float | getProcessSystemLoad (TMeasureType type=Instant) const |
| Get Sytem load for this process (children excluded). | |
| float | getProcessCUserLoad (TMeasureType type=Instant) const |
| Get User load for this process (children included). | |
| float | getProcessCSystemLoad (TMeasureType type=Instant) const |
| Get Sytem load for this process (children included). | |
| float | getProcessCLoad (TMeasureType type=Instant) const |
| Get overall load for this process (children included). | |
Static Public Member Functions | |
| static bool | getCPUTicks (uint64 &user, uint64 &nice, uint64 &system, uint64 &idle, uint64 &iowait) |
| Get absolute ticks value for the whole cpu set e.g. | |
| static bool | getPIDTicks (uint64 &utime, uint64 &stime, uint64 &cutime, uint64 &cstime, uint pid) |
| Get absolute ticks values for a specific pid. | |
Private Attributes | |
| uint32 | _PID |
| bool | _FirstTime |
| uint64 | _LastCPUTicks |
| CTickStat | _CPUUser |
| CTickStat | _CPUNice |
| CTickStat | _CPUSystem |
| CTickStat | _CPUIdle |
| CTickStat | _CPUIOWait |
| uint64 | _LastPIDTicks |
| CTickStat | _PIDUTime |
| CTickStat | _PIDSTime |
| CTickStat | _PIDCUTime |
| CTickStat | _PIDCSTime |
Measure peeking and reading | |
|
| |
| enum | TMeasureType { Instant, Mean, Peak } |
| void | peekMeasures () |
| Peek measure. | |
| float | getCPULoad (TMeasureType type=Instant) const |
| Get Overall CPU Load Call this method to know the overall server CPU usage (0=min, 1=max) All processes running on the same machine will return approximately the same value. | |
| float | getProcessLoad (TMeasureType type=Instant) const |
| Get overall load for this process (children excluded) Call this method to know the CPU usage for this process (0=min, 1=max) Please note that quadriprocessor machines will show maximum of 0.25 per process (0.5 for a biprocessor). | |
Utility class to read cpu time information from /proc/stat and /cpu/pid/stat Allows accurate timing measures for both cpu and process (at least at OS timing accuracy) Call peekMeasures() once in a while (once a second, for instance, to avoid to much load) then call each getCPU.
.. and getProcess... methods to get instant CPU or Process load.
Definition at line 45 of file cpu_time_stat.h.
Definition at line 68 of file cpu_time_stat.h.
| NLMISC::CCPUTimeStat::CCPUTimeStat | ( | ) |
Definition at line 101 of file cpu_time_stat.cpp.
References _PID.
| float NLMISC::CCPUTimeStat::getCPUIOWaitLoad | ( | TMeasureType | type = Instant |
) | const [inline] |
Get Nice Load.
Definition at line 111 of file cpu_time_stat.h.
References _CPUIOWait, and NLMISC::CCPUTimeStat::CTickStat::get().
Referenced by NLNET::NLMISC_CATEGORISED_DYNVARIABLE().
| float NLMISC::CCPUTimeStat::getCPULoad | ( | TMeasureType | type = Instant |
) | const [inline] |
Get Overall CPU Load Call this method to know the overall server CPU usage (0=min, 1=max) All processes running on the same machine will return approximately the same value.
Definition at line 81 of file cpu_time_stat.h.
References _CPUIOWait, _CPUNice, _CPUSystem, _CPUUser, and NLMISC::CCPUTimeStat::CTickStat::get().
Referenced by NLNET::NLMISC_CATEGORISED_DYNVARIABLE().
| float NLMISC::CCPUTimeStat::getCPUNiceLoad | ( | TMeasureType | type = Instant |
) | const [inline] |
Get Nice Load.
Definition at line 109 of file cpu_time_stat.h.
References _CPUNice, and NLMISC::CCPUTimeStat::CTickStat::get().
Referenced by NLNET::NLMISC_CATEGORISED_DYNVARIABLE().
| float NLMISC::CCPUTimeStat::getCPUSystemLoad | ( | TMeasureType | type = Instant |
) | const [inline] |
Get System Load.
Definition at line 107 of file cpu_time_stat.h.
References _CPUSystem, and NLMISC::CCPUTimeStat::CTickStat::get().
Referenced by NLNET::NLMISC_CATEGORISED_DYNVARIABLE().
| bool NLMISC::CCPUTimeStat::getCPUTicks | ( | uint64 & | user, | |
| uint64 & | nice, | |||
| uint64 & | system, | |||
| uint64 & | idle, | |||
| uint64 & | iowait | |||
| ) | [static] |
Get absolute ticks value for the whole cpu set e.g.
a foursome of cpu will all tell their ticks through these numbers
Definition at line 49 of file cpu_time_stat.cpp.
References NL_I64.
Referenced by peekMeasures().
| float NLMISC::CCPUTimeStat::getCPUUserLoad | ( | TMeasureType | type = Instant |
) | const [inline] |
Get User Load.
Definition at line 105 of file cpu_time_stat.h.
References _CPUUser, and NLMISC::CCPUTimeStat::CTickStat::get().
Referenced by NLNET::NLMISC_CATEGORISED_DYNVARIABLE().
| bool NLMISC::CCPUTimeStat::getPIDTicks | ( | uint64 & | utime, | |
| uint64 & | stime, | |||
| uint64 & | cutime, | |||
| uint64 & | cstime, | |||
| uint | pid | |||
| ) | [static] |
Get absolute ticks values for a specific pid.
Definition at line 74 of file cpu_time_stat.cpp.
References NL_I64, nlunreferenced, and NLMISC::toString().
Referenced by peekMeasures().
| float NLMISC::CCPUTimeStat::getProcessCLoad | ( | TMeasureType | type = Instant |
) | const [inline] |
Get overall load for this process (children included).
Definition at line 122 of file cpu_time_stat.h.
References _PIDCSTime, _PIDCUTime, and NLMISC::CCPUTimeStat::CTickStat::get().
| float NLMISC::CCPUTimeStat::getProcessCSystemLoad | ( | TMeasureType | type = Instant |
) | const [inline] |
Get Sytem load for this process (children included).
Definition at line 120 of file cpu_time_stat.h.
References _PIDCSTime, and NLMISC::CCPUTimeStat::CTickStat::get().
| float NLMISC::CCPUTimeStat::getProcessCUserLoad | ( | TMeasureType | type = Instant |
) | const [inline] |
Get User load for this process (children included).
Definition at line 118 of file cpu_time_stat.h.
References _PIDCUTime, and NLMISC::CCPUTimeStat::CTickStat::get().
| float NLMISC::CCPUTimeStat::getProcessLoad | ( | TMeasureType | type = Instant |
) | const [inline] |
Get overall load for this process (children excluded) Call this method to know the CPU usage for this process (0=min, 1=max) Please note that quadriprocessor machines will show maximum of 0.25 per process (0.5 for a biprocessor).
Children of a process are processes that have been launched from this process (that is, this process is marked as parent of the child process, see ppid, fork() and/or exec()) Unused but by the AES (all launched services are children of the AES)
Definition at line 92 of file cpu_time_stat.h.
References _PIDSTime, _PIDUTime, and NLMISC::CCPUTimeStat::CTickStat::get().
Referenced by NLNET::NLMISC_CATEGORISED_DYNVARIABLE().
| float NLMISC::CCPUTimeStat::getProcessSystemLoad | ( | TMeasureType | type = Instant |
) | const [inline] |
Get Sytem load for this process (children excluded).
Definition at line 116 of file cpu_time_stat.h.
References _PIDSTime, and NLMISC::CCPUTimeStat::CTickStat::get().
Referenced by NLNET::NLMISC_CATEGORISED_DYNVARIABLE().
| float NLMISC::CCPUTimeStat::getProcessUserLoad | ( | TMeasureType | type = Instant |
) | const [inline] |
Get User load for this process (children excluded).
Definition at line 114 of file cpu_time_stat.h.
References _PIDUTime, and NLMISC::CCPUTimeStat::CTickStat::get().
Referenced by NLNET::NLMISC_CATEGORISED_DYNVARIABLE().
| void NLMISC::CCPUTimeStat::peekMeasures | ( | ) |
Peek measure.
Definition at line 117 of file cpu_time_stat.cpp.
References _CPUIdle, _CPUIOWait, _CPUNice, _CPUSystem, _CPUUser, _FirstTime, _LastCPUTicks, _LastPIDTicks, _PID, _PIDCSTime, _PIDCUTime, _PIDSTime, _PIDUTime, NLMISC::CCPUTimeStat::CTickStat::computeDiff(), NLMISC::CCPUTimeStat::CTickStat::computeLoad(), NLMISC::CCPUTimeStat::CTickStat::Diff, getCPUTicks(), NLMISC::CTime::getLocalTime(), getPIDTicks(), and NLMISC::n.
Referenced by NLNET::IService::main().
CTickStat NLMISC::CCPUTimeStat::_CPUIdle [private] |
Definition at line 195 of file cpu_time_stat.h.
Referenced by peekMeasures().
CTickStat NLMISC::CCPUTimeStat::_CPUIOWait [private] |
Definition at line 196 of file cpu_time_stat.h.
Referenced by getCPUIOWaitLoad(), getCPULoad(), and peekMeasures().
CTickStat NLMISC::CCPUTimeStat::_CPUNice [private] |
Definition at line 193 of file cpu_time_stat.h.
Referenced by getCPULoad(), getCPUNiceLoad(), and peekMeasures().
CTickStat NLMISC::CCPUTimeStat::_CPUSystem [private] |
Definition at line 194 of file cpu_time_stat.h.
Referenced by getCPULoad(), getCPUSystemLoad(), and peekMeasures().
CTickStat NLMISC::CCPUTimeStat::_CPUUser [private] |
Definition at line 192 of file cpu_time_stat.h.
Referenced by getCPULoad(), getCPUUserLoad(), and peekMeasures().
bool NLMISC::CCPUTimeStat::_FirstTime [private] |
Definition at line 189 of file cpu_time_stat.h.
Referenced by peekMeasures().
uint64 NLMISC::CCPUTimeStat::_LastCPUTicks [private] |
Definition at line 191 of file cpu_time_stat.h.
Referenced by peekMeasures().
uint64 NLMISC::CCPUTimeStat::_LastPIDTicks [private] |
Definition at line 198 of file cpu_time_stat.h.
Referenced by peekMeasures().
uint32 NLMISC::CCPUTimeStat::_PID [private] |
Definition at line 188 of file cpu_time_stat.h.
Referenced by CCPUTimeStat(), and peekMeasures().
CTickStat NLMISC::CCPUTimeStat::_PIDCSTime [private] |
Definition at line 202 of file cpu_time_stat.h.
Referenced by getProcessCLoad(), getProcessCSystemLoad(), and peekMeasures().
CTickStat NLMISC::CCPUTimeStat::_PIDCUTime [private] |
Definition at line 201 of file cpu_time_stat.h.
Referenced by getProcessCLoad(), getProcessCUserLoad(), and peekMeasures().
CTickStat NLMISC::CCPUTimeStat::_PIDSTime [private] |
Definition at line 200 of file cpu_time_stat.h.
Referenced by getProcessLoad(), getProcessSystemLoad(), and peekMeasures().
CTickStat NLMISC::CCPUTimeStat::_PIDUTime [private] |
Definition at line 199 of file cpu_time_stat.h.
Referenced by getProcessLoad(), getProcessUserLoad(), and peekMeasures().
1.6.1