diff options
author | Angelos D. Keromytis <angelos@cvs.openbsd.org> | 2001-01-04 06:07:23 +0000 |
---|---|---|
committer | Angelos D. Keromytis <angelos@cvs.openbsd.org> | 2001-01-04 06:07:23 +0000 |
commit | 3403bc8618547ee1a0c342f28768876dc996a0d7 (patch) | |
tree | 10808b256a2b31166112e8e63d747040ff9ade3b | |
parent | a3ebe43514fc441692e32cffb0206e18f159ace0 (diff) |
Print the kern.malloc.* branch
-rw-r--r-- | sbin/sysctl/sysctl.8 | 9 | ||||
-rw-r--r-- | sbin/sysctl/sysctl.c | 84 |
2 files changed, 89 insertions, 4 deletions
diff --git a/sbin/sysctl/sysctl.8 b/sbin/sysctl/sysctl.8 index e3670e47b20..d5fd6b1df9a 100644 --- a/sbin/sysctl/sysctl.8 +++ b/sbin/sysctl/sysctl.8 @@ -1,4 +1,4 @@ -.\" $OpenBSD: sysctl.8,v 1.57 2000/12/21 01:14:14 itojun Exp $ +.\" $OpenBSD: sysctl.8,v 1.58 2001/01/04 06:07:22 angelos Exp $ .\" $NetBSD: sysctl.8,v 1.4 1995/09/30 07:12:49 thorpej Exp $ .\" .\" Copyright (c) 1993 @@ -142,6 +142,13 @@ privilege can change the value. .It kern.sysvsem integer no .It kern.sysvshm integer no .It kern.arandom u_int no +.It kern.malloc.buckets string no +.It kern.malloc.bucket.<sz>.calls quad no +.It kern.malloc.bucket.<sz>.total_allocated quad no +.It kern.malloc.bucket.<sz>.total_free quad no +.It kern.malloc.bucket.<sz>.elements quad no +.It kern.malloc.bucket.<sz>.high_watermark quad no +.It kern.malloc.bucket.<sz>.could_free quad no .It vm.loadavg struct no .It vm.psstrings struct no .It vm.swapencrypt.enable integer yes diff --git a/sbin/sysctl/sysctl.c b/sbin/sysctl/sysctl.c index 2cf4219711f..956089ffd8a 100644 --- a/sbin/sysctl/sysctl.c +++ b/sbin/sysctl/sysctl.c @@ -1,4 +1,4 @@ -/* $OpenBSD: sysctl.c,v 1.55 2000/12/22 22:47:04 deraadt Exp $ */ +/* $OpenBSD: sysctl.c,v 1.56 2001/01/04 06:07:22 angelos Exp $ */ /* $NetBSD: sysctl.c,v 1.9 1995/09/30 07:12:50 thorpej Exp $ */ /* @@ -44,7 +44,7 @@ static char copyright[] = #if 0 static char sccsid[] = "@(#)sysctl.c 8.5 (Berkeley) 5/9/95"; #else -static char *rcsid = "$OpenBSD: sysctl.c,v 1.55 2000/12/22 22:47:04 deraadt Exp $"; +static char *rcsid = "$OpenBSD: sysctl.c,v 1.56 2001/01/04 06:07:22 angelos Exp $"; #endif #endif /* not lint */ @@ -54,6 +54,7 @@ static char *rcsid = "$OpenBSD: sysctl.c,v 1.55 2000/12/22 22:47:04 deraadt Exp #include <sys/stat.h> #include <sys/sysctl.h> #include <sys/socket.h> +#include <sys/malloc.h> #include <vm/vm_param.h> #include <machine/cpu.h> #include <net/route.h> @@ -121,6 +122,8 @@ struct ctlname netname[] = CTL_NET_NAMES; struct ctlname hwname[] = CTL_HW_NAMES; struct ctlname username[] = CTL_USER_NAMES; struct ctlname debugname[CTL_DEBUG_MAXID]; +struct ctlname kernmallocname[] = CTL_KERN_MALLOC_NAMES; +struct ctlname kernbucketname[] = CTL_KERN_MALLOC_BUCKET_NAMES; struct ctlname *vfsname; #ifdef CTL_MACHDEP_NAMES struct ctlname machdepname[] = CTL_MACHDEP_NAMES; @@ -329,6 +332,12 @@ parse(string, flags) (void)printf("%s = %s\n", string, state == GMON_PROF_OFF ? "off" : "running"); return; + case KERN_MALLOCSTATS: + len = sysctl_malloc(string, &bufp, mib, flags, &type); + if (len < 0) + return; + newsize = 0; + break; case KERN_VNODE: case KERN_FILE: if (flags == 0) @@ -1058,7 +1067,7 @@ sysctl_bios(string, bufpp, mib, flags, typep) } mib[3] = atoi(name); *typep = CTLTYPE_STRUCT; - return 4; + return(4); } else { *typep = bioslist.list[indx].ctl_type; return(3); @@ -1209,6 +1218,75 @@ struct list inetvars[] = { { etheripname, ETHERIPCTL_MAXID }, }; +struct list kernmalloclist = { kernmallocname, KERN_MALLOC_MAXID }; +struct list kernbucketlist = { kernbucketname, KERN_MALLOC_BUCKET_MAXID }; + +/* + * handle malloc statistics + */ +int +sysctl_malloc(string, bufpp, mib, flags, typep) + char *string; + char **bufpp; + int mib[]; + int flags; + int *typep; +{ + int indx, size, stor, i; + char *name, bufp[BUFSIZ], *buf; + struct list lp; + + if (*bufpp == NULL) { + listall(string, &kernmalloclist); + return(-1); + } + if ((indx = findname(string, "third", bufpp, &kernmalloclist)) == -1) + return (-1); + mib[2] = indx; + if (mib[2] == KERN_MALLOC_BUCKET) { + if ((name = strsep(bufpp, ".")) == NULL) { + size = BUFSIZ; + stor = mib[2]; + mib[2] = KERN_MALLOC_BUCKETS; + buf = bufp; + if (sysctl(mib, 3, buf, &size, NULL, 0) < 0) + return(-1); + mib[2] = stor; + for (stor = 0, i = 0; i < size; i++) + if (buf[i] == ',') + stor++; + lp.list = calloc(stor + 2, sizeof(struct ctlname)); + if (lp.list == NULL) + return(-1); + lp.size = stor + 2; + for (i = 1; + (lp.list[i].ctl_name = strsep(&buf, ",")) != NULL; + i++) { + lp.list[i].ctl_type = CTLTYPE_QUAD; + } + lp.list[i].ctl_name = buf; + lp.list[i].ctl_type = CTLTYPE_QUAD; + listall(string, &lp); + free(lp.list); + return(-1); + } + mib[3] = atoi(name); + if (*bufpp == NULL) { + listall(string, &kernbucketlist); + return(-1); + } + if ((indx = findname(string, "fifth", bufpp, + &kernbucketlist)) == -1) + return (-1); + mib[4] = indx; + *typep = CTLTYPE_QUAD; + return(5); + } else { + *typep = CTLTYPE_STRING; + return(3); + } +} + /* * handle internet requests */ |