From 8f3a1c7ede4fa87314f4a007a62c61c1c23399db Mon Sep 17 00:00:00 2001 From: pixel Date: Mon, 19 Sep 2022 09:17:12 +0200 Subject: [PATCH] Rework macOS memory calculation to work on Apple silicon Based on dylanaraps/neofetch@4d7ec21ad5c4ae24e634c92763eaa26ea2655b0f --- pfetch | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/pfetch b/pfetch index d47b878..c13f93e 100755 --- a/pfetch +++ b/pfetch @@ -735,17 +735,19 @@ get_memory() { ;; # Used memory is calculated using the following "formula": - # (wired + active + occupied) * 4 / 1024 + # (app + wired + occupied) * pagesize / 1024 / 1024 (Darwin*) + hw_pagesize="$(sysctl -n hw.pagesize)" mem_full=$(($(sysctl -n hw.memsize) / 1024 / 1024)) + pages_used="$(($(sysctl -n vm.page_pageable_internal_count) - $(sysctl -n vm.page_purgeable_count)))" # Parse the 'vmstat' file splitting on ':' and '.'. # The format of the file is 'key: 000.' and an additional # split is used on '.' to filter it out. while IFS=:. read -r key val; do case $key in - (*' wired'*|*' active'*|*' occupied'*) - mem_used=$((mem_used + ${val:-0})) + (*' wired'*|*' occupied'*) + pages_used=$((pages_used + ${val:-0})) ;; esac @@ -757,7 +759,7 @@ get_memory() { $(vm_stat) EOF - mem_used=$((mem_used * 4 / 1024)) + mem_used=$((pages_used * hw_pagesize / 1024 / 1024)) ;; (OpenBSD*)