From d075e4d0489d7db6d14244a7bca83ddc28336c70 Mon Sep 17 00:00:00 2001 From: Artur Tsuda <9158970+arturts@users.noreply.github.com> Date: Tue, 10 Aug 2021 16:56:52 -0300 Subject: [PATCH] Fix $used_mem when page size is not 4Kb --- scripts/ram_info.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/ram_info.sh b/scripts/ram_info.sh index 625ad61..4526019 100755 --- a/scripts/ram_info.sh +++ b/scripts/ram_info.sh @@ -37,8 +37,8 @@ get_percent() Darwin) # percent=$(ps -A -o %mem | awk '{mem += $1} END {print mem}') - # Get used memory blocks with vm_stat, multiply by 4096 to get size in bytes, then convert to MiB - used_mem=$(vm_stat | grep ' active\|wired ' | sed 's/[^0-9]//g' | paste -sd ' ' - | awk '{printf "%d\n", ($1+$2) * 4096 / 1048576}') + # Get used memory blocks with vm_stat, multiply by page size to get size in bytes, then convert to MiB + used_mem=$(vm_stat | grep ' active\|wired ' | sed 's/[^0-9]//g' | paste -sd ' ' - | awk -v pagesize=$(pagesize) '{printf "%d\n", ($1+$2) * pagesize / 1048576}') total_mem=$(system_profiler SPHardwareDataType | grep "Memory:" | awk '{print $2 $3}') if (( $used_mem < 1024 )); then echo $used_mem\M\B/$total_mem