2022-09-21 10:47:15 +08:00
|
|
|
#include "fastfetch.h"
|
|
|
|
|
#include "cpuUsage.h"
|
|
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
2022-09-27 22:06:53 +08:00
|
|
|
const char* ffGetCpuUsageInfo(long* inUseAll, long* totalAll)
|
2022-09-21 10:47:15 +08:00
|
|
|
{
|
|
|
|
|
long user, nice, system, idle, iowait, irq, softirq;
|
|
|
|
|
|
2022-09-27 22:06:53 +08:00
|
|
|
FILE* procStat = fopen("/proc/stat", "r");
|
|
|
|
|
if(procStat == NULL)
|
|
|
|
|
return "fopen(\"""/proc/stat\", \"r\") == NULL";
|
|
|
|
|
|
2022-09-21 10:47:15 +08:00
|
|
|
if (fscanf(procStat, "cpu%ld%ld%ld%ld%ld%ld%ld", &user, &nice, &system, &idle, &iowait, &irq, &softirq) < 0)
|
|
|
|
|
{
|
|
|
|
|
fclose(procStat);
|
|
|
|
|
return "fscanf() failed";
|
|
|
|
|
}
|
|
|
|
|
*inUseAll = user + nice + system;
|
|
|
|
|
*totalAll = *inUseAll + idle + iowait + irq + softirq;
|
|
|
|
|
|
|
|
|
|
fclose(procStat);
|
2022-09-27 22:06:53 +08:00
|
|
|
|
|
|
|
|
return NULL;
|
2022-09-21 10:47:15 +08:00
|
|
|
}
|