Added stats about number of bytes cached in tcache currently.

This commit is contained in:
Qi Wang 2016-04-22 18:37:44 -07:00 committed by Qi Wang
parent 12ab4383e9
commit 58424e679d
4 changed files with 40 additions and 0 deletions

View File

@ -100,6 +100,9 @@ struct arena_stats_s {
uint64_t ndalloc_large;
uint64_t nrequests_large;
/* Number of bytes cached in tcache associated with this arena. */
size_t tcache_bytes;
/* One element for each large size class. */
malloc_large_stats_t lstats[NSIZES - NBINS];
};

View File

@ -1625,6 +1625,21 @@ arena_stats_merge(tsdn_t *tsdn, arena_t *arena, unsigned *nthreads,
lstats[i].nrequests += arena->stats.lstats[i].nrequests;
lstats[i].curlextents += arena->stats.lstats[i].curlextents;
}
if (config_tcache) {
tcache_bin_t *tbin;
tcache_t *tcache;
/* tcache_bytes counts currently cached bytes. */
astats->tcache_bytes = 0;
ql_foreach(tcache, &arena->tcache_ql, link) {
for (i = 0; i < nhbins; i++) {
tbin = &tcache->tbins[i];
astats->tcache_bytes += tbin->ncached *
index2size(i);
}
}
}
malloc_mutex_unlock(tsdn, &arena->lock);
for (i = 0; i < NBINS; i++) {

View File

@ -161,6 +161,7 @@ CTL_PROTO(stats_arenas_i_nmadvise)
CTL_PROTO(stats_arenas_i_purged)
CTL_PROTO(stats_arenas_i_base)
CTL_PROTO(stats_arenas_i_internal)
CTL_PROTO(stats_arenas_i_tcache_bytes)
CTL_PROTO(stats_arenas_i_resident)
INDEX_PROTO(stats_arenas_i)
CTL_PROTO(stats_allocated)
@ -382,6 +383,7 @@ static const ctl_named_node_t stats_arenas_i_node[] = {
{NAME("purged"), CTL(stats_arenas_i_purged)},
{NAME("base"), CTL(stats_arenas_i_base)},
{NAME("internal"), CTL(stats_arenas_i_internal)},
{NAME("tcache_bytes"), CTL(stats_arenas_i_tcache_bytes)},
{NAME("resident"), CTL(stats_arenas_i_resident)},
{NAME("small"), CHILD(named, stats_arenas_i_small)},
{NAME("large"), CHILD(named, stats_arenas_i_large)},
@ -601,6 +603,11 @@ ctl_arena_stats_sdmerge(ctl_arena_stats_t *sdstats, ctl_arena_stats_t *astats,
sdstats->astats.nrequests_large +=
astats->astats.nrequests_large;
if (config_tcache) {
sdstats->astats.tcache_bytes +=
astats->astats.tcache_bytes;
}
for (i = 0; i < NBINS; i++) {
sdstats->bstats[i].nmalloc += astats->bstats[i].nmalloc;
sdstats->bstats[i].ndalloc += astats->bstats[i].ndalloc;
@ -2105,6 +2112,8 @@ CTL_RO_CGEN(config_stats, stats_arenas_i_base,
stats_arenas_i(mib[2])->astats.base, size_t)
CTL_RO_CGEN(config_stats, stats_arenas_i_internal,
stats_arenas_i(mib[2])->astats.internal, size_t)
CTL_RO_CGEN(config_stats && config_tcache, stats_arenas_i_tcache_bytes,
stats_arenas_i(mib[2])->astats.tcache_bytes, size_t)
CTL_RO_CGEN(config_stats, stats_arenas_i_resident,
stats_arenas_i(mib[2])->astats.resident, size_t)

View File

@ -261,6 +261,7 @@ stats_arena_print(void (*write_cb)(void *, const char *), void *cbopaque,
uint64_t small_nmalloc, small_ndalloc, small_nrequests;
size_t large_allocated;
uint64_t large_nmalloc, large_ndalloc, large_nrequests;
size_t tcache_bytes;
CTL_GET("arenas.page", &page, size_t);
@ -423,6 +424,18 @@ stats_arena_print(void (*write_cb)(void *, const char *), void *cbopaque,
"internal: %12zu\n", internal);
}
if (config_tcache) {
CTL_M2_GET("stats.arenas.0.tcache_bytes", i, &tcache_bytes,
size_t);
if (json) {
malloc_cprintf(write_cb, cbopaque,
"\t\t\t\t\"tcache\": %zu,\n", tcache_bytes);
} else {
malloc_cprintf(write_cb, cbopaque,
"tcache: %12zu\n", tcache_bytes);
}
}
CTL_M2_GET("stats.arenas.0.resident", i, &resident, size_t);
if (json) {
malloc_cprintf(write_cb, cbopaque,