Merge pull request #243 from aftaylor2/fix_ram_info_darwin_total_mem

Fix: Avoid potential delay in calc of RAM (darwin)
This commit is contained in:
Ethan Edwards 2023-12-16 22:59:56 -05:00 committed by GitHub
commit 3f2466af44
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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