2010-01-17 01:53:50 +08:00
|
|
|
#define JEMALLOC_STATS_C_
|
2010-02-12 06:45:59 +08:00
|
|
|
#include "jemalloc/internal/jemalloc_internal.h"
|
2010-01-17 01:53:50 +08:00
|
|
|
|
2010-01-28 05:10:55 +08:00
|
|
|
#define CTL_GET(n, v, t) do { \
|
|
|
|
size_t sz = sizeof(t); \
|
|
|
|
xmallctl(n, v, &sz, NULL, 0); \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
#define CTL_I_GET(n, v, t) do { \
|
|
|
|
size_t mib[6]; \
|
|
|
|
size_t miblen = sizeof(mib) / sizeof(size_t); \
|
|
|
|
size_t sz = sizeof(t); \
|
|
|
|
xmallctlnametomib(n, mib, &miblen); \
|
|
|
|
mib[2] = i; \
|
|
|
|
xmallctlbymib(mib, miblen, v, &sz, NULL, 0); \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
#define CTL_J_GET(n, v, t) do { \
|
|
|
|
size_t mib[6]; \
|
|
|
|
size_t miblen = sizeof(mib) / sizeof(size_t); \
|
|
|
|
size_t sz = sizeof(t); \
|
|
|
|
xmallctlnametomib(n, mib, &miblen); \
|
|
|
|
mib[2] = j; \
|
|
|
|
xmallctlbymib(mib, miblen, v, &sz, NULL, 0); \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
#define CTL_IJ_GET(n, v, t) do { \
|
|
|
|
size_t mib[6]; \
|
|
|
|
size_t miblen = sizeof(mib) / sizeof(size_t); \
|
|
|
|
size_t sz = sizeof(t); \
|
|
|
|
xmallctlnametomib(n, mib, &miblen); \
|
|
|
|
mib[2] = i; \
|
|
|
|
mib[4] = j; \
|
|
|
|
xmallctlbymib(mib, miblen, v, &sz, NULL, 0); \
|
|
|
|
} while (0)
|
|
|
|
|
2010-01-17 01:53:50 +08:00
|
|
|
/******************************************************************************/
|
|
|
|
/* Data. */
|
|
|
|
|
|
|
|
bool opt_stats_print = false;
|
|
|
|
|
2011-03-19 08:56:14 +08:00
|
|
|
size_t stats_cactive = 0;
|
|
|
|
|
2010-01-18 07:49:25 +08:00
|
|
|
/******************************************************************************/
|
|
|
|
/* Function prototypes for non-inline static functions. */
|
|
|
|
|
2010-03-04 09:45:38 +08:00
|
|
|
static void stats_arena_bins_print(void (*write_cb)(void *, const char *),
|
|
|
|
void *cbopaque, unsigned i);
|
|
|
|
static void stats_arena_lruns_print(void (*write_cb)(void *, const char *),
|
|
|
|
void *cbopaque, unsigned i);
|
|
|
|
static void stats_arena_print(void (*write_cb)(void *, const char *),
|
2012-03-13 23:46:12 +08:00
|
|
|
void *cbopaque, unsigned i, bool bins, bool large);
|
2010-01-18 07:49:25 +08:00
|
|
|
|
2010-01-17 01:53:50 +08:00
|
|
|
/******************************************************************************/
|
|
|
|
|
2010-01-28 05:10:55 +08:00
|
|
|
static void
|
2010-03-04 09:45:38 +08:00
|
|
|
stats_arena_bins_print(void (*write_cb)(void *, const char *), void *cbopaque,
|
|
|
|
unsigned i)
|
2010-01-28 05:10:55 +08:00
|
|
|
{
|
|
|
|
size_t pagesize;
|
|
|
|
bool config_tcache;
|
|
|
|
unsigned nbins, j, gap_start;
|
|
|
|
|
|
|
|
CTL_GET("arenas.pagesize", &pagesize, size_t);
|
|
|
|
|
|
|
|
CTL_GET("config.tcache", &config_tcache, bool);
|
|
|
|
if (config_tcache) {
|
2010-03-04 09:45:38 +08:00
|
|
|
malloc_cprintf(write_cb, cbopaque,
|
2012-02-29 08:50:47 +08:00
|
|
|
"bins: bin size regs pgs allocated nmalloc"
|
2010-03-16 06:50:48 +08:00
|
|
|
" ndalloc nrequests nfills nflushes"
|
2012-02-14 07:18:19 +08:00
|
|
|
" newruns reruns curruns\n");
|
2010-01-28 05:10:55 +08:00
|
|
|
} else {
|
2010-03-04 09:45:38 +08:00
|
|
|
malloc_cprintf(write_cb, cbopaque,
|
2012-02-29 08:50:47 +08:00
|
|
|
"bins: bin size regs pgs allocated nmalloc"
|
2012-02-14 07:18:19 +08:00
|
|
|
" ndalloc newruns reruns curruns\n");
|
2010-01-28 05:10:55 +08:00
|
|
|
}
|
|
|
|
CTL_GET("arenas.nbins", &nbins, unsigned);
|
|
|
|
for (j = 0, gap_start = UINT_MAX; j < nbins; j++) {
|
|
|
|
uint64_t nruns;
|
|
|
|
|
|
|
|
CTL_IJ_GET("stats.arenas.0.bins.0.nruns", &nruns, uint64_t);
|
|
|
|
if (nruns == 0) {
|
|
|
|
if (gap_start == UINT_MAX)
|
|
|
|
gap_start = j;
|
|
|
|
} else {
|
2010-03-14 12:32:56 +08:00
|
|
|
size_t reg_size, run_size, allocated;
|
2010-01-28 05:10:55 +08:00
|
|
|
uint32_t nregs;
|
2010-03-14 12:32:56 +08:00
|
|
|
uint64_t nmalloc, ndalloc, nrequests, nfills, nflushes;
|
|
|
|
uint64_t reruns;
|
2012-02-14 07:18:19 +08:00
|
|
|
size_t curruns;
|
2010-01-28 05:10:55 +08:00
|
|
|
|
|
|
|
if (gap_start != UINT_MAX) {
|
|
|
|
if (j > gap_start + 1) {
|
|
|
|
/* Gap of more than one size class. */
|
2010-03-04 09:45:38 +08:00
|
|
|
malloc_cprintf(write_cb, cbopaque,
|
2010-01-28 05:10:55 +08:00
|
|
|
"[%u..%u]\n", gap_start,
|
|
|
|
j - 1);
|
|
|
|
} else {
|
|
|
|
/* Gap of one size class. */
|
2010-03-04 09:45:38 +08:00
|
|
|
malloc_cprintf(write_cb, cbopaque,
|
2010-01-28 05:10:55 +08:00
|
|
|
"[%u]\n", gap_start);
|
|
|
|
}
|
|
|
|
gap_start = UINT_MAX;
|
|
|
|
}
|
|
|
|
CTL_J_GET("arenas.bin.0.size", ®_size, size_t);
|
|
|
|
CTL_J_GET("arenas.bin.0.nregs", &nregs, uint32_t);
|
|
|
|
CTL_J_GET("arenas.bin.0.run_size", &run_size, size_t);
|
2010-03-14 12:32:56 +08:00
|
|
|
CTL_IJ_GET("stats.arenas.0.bins.0.allocated",
|
|
|
|
&allocated, size_t);
|
|
|
|
CTL_IJ_GET("stats.arenas.0.bins.0.nmalloc",
|
|
|
|
&nmalloc, uint64_t);
|
|
|
|
CTL_IJ_GET("stats.arenas.0.bins.0.ndalloc",
|
|
|
|
&ndalloc, uint64_t);
|
2010-01-28 05:10:55 +08:00
|
|
|
if (config_tcache) {
|
2010-03-14 12:32:56 +08:00
|
|
|
CTL_IJ_GET("stats.arenas.0.bins.0.nrequests",
|
|
|
|
&nrequests, uint64_t);
|
2010-01-28 05:10:55 +08:00
|
|
|
CTL_IJ_GET("stats.arenas.0.bins.0.nfills",
|
|
|
|
&nfills, uint64_t);
|
|
|
|
CTL_IJ_GET("stats.arenas.0.bins.0.nflushes",
|
|
|
|
&nflushes, uint64_t);
|
|
|
|
}
|
|
|
|
CTL_IJ_GET("stats.arenas.0.bins.0.nreruns", &reruns,
|
|
|
|
uint64_t);
|
|
|
|
CTL_IJ_GET("stats.arenas.0.bins.0.curruns", &curruns,
|
|
|
|
size_t);
|
|
|
|
if (config_tcache) {
|
2010-03-04 09:45:38 +08:00
|
|
|
malloc_cprintf(write_cb, cbopaque,
|
2012-02-29 08:50:47 +08:00
|
|
|
"%13u %5zu %4u %3zu %12zu %12"PRIu64
|
2010-03-16 06:50:48 +08:00
|
|
|
" %12"PRIu64" %12"PRIu64" %12"PRIu64
|
|
|
|
" %12"PRIu64" %12"PRIu64" %12"PRIu64
|
2012-02-14 07:18:19 +08:00
|
|
|
" %12zu\n",
|
2012-02-29 08:50:47 +08:00
|
|
|
j, reg_size, nregs, run_size / pagesize,
|
2010-03-14 12:32:56 +08:00
|
|
|
allocated, nmalloc, ndalloc, nrequests,
|
2012-02-14 07:18:19 +08:00
|
|
|
nfills, nflushes, nruns, reruns, curruns);
|
2010-01-28 05:10:55 +08:00
|
|
|
} else {
|
2010-03-04 09:45:38 +08:00
|
|
|
malloc_cprintf(write_cb, cbopaque,
|
2012-02-29 08:50:47 +08:00
|
|
|
"%13u %5zu %4u %3zu %12zu %12"PRIu64
|
2010-03-16 06:50:48 +08:00
|
|
|
" %12"PRIu64" %12"PRIu64" %12"PRIu64
|
2012-02-14 07:18:19 +08:00
|
|
|
" %12zu\n",
|
2012-02-29 08:50:47 +08:00
|
|
|
j, reg_size, nregs, run_size / pagesize,
|
2010-03-14 12:32:56 +08:00
|
|
|
allocated, nmalloc, ndalloc, nruns, reruns,
|
2012-02-14 07:18:19 +08:00
|
|
|
curruns);
|
2010-01-28 05:10:55 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (gap_start != UINT_MAX) {
|
|
|
|
if (j > gap_start + 1) {
|
|
|
|
/* Gap of more than one size class. */
|
2010-03-04 09:45:38 +08:00
|
|
|
malloc_cprintf(write_cb, cbopaque, "[%u..%u]\n",
|
2010-01-28 05:10:55 +08:00
|
|
|
gap_start, j - 1);
|
|
|
|
} else {
|
|
|
|
/* Gap of one size class. */
|
2010-03-04 09:45:38 +08:00
|
|
|
malloc_cprintf(write_cb, cbopaque, "[%u]\n", gap_start);
|
2010-01-28 05:10:55 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-03-04 09:45:38 +08:00
|
|
|
stats_arena_lruns_print(void (*write_cb)(void *, const char *), void *cbopaque,
|
|
|
|
unsigned i)
|
2010-01-28 05:10:55 +08:00
|
|
|
{
|
|
|
|
size_t pagesize, nlruns, j;
|
|
|
|
ssize_t gap_start;
|
|
|
|
|
|
|
|
CTL_GET("arenas.pagesize", &pagesize, size_t);
|
|
|
|
|
2010-03-04 09:45:38 +08:00
|
|
|
malloc_cprintf(write_cb, cbopaque,
|
2010-03-18 07:27:39 +08:00
|
|
|
"large: size pages nmalloc ndalloc nrequests"
|
2012-02-14 07:18:19 +08:00
|
|
|
" curruns\n");
|
2010-01-30 03:24:19 +08:00
|
|
|
CTL_GET("arenas.nlruns", &nlruns, size_t);
|
2010-01-28 05:10:55 +08:00
|
|
|
for (j = 0, gap_start = -1; j < nlruns; j++) {
|
2010-03-18 07:27:39 +08:00
|
|
|
uint64_t nmalloc, ndalloc, nrequests;
|
2012-02-14 07:18:19 +08:00
|
|
|
size_t run_size, curruns;
|
2010-01-28 05:10:55 +08:00
|
|
|
|
2010-03-18 07:27:39 +08:00
|
|
|
CTL_IJ_GET("stats.arenas.0.lruns.0.nmalloc", &nmalloc,
|
|
|
|
uint64_t);
|
|
|
|
CTL_IJ_GET("stats.arenas.0.lruns.0.ndalloc", &ndalloc,
|
|
|
|
uint64_t);
|
2010-01-28 05:10:55 +08:00
|
|
|
CTL_IJ_GET("stats.arenas.0.lruns.0.nrequests", &nrequests,
|
|
|
|
uint64_t);
|
|
|
|
if (nrequests == 0) {
|
|
|
|
if (gap_start == -1)
|
|
|
|
gap_start = j;
|
|
|
|
} else {
|
|
|
|
CTL_J_GET("arenas.lrun.0.size", &run_size, size_t);
|
|
|
|
CTL_IJ_GET("stats.arenas.0.lruns.0.curruns", &curruns,
|
|
|
|
size_t);
|
|
|
|
if (gap_start != -1) {
|
2010-03-04 09:45:38 +08:00
|
|
|
malloc_cprintf(write_cb, cbopaque, "[%zu]\n",
|
2010-01-28 05:10:55 +08:00
|
|
|
j - gap_start);
|
|
|
|
gap_start = -1;
|
|
|
|
}
|
2010-03-04 09:45:38 +08:00
|
|
|
malloc_cprintf(write_cb, cbopaque,
|
2010-03-18 07:27:39 +08:00
|
|
|
"%13zu %5zu %12"PRIu64" %12"PRIu64" %12"PRIu64
|
2012-02-14 07:18:19 +08:00
|
|
|
" %12zu\n",
|
2010-03-18 07:27:39 +08:00
|
|
|
run_size, run_size / pagesize, nmalloc, ndalloc,
|
2012-02-14 07:18:19 +08:00
|
|
|
nrequests, curruns);
|
2010-01-28 05:10:55 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (gap_start != -1)
|
2010-03-04 09:45:38 +08:00
|
|
|
malloc_cprintf(write_cb, cbopaque, "[%zu]\n", j - gap_start);
|
2010-01-28 05:10:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-03-04 09:45:38 +08:00
|
|
|
stats_arena_print(void (*write_cb)(void *, const char *), void *cbopaque,
|
2012-03-13 23:46:12 +08:00
|
|
|
unsigned i, bool bins, bool large)
|
2010-01-28 05:10:55 +08:00
|
|
|
{
|
2011-03-19 04:41:33 +08:00
|
|
|
unsigned nthreads;
|
2010-01-30 03:24:19 +08:00
|
|
|
size_t pagesize, pactive, pdirty, mapped;
|
2010-01-28 05:10:55 +08:00
|
|
|
uint64_t npurge, nmadvise, purged;
|
|
|
|
size_t small_allocated;
|
2010-03-14 12:32:56 +08:00
|
|
|
uint64_t small_nmalloc, small_ndalloc, small_nrequests;
|
2010-01-28 05:10:55 +08:00
|
|
|
size_t large_allocated;
|
2010-03-18 07:27:39 +08:00
|
|
|
uint64_t large_nmalloc, large_ndalloc, large_nrequests;
|
2010-01-28 05:10:55 +08:00
|
|
|
|
2010-01-30 03:24:19 +08:00
|
|
|
CTL_GET("arenas.pagesize", &pagesize, size_t);
|
|
|
|
|
2011-03-19 04:41:33 +08:00
|
|
|
CTL_I_GET("stats.arenas.0.nthreads", &nthreads, unsigned);
|
|
|
|
malloc_cprintf(write_cb, cbopaque,
|
|
|
|
"assigned threads: %u\n", nthreads);
|
2010-01-28 05:10:55 +08:00
|
|
|
CTL_I_GET("stats.arenas.0.pactive", &pactive, size_t);
|
|
|
|
CTL_I_GET("stats.arenas.0.pdirty", &pdirty, size_t);
|
|
|
|
CTL_I_GET("stats.arenas.0.npurge", &npurge, uint64_t);
|
|
|
|
CTL_I_GET("stats.arenas.0.nmadvise", &nmadvise, uint64_t);
|
|
|
|
CTL_I_GET("stats.arenas.0.purged", &purged, uint64_t);
|
2010-03-04 09:45:38 +08:00
|
|
|
malloc_cprintf(write_cb, cbopaque,
|
2010-01-28 05:10:55 +08:00
|
|
|
"dirty pages: %zu:%zu active:dirty, %"PRIu64" sweep%s,"
|
|
|
|
" %"PRIu64" madvise%s, %"PRIu64" purged\n",
|
|
|
|
pactive, pdirty, npurge, npurge == 1 ? "" : "s",
|
|
|
|
nmadvise, nmadvise == 1 ? "" : "s", purged);
|
|
|
|
|
2010-03-04 09:45:38 +08:00
|
|
|
malloc_cprintf(write_cb, cbopaque,
|
2010-03-14 12:32:56 +08:00
|
|
|
" allocated nmalloc ndalloc nrequests\n");
|
2010-01-28 05:10:55 +08:00
|
|
|
CTL_I_GET("stats.arenas.0.small.allocated", &small_allocated, size_t);
|
|
|
|
CTL_I_GET("stats.arenas.0.small.nmalloc", &small_nmalloc, uint64_t);
|
|
|
|
CTL_I_GET("stats.arenas.0.small.ndalloc", &small_ndalloc, uint64_t);
|
2010-03-14 12:32:56 +08:00
|
|
|
CTL_I_GET("stats.arenas.0.small.nrequests", &small_nrequests, uint64_t);
|
2010-03-04 09:45:38 +08:00
|
|
|
malloc_cprintf(write_cb, cbopaque,
|
2010-03-14 12:32:56 +08:00
|
|
|
"small: %12zu %12"PRIu64" %12"PRIu64" %12"PRIu64"\n",
|
|
|
|
small_allocated, small_nmalloc, small_ndalloc, small_nrequests);
|
2010-01-28 05:10:55 +08:00
|
|
|
CTL_I_GET("stats.arenas.0.large.allocated", &large_allocated, size_t);
|
|
|
|
CTL_I_GET("stats.arenas.0.large.nmalloc", &large_nmalloc, uint64_t);
|
|
|
|
CTL_I_GET("stats.arenas.0.large.ndalloc", &large_ndalloc, uint64_t);
|
2010-03-18 07:27:39 +08:00
|
|
|
CTL_I_GET("stats.arenas.0.large.nrequests", &large_nrequests, uint64_t);
|
2010-03-04 09:45:38 +08:00
|
|
|
malloc_cprintf(write_cb, cbopaque,
|
2010-03-14 12:32:56 +08:00
|
|
|
"large: %12zu %12"PRIu64" %12"PRIu64" %12"PRIu64"\n",
|
2010-03-18 07:27:39 +08:00
|
|
|
large_allocated, large_nmalloc, large_ndalloc, large_nrequests);
|
2010-03-04 09:45:38 +08:00
|
|
|
malloc_cprintf(write_cb, cbopaque,
|
2010-03-14 12:32:56 +08:00
|
|
|
"total: %12zu %12"PRIu64" %12"PRIu64" %12"PRIu64"\n",
|
2010-03-18 07:27:39 +08:00
|
|
|
small_allocated + large_allocated,
|
|
|
|
small_nmalloc + large_nmalloc,
|
|
|
|
small_ndalloc + large_ndalloc,
|
|
|
|
small_nrequests + large_nrequests);
|
2010-03-04 09:45:38 +08:00
|
|
|
malloc_cprintf(write_cb, cbopaque, "active: %12zu\n",
|
2010-01-30 03:24:19 +08:00
|
|
|
pactive * pagesize );
|
2010-01-28 05:10:55 +08:00
|
|
|
CTL_I_GET("stats.arenas.0.mapped", &mapped, size_t);
|
2010-03-04 09:45:38 +08:00
|
|
|
malloc_cprintf(write_cb, cbopaque, "mapped: %12zu\n", mapped);
|
2010-01-28 05:10:55 +08:00
|
|
|
|
2012-03-13 23:46:12 +08:00
|
|
|
if (bins)
|
|
|
|
stats_arena_bins_print(write_cb, cbopaque, i);
|
|
|
|
if (large)
|
|
|
|
stats_arena_lruns_print(write_cb, cbopaque, i);
|
2010-01-28 05:10:55 +08:00
|
|
|
}
|
|
|
|
|
2010-01-17 01:53:50 +08:00
|
|
|
void
|
2010-03-04 09:45:38 +08:00
|
|
|
stats_print(void (*write_cb)(void *, const char *), void *cbopaque,
|
|
|
|
const char *opts)
|
2010-01-17 01:53:50 +08:00
|
|
|
{
|
2010-10-24 09:37:06 +08:00
|
|
|
int err;
|
2010-01-28 05:10:55 +08:00
|
|
|
uint64_t epoch;
|
|
|
|
size_t u64sz;
|
2010-01-17 01:53:50 +08:00
|
|
|
bool general = true;
|
2010-01-18 09:35:19 +08:00
|
|
|
bool merged = true;
|
|
|
|
bool unmerged = true;
|
2010-01-17 01:53:50 +08:00
|
|
|
bool bins = true;
|
|
|
|
bool large = true;
|
|
|
|
|
2010-10-24 09:37:06 +08:00
|
|
|
/*
|
|
|
|
* Refresh stats, in case mallctl() was called by the application.
|
|
|
|
*
|
|
|
|
* Check for OOM here, since refreshing the ctl cache can trigger
|
|
|
|
* allocation. In practice, none of the subsequent mallctl()-related
|
|
|
|
* calls in this function will cause OOM if this one succeeds.
|
|
|
|
* */
|
2010-01-28 05:10:55 +08:00
|
|
|
epoch = 1;
|
|
|
|
u64sz = sizeof(uint64_t);
|
2012-03-02 09:19:20 +08:00
|
|
|
err = je_mallctl("epoch", &epoch, &u64sz, &epoch, sizeof(uint64_t));
|
2010-10-24 09:37:06 +08:00
|
|
|
if (err != 0) {
|
|
|
|
if (err == EAGAIN) {
|
|
|
|
malloc_write("<jemalloc>: Memory allocation failure in "
|
|
|
|
"mallctl(\"epoch\", ...)\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
malloc_write("<jemalloc>: Failure in mallctl(\"epoch\", "
|
|
|
|
"...)\n");
|
|
|
|
abort();
|
|
|
|
}
|
2010-01-28 05:10:55 +08:00
|
|
|
|
2010-03-04 09:45:38 +08:00
|
|
|
if (write_cb == NULL) {
|
2010-01-18 07:49:25 +08:00
|
|
|
/*
|
2010-03-04 09:45:38 +08:00
|
|
|
* The caller did not provide an alternate write_cb callback
|
|
|
|
* function, so use the default one. malloc_write() is an
|
2010-01-18 07:49:25 +08:00
|
|
|
* inline function, so use malloc_message() directly here.
|
|
|
|
*/
|
2012-03-02 09:19:20 +08:00
|
|
|
write_cb = je_malloc_message;
|
2010-03-04 09:45:38 +08:00
|
|
|
cbopaque = NULL;
|
2010-01-18 07:49:25 +08:00
|
|
|
}
|
|
|
|
|
2010-01-17 01:53:50 +08:00
|
|
|
if (opts != NULL) {
|
|
|
|
unsigned i;
|
|
|
|
|
|
|
|
for (i = 0; opts[i] != '\0'; i++) {
|
|
|
|
switch (opts[i]) {
|
2012-03-07 06:57:45 +08:00
|
|
|
case 'g':
|
|
|
|
general = false;
|
|
|
|
break;
|
|
|
|
case 'm':
|
|
|
|
merged = false;
|
|
|
|
break;
|
|
|
|
case 'a':
|
|
|
|
unmerged = false;
|
|
|
|
break;
|
|
|
|
case 'b':
|
|
|
|
bins = false;
|
|
|
|
break;
|
|
|
|
case 'l':
|
|
|
|
large = false;
|
|
|
|
break;
|
|
|
|
default:;
|
2010-01-17 01:53:50 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-03-04 09:45:38 +08:00
|
|
|
write_cb(cbopaque, "___ Begin jemalloc statistics ___\n");
|
2010-01-17 01:53:50 +08:00
|
|
|
if (general) {
|
2010-01-28 05:10:55 +08:00
|
|
|
int err;
|
2010-03-04 09:55:03 +08:00
|
|
|
const char *cpv;
|
2010-01-28 05:10:55 +08:00
|
|
|
bool bv;
|
|
|
|
unsigned uv;
|
|
|
|
ssize_t ssv;
|
2010-10-24 09:37:06 +08:00
|
|
|
size_t sv, bsz, ssz, sssz, cpsz;
|
2010-01-28 05:10:55 +08:00
|
|
|
|
|
|
|
bsz = sizeof(bool);
|
|
|
|
ssz = sizeof(size_t);
|
2010-10-24 09:37:06 +08:00
|
|
|
sssz = sizeof(ssize_t);
|
|
|
|
cpsz = sizeof(const char *);
|
2010-01-28 05:10:55 +08:00
|
|
|
|
2010-03-04 09:55:03 +08:00
|
|
|
CTL_GET("version", &cpv, const char *);
|
2012-03-07 06:57:45 +08:00
|
|
|
malloc_cprintf(write_cb, cbopaque, "Version: %s\n", cpv);
|
2010-01-28 05:10:55 +08:00
|
|
|
CTL_GET("config.debug", &bv, bool);
|
2012-03-07 06:57:45 +08:00
|
|
|
malloc_cprintf(write_cb, cbopaque, "Assertions %s\n",
|
|
|
|
bv ? "enabled" : "disabled");
|
2010-01-28 05:10:55 +08:00
|
|
|
|
2010-10-24 09:37:06 +08:00
|
|
|
#define OPT_WRITE_BOOL(n) \
|
2012-03-02 09:19:20 +08:00
|
|
|
if ((err = je_mallctl("opt."#n, &bv, &bsz, NULL, 0)) \
|
|
|
|
== 0) { \
|
2012-03-07 06:57:45 +08:00
|
|
|
malloc_cprintf(write_cb, cbopaque, \
|
|
|
|
" opt."#n": %s\n", bv ? "true" : "false"); \
|
2010-10-24 09:37:06 +08:00
|
|
|
}
|
|
|
|
#define OPT_WRITE_SIZE_T(n) \
|
2012-03-02 09:19:20 +08:00
|
|
|
if ((err = je_mallctl("opt."#n, &sv, &ssz, NULL, 0)) \
|
|
|
|
== 0) { \
|
2012-03-07 06:57:45 +08:00
|
|
|
malloc_cprintf(write_cb, cbopaque, \
|
|
|
|
" opt."#n": %zu\n", sv); \
|
2010-10-24 09:37:06 +08:00
|
|
|
}
|
|
|
|
#define OPT_WRITE_SSIZE_T(n) \
|
2012-03-02 09:19:20 +08:00
|
|
|
if ((err = je_mallctl("opt."#n, &ssv, &sssz, NULL, 0)) \
|
|
|
|
== 0) { \
|
2012-03-07 06:57:45 +08:00
|
|
|
malloc_cprintf(write_cb, cbopaque, \
|
|
|
|
" opt."#n": %zd\n", ssv); \
|
2010-10-24 09:37:06 +08:00
|
|
|
}
|
|
|
|
#define OPT_WRITE_CHAR_P(n) \
|
2012-03-02 09:19:20 +08:00
|
|
|
if ((err = je_mallctl("opt."#n, &cpv, &cpsz, NULL, 0)) \
|
|
|
|
== 0) { \
|
2012-03-07 06:57:45 +08:00
|
|
|
malloc_cprintf(write_cb, cbopaque, \
|
|
|
|
" opt."#n": \"%s\"\n", cpv); \
|
2010-10-24 09:37:06 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
write_cb(cbopaque, "Run-time option settings:\n");
|
|
|
|
OPT_WRITE_BOOL(abort)
|
|
|
|
OPT_WRITE_SIZE_T(lg_chunk)
|
|
|
|
OPT_WRITE_SIZE_T(narenas)
|
|
|
|
OPT_WRITE_SSIZE_T(lg_dirty_mult)
|
|
|
|
OPT_WRITE_BOOL(stats_print)
|
|
|
|
OPT_WRITE_BOOL(junk)
|
|
|
|
OPT_WRITE_BOOL(zero)
|
|
|
|
OPT_WRITE_BOOL(xmalloc)
|
|
|
|
OPT_WRITE_BOOL(tcache)
|
|
|
|
OPT_WRITE_SSIZE_T(lg_tcache_max)
|
|
|
|
OPT_WRITE_BOOL(prof)
|
|
|
|
OPT_WRITE_CHAR_P(prof_prefix)
|
|
|
|
OPT_WRITE_BOOL(prof_active)
|
|
|
|
OPT_WRITE_SSIZE_T(lg_prof_sample)
|
|
|
|
OPT_WRITE_BOOL(prof_accum)
|
|
|
|
OPT_WRITE_SSIZE_T(lg_prof_interval)
|
|
|
|
OPT_WRITE_BOOL(prof_gdump)
|
|
|
|
OPT_WRITE_BOOL(prof_leak)
|
|
|
|
|
|
|
|
#undef OPT_WRITE_BOOL
|
|
|
|
#undef OPT_WRITE_SIZE_T
|
|
|
|
#undef OPT_WRITE_SSIZE_T
|
|
|
|
#undef OPT_WRITE_CHAR_P
|
2010-01-17 01:53:50 +08:00
|
|
|
|
2012-03-07 06:57:45 +08:00
|
|
|
malloc_cprintf(write_cb, cbopaque, "CPUs: %u\n", ncpus);
|
2010-01-28 05:10:55 +08:00
|
|
|
|
|
|
|
CTL_GET("arenas.narenas", &uv, unsigned);
|
2012-03-07 06:57:45 +08:00
|
|
|
malloc_cprintf(write_cb, cbopaque, "Max arenas: %u\n", uv);
|
2010-01-28 05:10:55 +08:00
|
|
|
|
2012-03-07 06:57:45 +08:00
|
|
|
malloc_cprintf(write_cb, cbopaque, "Pointer size: %zu\n",
|
|
|
|
sizeof(void *));
|
2010-01-28 05:10:55 +08:00
|
|
|
|
|
|
|
CTL_GET("arenas.quantum", &sv, size_t);
|
2012-03-07 06:57:45 +08:00
|
|
|
malloc_cprintf(write_cb, cbopaque, "Quantum size: %zu\n", sv);
|
2010-01-28 05:10:55 +08:00
|
|
|
|
|
|
|
CTL_GET("opt.lg_dirty_mult", &ssv, ssize_t);
|
|
|
|
if (ssv >= 0) {
|
2012-03-07 06:57:45 +08:00
|
|
|
malloc_cprintf(write_cb, cbopaque,
|
|
|
|
"Min active:dirty page ratio per arena: %u:1\n",
|
|
|
|
(1U << ssv));
|
2010-01-17 01:53:50 +08:00
|
|
|
} else {
|
2010-03-04 09:45:38 +08:00
|
|
|
write_cb(cbopaque,
|
|
|
|
"Min active:dirty page ratio per arena: N/A\n");
|
2010-01-17 01:53:50 +08:00
|
|
|
}
|
2012-03-02 09:19:20 +08:00
|
|
|
if ((err = je_mallctl("arenas.tcache_max", &sv, &ssz, NULL, 0))
|
|
|
|
== 0) {
|
2012-03-07 06:57:45 +08:00
|
|
|
malloc_cprintf(write_cb, cbopaque,
|
|
|
|
"Maximum thread-cached size class: %zu\n", sv);
|
2010-03-18 07:27:39 +08:00
|
|
|
}
|
2012-03-02 09:19:20 +08:00
|
|
|
if ((err = je_mallctl("opt.prof", &bv, &bsz, NULL, 0)) == 0 &&
|
|
|
|
bv) {
|
2010-03-15 10:55:32 +08:00
|
|
|
CTL_GET("opt.lg_prof_sample", &sv, size_t);
|
2012-03-07 06:57:45 +08:00
|
|
|
malloc_cprintf(write_cb, cbopaque,
|
|
|
|
"Average profile sample interval: %"PRIu64
|
|
|
|
" (2^%zu)\n", (((uint64_t)1U) << sv), sv);
|
2010-03-02 12:15:26 +08:00
|
|
|
|
2010-04-01 08:35:51 +08:00
|
|
|
CTL_GET("opt.lg_prof_interval", &ssv, ssize_t);
|
|
|
|
if (ssv >= 0) {
|
2012-03-07 06:57:45 +08:00
|
|
|
malloc_cprintf(write_cb, cbopaque,
|
|
|
|
"Average profile dump interval: %"PRIu64
|
|
|
|
" (2^%zd)\n",
|
|
|
|
(((uint64_t)1U) << ssv), ssv);
|
|
|
|
} else {
|
|
|
|
write_cb(cbopaque,
|
|
|
|
"Average profile dump interval: N/A\n");
|
|
|
|
}
|
2010-02-12 05:19:21 +08:00
|
|
|
}
|
2010-01-28 05:10:55 +08:00
|
|
|
CTL_GET("opt.lg_chunk", &sv, size_t);
|
2012-03-07 06:57:45 +08:00
|
|
|
malloc_cprintf(write_cb, cbopaque, "Chunk size: %zu (2^%zu)\n",
|
|
|
|
(ZU(1) << sv), sv);
|
2010-01-17 01:53:50 +08:00
|
|
|
}
|
|
|
|
|
2012-02-11 12:22:09 +08:00
|
|
|
if (config_stats) {
|
2011-03-19 08:56:14 +08:00
|
|
|
size_t *cactive;
|
2010-01-30 03:24:19 +08:00
|
|
|
size_t allocated, active, mapped;
|
2012-02-14 02:56:17 +08:00
|
|
|
size_t chunks_current, chunks_high;
|
2010-01-28 05:10:55 +08:00
|
|
|
uint64_t chunks_total;
|
|
|
|
size_t huge_allocated;
|
|
|
|
uint64_t huge_nmalloc, huge_ndalloc;
|
2010-01-17 01:53:50 +08:00
|
|
|
|
2011-03-19 08:56:14 +08:00
|
|
|
CTL_GET("stats.cactive", &cactive, size_t *);
|
2010-01-28 05:10:55 +08:00
|
|
|
CTL_GET("stats.allocated", &allocated, size_t);
|
2010-01-30 03:24:19 +08:00
|
|
|
CTL_GET("stats.active", &active, size_t);
|
2010-01-28 05:10:55 +08:00
|
|
|
CTL_GET("stats.mapped", &mapped, size_t);
|
2010-03-04 09:45:38 +08:00
|
|
|
malloc_cprintf(write_cb, cbopaque,
|
2011-03-19 08:56:14 +08:00
|
|
|
"Allocated: %zu, active: %zu, mapped: %zu\n",
|
|
|
|
allocated, active, mapped);
|
|
|
|
malloc_cprintf(write_cb, cbopaque,
|
|
|
|
"Current active ceiling: %zu\n", atomic_read_z(cactive));
|
2010-01-17 01:53:50 +08:00
|
|
|
|
|
|
|
/* Print chunk stats. */
|
2010-01-28 05:10:55 +08:00
|
|
|
CTL_GET("stats.chunks.total", &chunks_total, uint64_t);
|
|
|
|
CTL_GET("stats.chunks.high", &chunks_high, size_t);
|
|
|
|
CTL_GET("stats.chunks.current", &chunks_current, size_t);
|
2012-02-14 02:56:17 +08:00
|
|
|
malloc_cprintf(write_cb, cbopaque, "chunks: nchunks "
|
|
|
|
"highchunks curchunks\n");
|
|
|
|
malloc_cprintf(write_cb, cbopaque, " %13"PRIu64"%13zu%13zu\n",
|
|
|
|
chunks_total, chunks_high, chunks_current);
|
2010-01-17 01:53:50 +08:00
|
|
|
|
2010-01-28 05:10:55 +08:00
|
|
|
/* Print huge stats. */
|
|
|
|
CTL_GET("stats.huge.nmalloc", &huge_nmalloc, uint64_t);
|
|
|
|
CTL_GET("stats.huge.ndalloc", &huge_ndalloc, uint64_t);
|
|
|
|
CTL_GET("stats.huge.allocated", &huge_allocated, size_t);
|
2010-03-04 09:45:38 +08:00
|
|
|
malloc_cprintf(write_cb, cbopaque,
|
2010-01-17 01:53:50 +08:00
|
|
|
"huge: nmalloc ndalloc allocated\n");
|
2010-03-04 09:45:38 +08:00
|
|
|
malloc_cprintf(write_cb, cbopaque,
|
2010-01-25 08:41:01 +08:00
|
|
|
" %12"PRIu64" %12"PRIu64" %12zu\n",
|
2010-01-20 04:11:25 +08:00
|
|
|
huge_nmalloc, huge_ndalloc, huge_allocated);
|
2010-01-17 01:53:50 +08:00
|
|
|
|
2010-01-18 09:35:19 +08:00
|
|
|
if (merged) {
|
2010-01-28 05:10:55 +08:00
|
|
|
unsigned narenas;
|
|
|
|
|
|
|
|
CTL_GET("arenas.narenas", &narenas, unsigned);
|
|
|
|
{
|
|
|
|
bool initialized[narenas];
|
|
|
|
size_t isz;
|
|
|
|
unsigned i, ninitialized;
|
|
|
|
|
|
|
|
isz = sizeof(initialized);
|
|
|
|
xmallctl("arenas.initialized", initialized,
|
|
|
|
&isz, NULL, 0);
|
|
|
|
for (i = ninitialized = 0; i < narenas; i++) {
|
|
|
|
if (initialized[i])
|
|
|
|
ninitialized++;
|
2010-01-18 09:35:19 +08:00
|
|
|
}
|
2010-01-25 09:21:47 +08:00
|
|
|
|
2011-11-12 06:46:04 +08:00
|
|
|
if (ninitialized > 1 || unmerged == false) {
|
2010-01-28 05:10:55 +08:00
|
|
|
/* Print merged arena stats. */
|
2010-03-04 09:45:38 +08:00
|
|
|
malloc_cprintf(write_cb, cbopaque,
|
2010-01-31 19:57:29 +08:00
|
|
|
"\nMerged arenas stats:\n");
|
2010-03-04 09:45:38 +08:00
|
|
|
stats_arena_print(write_cb, cbopaque,
|
2012-03-13 23:46:12 +08:00
|
|
|
narenas, bins, large);
|
2010-01-28 05:10:55 +08:00
|
|
|
}
|
2010-01-25 09:21:47 +08:00
|
|
|
}
|
2010-01-18 09:35:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (unmerged) {
|
2010-01-28 05:10:55 +08:00
|
|
|
unsigned narenas;
|
|
|
|
|
2010-01-18 09:35:19 +08:00
|
|
|
/* Print stats for each arena. */
|
2010-01-28 05:10:55 +08:00
|
|
|
|
|
|
|
CTL_GET("arenas.narenas", &narenas, unsigned);
|
|
|
|
{
|
|
|
|
bool initialized[narenas];
|
|
|
|
size_t isz;
|
|
|
|
unsigned i;
|
|
|
|
|
|
|
|
isz = sizeof(initialized);
|
|
|
|
xmallctl("arenas.initialized", initialized,
|
|
|
|
&isz, NULL, 0);
|
|
|
|
|
|
|
|
for (i = 0; i < narenas; i++) {
|
|
|
|
if (initialized[i]) {
|
2010-03-18 07:27:39 +08:00
|
|
|
malloc_cprintf(write_cb,
|
|
|
|
cbopaque,
|
2010-01-28 05:10:55 +08:00
|
|
|
"\narenas[%u]:\n", i);
|
2010-03-04 09:45:38 +08:00
|
|
|
stats_arena_print(write_cb,
|
2012-03-13 23:46:12 +08:00
|
|
|
cbopaque, i, bins, large);
|
2010-01-28 05:10:55 +08:00
|
|
|
}
|
2010-01-18 09:35:19 +08:00
|
|
|
}
|
2010-01-17 01:53:50 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-03-04 09:45:38 +08:00
|
|
|
write_cb(cbopaque, "--- End jemalloc statistics ---\n");
|
2010-01-17 01:53:50 +08:00
|
|
|
}
|