非代码
首先介绍在Ubuntu下不使用代码查看的方式来查看CPU使用率、GPU使用率、GPU温度。
查看CPU使用率:
top
查看GPU使用率及温度:
nvidia-smi
代码
介绍在Ubuntu下不使用代码查看的方式来查看CPU使用率、GPU使用率、GPU温度。
纯linux c++获取CPU使用率
typedef struct cpu_occupy_ //定义一个cpu occupy的结构体
{
char name[20]; //定义一个char类型的数组名name有20个元素
unsigned int user; //定义一个无符号的int类型的user
unsigned int nice; //定义一个无符号的int类型的nice
unsigned int system; //定义一个无符号的int类型的system
unsigned int idle; //定义一个无符号的int类型的idle
unsigned int iowait;
unsigned int irq;
unsigned int softirq;
}cpu_occupy_t;
double cal_cpuoccupy (cpu_occupy_t *o, cpu_occupy_t *n)
{
double od = (double) (o->user + o->nice + o->system +o->idle+o->softirq+o->iowait+o->irq);//第一次(用户+优先级+系统+空闲)的时间再赋给od
double nd = (double) (n->user + n