summaryrefslogtreecommitdiffstats
path: root/src/detection/cpuusage/cpuusage_apple.c
diff options
context:
space:
mode:
authorsumuel <samuel@yakubos.org>2026-08-17 20:44:55 +0000
committersumuel <samuel@yakubos.org>2026-08-17 20:44:55 +0000
commit76424950e373d3b04ac3dd13019151bfba3e8423 (patch)
tree4c3cfdbda039e592b9186be3e28f8d7cfd439e8a /src/detection/cpuusage/cpuusage_apple.c
Add the files
Diffstat (limited to 'src/detection/cpuusage/cpuusage_apple.c')
-rw-r--r--src/detection/cpuusage/cpuusage_apple.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/src/detection/cpuusage/cpuusage_apple.c b/src/detection/cpuusage/cpuusage_apple.c
new file mode 100644
index 0000000..50a8b15
--- /dev/null
+++ b/src/detection/cpuusage/cpuusage_apple.c
@@ -0,0 +1,33 @@
+#include "fastfetch.h"
+#include "detection/cpuusage/cpuusage.h"
+
+#include <mach/processor_info.h>
+#include <mach/mach_host.h>
+#include <mach/vm_map.h>
+
+const char* ffGetCpuUsageInfo(FFlist* cpuTimes) {
+ natural_t numCPUs = 0U;
+ processor_info_array_t cpuInfo;
+ mach_msg_type_number_t numCpuInfo;
+
+ if (host_processor_info(mach_host_self(), PROCESSOR_CPU_LOAD_INFO, &numCPUs, &cpuInfo, &numCpuInfo) != KERN_SUCCESS) {
+ return "host_processor_info() failed";
+ }
+ if (numCPUs * CPU_STATE_MAX != numCpuInfo) {
+ return "Unexpected host_processor_info() result";
+ }
+
+ for (natural_t i = 0U; i < numCPUs; ++i) {
+ integer_t inUse = cpuInfo[CPU_STATE_MAX * i + CPU_STATE_USER] + cpuInfo[CPU_STATE_MAX * i + CPU_STATE_SYSTEM] + cpuInfo[CPU_STATE_MAX * i + CPU_STATE_NICE];
+ integer_t total = inUse + cpuInfo[CPU_STATE_MAX * i + CPU_STATE_IDLE];
+
+ FFCpuUsageInfo* info = FF_LIST_ADD(FFCpuUsageInfo, *cpuTimes);
+ *info = (FFCpuUsageInfo) {
+ .inUseAll = (uint64_t) inUse,
+ .totalAll = (uint64_t) total,
+ };
+ }
+
+ vm_deallocate(mach_task_self(), (vm_address_t) cpuInfo, numCpuInfo * sizeof(integer_t));
+ return NULL;
+}