From e804dfc49e6a51c90b272ad57bd88d04ad135b01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Thu, 14 Dec 2023 16:12:19 +0800 Subject: [PATCH] Memory (macOS): align algo of memory usage counting to `stats` Which seems to print the same result of neofetch --- CHANGELOG.md | 1 + src/detection/memory/memory_apple.c | 11 ++++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c07d14ec3..e40e54deb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ Features: Bugfixes: * Fix crashes sometimes when `--logo-padding-top` is not set (Logo) +* Fix memory usage counting algorithm (Memory, macOS) # 2.3.4 diff --git a/src/detection/memory/memory_apple.c b/src/detection/memory/memory_apple.c index b3a50a1eb..19e67f1a4 100644 --- a/src/detection/memory/memory_apple.c +++ b/src/detection/memory/memory_apple.c @@ -16,7 +16,16 @@ const char* ffDetectMemory(FFMemoryResult* ram) if(host_statistics64(mach_host_self(), HOST_VM_INFO64, (host_info64_t) (&vmstat), &count) != KERN_SUCCESS) return "Failed to read host_statistics64"; - ram->bytesUsed = ((uint64_t) vmstat.active_count + vmstat.wire_count) * instance.state.platform.pageSize; + // https://github.com/exelban/stats/blob/master/Modules/RAM/readers.swift#L56 + ram->bytesUsed = ((uint64_t) + + vmstat.active_count + + vmstat.inactive_count + + vmstat.speculative_count + + vmstat.wire_count + + vmstat.compressor_page_count + - vmstat.purgeable_count + - vmstat.external_page_count + ) * instance.state.platform.pageSize; return NULL; }