CpuUsage: support freebsd

This commit is contained in:
李通洲
2022-10-27 10:08:22 +08:00
parent b878d3ccf6
commit 60ad6792ba
2 changed files with 21 additions and 1 deletions
+2 -1
View File
@@ -310,6 +310,7 @@ endif()
if(LINUX OR ANDROID)
list(APPEND LIBFASTFETCH_SRC
src/detection/cpu/cpu_linux.c
src/detection/cpuUsage/cpuUsage_linux.c
src/detection/memory/memory_linux.c
src/detection/processes/processes_linux.c
src/detection/swap/swap_linux.c
@@ -319,7 +320,6 @@ endif()
if(LINUX OR ANDROID OR BSD)
list(APPEND LIBFASTFETCH_SRC
src/detection/cpuUsage/cpuUsage_linux.c
src/detection/disk/disk_linux.c
src/detection/temps/temps_linux.c
src/detection/opengl/opengl_linux.c
@@ -418,6 +418,7 @@ endif()
if(BSD)
list(APPEND LIBFASTFETCH_SRC
src/detection/cpu/cpu_bsd.c
src/detection/cpuUsage/cpuUsage_bsd.c
src/detection/memory/memory_bsd.c
src/detection/swap/swap_bsd.c
)
+19
View File
@@ -0,0 +1,19 @@
#include "cpuUsage.h"
#include <sys/types.h>
#include <sys/user.h>
#include <sys/sysctl.h>
const char* ffGetCpuUsageInfo(uint64_t* inUseAll, uint64_t* totalAll)
{
// interrupt processing, user processes, system processing, lock spinning, and idling
uint64_t cpTime[5];
size_t neededLength = sizeof(cpTime);
if(sysctlbyname("kern.cp_time", cpTime, &neededLength, NULL, 0) != 0)
return "sysctlbyname(kern.cp_time) failed";
*inUseAll = cpTime[0] + cpTime[1] + cpTime[2] + cpTime[3];
*totalAll = *inUseAll + cpTime[4];
return NULL;
}