From 633ab4776b995970c55fd75ba5a538be001b46a3 Mon Sep 17 00:00:00 2001 From: Christopher Sardegna Date: Thu, 23 Jul 2020 10:45:49 -0400 Subject: [PATCH 1/3] Fix reporting negative memory usage on MacOS --- scripts/ram_info.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/scripts/ram_info.sh b/scripts/ram_info.sh index 3d40303..d82441a 100755 --- a/scripts/ram_info.sh +++ b/scripts/ram_info.sh @@ -1,4 +1,4 @@ -#!/usr/bin/env bash +2#!/usr/bin/env bash get_percent() { @@ -18,7 +18,8 @@ get_percent() Darwin) # percent=$(ps -A -o %mem | awk '{mem += $1} END {print mem}') - used_mem=$(top -l 1 -s 0 | grep PhysMem | sed 's/[a-z]//g; s/[A-Z]//g; s/[()]//g' | awk '{printf "%d\n", $2-$3-$5}') + # 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') total_mem=$(system_profiler SPHardwareDataType | grep "Memory:" | awk '{print $2 $3}') if (( $used_mem < 1024 )); then echo $used_mem\M\B/$total_mem From 15a078a7dd1345f35cd9fb4f4bc608f32d0c76b8 Mon Sep 17 00:00:00 2001 From: Christopher Sardegna Date: Thu, 23 Jul 2020 10:47:18 -0400 Subject: [PATCH 2/3] Fix typo in shebang --- scripts/ram_info.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/ram_info.sh b/scripts/ram_info.sh index d82441a..246a409 100755 --- a/scripts/ram_info.sh +++ b/scripts/ram_info.sh @@ -1,4 +1,4 @@ -2#!/usr/bin/env bash +#!/usr/bin/env bash get_percent() { From 8d525470252cf755a1a927249ea93937a99aaf76 Mon Sep 17 00:00:00 2001 From: Christopher Sardegna Date: Thu, 23 Jul 2020 23:12:23 -0400 Subject: [PATCH 3/3] Update ram_info.sh Fix brace --- scripts/ram_info.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/ram_info.sh b/scripts/ram_info.sh index 246a409..7b3a6a2 100755 --- a/scripts/ram_info.sh +++ b/scripts/ram_info.sh @@ -19,7 +19,7 @@ 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') + used_mem=$(vm_stat | grep ' active\|wired ' | sed 's/[^0-9]//g' | paste -sd ' ' - | awk '{printf "%d\n", ($1+$2) * 4096 / 1048576}') total_mem=$(system_profiler SPHardwareDataType | grep "Memory:" | awk '{print $2 $3}') if (( $used_mem < 1024 )); then echo $used_mem\M\B/$total_mem