#include <vector>
#include "sys/config.h"
SYS_NAMESPACE_BEGIN
/***
* 用来获取系统、内核和进程的各类实时信息,如CPU和内存数据
*/
class CInfo
{
public:
/***
* 系统当前实时信息
*/
typedef struct
{
long uptime_second; /* Seconds since boot */
unsigned long average_load[3]; /* 1, 5, and 15 minute load averages */
unsigned long ram_total; /* Total usable main memory size */
unsigned long ram_free; /* Available memory size */
unsigned long ram_shared; /* Amount of shared memory */
unsigned long ram_buffer; /* Memory used by buffers */
unsigned long swap_total; /* Total swap space size */
unsigned long swap_free; /* swap space still available */
unsigned short process_number; /* Number of current processes */
}sys_info_t;
/***
* 当前进程时间信息
*/
typedef struct
{
long user_time; /* user time */
long system_time; /* system time */
long user_time_children; /* user time of children */
long system_time_children; /* system time of children */
}process_time_t;
/***
* 当前系统CPU信息
*/
typedef struct
{
// 单位: jiffies, 1jiffies=0.01秒
uint64_t total;
uint32_t user; /** 从系统启动开始累计到当前时刻,处于用户态的运行时间,不包含 nice值为负进程 */
uint32_t nice; /** 从系统启动开始累计到当前时刻,nice值为负的进程所占用的CPU时间 */
uint32_t system; /** 从系统启动开始累计到当前时刻,处于核心态的运行时间 */
uint32_t idle; /** 从系统启动开始累计到当前时刻,除IO等待时间以外的其它等待时间 */
uint32_t iowait; /** 从系统启动开始累计到当前时刻,IO等待时间(2.5.41) */
uint32_t irq; /** 从系统启动开始累计到当前时刻,硬中断时间(2.6.0) */
uint32_t softirq; /** 从系统启动开始累计到当前时刻,软中断时间(2.6.0) */
//uint32_t stealstolen; /** which is the time spent in other operating systems when running in a virtualized environment(2.6.11) */
//uint32_t guest; /** which is the time spent running a virtual CPU
Linux下用来获取各种系统信息的C++类
最新推荐文章于 2024-03-16 14:18:11 发布
该C++类库提供获取Linux系统、内核、进程的实时信息功能,包括CPU、内存、进程状态、内核版本和网卡流量等数据。
摘要由CSDN通过智能技术生成