Path: blob/main/contrib/jemalloc/src/prof_stats.c
101232 views
#include "jemalloc/internal/jemalloc_preamble.h"1#include "jemalloc/internal/jemalloc_internal_includes.h"23#include "jemalloc/internal/prof_stats.h"45bool opt_prof_stats = false;6malloc_mutex_t prof_stats_mtx;7static prof_stats_t prof_stats_live[PROF_SC_NSIZES];8static prof_stats_t prof_stats_accum[PROF_SC_NSIZES];910static void11prof_stats_enter(tsd_t *tsd, szind_t ind) {12assert(opt_prof && opt_prof_stats);13assert(ind < SC_NSIZES);14malloc_mutex_lock(tsd_tsdn(tsd), &prof_stats_mtx);15}1617static void18prof_stats_leave(tsd_t *tsd) {19malloc_mutex_unlock(tsd_tsdn(tsd), &prof_stats_mtx);20}2122void23prof_stats_inc(tsd_t *tsd, szind_t ind, size_t size) {24cassert(config_prof);25prof_stats_enter(tsd, ind);26prof_stats_live[ind].req_sum += size;27prof_stats_live[ind].count++;28prof_stats_accum[ind].req_sum += size;29prof_stats_accum[ind].count++;30prof_stats_leave(tsd);31}3233void34prof_stats_dec(tsd_t *tsd, szind_t ind, size_t size) {35cassert(config_prof);36prof_stats_enter(tsd, ind);37prof_stats_live[ind].req_sum -= size;38prof_stats_live[ind].count--;39prof_stats_leave(tsd);40}4142void43prof_stats_get_live(tsd_t *tsd, szind_t ind, prof_stats_t *stats) {44cassert(config_prof);45prof_stats_enter(tsd, ind);46memcpy(stats, &prof_stats_live[ind], sizeof(prof_stats_t));47prof_stats_leave(tsd);48}4950void51prof_stats_get_accum(tsd_t *tsd, szind_t ind, prof_stats_t *stats) {52cassert(config_prof);53prof_stats_enter(tsd, ind);54memcpy(stats, &prof_stats_accum[ind], sizeof(prof_stats_t));55prof_stats_leave(tsd);56}575859