From 0c39f603441c542d0c7ba57d8e8a9aa4028286ce Mon Sep 17 00:00:00 2001 From: Ian Moffett Date: Tue, 12 Aug 2025 21:22:19 -0400 Subject: usr: kstat: Add support for '/ctl/vm/stat' Signed-off-by: Ian Moffett --- usr.bin/kstat/kstat.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'usr.bin/kstat') diff --git a/usr.bin/kstat/kstat.c b/usr.bin/kstat/kstat.c index e3b7e6a..2b0c52f 100644 --- a/usr.bin/kstat/kstat.c +++ b/usr.bin/kstat/kstat.c @@ -28,10 +28,34 @@ */ #include +#include #include #include #include +static void +get_vm_stat(void) +{ + struct vm_stat vmstat; + int retval, fd; + + fd = open("/ctl/vm/stat", O_RDONLY); + if (fd < 0) { + printf("failed to open '/ctl/vm/stat'\n"); + return; + } + + retval = read(fd, &vmstat, sizeof(vmstat)); + if (retval <= 0) { + printf("failed to read vmstat\n"); + return; + } + + close(fd); + printf("memory available: %d MiB\n", vmstat.mem_avail); + printf("memory used: %d MiB\n", vmstat.mem_used); +} + static void get_sched_stat(void) { @@ -76,5 +100,6 @@ int main(void) { get_sched_stat(); + get_vm_stat(); return 0; } -- cgit v1.2.3