From 02adca46e37dc8446c0b041110dec53af9e1e2e9 Mon Sep 17 00:00:00 2001 From: Marcus Holland-Moritz Date: Sat, 24 May 2025 16:35:26 +0200 Subject: [PATCH] wip: apple memory usage --- src/util.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/util.cpp b/src/util.cpp index a3342d4d..595eb1d1 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -64,6 +64,10 @@ #endif #endif +#ifdef __APPLE__ +#include +#endif + #include #include #include @@ -576,7 +580,13 @@ std::optional get_self_memory_usage() { #if defined(_WIN32) // TODO #elif defined(__APPLE__) - // TODO + mach_task_vm_info info{}; + mach_msg_type_number_t count = TASK_VM_INFO_COUNT; + + if (task_info(mach_task_self(), TASK_VM_INFO, + reinterpret_cast(&info), &count) == KERN_SUCCESS) { + return info.phys_footprint; + } #elif defined(__linux__) static constexpr auto kSmapsPath{"/proc/self/smaps_rollup"}; std::ifstream smaps(kSmapsPath);