stats.h revision 746868929afae3e346b47d0fa8a78d7fb131d5a4
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 /* Current number of runs in this bin. */ 63 size_t curruns; 64}; 65 66struct malloc_large_stats_s { 67 /* 68 * Total number of allocation/deallocation requests served directly by 69 * the arena. Note that tcache may allocate an object, then recycle it 70 * many times, resulting many increments to nrequests, but only one 71 * each to nmalloc and ndalloc. 72 */ 73 uint64_t nmalloc; 74 uint64_t ndalloc; 75 76 /* 77 * Number of allocation requests that correspond to this size class. 78 * This includes requests served by tcache, though tcache only 79 * periodically merges into this counter. 80 */ 81 uint64_t nrequests; 82 83 /* Current number of runs of this size class. */ 84 size_t curruns; 85}; 86 87struct arena_stats_s { 88 /* Number of bytes currently mapped. */ 89 size_t mapped; 90 91 /* 92 * Total number of purge sweeps, total number of madvise calls made, 93 * and total pages purged in order to keep dirty unused memory under 94 * control. 95 */ 96 uint64_t npurge; 97 uint64_t nmadvise; 98 uint64_t purged; 99 100 /* Per-size-category statistics. */ 101 size_t allocated_large; 102 uint64_t nmalloc_large; 103 uint64_t ndalloc_large; 104 uint64_t nrequests_large; 105 106 /* 107 * One element for each possible size class, including sizes that 108 * overlap with bin size classes. This is necessary because ipalloc() 109 * sometimes has to use such large objects in order to assure proper 110 * alignment. 111 */ 112 malloc_large_stats_t *lstats; 113}; 114 115struct chunk_stats_s { 116 /* Number of chunks that were allocated. */ 117 uint64_t nchunks; 118 119 /* High-water mark for number of chunks allocated. */ 120 size_t highchunks; 121 122 /* 123 * Current number of chunks allocated. This value isn't maintained for 124 * any other purpose, so keep track of it in order to be able to set 125 * highchunks. 126 */ 127 size_t curchunks; 128}; 129 130#endif /* JEMALLOC_H_STRUCTS */ 131/******************************************************************************/ 132#ifdef JEMALLOC_H_EXTERNS 133 134extern bool opt_stats_print; 135 136extern size_t stats_cactive; 137 138char *u2s(uint64_t x, unsigned base, char *s); 139void malloc_cprintf(void (*write)(void *, const char *), void *cbopaque, 140 const char *format, ...) JEMALLOC_ATTR(format(printf, 3, 4)); 141void malloc_printf(const char *format, ...) 142 JEMALLOC_ATTR(format(printf, 1, 2)); 143void stats_print(void (*write)(void *, const char *), void *cbopaque, 144 const char *opts); 145 146#endif /* JEMALLOC_H_EXTERNS */ 147/******************************************************************************/ 148#ifdef JEMALLOC_H_INLINES 149 150#ifndef JEMALLOC_ENABLE_INLINE 151size_t stats_cactive_get(void); 152void stats_cactive_add(size_t size); 153void stats_cactive_sub(size_t size); 154#endif 155 156#if (defined(JEMALLOC_ENABLE_INLINE) || defined(JEMALLOC_STATS_C_)) 157JEMALLOC_INLINE size_t 158stats_cactive_get(void) 159{ 160 161 return (atomic_read_z(&stats_cactive)); 162} 163 164JEMALLOC_INLINE void 165stats_cactive_add(size_t size) 166{ 167 168 atomic_add_z(&stats_cactive, size); 169} 170 171JEMALLOC_INLINE void 172stats_cactive_sub(size_t size) 173{ 174 175 atomic_sub_z(&stats_cactive, size); 176} 177#endif 178 179#endif /* JEMALLOC_H_INLINES */ 180/******************************************************************************/ 181