stats.h revision 7372b15a31c63ac5cb9ed8aeabc2a0a3c005e8bf
1/******************************************************************************/
2#ifdef JEMALLOC_H_TYPES
3
4#define	UMAX2S_BUFSIZE	65
5
6typedef struct tcache_bin_stats_s tcache_bin_stats_t;
7typedef struct malloc_bin_stats_s malloc_bin_stats_t;
8typedef struct malloc_large_stats_s malloc_large_stats_t;
9typedef struct arena_stats_s arena_stats_t;
10typedef struct chunk_stats_s chunk_stats_t;
11
12#endif /* JEMALLOC_H_TYPES */
13/******************************************************************************/
14#ifdef JEMALLOC_H_STRUCTS
15
16struct tcache_bin_stats_s {
17	/*
18	 * Number of allocation requests that corresponded to the size of this
19	 * bin.
20	 */
21	uint64_t	nrequests;
22};
23
24struct malloc_bin_stats_s {
25	/*
26	 * Current number of bytes allocated, including objects currently
27	 * cached by tcache.
28	 */
29	size_t		allocated;
30
31	/*
32	 * Total number of allocation/deallocation requests served directly by
33	 * the bin.  Note that tcache may allocate an object, then recycle it
34	 * many times, resulting many increments to nrequests, but only one
35	 * each to nmalloc and ndalloc.
36	 */
37	uint64_t	nmalloc;
38	uint64_t	ndalloc;
39
40	/*
41	 * Number of allocation requests that correspond to the size of this
42	 * bin.  This includes requests served by tcache, though tcache only
43	 * periodically merges into this counter.
44	 */
45	uint64_t	nrequests;
46
47	/* Number of tcache fills from this bin. */
48	uint64_t	nfills;
49
50	/* Number of tcache flushes to this bin. */
51	uint64_t	nflushes;
52
53	/* Total number of runs created for this bin's size class. */
54	uint64_t	nruns;
55
56	/*
57	 * Total number of runs reused by extracting them from the runs tree for
58	 * this bin's size class.
59	 */
60	uint64_t	reruns;
61
62	/* High-water mark for this bin. */
63	size_t		highruns;
64
65	/* Current number of runs in this bin. */
66	size_t		curruns;
67};
68
69struct malloc_large_stats_s {
70	/*
71	 * Total number of allocation/deallocation requests served directly by
72	 * the arena.  Note that tcache may allocate an object, then recycle it
73	 * many times, resulting many increments to nrequests, but only one
74	 * each to nmalloc and ndalloc.
75	 */
76	uint64_t	nmalloc;
77	uint64_t	ndalloc;
78
79	/*
80	 * Number of allocation requests that correspond to this size class.
81	 * This includes requests served by tcache, though tcache only
82	 * periodically merges into this counter.
83	 */
84	uint64_t	nrequests;
85
86	/* High-water mark for this size class. */
87	size_t		highruns;
88
89	/* Current number of runs of this size class. */
90	size_t		curruns;
91};
92
93struct arena_stats_s {
94	/* Number of bytes currently mapped. */
95	size_t		mapped;
96
97	/*
98	 * Total number of purge sweeps, total number of madvise calls made,
99	 * and total pages purged in order to keep dirty unused memory under
100	 * control.
101	 */
102	uint64_t	npurge;
103	uint64_t	nmadvise;
104	uint64_t	purged;
105
106	/* Per-size-category statistics. */
107	size_t		allocated_large;
108	uint64_t	nmalloc_large;
109	uint64_t	ndalloc_large;
110	uint64_t	nrequests_large;
111
112	/*
113	 * One element for each possible size class, including sizes that
114	 * overlap with bin size classes.  This is necessary because ipalloc()
115	 * sometimes has to use such large objects in order to assure proper
116	 * alignment.
117	 */
118	malloc_large_stats_t	*lstats;
119};
120
121struct chunk_stats_s {
122	/* Number of chunks that were allocated. */
123	uint64_t	nchunks;
124
125	/* High-water mark for number of chunks allocated. */
126	size_t		highchunks;
127
128	/*
129	 * Current number of chunks allocated.  This value isn't maintained for
130	 * any other purpose, so keep track of it in order to be able to set
131	 * highchunks.
132	 */
133	size_t		curchunks;
134};
135
136#endif /* JEMALLOC_H_STRUCTS */
137/******************************************************************************/
138#ifdef JEMALLOC_H_EXTERNS
139
140extern bool	opt_stats_print;
141
142extern size_t	stats_cactive;
143
144char	*u2s(uint64_t x, unsigned base, char *s);
145void malloc_cprintf(void (*write)(void *, const char *), void *cbopaque,
146    const char *format, ...) JEMALLOC_ATTR(format(printf, 3, 4));
147void	malloc_printf(const char *format, ...)
148    JEMALLOC_ATTR(format(printf, 1, 2));
149void	stats_print(void (*write)(void *, const char *), void *cbopaque,
150    const char *opts);
151
152#endif /* JEMALLOC_H_EXTERNS */
153/******************************************************************************/
154#ifdef JEMALLOC_H_INLINES
155
156#ifndef JEMALLOC_ENABLE_INLINE
157size_t	stats_cactive_get(void);
158void	stats_cactive_add(size_t size);
159void	stats_cactive_sub(size_t size);
160#endif
161
162#if (defined(JEMALLOC_ENABLE_INLINE) || defined(JEMALLOC_STATS_C_))
163JEMALLOC_INLINE size_t
164stats_cactive_get(void)
165{
166
167	return (atomic_read_z(&stats_cactive));
168}
169
170JEMALLOC_INLINE void
171stats_cactive_add(size_t size)
172{
173
174	atomic_add_z(&stats_cactive, size);
175}
176
177JEMALLOC_INLINE void
178stats_cactive_sub(size_t size)
179{
180
181	atomic_sub_z(&stats_cactive, size);
182}
183#endif
184
185#endif /* JEMALLOC_H_INLINES */
186/******************************************************************************/
187