From 376f5b97a9bbde9150c783521a18ac104cde8511 Mon Sep 17 00:00:00 2001 From: Sergey Fedorov Date: Mon, 12 May 2025 18:08:07 +0800 Subject: [PATCH] btop_collect.cpp: fix vm_statistics --- src/osx/btop_collect.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git src/osx/btop_collect.cpp src/osx/btop_collect.cpp index 40d323f..0300304 100644 --- src/osx/btop_collect.cpp +++ src/osx/btop_collect.cpp @@ -1218,6 +1218,7 @@ auto &mem = current_mem; static bool snapped = (getenv("BTOP_SNAPPED") != nullptr); +#if __MAC_OS_X_VERSION_MIN_REQUIRED >= 1070 vm_statistics64 p; mach_msg_type_number_t info_size = HOST_VM_INFO64_COUNT; if (host_statistics64(mach_host_self(), HOST_VM_INFO64, (host_info64_t)&p, &info_size) == 0) { @@ -1226,6 +1227,16 @@ mem.stats.at("used") = (p.active_count + p.wire_count) * Shared::pageSize; mem.stats.at("available") = Shared::totalMem - mem.stats.at("used"); } +#else + vm_statistics p; + mach_msg_type_number_t info_size = HOST_VM_INFO_COUNT; + if (host_statistics(mach_host_self(), HOST_VM_INFO, (host_info_t)&p, &info_size) == KERN_SUCCESS) { + mem.stats.at("free") = p.free_count * Shared::pageSize; + mem.stats.at("cached") = p.inactive_count * Shared::pageSize; + mem.stats.at("used") = (p.active_count + p.wire_count) * Shared::pageSize; + mem.stats.at("available") = Shared::totalMem - mem.stats.at("used"); + } +#endif int mib[2] = {CTL_VM, VM_SWAPUSAGE};