Add memory usage statistics on macOS (#6644)

Add memory usage statistics on macOS
This commit is contained in:
Geza Lore 2025-11-05 15:45:35 +00:00 committed by GitHub
parent 96ece751fa
commit a35d4a4b4b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 13 additions and 0 deletions

View File

@ -41,6 +41,10 @@
#if defined(__APPLE__) && !defined(__arm64__) && !defined(__POWERPC__)
# include <cpuid.h> // For __cpuid_count()
#endif
#if defined(__APPLE__) && defined(__MACH__)
# include <mach/mach.h> // For task_info()
#endif
// clang-format on
namespace VlOs {
@ -146,6 +150,15 @@ void memUsageBytes(uint64_t& peakr, uint64_t& currentr) VL_MT_SAFE {
peakr = pmc.PeakWorkingSetSize;
currentr = pmc.WorkingSetSize;
}
#elif defined(__APPLE__) && defined(__MACH__)
mach_task_basic_info_data_t info;
mach_msg_type_number_t count = MACH_TASK_BASIC_INFO_COUNT;
const kern_return_t ret
= task_info(mach_task_self(), MACH_TASK_BASIC_INFO, (task_info_t)&info, &count);
if (ret == KERN_SUCCESS && count == MACH_TASK_BASIC_INFO_COUNT) {
peakr = info.resident_size_max;
currentr = info.resident_size;
}
#else
// Highly unportable. Sorry
std::ifstream is{"/proc/self/status"};