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)
|
|
|
|
|
2015-03-21 09:08:10 +08:00
|
|
|
#define CTL_M2_GET(n, i, v, t) do { \
|
2010-01-28 05:10:55 +08:00
|
|
|
size_t mib[6]; \
|
|
|
|
size_t miblen = sizeof(mib) / sizeof(size_t); \
|
|
|
|
size_t sz = sizeof(t); \
|
|
|
|
xmallctlnametomib(n, mib, &miblen); \
|
2015-03-21 09:08:10 +08:00
|
|
|
mib[2] = (i); \
|
2010-01-28 05:10:55 +08:00
|
|
|
xmallctlbymib(mib, miblen, v, &sz, NULL, 0); \
|
|
|
|
} while (0)
|
|
|
|
|
2015-03-21 09:08:10 +08:00
|
|
|
#define CTL_M2_M4_GET(n, i, j, v, t) do { \
|
2010-01-28 05:10:55 +08:00
|
|
|
size_t mib[6]; \
|
|
|
|
size_t miblen = sizeof(mib) / sizeof(size_t); \
|
|
|
|
size_t sz = sizeof(t); \
|
|
|
|
xmallctlnametomib(n, mib, &miblen); \
|
2015-03-21 09:08:10 +08:00
|
|
|
mib[2] = (i); \
|
|
|
|
mib[4] = (j); \
|
2010-01-28 05:10:55 +08:00
|
|
|
xmallctlbymib(mib, miblen, v, &sz, NULL, 0); \
|
|
|
|
} while (0)
|
|
|
|
|
2010-01-17 01:53:50 +08:00
|
|
|
/******************************************************************************/
|
|
|
|
/* Data. */
|
|
|
|
|
|
|
|
bool opt_stats_print = false;
|
|
|
|
|
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);
|
2016-06-01 05:50:21 +08:00
|
|
|
static void stats_arena_lextents_print(
|
2014-10-13 13:53:59 +08:00
|
|
|
void (*write_cb)(void *, const char *), void *cbopaque, unsigned i);
|
2010-03-04 09:45:38 +08:00
|
|
|
static void stats_arena_print(void (*write_cb)(void *, const char *),
|
2016-06-01 05:50:21 +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
|
|
|
{
|
2012-04-02 22:15:42 +08:00
|
|
|
size_t page;
|
2014-10-13 13:53:59 +08:00
|
|
|
bool config_tcache, in_gap;
|
|
|
|
unsigned nbins, j;
|
2010-01-28 05:10:55 +08:00
|
|
|
|
2012-04-02 22:15:42 +08:00
|
|
|
CTL_GET("arenas.page", &page, size_t);
|
2010-01-28 05:10:55 +08:00
|
|
|
|
|
|
|
CTL_GET("config.tcache", &config_tcache, bool);
|
|
|
|
if (config_tcache) {
|
2010-03-04 09:45:38 +08:00
|
|
|
malloc_cprintf(write_cb, cbopaque,
|
2014-10-13 13:53:59 +08:00
|
|
|
"bins: size ind allocated nmalloc"
|
2016-05-30 09:34:50 +08:00
|
|
|
" ndalloc nrequests curregs curslabs regs"
|
|
|
|
" pgs util nfills nflushes newslabs"
|
|
|
|
" reslabs\n");
|
2010-01-28 05:10:55 +08:00
|
|
|
} else {
|
2010-03-04 09:45:38 +08:00
|
|
|
malloc_cprintf(write_cb, cbopaque,
|
2014-10-13 13:53:59 +08:00
|
|
|
"bins: size ind allocated nmalloc"
|
2016-05-30 09:34:50 +08:00
|
|
|
" ndalloc nrequests curregs curslabs regs"
|
|
|
|
" pgs util newslabs reslabs\n");
|
2010-01-28 05:10:55 +08:00
|
|
|
}
|
|
|
|
CTL_GET("arenas.nbins", &nbins, unsigned);
|
2014-10-13 13:53:59 +08:00
|
|
|
for (j = 0, in_gap = false; j < nbins; j++) {
|
2016-05-30 09:34:50 +08:00
|
|
|
uint64_t nslabs;
|
2010-01-28 05:10:55 +08:00
|
|
|
|
2016-05-30 09:34:50 +08:00
|
|
|
CTL_M2_M4_GET("stats.arenas.0.bins.0.nslabs", i, j, &nslabs,
|
2015-03-21 09:08:10 +08:00
|
|
|
uint64_t);
|
2016-05-30 09:34:50 +08:00
|
|
|
if (nslabs == 0)
|
2014-10-13 13:53:59 +08:00
|
|
|
in_gap = true;
|
|
|
|
else {
|
2016-05-30 09:34:50 +08:00
|
|
|
size_t reg_size, slab_size, curregs, availregs, milli;
|
|
|
|
size_t curslabs;
|
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;
|
2016-05-30 09:34:50 +08:00
|
|
|
uint64_t reslabs;
|
2014-10-16 07:18:42 +08:00
|
|
|
char util[6]; /* "x.yyy". */
|
2010-01-28 05:10:55 +08:00
|
|
|
|
2014-10-13 13:53:59 +08:00
|
|
|
if (in_gap) {
|
|
|
|
malloc_cprintf(write_cb, cbopaque,
|
|
|
|
" ---\n");
|
|
|
|
in_gap = false;
|
2010-01-28 05:10:55 +08:00
|
|
|
}
|
2015-03-21 09:08:10 +08:00
|
|
|
CTL_M2_GET("arenas.bin.0.size", j, ®_size, size_t);
|
|
|
|
CTL_M2_GET("arenas.bin.0.nregs", j, &nregs, uint32_t);
|
2016-05-30 09:34:50 +08:00
|
|
|
CTL_M2_GET("arenas.bin.0.slab_size", j, &slab_size,
|
2015-03-21 09:08:10 +08:00
|
|
|
size_t);
|
|
|
|
CTL_M2_M4_GET("stats.arenas.0.bins.0.nmalloc", i, j,
|
2010-03-14 12:32:56 +08:00
|
|
|
&nmalloc, uint64_t);
|
2015-03-21 09:08:10 +08:00
|
|
|
CTL_M2_M4_GET("stats.arenas.0.bins.0.ndalloc", i, j,
|
2010-03-14 12:32:56 +08:00
|
|
|
&ndalloc, uint64_t);
|
2015-03-21 09:08:10 +08:00
|
|
|
CTL_M2_M4_GET("stats.arenas.0.bins.0.curregs", i, j,
|
2014-10-13 13:53:59 +08:00
|
|
|
&curregs, size_t);
|
2015-03-21 09:08:10 +08:00
|
|
|
CTL_M2_M4_GET("stats.arenas.0.bins.0.nrequests", i, j,
|
2014-10-13 13:53:59 +08:00
|
|
|
&nrequests, uint64_t);
|
2010-01-28 05:10:55 +08:00
|
|
|
if (config_tcache) {
|
2015-03-21 09:08:10 +08:00
|
|
|
CTL_M2_M4_GET("stats.arenas.0.bins.0.nfills", i,
|
|
|
|
j, &nfills, uint64_t);
|
|
|
|
CTL_M2_M4_GET("stats.arenas.0.bins.0.nflushes",
|
|
|
|
i, j, &nflushes, uint64_t);
|
2010-01-28 05:10:55 +08:00
|
|
|
}
|
2016-05-30 09:34:50 +08:00
|
|
|
CTL_M2_M4_GET("stats.arenas.0.bins.0.nreslabs", i, j,
|
|
|
|
&reslabs, uint64_t);
|
|
|
|
CTL_M2_M4_GET("stats.arenas.0.bins.0.curslabs", i, j,
|
|
|
|
&curslabs, size_t);
|
2014-10-16 07:18:42 +08:00
|
|
|
|
2016-05-30 09:34:50 +08:00
|
|
|
availregs = nregs * curslabs;
|
2014-10-16 07:18:42 +08:00
|
|
|
milli = (availregs != 0) ? (1000 * curregs) / availregs
|
|
|
|
: 1000;
|
|
|
|
assert(milli <= 1000);
|
|
|
|
if (milli < 10) {
|
2015-07-08 04:12:05 +08:00
|
|
|
malloc_snprintf(util, sizeof(util),
|
2015-07-24 04:56:25 +08:00
|
|
|
"0.00%zu", milli);
|
2014-10-16 07:18:42 +08:00
|
|
|
} else if (milli < 100) {
|
2015-07-24 04:56:25 +08:00
|
|
|
malloc_snprintf(util, sizeof(util), "0.0%zu",
|
2014-10-16 07:18:42 +08:00
|
|
|
milli);
|
|
|
|
} else if (milli < 1000) {
|
2015-07-24 04:56:25 +08:00
|
|
|
malloc_snprintf(util, sizeof(util), "0.%zu",
|
2014-10-16 07:18:42 +08:00
|
|
|
milli);
|
|
|
|
} else
|
|
|
|
malloc_snprintf(util, sizeof(util), "1");
|
|
|
|
|
2010-01-28 05:10:55 +08:00
|
|
|
if (config_tcache) {
|
2010-03-04 09:45:38 +08:00
|
|
|
malloc_cprintf(write_cb, cbopaque,
|
2015-07-24 04:56:25 +08:00
|
|
|
"%20zu %3u %12zu %12"FMTu64
|
|
|
|
" %12"FMTu64" %12"FMTu64" %12zu"
|
|
|
|
" %12zu %4u %3zu %-5s %12"FMTu64
|
|
|
|
" %12"FMTu64" %12"FMTu64" %12"FMTu64"\n",
|
2014-10-13 13:53:59 +08:00
|
|
|
reg_size, j, curregs * reg_size, nmalloc,
|
2016-05-30 09:34:50 +08:00
|
|
|
ndalloc, nrequests, curregs, curslabs,
|
|
|
|
nregs, slab_size / page, util, nfills,
|
|
|
|
nflushes, nslabs, reslabs);
|
2010-01-28 05:10:55 +08:00
|
|
|
} else {
|
2010-03-04 09:45:38 +08:00
|
|
|
malloc_cprintf(write_cb, cbopaque,
|
2015-07-24 04:56:25 +08:00
|
|
|
"%20zu %3u %12zu %12"FMTu64
|
|
|
|
" %12"FMTu64" %12"FMTu64" %12zu"
|
|
|
|
" %12zu %4u %3zu %-5s %12"FMTu64
|
|
|
|
" %12"FMTu64"\n",
|
2014-10-13 13:53:59 +08:00
|
|
|
reg_size, j, curregs * reg_size, nmalloc,
|
2016-05-30 09:34:50 +08:00
|
|
|
ndalloc, nrequests, curregs, curslabs,
|
|
|
|
nregs, slab_size / page, util, nslabs,
|
|
|
|
reslabs);
|
2010-01-28 05:10:55 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-10-13 13:53:59 +08:00
|
|
|
if (in_gap) {
|
|
|
|
malloc_cprintf(write_cb, cbopaque,
|
|
|
|
" ---\n");
|
2010-01-28 05:10:55 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-13 13:53:59 +08:00
|
|
|
static void
|
2016-06-01 05:50:21 +08:00
|
|
|
stats_arena_lextents_print(void (*write_cb)(void *, const char *),
|
2014-10-13 13:53:59 +08:00
|
|
|
void *cbopaque, unsigned i)
|
|
|
|
{
|
2016-06-01 05:50:21 +08:00
|
|
|
unsigned nbins, nlextents, j;
|
2014-10-13 13:53:59 +08:00
|
|
|
bool in_gap;
|
|
|
|
|
|
|
|
malloc_cprintf(write_cb, cbopaque,
|
2016-06-01 05:50:21 +08:00
|
|
|
"large: size ind allocated nmalloc ndalloc"
|
|
|
|
" nrequests curlextents\n");
|
2014-10-13 13:53:59 +08:00
|
|
|
CTL_GET("arenas.nbins", &nbins, unsigned);
|
2016-06-01 05:50:21 +08:00
|
|
|
CTL_GET("arenas.nlextents", &nlextents, unsigned);
|
|
|
|
for (j = 0, in_gap = false; j < nlextents; j++) {
|
2014-10-13 13:53:59 +08:00
|
|
|
uint64_t nmalloc, ndalloc, nrequests;
|
2016-06-01 05:50:21 +08:00
|
|
|
size_t lextent_size, curlextents;
|
2014-10-13 13:53:59 +08:00
|
|
|
|
2016-06-01 05:50:21 +08:00
|
|
|
CTL_M2_M4_GET("stats.arenas.0.lextents.0.nmalloc", i, j,
|
2015-03-21 09:08:10 +08:00
|
|
|
&nmalloc, uint64_t);
|
2016-06-01 05:50:21 +08:00
|
|
|
CTL_M2_M4_GET("stats.arenas.0.lextents.0.ndalloc", i, j,
|
2015-03-21 09:08:10 +08:00
|
|
|
&ndalloc, uint64_t);
|
2016-06-01 05:50:21 +08:00
|
|
|
CTL_M2_M4_GET("stats.arenas.0.lextents.0.nrequests", i, j,
|
2015-03-21 09:08:10 +08:00
|
|
|
&nrequests, uint64_t);
|
2014-10-13 13:53:59 +08:00
|
|
|
if (nrequests == 0)
|
|
|
|
in_gap = true;
|
|
|
|
else {
|
2016-06-01 05:50:21 +08:00
|
|
|
CTL_M2_GET("arenas.lextent.0.size", j, &lextent_size,
|
2014-10-13 13:53:59 +08:00
|
|
|
size_t);
|
2016-06-01 05:50:21 +08:00
|
|
|
CTL_M2_M4_GET("stats.arenas.0.lextents.0.curlextents",
|
|
|
|
i, j, &curlextents, size_t);
|
2014-10-13 13:53:59 +08:00
|
|
|
if (in_gap) {
|
|
|
|
malloc_cprintf(write_cb, cbopaque,
|
|
|
|
" ---\n");
|
|
|
|
in_gap = false;
|
2010-01-28 05:10:55 +08:00
|
|
|
}
|
2010-03-04 09:45:38 +08:00
|
|
|
malloc_cprintf(write_cb, cbopaque,
|
2015-07-24 04:56:25 +08:00
|
|
|
"%20zu %3u %12zu %12"FMTu64" %12"FMTu64
|
|
|
|
" %12"FMTu64" %12zu\n",
|
2016-06-01 05:50:21 +08:00
|
|
|
lextent_size, nbins + j,
|
|
|
|
curlextents * lextent_size, nmalloc, ndalloc,
|
|
|
|
nrequests, curlextents);
|
2010-01-28 05:10:55 +08:00
|
|
|
}
|
|
|
|
}
|
2014-10-13 13:53:59 +08:00
|
|
|
if (in_gap) {
|
|
|
|
malloc_cprintf(write_cb, cbopaque,
|
|
|
|
" ---\n");
|
|
|
|
}
|
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,
|
2016-06-01 05:50:21 +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;
|
2012-10-12 04:53:15 +08:00
|
|
|
const char *dss;
|
2016-10-13 01:40:27 +08:00
|
|
|
ssize_t decay_time;
|
2016-06-02 04:40:48 +08:00
|
|
|
size_t page, pactive, pdirty, mapped, retained, metadata;
|
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;
|
2016-06-01 05:50:21 +08:00
|
|
|
size_t large_allocated;
|
|
|
|
uint64_t large_nmalloc, large_ndalloc, large_nrequests;
|
2010-01-28 05:10:55 +08:00
|
|
|
|
2012-04-02 22:15:42 +08:00
|
|
|
CTL_GET("arenas.page", &page, size_t);
|
2010-01-30 03:24:19 +08:00
|
|
|
|
2015-03-21 09:08:10 +08:00
|
|
|
CTL_M2_GET("stats.arenas.0.nthreads", i, &nthreads, unsigned);
|
2011-03-19 04:41:33 +08:00
|
|
|
malloc_cprintf(write_cb, cbopaque,
|
|
|
|
"assigned threads: %u\n", nthreads);
|
2015-03-21 09:08:10 +08:00
|
|
|
CTL_M2_GET("stats.arenas.0.dss", i, &dss, const char *);
|
2012-10-12 04:53:15 +08:00
|
|
|
malloc_cprintf(write_cb, cbopaque, "dss allocation precedence: %s\n",
|
|
|
|
dss);
|
2016-02-20 12:09:31 +08:00
|
|
|
CTL_M2_GET("stats.arenas.0.decay_time", i, &decay_time, ssize_t);
|
2016-10-13 01:40:27 +08:00
|
|
|
if (decay_time >= 0) {
|
|
|
|
malloc_cprintf(write_cb, cbopaque, "decay time: %zd\n",
|
|
|
|
decay_time);
|
|
|
|
} else
|
|
|
|
malloc_cprintf(write_cb, cbopaque, "decay time: N/A\n");
|
2015-03-21 09:08:10 +08:00
|
|
|
CTL_M2_GET("stats.arenas.0.pactive", i, &pactive, size_t);
|
|
|
|
CTL_M2_GET("stats.arenas.0.pdirty", i, &pdirty, size_t);
|
|
|
|
CTL_M2_GET("stats.arenas.0.npurge", i, &npurge, uint64_t);
|
|
|
|
CTL_M2_GET("stats.arenas.0.nmadvise", i, &nmadvise, uint64_t);
|
|
|
|
CTL_M2_GET("stats.arenas.0.purged", i, &purged, uint64_t);
|
2010-03-04 09:45:38 +08:00
|
|
|
malloc_cprintf(write_cb, cbopaque,
|
2016-02-20 12:09:31 +08:00
|
|
|
"purging: dirty: %zu, sweeps: %"FMTu64", madvises: %"FMTu64", "
|
|
|
|
"purged: %"FMTu64"\n", pdirty, npurge, nmadvise, purged);
|
2010-01-28 05:10:55 +08:00
|
|
|
|
2010-03-04 09:45:38 +08:00
|
|
|
malloc_cprintf(write_cb, cbopaque,
|
2014-10-13 13:53:59 +08:00
|
|
|
" allocated nmalloc ndalloc"
|
|
|
|
" nrequests\n");
|
2015-03-21 09:08:10 +08:00
|
|
|
CTL_M2_GET("stats.arenas.0.small.allocated", i, &small_allocated,
|
|
|
|
size_t);
|
|
|
|
CTL_M2_GET("stats.arenas.0.small.nmalloc", i, &small_nmalloc, uint64_t);
|
|
|
|
CTL_M2_GET("stats.arenas.0.small.ndalloc", i, &small_ndalloc, uint64_t);
|
|
|
|
CTL_M2_GET("stats.arenas.0.small.nrequests", i, &small_nrequests,
|
|
|
|
uint64_t);
|
2010-03-04 09:45:38 +08:00
|
|
|
malloc_cprintf(write_cb, cbopaque,
|
2015-07-24 04:56:25 +08:00
|
|
|
"small: %12zu %12"FMTu64" %12"FMTu64
|
|
|
|
" %12"FMTu64"\n",
|
2010-03-14 12:32:56 +08:00
|
|
|
small_allocated, small_nmalloc, small_ndalloc, small_nrequests);
|
2016-06-01 05:50:21 +08:00
|
|
|
CTL_M2_GET("stats.arenas.0.large.allocated", i, &large_allocated,
|
|
|
|
size_t);
|
|
|
|
CTL_M2_GET("stats.arenas.0.large.nmalloc", i, &large_nmalloc, uint64_t);
|
|
|
|
CTL_M2_GET("stats.arenas.0.large.ndalloc", i, &large_ndalloc, uint64_t);
|
|
|
|
CTL_M2_GET("stats.arenas.0.large.nrequests", i, &large_nrequests,
|
2015-03-21 09:08:10 +08:00
|
|
|
uint64_t);
|
2014-05-16 13:22:27 +08:00
|
|
|
malloc_cprintf(write_cb, cbopaque,
|
2016-06-01 05:50:21 +08:00
|
|
|
"large: %12zu %12"FMTu64" %12"FMTu64
|
2015-07-24 04:56:25 +08:00
|
|
|
" %12"FMTu64"\n",
|
2016-06-01 05:50:21 +08:00
|
|
|
large_allocated, large_nmalloc, large_ndalloc, large_nrequests);
|
2010-03-04 09:45:38 +08:00
|
|
|
malloc_cprintf(write_cb, cbopaque,
|
2015-07-24 04:56:25 +08:00
|
|
|
"total: %12zu %12"FMTu64" %12"FMTu64
|
|
|
|
" %12"FMTu64"\n",
|
2016-06-01 05:50:21 +08:00
|
|
|
small_allocated + large_allocated, small_nmalloc + large_nmalloc,
|
|
|
|
small_ndalloc + large_ndalloc, small_nrequests + large_nrequests);
|
2015-07-08 04:12:05 +08:00
|
|
|
malloc_cprintf(write_cb, cbopaque,
|
2015-07-24 04:56:25 +08:00
|
|
|
"active: %12zu\n", pactive * page);
|
2015-03-21 09:08:10 +08:00
|
|
|
CTL_M2_GET("stats.arenas.0.mapped", i, &mapped, size_t);
|
2015-07-08 04:12:05 +08:00
|
|
|
malloc_cprintf(write_cb, cbopaque,
|
2015-07-24 04:56:25 +08:00
|
|
|
"mapped: %12zu\n", mapped);
|
2016-05-04 13:11:35 +08:00
|
|
|
CTL_M2_GET("stats.arenas.0.retained", i, &retained, size_t);
|
|
|
|
malloc_cprintf(write_cb, cbopaque,
|
|
|
|
"retained: %12zu\n", retained);
|
2016-06-02 04:40:48 +08:00
|
|
|
CTL_M2_GET("stats.arenas.0.metadata", i, &metadata, size_t);
|
|
|
|
malloc_cprintf(write_cb, cbopaque, "metadata: %12zu\n",
|
|
|
|
metadata);
|
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);
|
2016-06-01 05:50:21 +08:00
|
|
|
if (large)
|
|
|
|
stats_arena_lextents_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;
|
2016-06-01 05:50:21 +08:00
|
|
|
bool large = true;
|
2010-01-17 01:53:50 +08:00
|
|
|
|
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-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':
|
2016-06-01 05:50:21 +08:00
|
|
|
large = false;
|
2014-10-13 13:53:59 +08:00
|
|
|
break;
|
2012-03-07 06:57:45 +08:00
|
|
|
default:;
|
2010-01-17 01:53:50 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-02 19:15:00 +08:00
|
|
|
malloc_cprintf(write_cb, cbopaque,
|
|
|
|
"___ Begin jemalloc statistics ___\n");
|
2010-01-17 01:53:50 +08:00
|
|
|
if (general) {
|
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;
|
2016-02-25 03:03:40 +08:00
|
|
|
size_t sv, bsz, usz, ssz, sssz, cpsz;
|
2010-01-28 05:10:55 +08:00
|
|
|
|
|
|
|
bsz = sizeof(bool);
|
2016-02-25 03:03:40 +08:00
|
|
|
usz = sizeof(unsigned);
|
2010-01-28 05:10:55 +08:00
|
|
|
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");
|
2016-02-08 06:23:22 +08:00
|
|
|
malloc_cprintf(write_cb, cbopaque,
|
|
|
|
"config.malloc_conf: \"%s\"\n", config_malloc_conf);
|
2010-01-28 05:10:55 +08:00
|
|
|
|
2013-12-09 14:28:27 +08:00
|
|
|
#define OPT_WRITE_BOOL(n) \
|
2014-10-04 14:25:30 +08:00
|
|
|
if (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
|
|
|
}
|
2014-10-04 14:25:30 +08:00
|
|
|
#define OPT_WRITE_BOOL_MUTABLE(n, m) { \
|
|
|
|
bool bv2; \
|
|
|
|
if (je_mallctl("opt."#n, &bv, &bsz, NULL, 0) == 0 && \
|
|
|
|
je_mallctl(#m, &bv2, &bsz, NULL, 0) == 0) { \
|
|
|
|
malloc_cprintf(write_cb, cbopaque, \
|
|
|
|
" opt."#n": %s ("#m": %s)\n", bv ? "true" \
|
|
|
|
: "false", bv2 ? "true" : "false"); \
|
|
|
|
} \
|
|
|
|
}
|
2016-02-25 03:03:40 +08:00
|
|
|
#define OPT_WRITE_UNSIGNED(n) \
|
|
|
|
if (je_mallctl("opt."#n, &uv, &usz, NULL, 0) == 0) { \
|
|
|
|
malloc_cprintf(write_cb, cbopaque, \
|
2016-04-12 09:47:18 +08:00
|
|
|
" opt."#n": %u\n", uv); \
|
2016-02-25 03:03:40 +08:00
|
|
|
}
|
2013-12-09 14:28:27 +08:00
|
|
|
#define OPT_WRITE_SIZE_T(n) \
|
2014-10-04 14:25:30 +08:00
|
|
|
if (je_mallctl("opt."#n, &sv, &ssz, NULL, 0) == 0) { \
|
2012-03-07 06:57:45 +08:00
|
|
|
malloc_cprintf(write_cb, cbopaque, \
|
2015-07-24 04:56:25 +08:00
|
|
|
" opt."#n": %zu\n", sv); \
|
2010-10-24 09:37:06 +08:00
|
|
|
}
|
2013-12-09 14:28:27 +08:00
|
|
|
#define OPT_WRITE_SSIZE_T(n) \
|
2014-10-04 14:25:30 +08:00
|
|
|
if (je_mallctl("opt."#n, &ssv, &sssz, NULL, 0) == 0) { \
|
2012-03-07 06:57:45 +08:00
|
|
|
malloc_cprintf(write_cb, cbopaque, \
|
2015-07-24 04:56:25 +08:00
|
|
|
" opt."#n": %zd\n", ssv); \
|
2010-10-24 09:37:06 +08:00
|
|
|
}
|
2015-03-22 01:18:39 +08:00
|
|
|
#define OPT_WRITE_SSIZE_T_MUTABLE(n, m) { \
|
2015-03-21 09:08:10 +08:00
|
|
|
ssize_t ssv2; \
|
|
|
|
if (je_mallctl("opt."#n, &ssv, &sssz, NULL, 0) == 0 && \
|
|
|
|
je_mallctl(#m, &ssv2, &sssz, NULL, 0) == 0) { \
|
|
|
|
malloc_cprintf(write_cb, cbopaque, \
|
2015-07-24 04:56:25 +08:00
|
|
|
" opt."#n": %zd ("#m": %zd)\n", \
|
2015-07-08 04:12:05 +08:00
|
|
|
ssv, ssv2); \
|
2015-03-22 01:18:39 +08:00
|
|
|
} \
|
|
|
|
}
|
2013-12-09 14:28:27 +08:00
|
|
|
#define OPT_WRITE_CHAR_P(n) \
|
2014-10-04 14:25:30 +08:00
|
|
|
if (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
|
|
|
}
|
|
|
|
|
2012-05-02 19:15:00 +08:00
|
|
|
malloc_cprintf(write_cb, cbopaque,
|
|
|
|
"Run-time option settings:\n");
|
2010-10-24 09:37:06 +08:00
|
|
|
OPT_WRITE_BOOL(abort)
|
2012-10-12 04:53:15 +08:00
|
|
|
OPT_WRITE_CHAR_P(dss)
|
2016-02-25 03:03:40 +08:00
|
|
|
OPT_WRITE_UNSIGNED(narenas)
|
2016-02-20 12:09:31 +08:00
|
|
|
OPT_WRITE_CHAR_P(purge)
|
2016-10-13 01:40:27 +08:00
|
|
|
OPT_WRITE_SSIZE_T_MUTABLE(decay_time, arenas.decay_time)
|
2010-10-24 09:37:06 +08:00
|
|
|
OPT_WRITE_BOOL(stats_print)
|
2015-01-23 20:52:13 +08:00
|
|
|
OPT_WRITE_CHAR_P(junk)
|
2010-10-24 09:37:06 +08:00
|
|
|
OPT_WRITE_BOOL(zero)
|
2012-04-06 04:36:17 +08:00
|
|
|
OPT_WRITE_BOOL(utrace)
|
2010-10-24 09:37:06 +08:00
|
|
|
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)
|
2014-10-04 14:25:30 +08:00
|
|
|
OPT_WRITE_BOOL_MUTABLE(prof_active, prof.active)
|
|
|
|
OPT_WRITE_BOOL_MUTABLE(prof_thread_active_init,
|
|
|
|
prof.thread_active_init)
|
2010-10-24 09:37:06 +08:00
|
|
|
OPT_WRITE_SSIZE_T(lg_prof_sample)
|
|
|
|
OPT_WRITE_BOOL(prof_accum)
|
|
|
|
OPT_WRITE_SSIZE_T(lg_prof_interval)
|
|
|
|
OPT_WRITE_BOOL(prof_gdump)
|
2012-04-18 07:39:33 +08:00
|
|
|
OPT_WRITE_BOOL(prof_final)
|
2010-10-24 09:37:06 +08:00
|
|
|
OPT_WRITE_BOOL(prof_leak)
|
|
|
|
|
|
|
|
#undef OPT_WRITE_BOOL
|
2014-10-04 14:25:30 +08:00
|
|
|
#undef OPT_WRITE_BOOL_MUTABLE
|
2010-10-24 09:37:06 +08:00
|
|
|
#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-10-12 04:53:15 +08:00
|
|
|
malloc_cprintf(write_cb, cbopaque, "Arenas: %u\n", uv);
|
2010-01-28 05:10:55 +08:00
|
|
|
|
2015-07-24 04:56:25 +08:00
|
|
|
malloc_cprintf(write_cb, cbopaque, "Pointer size: %zu\n",
|
2012-03-07 06:57:45 +08:00
|
|
|
sizeof(void *));
|
2010-01-28 05:10:55 +08:00
|
|
|
|
|
|
|
CTL_GET("arenas.quantum", &sv, size_t);
|
2015-07-24 04:56:25 +08:00
|
|
|
malloc_cprintf(write_cb, cbopaque, "Quantum size: %zu\n",
|
2015-07-08 04:12:05 +08:00
|
|
|
sv);
|
2010-01-28 05:10:55 +08:00
|
|
|
|
2012-04-02 22:04:34 +08:00
|
|
|
CTL_GET("arenas.page", &sv, size_t);
|
2015-07-24 04:56:25 +08:00
|
|
|
malloc_cprintf(write_cb, cbopaque, "Page size: %zu\n", sv);
|
2012-04-02 22:04:34 +08:00
|
|
|
|
2016-02-20 12:09:31 +08:00
|
|
|
CTL_GET("arenas.decay_time", &ssv, ssize_t);
|
2016-10-13 01:40:27 +08:00
|
|
|
malloc_cprintf(write_cb, cbopaque,
|
|
|
|
"Unused dirty page decay time: %zd%s\n", ssv, (ssv < 0) ?
|
|
|
|
" (no decay)" : "");
|
2014-10-04 14:25:30 +08:00
|
|
|
if (je_mallctl("arenas.tcache_max", &sv, &ssz, NULL, 0) == 0) {
|
2012-03-07 06:57:45 +08:00
|
|
|
malloc_cprintf(write_cb, cbopaque,
|
2015-07-24 04:56:25 +08:00
|
|
|
"Maximum thread-cached size class: %zu\n", sv);
|
2010-03-18 07:27:39 +08:00
|
|
|
}
|
2014-10-04 14:25:30 +08:00
|
|
|
if (je_mallctl("opt.prof", &bv, &bsz, NULL, 0) == 0 && bv) {
|
2014-08-19 07:22:13 +08:00
|
|
|
CTL_GET("prof.lg_sample", &sv, size_t);
|
2012-03-07 06:57:45 +08:00
|
|
|
malloc_cprintf(write_cb, cbopaque,
|
2015-07-24 04:56:25 +08:00
|
|
|
"Average profile sample interval: %"FMTu64
|
|
|
|
" (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,
|
2015-07-24 04:56:25 +08:00
|
|
|
"Average profile dump interval: %"FMTu64
|
|
|
|
" (2^%zd)\n",
|
2012-03-07 06:57:45 +08:00
|
|
|
(((uint64_t)1U) << ssv), ssv);
|
|
|
|
} else {
|
2012-05-02 19:15:00 +08:00
|
|
|
malloc_cprintf(write_cb, cbopaque,
|
2012-03-07 06:57:45 +08:00
|
|
|
"Average profile dump interval: N/A\n");
|
|
|
|
}
|
2010-02-12 05:19:21 +08:00
|
|
|
}
|
2010-01-17 01:53:50 +08:00
|
|
|
}
|
|
|
|
|
2012-02-11 12:22:09 +08:00
|
|
|
if (config_stats) {
|
2016-05-04 13:11:35 +08:00
|
|
|
size_t allocated, active, metadata, resident, mapped, retained;
|
2010-01-17 01:53:50 +08:00
|
|
|
|
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);
|
2014-11-28 03:22:36 +08:00
|
|
|
CTL_GET("stats.metadata", &metadata, size_t);
|
2015-03-24 08:25:57 +08:00
|
|
|
CTL_GET("stats.resident", &resident, size_t);
|
2010-01-28 05:10:55 +08:00
|
|
|
CTL_GET("stats.mapped", &mapped, size_t);
|
2016-05-04 13:11:35 +08:00
|
|
|
CTL_GET("stats.retained", &retained, size_t);
|
2010-03-04 09:45:38 +08:00
|
|
|
malloc_cprintf(write_cb, cbopaque,
|
2015-07-24 04:56:25 +08:00
|
|
|
"Allocated: %zu, active: %zu, metadata: %zu,"
|
2016-05-04 13:11:35 +08:00
|
|
|
" resident: %zu, mapped: %zu, retained: %zu\n",
|
|
|
|
allocated, active, metadata, resident, mapped, retained);
|
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);
|
|
|
|
{
|
2012-04-25 05:22:02 +08:00
|
|
|
VARIABLE_ARRAY(bool, initialized, narenas);
|
2010-01-28 05:10:55 +08:00
|
|
|
size_t isz;
|
|
|
|
unsigned i, ninitialized;
|
|
|
|
|
2012-05-03 03:30:53 +08:00
|
|
|
isz = sizeof(bool) * narenas;
|
2010-01-28 05:10:55 +08:00
|
|
|
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
|
|
|
|
2014-10-04 01:16:09 +08:00
|
|
|
if (ninitialized > 1 || !unmerged) {
|
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,
|
2016-06-01 05:50:21 +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);
|
|
|
|
{
|
2012-04-25 05:22:02 +08:00
|
|
|
VARIABLE_ARRAY(bool, initialized, narenas);
|
2010-01-28 05:10:55 +08:00
|
|
|
size_t isz;
|
|
|
|
unsigned i;
|
|
|
|
|
2012-05-03 03:30:53 +08:00
|
|
|
isz = sizeof(bool) * narenas;
|
2010-01-28 05:10:55 +08:00
|
|
|
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,
|
2016-06-01 05:50:21 +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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-05-02 19:15:00 +08:00
|
|
|
malloc_cprintf(write_cb, cbopaque, "--- End jemalloc statistics ---\n");
|
2010-01-17 01:53:50 +08:00
|
|
|
}
|