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