Skip to content
Permalink
Browse files
Fix macos free_memory calculate by using vm_stat (#82)
  • Loading branch information
coderzc committed Mar 22, 2021
1 parent 52e6a28 commit 523042bc2e1faa1b38f9da9b31c2457479339387
Showing 1 changed file with 4 additions and 2 deletions.
@@ -147,8 +147,10 @@ function free_memory() {
free=`expr $mem_free + $mem_buffer + $mem_cached`
free=`expr $free / 1024`
elif [ "$os" == "Darwin" ]; then
free=`top -l 1 | head -n 10 | grep PhysMem | awk -F',' '{print $2}' \
| awk -F'M' '{print $1}' | tr -d " "`
local pages_free=`vm_stat | awk '/Pages free/{print $0}' | awk -F'[:.]+' '{print $2}' | tr -d " "`
local pages_inactive=`vm_stat | awk '/Pages inactive/{print $0}' | awk -F'[:.]+' '{print $2}' | tr -d " "`
local pages_available=`expr $pages_free + $pages_inactive`
free=`expr $pages_available \* 4096 / 1024 / 1024`
else
echo "Unsupported operating system $os"
exit 1

0 comments on commit 523042b

Please sign in to comment.