diff options
author | rwatson <rwatson@FreeBSD.org> | 2005-10-20 17:41:47 +0000 |
---|---|---|
committer | rwatson <rwatson@FreeBSD.org> | 2005-10-20 17:41:47 +0000 |
commit | dc9d32cb6e56d6ebd74293dd58f3ee29d121fb47 (patch) | |
tree | ccd654d68d8df3b9957f547fd75e54ac06c2920a /sys/kern/kern_malloc.c | |
parent | bcc6df344cf0d6e1d64028df0e75c816c6813873 (diff) | |
download | FreeBSD-src-dc9d32cb6e56d6ebd74293dd58f3ee29d121fb47.zip FreeBSD-src-dc9d32cb6e56d6ebd74293dd58f3ee29d121fb47.tar.gz |
Add a "show malloc" command to DDB, which prints out the current stats for
available kernel malloc types. Quite useful for post-mortem debugging of
memory leaks without a dump device configured on a panicked box.
MFC after: 2 weeks
Diffstat (limited to 'sys/kern/kern_malloc.c')
-rw-r--r-- | sys/kern/kern_malloc.c | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/sys/kern/kern_malloc.c b/sys/kern/kern_malloc.c index 2171817..3cb720d 100644 --- a/sys/kern/kern_malloc.c +++ b/sys/kern/kern_malloc.c @@ -34,6 +34,7 @@ #include <sys/cdefs.h> __FBSDID("$FreeBSD$"); +#include "opt_ddb.h" #include "opt_vm.h" #include <sys/param.h> @@ -69,6 +70,8 @@ __FBSDID("$FreeBSD$"); #include <machine/cpu.h> #endif +#include <ddb/ddb.h> + /* * When realloc() is called, if the new size is sufficiently smaller than * the old size, realloc() will allocate a new, smaller block to avoid @@ -813,6 +816,30 @@ SYSCTL_PROC(_kern, OID_AUTO, malloc_stats, CTLFLAG_RD|CTLTYPE_STRUCT, SYSCTL_INT(_kern, OID_AUTO, malloc_count, CTLFLAG_RD, &kmemcount, 0, "Count of kernel malloc types"); +#ifdef DDB +DB_SHOW_COMMAND(malloc, db_show_malloc) +{ + struct malloc_type_internal *mtip; + struct malloc_type *mtp; + u_int64_t allocs, frees; + int i; + + db_printf("%18s %12s %12s %12s\n", "Type", "Allocs", "Frees", + "Used"); + for (mtp = kmemstatistics; mtp != NULL; mtp = mtp->ks_next) { + mtip = (struct malloc_type_internal *)mtp->ks_handle; + allocs = 0; + frees = 0; + for (i = 0; i < MAXCPU; i++) { + allocs += mtip->mti_stats[i].mts_numallocs; + frees += mtip->mti_stats[i].mts_numfrees; + } + db_printf("%18s %12llu %12llu %12llu\n", mtp->ks_shortdesc, + allocs, frees, allocs - frees); + } +} +#endif + #ifdef MALLOC_PROFILE static int |