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

34 lines
985 B
C
Raw Normal View History

#include "memory.h"
2022-09-05 02:46:53 -07:00
2022-09-08 14:51:31 +02:00
#include <string.h>
2022-09-05 02:46:53 -07:00
#include <mach/mach.h>
#include <sys/sysctl.h>
2022-12-28 15:55:31 +08:00
void ffDetectMemory(FFMemoryStorage* ram)
{
size_t length = sizeof(ram->bytesTotal);
if (sysctl((int[]){ CTL_HW, HW_MEMSIZE }, 2, &ram->bytesTotal, &length, NULL, 0))
2022-09-20 15:12:24 +02:00
{
ffStrbufAppendS(&ram->error, "Failed to read hw.memsize");
return;
}
2022-09-05 02:46:53 -07:00
uint32_t pagesize;
length = sizeof(pagesize);
if (sysctl((int[]){ CTL_HW, HW_PAGESIZE }, 2, &pagesize, &length, NULL, 0))
2022-09-20 15:12:24 +02:00
{
ffStrbufAppendS(&ram->error, "Failed to read hw.pagesize");
2022-09-05 02:46:53 -07:00
return;
2022-09-20 15:12:24 +02:00
}
2022-09-05 02:46:53 -07:00
mach_msg_type_number_t count = HOST_VM_INFO64_COUNT;
vm_statistics64_data_t vmstat;
if(host_statistics64(mach_host_self(), HOST_VM_INFO64, (host_info64_t) (&vmstat), &count) != KERN_SUCCESS)
2022-09-20 15:12:24 +02:00
{
ffStrbufAppendS(&ram->error, "Failed to read host_statistics64");
2022-09-05 02:46:53 -07:00
return;
2022-09-20 15:12:24 +02:00
}
2022-09-05 02:46:53 -07:00
2022-09-20 15:21:39 +02:00
ram->bytesUsed = ((uint64_t) vmstat.active_count + vmstat.wire_count) * pagesize;
2022-09-20 15:12:24 +02:00
}