From 38e4a3eaa01709d613ef91e27d1ae5d3134ed343 Mon Sep 17 00:00:00 2001 From: Lizonghang <870644199@qq.com> Date: Thu, 23 Jan 2025 16:09:04 +0400 Subject: [PATCH] add device_macos_swappable_memory --- common/profiler.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/common/profiler.cpp b/common/profiler.cpp index a9a99c0e..fee9e918 100644 --- a/common/profiler.cpp +++ b/common/profiler.cpp @@ -1393,7 +1393,28 @@ static uint64_t device_termux_swappable_memory() { return total_swappable; } +static uint64_t device_macos_swappable_memory() { +#if defined(__APPLE__) && defined(__MACH__) + mach_msg_type_number_t count = HOST_VM_INFO64_COUNT; + vm_statistics64_data_t vm_stats; + kern_return_t kr = host_statistics64(mach_host_self(), HOST_VM_INFO64, (host_info64_t)&vm_stats, &count); + if (kr != KERN_SUCCESS) { + LOG_INF("Failed to get VM statistics\n"); + return 0; + } + return vm_stats.internal_page_count * get_page_size(); + +#else + return 0; + +#endif +} + uint64_t device_swappable_memory() { +#if defined(__APPLE__) && defined(__MACH__) + return device_macos_swappable_memory(); +#endif + if (access("/data/data/com.termux/files/usr/bin", F_OK) == 0) { return device_termux_swappable_memory(); }