Skip to content

Commit

Permalink
Merge pull request #243 from aftaylor2/fix_ram_info_darwin_total_mem
Browse files Browse the repository at this point in the history
Fix: Avoid potential delay in calc of RAM (darwin)
  • Loading branch information
ethancedwards8 authored Dec 17, 2023
2 parents d8b7d01 + bb44e5c commit 3f2466a
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion scripts/ram_info.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ get_ratio()
Darwin)
# 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}')
# System Profiler performs an activation lock check, which can result in
# time outs or a lagged response. (~10 seconds)
# total_mem=$(system_profiler SPHardwareDataType | grep "Memory:" | awk '{print $2 $3}')
total_mem=$(sysctl -n hw.memsize | awk '{print $0/1024/1024/1024 " GB"}')
if ((used_mem < 1024 )); then
echo "${used_mem}MB/$total_mem"
else
Expand Down

0 comments on commit 3f2466a

Please sign in to comment.