master ohmu/fastfetch-openbsd / src / detection / cpuusage / cpuusage_haiku.c
ohmu  ·  2026-10-15
 1#include "fastfetch.h"
 2#include "detection/cpuusage/cpuusage.h"
 3#include "common/debug.h"
 4#include "common/mallocHelper.h"
 5
 6#include <OS.h>
 7
 8const char* ffGetCpuUsageInfo(FFlist* cpuTimes) {
 9    system_info sysInfo;
10    if (get_system_info(&sysInfo) != B_OK) {
11        FF_DEBUG("get_system_info() failed");
12        return "get_system_info() failed";
13    }
14
15    FF_AUTO_FREE cpu_info* cpuInfo = malloc(sizeof(*cpuInfo) * sysInfo.cpu_count);
16    if (get_cpu_info(0, sysInfo.cpu_count, cpuInfo) != B_OK) {
17        FF_DEBUG("get_cpu_info() failed");
18        return "get_cpu_info() failed";
19    }
20
21    uint64_t uptime = (uint64_t) system_time();
22
23    for (uint32_t i = 0; i < sysInfo.cpu_count; ++i) {
24        FFCpuUsageInfo* info = FF_LIST_ADD(FFCpuUsageInfo, *cpuTimes);
25        info->inUseAll = (uint64_t) cpuInfo[i].active_time;
26        info->totalAll = uptime;
27    }
28
29    return nullptr;
30}