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

32 lines
1001 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>
2023-05-11 20:39:54 +08:00
#include <unistd.h>
2023-05-11 20:39:54 +08:00
const char* ffDetectMemory(FFMemoryResult* ram)
{
size_t length = sizeof(ram->bytesTotal);
if (sysctl((int[]){ CTL_HW, HW_MEMSIZE }, 2, &ram->bytesTotal, &length, NULL, 0))
2023-05-11 20:39:54 +08:00
return "Failed to read hw.memsize";
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)
2023-05-11 20:39:54 +08:00
return "Failed to read host_statistics64";
2022-09-05 02:46:53 -07:00
// https://github.com/exelban/stats/blob/master/Modules/RAM/readers.swift#L56
ram->bytesUsed = ((uint64_t)
+ vmstat.active_count
+ vmstat.inactive_count
+ vmstat.speculative_count
+ vmstat.wire_count
+ vmstat.compressor_page_count
- vmstat.purgeable_count
- vmstat.external_page_count
) * instance.state.platform.pageSize;
2023-05-11 20:39:54 +08:00
return NULL;
2022-09-20 15:12:24 +02:00
}