| 1 | /* mstats.h - definitions for malloc statistics */
|
|---|
| 2 |
|
|---|
| 3 | /* Copyright (C) 2001-2003 Free Software Foundation, Inc.
|
|---|
| 4 |
|
|---|
| 5 | This program is free software; you can redistribute it and/or modify
|
|---|
| 6 | it under the terms of the GNU General Public License as published by
|
|---|
| 7 | the Free Software Foundation; either version 2, or (at your option)
|
|---|
| 8 | any later version.
|
|---|
| 9 |
|
|---|
| 10 | This program is distributed in the hope that it will be useful,
|
|---|
| 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|---|
| 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|---|
| 13 | GNU General Public License for more details.
|
|---|
| 14 |
|
|---|
| 15 | You should have received a copy of the GNU General Public License
|
|---|
| 16 | along with this program; if not, write to the Free Software
|
|---|
| 17 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA. */
|
|---|
| 18 |
|
|---|
| 19 | #ifndef _MSTATS_H
|
|---|
| 20 | #define _MSTATS_H
|
|---|
| 21 |
|
|---|
| 22 | #include "imalloc.h"
|
|---|
| 23 |
|
|---|
| 24 | #ifdef MALLOC_STATS
|
|---|
| 25 |
|
|---|
| 26 | #ifndef NBUCKETS
|
|---|
| 27 | # define NBUCKETS 30
|
|---|
| 28 | #endif
|
|---|
| 29 |
|
|---|
| 30 | /*
|
|---|
| 31 | * NMALLOC[i] is the difference between the number of mallocs and frees
|
|---|
| 32 | * for a given block size. TMALLOC[i] is the total number of mallocs for
|
|---|
| 33 | * a given block size. NMORECORE[i] is the total number of calls to
|
|---|
| 34 | * morecore(i). NLESSCORE[i] is the total number of calls to lesscore(i).
|
|---|
| 35 | *
|
|---|
| 36 | * NMAL and NFRE are counts of the number of calls to malloc() and free(),
|
|---|
| 37 | * respectively. NREALLOC is the total number of calls to realloc();
|
|---|
| 38 | * NRCOPY is the number of times realloc() had to allocate new memory and
|
|---|
| 39 | * copy to it. NRECURSE is a count of the number of recursive calls to
|
|---|
| 40 | * malloc() for the same bucket size, which can be caused by calls to
|
|---|
| 41 | * malloc() from a signal handler.
|
|---|
| 42 | *
|
|---|
| 43 | * NSBRK is the number of calls to sbrk() (whether by morecore() or for
|
|---|
| 44 | * alignment); TSBRK is the total number of bytes requested from the kernel
|
|---|
| 45 | * with sbrk().
|
|---|
| 46 | *
|
|---|
| 47 | * BYTESUSED is the total number of bytes consumed by blocks currently in
|
|---|
| 48 | * use; BYTESFREE is the total number of bytes currently on all of the free
|
|---|
| 49 | * lists. BYTESREQ is the total number of bytes requested by the caller
|
|---|
| 50 | * via calls to malloc() and realloc().
|
|---|
| 51 | *
|
|---|
| 52 | * TBSPLIT is the number of times a larger block was split to satisfy a
|
|---|
| 53 | * smaller request. NSPLIT[i] is the number of times a block of size I was
|
|---|
| 54 | * split.
|
|---|
| 55 | *
|
|---|
| 56 | * TBCOALESCE is the number of times two adjacent smaller blocks off the free
|
|---|
| 57 | * list were combined to satisfy a larger request.
|
|---|
| 58 | */
|
|---|
| 59 | struct _malstats {
|
|---|
| 60 | int nmalloc[NBUCKETS];
|
|---|
| 61 | int tmalloc[NBUCKETS];
|
|---|
| 62 | int nmorecore[NBUCKETS];
|
|---|
| 63 | int nlesscore[NBUCKETS];
|
|---|
| 64 | int nmal;
|
|---|
| 65 | int nfre;
|
|---|
| 66 | int nrealloc;
|
|---|
| 67 | int nrcopy;
|
|---|
| 68 | int nrecurse;
|
|---|
| 69 | int nsbrk;
|
|---|
| 70 | bits32_t tsbrk;
|
|---|
| 71 | bits32_t bytesused;
|
|---|
| 72 | bits32_t bytesfree;
|
|---|
| 73 | u_bits32_t bytesreq;
|
|---|
| 74 | int tbsplit;
|
|---|
| 75 | int nsplit[NBUCKETS];
|
|---|
| 76 | int tbcoalesce;
|
|---|
| 77 | int ncoalesce[NBUCKETS];
|
|---|
| 78 | };
|
|---|
| 79 |
|
|---|
| 80 | /* Return statistics describing allocation of blocks of size BLOCKSIZE.
|
|---|
| 81 | NFREE is the number of free blocks for this allocation size. NUSED
|
|---|
| 82 | is the number of blocks in use. NMAL is the number of requests for
|
|---|
| 83 | blocks of size BLOCKSIZE. NMORECORE is the number of times we had
|
|---|
| 84 | to call MORECORE to repopulate the free list for this bucket.
|
|---|
| 85 | NLESSCORE is the number of times we gave memory back to the system
|
|---|
| 86 | from this bucket. NSPLIT is the number of times a block of this size
|
|---|
| 87 | was split to satisfy a smaller request. NCOALESCE is the number of
|
|---|
| 88 | times two blocks of this size were combined to satisfy a larger
|
|---|
| 89 | request. */
|
|---|
| 90 | struct bucket_stats {
|
|---|
| 91 | u_bits32_t blocksize;
|
|---|
| 92 | int nfree;
|
|---|
| 93 | int nused;
|
|---|
| 94 | int nmal;
|
|---|
| 95 | int nmorecore;
|
|---|
| 96 | int nlesscore;
|
|---|
| 97 | int nsplit;
|
|---|
| 98 | int ncoalesce;
|
|---|
| 99 | };
|
|---|
| 100 |
|
|---|
| 101 | extern struct bucket_stats malloc_bucket_stats __P((int));
|
|---|
| 102 | extern struct _malstats malloc_stats __P((void));
|
|---|
| 103 | extern void print_malloc_stats __P((char *));
|
|---|
| 104 | extern void trace_malloc_stats __P((char *, char *));
|
|---|
| 105 |
|
|---|
| 106 | #endif /* MALLOC_STATS */
|
|---|
| 107 |
|
|---|
| 108 | #endif /* _MSTATS_H */
|
|---|