summaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
authorIan Moffett <ian@osmora.org>2025-08-12 21:22:19 -0400
committerIan Moffett <ian@osmora.org>2025-08-12 21:35:46 -0400
commit0c39f603441c542d0c7ba57d8e8a9aa4028286ce (patch)
treec1197135ca4403ad39c8f58f91a9d8204e363188 /usr.bin
parentd5b7792f4721b3215e948e6d6d91d287ce17b0f1 (diff)
usr: kstat: Add support for '/ctl/vm/stat'
Signed-off-by: Ian Moffett <ian@osmora.org>
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/kstat/kstat.c25
1 files changed, 25 insertions, 0 deletions
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,11 +28,35 @@
*/
#include <sys/sched.h>
+#include <sys/vmstat.h>
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
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)
{
struct sched_stat stat;
@@ -76,5 +100,6 @@ int
main(void)
{
get_sched_stat();
+ get_vm_stat();
return 0;
}