2022-09-05 10:57:09 +02:00
|
|
|
#include "memory.h"
|
2022-09-05 02:46:53 -07:00
|
|
|
#include "common/settings.h"
|
|
|
|
|
|
2022-09-08 14:51:31 +02:00
|
|
|
#include <string.h>
|
2022-09-05 02:46:53 -07:00
|
|
|
#include <mach/mach.h>
|
2022-09-17 11:21:05 +08:00
|
|
|
#include <sys/sysctl.h>
|
2022-09-05 10:57:09 +02:00
|
|
|
|
|
|
|
|
void ffDetectMemoryImpl(FFMemoryResult* memory)
|
|
|
|
|
{
|
2022-09-08 14:51:31 +02:00
|
|
|
memset(memory, 0, sizeof(FFMemoryResult));
|
2022-09-05 02:46:53 -07:00
|
|
|
|
2022-09-08 14:51:31 +02:00
|
|
|
memory->ram.bytesTotal = (uint64_t) ffSettingsGetAppleInt64("hw.memsize", 0);
|
2022-09-05 02:46:53 -07:00
|
|
|
|
|
|
|
|
uint32_t pagesize = (uint32_t) ffSettingsGetAppleInt("hw.pagesize", 0);
|
|
|
|
|
if(pagesize == 0)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
return;
|
|
|
|
|
|
2022-09-08 14:51:31 +02:00
|
|
|
memory->ram.bytesUsed = ((uint64_t) vmstat.active_count + vmstat.wire_count) * pagesize;
|
2022-09-17 11:21:05 +08:00
|
|
|
|
|
|
|
|
struct xsw_usage swap;
|
|
|
|
|
size_t size = sizeof(swap);
|
|
|
|
|
if (sysctlbyname("vm.swapusage", &swap, &size, 0, 0) == -1)
|
|
|
|
|
return;
|
|
|
|
|
memory->swap.bytesTotal = swap.xsu_total;
|
|
|
|
|
memory->swap.bytesUsed = swap.xsu_used;
|
2022-09-05 10:57:09 +02:00
|
|
|
}
|