]> git.ipfire.org Git - thirdparty/bash.git/blob - lib/malloc/mstats.h
bash-5.1 distribution sources and documentation
[thirdparty/bash.git] / lib / malloc / mstats.h
1 /* mstats.h - definitions for malloc statistics */
2
3 /* Copyright (C) 2001-2020 Free Software Foundation, Inc.
4
5 This file is part of GNU Bash, the Bourne-Again SHell.
6
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.
11
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 */
20
21 #ifndef _MSTATS_H
22 #define _MSTATS_H
23
24 #include "imalloc.h"
25
26 #ifdef MALLOC_STATS
27
28 /* This needs to change if the definition in malloc.c changes */
29 #ifndef NBUCKETS
30 # define NBUCKETS 30
31 #endif
32
33 /*
34 * NMALLOC[i] is the difference between the number of mallocs and frees
35 * for a given block size. TMALLOC[i] is the total number of mallocs for
36 * a given block size. NMORECORE[i] is the total number of calls to
37 * morecore(i). NLESSCORE[i] is the total number of calls to lesscore(i).
38 *
39 * NMAL and NFRE are counts of the number of calls to malloc() and free(),
40 * respectively. NREALLOC is the total number of calls to realloc();
41 * NRCOPY is the number of times realloc() had to allocate new memory and
42 * copy to it. NRECURSE is a count of the number of recursive calls to
43 * malloc() for the same bucket size, which can be caused by calls to
44 * malloc() from a signal handler.
45 *
46 * NSBRK is the number of calls to sbrk() (whether by morecore() or for
47 * alignment); TSBRK is the total number of bytes requested from the kernel
48 * with sbrk().
49 *
50 * BYTESUSED is the total number of bytes consumed by blocks currently in
51 * use; BYTESFREE is the total number of bytes currently on all of the free
52 * lists. BYTESREQ is the total number of bytes requested by the caller
53 * via calls to malloc() and realloc().
54 *
55 * TBSPLIT is the number of times a larger block was split to satisfy a
56 * smaller request. NSPLIT[i] is the number of times a block of size I was
57 * split.
58 *
59 * TBCOALESCE is the number of times two adjacent smaller blocks off the free
60 * list were combined to satisfy a larger request.
61 */
62 struct _malstats {
63 int nmalloc[NBUCKETS];
64 int tmalloc[NBUCKETS];
65 int nmorecore[NBUCKETS];
66 int nlesscore[NBUCKETS];
67 int nmal;
68 int nfre;
69 int nrealloc;
70 int nrcopy;
71 int nrecurse;
72 int nsbrk;
73 bits32_t tsbrk;
74 bits32_t bytesused;
75 bits32_t bytesfree;
76 u_bits32_t bytesreq;
77 int tbsplit;
78 int nsplit[NBUCKETS];
79 int tbcoalesce;
80 int ncoalesce[NBUCKETS];
81 int nmmap;
82 bits32_t tmmap;
83 };
84
85 /* Return statistics describing allocation of blocks of size BLOCKSIZE.
86 NFREE is the number of free blocks for this allocation size. NUSED
87 is the number of blocks in use. NMAL is the number of requests for
88 blocks of size BLOCKSIZE. NMORECORE is the number of times we had
89 to call MORECORE to repopulate the free list for this bucket.
90 NLESSCORE is the number of times we gave memory back to the system
91 from this bucket. NSPLIT is the number of times a block of this size
92 was split to satisfy a smaller request. NCOALESCE is the number of
93 times two blocks of this size were combined to satisfy a larger
94 request. */
95 struct bucket_stats {
96 u_bits32_t blocksize;
97 int nfree;
98 int nused;
99 int nmal;
100 int nmorecore;
101 int nlesscore;
102 int nsplit;
103 int ncoalesce;
104 int nmmap; /* currently unused */
105 };
106
107 extern struct bucket_stats malloc_bucket_stats PARAMS((int));
108 extern struct _malstats malloc_stats PARAMS((void));
109 extern void print_malloc_stats PARAMS((char *));
110 extern void trace_malloc_stats PARAMS((char *, char *));
111
112 #endif /* MALLOC_STATS */
113
114 #endif /* _MSTATS_H */