From 43d0ba8dcfb5c2455939731f95ee3a74c44c4694 Mon Sep 17 00:00:00 2001 From: kstailey Date: Sat, 22 Feb 1997 17:20:30 +0000 Subject: [PATCH] if sys/kern/malloc.c does not #define KMEMSTATS (and DIAGNOSTIC is also not #defined) then vmstat should not try to print kernel memory stats. Fixes NetBSD PR #3187. --- usr.bin/vmstat/vmstat.c | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/usr.bin/vmstat/vmstat.c b/usr.bin/vmstat/vmstat.c index 9c4d5f7c2e2..60c35d3d4c6 100644 --- a/usr.bin/vmstat/vmstat.c +++ b/usr.bin/vmstat/vmstat.c @@ -1,5 +1,5 @@ /* $NetBSD: vmstat.c,v 1.29.4.1 1996/06/05 00:21:05 cgd Exp $ */ -/* $OpenBSD: vmstat.c,v 1.17 1997/02/13 20:17:16 kstailey Exp $ */ +/* $OpenBSD: vmstat.c,v 1.18 1997/02/22 17:20:30 kstailey Exp $ */ /* * Copyright (c) 1980, 1986, 1991, 1993 @@ -843,12 +843,16 @@ domem() struct kmembuckets buckets[MINBUCKET + 16]; kread(X_KMEMBUCKETS, buckets, sizeof(buckets)); - (void)printf("Memory statistics by bucket size\n"); - (void)printf( - " Size In Use Free Requests HighWater Couldfree\n"); - for (i = MINBUCKET, kp = &buckets[i]; i < MINBUCKET + 16; i++, kp++) { + for (first = 1, i = MINBUCKET, kp = &buckets[i]; i < MINBUCKET + 16; + i++, kp++) { if (kp->kb_calls == 0) continue; + if (first) { + (void)printf("Memory statistics by bucket size\n"); + (void)printf( + " Size In Use Free Requests HighWater Couldfree\n"); + first = 0; + } size = 1 << i; (void)printf("%8d %8ld %6ld %10ld %7ld %10ld\n", size, kp->kb_total - kp->kb_totalfree, @@ -857,6 +861,16 @@ domem() totfree += size * kp->kb_totalfree; } + /* + * If kmem statistics are not being gathered by the kernel, + * first will still be 1. + */ + if (first) { + printf( + "Kmem statistics are not being gathered by the kernel.\n"); + return; + } + kread(X_KMEMSTAT, kmemstats, sizeof(kmemstats)); (void)printf("\nMemory usage type by bucket size\n"); (void)printf(" Size Type(s)\n"); -- 2.20.1