From fc4dba5112572ee33ce502afbdb00db647959bf2 Mon Sep 17 00:00:00 2001 From: pants Date: Tue, 6 Jan 2026 21:08:44 -0800 Subject: [PATCH] write sysctl version for free bsd --- bin/st-mem | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/bin/st-mem b/bin/st-mem index 57b1a0a..d8d4e17 100755 --- a/bin/st-mem +++ b/bin/st-mem @@ -1,3 +1,18 @@ #!/bin/sh -MEMORY_USED=$(free -h | awk 'NR==2 {print $3}') +#MEMORY_USED=$(free -h | awk 'NR==2 {print $3}') + +# freebsd (and maybe better for linux too) +PAGES_WIRED=$(sysctl vm.stats.vm.v_wire_count | awk '{print $2}') +PAGES_ACTIVE=$(sysctl vm.stats.vm.v_active_count | awk '{print $2}') +PAGES_DIRTY=$(sysctl vm.stats.vm.v_laundry_count | awk '{print $2}') +TOTAL_PAGES=$(echo "scale=0; $PAGES_WIRED+$PAGES_ACTIVE+$PAGES_DIRTY" | bc) + +BYTES_USED=$(echo "scale=0; $TOTAL_PAGES*4096" | bc) + +if [ $BYTES_USED -ge 1073741824 ]; then + MEMORY_USED="$(echo "scale=1; $BYTES_USED/1024^3" | bc) GiB" +else + MEMORY_USED="$(echo "scale=1; $BYTES_USED/1024^2" | bc) MiB" +fi + echo $MEMORY_USED