df51485d0918befa43f7c829356ce18371584fc9
[platform/upstream/bash.git] / lib / malloc / mstats.h
1 /* mstats.h - definitions for malloc statistics */
2
3 /*  Copyright (C) 2001 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).  NMAL and NFRE are counts of the number of calls to malloc()
35  * and free(), respectively.  NREALLOC is the total number of calls to
36  * realloc(); NRCOPY is the number of times realloc() had to allocate new
37  * memory and copy to it.  NRECURSE is a count of the number of recursive
38  * calls to malloc() for the same bucket size, which can be caused by calls
39  * to malloc() from a signal handler.  NSBRK is the number of calls to sbrk()
40  * (whether by morecore() or for alignment); TSBRK is the total number of
41  * bytes requested from the kernel with sbrk().  BYTESUSED is the total
42  * number of bytes consumed by blocks currently in use; BYTESFREE is the
43  * total number of bytes currently on all of the free lists.  TBSPLIT is
44  * the number of times a larger block was split to satisfy a smaller request.
45  * NSPLIT[i] is the number of times a block of size I was split.
46  * TBCOALESCE is the number of times two adjacent smaller blocks off the free
47  * list were combined to satisfy a larger request.
48  */
49 struct _malstats {
50   int nmalloc[NBUCKETS];
51   int tmalloc[NBUCKETS];
52   int nmorecore[NBUCKETS];
53   int nmal;
54   int nfre;
55   int nrealloc;
56   int nrcopy;
57   int nrecurse;
58   int nsbrk;
59   bits32_t tsbrk;
60   bits32_t bytesused;
61   bits32_t bytesfree;
62   int tbsplit;
63   int nsplit[NBUCKETS];
64   int tbcoalesce;
65 };
66
67 /* Return statistics describing allocation of blocks of size BLOCKSIZE.
68    NFREE is the number of free blocks for this allocation size.  NUSED
69    is the number of blocks in use.  NMAL is the number of requests for
70    blocks of size BLOCKSIZE.  NMORECORE is the number of times we had
71    to call MORECORE to repopulate the free list for this bucket.  NSPLIT
72    is the number of times a block of this size was split to satisfy a
73    smaller request. */
74 struct bucket_stats {
75   u_bits32_t blocksize;
76   int nfree;
77   int nused;
78   int nmal;
79   int nmorecore;
80   int nsplit;
81 };
82
83 extern struct bucket_stats malloc_bucket_stats ();
84 extern struct _malstats malloc_stats ();
85 extern void print_malloc_stats ();
86 extern void trace_malloc_stats ();
87
88 #endif /* MALLOC_STATS */
89
90 #endif /* _MSTATS_H */