Files
fastfetch/src/detection/memory/memory_bsd.c
T

24 lines
771 B
C
Raw Normal View History

2022-09-19 22:23:31 +02:00
#include "memory.h"
2022-09-19 23:16:43 +02:00
#include "common/sysctl.h"
2022-09-19 22:23:31 +02:00
2023-05-11 20:39:54 +08:00
const char* ffDetectMemory(FFMemoryResult* ram)
2022-09-19 22:23:31 +02:00
{
size_t length = sizeof(ram->bytesTotal);
if (sysctl((int[]){ CTL_HW, HW_PHYSMEM }, 2, &ram->bytesTotal, &length, NULL, 0))
return "Failed to read hw.physmem";
2023-05-11 20:39:54 +08:00
uint32_t pageSize;
length = sizeof(pageSize);
2023-05-11 20:39:54 +08:00
if (sysctl((int[]){ CTL_HW, HW_PAGESIZE }, 2, &pageSize, &length, NULL, 0))
return "Failed to read hw.pagesize";
2022-09-20 11:16:08 +02:00
// vm.stats.vm.* are int values
int32_t pagesFree = ffSysctlGetInt("vm.stats.vm.v_free_count", 0)
+ ffSysctlGetInt("vm.stats.vm.v_inactive_count", 0)
+ ffSysctlGetInt("vm.stats.vm.v_cache_count", 0);
2022-09-20 15:12:24 +02:00
ram->bytesUsed = ram->bytesTotal - (uint64_t) pagesFree * pageSize;
2023-05-11 20:39:54 +08:00
return NULL;
2022-09-20 15:12:24 +02:00
}