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

33 lines
901 B
C
Raw Normal View History

#include "memory.h"
2022-09-19 21:45:39 +02:00
#include "common/sysctl.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>
2022-10-18 23:46:42 +08:00
void ffDetectMemoryImpl(FFMemoryStorage* ram)
{
2022-09-20 15:21:39 +02:00
ram->bytesTotal = (uint64_t) ffSysctlGetInt64("hw.memsize", 0);
2022-09-20 15:12:24 +02:00
if(ram->bytesTotal == 0)
{
ffStrbufAppendS(&ram->error, "Failed to read hw.memsize");
return;
}
2022-09-05 02:46:53 -07:00
2022-09-19 21:31:50 +02:00
uint32_t pagesize = (uint32_t) ffSysctlGetInt("hw.pagesize", 0);
2022-09-05 02:46:53 -07:00
if(pagesize == 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_INFO_COUNT;
vm_statistics_data_t vmstat;
if(host_statistics(mach_host_self(), HOST_VM_INFO, (host_info_t) (&vmstat), &count) != KERN_SUCCESS)
2022-09-20 15:12:24 +02:00
{
ffStrbufAppendS(&ram->error, "Failed to read vm statistics");
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
}