xref: /freebsd/contrib/jemalloc/src/prof_stats.c (revision c43cad87172039ccf38172129c79755ea79e6102)
1 #include "jemalloc/internal/jemalloc_preamble.h"
2 #include "jemalloc/internal/jemalloc_internal_includes.h"
3 
4 #include "jemalloc/internal/prof_stats.h"
5 
6 bool opt_prof_stats = false;
7 malloc_mutex_t prof_stats_mtx;
8 static prof_stats_t prof_stats_live[PROF_SC_NSIZES];
9 static prof_stats_t prof_stats_accum[PROF_SC_NSIZES];
10 
11 static void
12 prof_stats_enter(tsd_t *tsd, szind_t ind) {
13 	assert(opt_prof && opt_prof_stats);
14 	assert(ind < SC_NSIZES);
15 	malloc_mutex_lock(tsd_tsdn(tsd), &prof_stats_mtx);
16 }
17 
18 static void
19 prof_stats_leave(tsd_t *tsd) {
20 	malloc_mutex_unlock(tsd_tsdn(tsd), &prof_stats_mtx);
21 }
22 
23 void
24 prof_stats_inc(tsd_t *tsd, szind_t ind, size_t size) {
25 	cassert(config_prof);
26 	prof_stats_enter(tsd, ind);
27 	prof_stats_live[ind].req_sum += size;
28 	prof_stats_live[ind].count++;
29 	prof_stats_accum[ind].req_sum += size;
30 	prof_stats_accum[ind].count++;
31 	prof_stats_leave(tsd);
32 }
33 
34 void
35 prof_stats_dec(tsd_t *tsd, szind_t ind, size_t size) {
36 	cassert(config_prof);
37 	prof_stats_enter(tsd, ind);
38 	prof_stats_live[ind].req_sum -= size;
39 	prof_stats_live[ind].count--;
40 	prof_stats_leave(tsd);
41 }
42 
43 void
44 prof_stats_get_live(tsd_t *tsd, szind_t ind, prof_stats_t *stats) {
45 	cassert(config_prof);
46 	prof_stats_enter(tsd, ind);
47 	memcpy(stats, &prof_stats_live[ind], sizeof(prof_stats_t));
48 	prof_stats_leave(tsd);
49 }
50 
51 void
52 prof_stats_get_accum(tsd_t *tsd, szind_t ind, prof_stats_t *stats) {
53 	cassert(config_prof);
54 	prof_stats_enter(tsd, ind);
55 	memcpy(stats, &prof_stats_accum[ind], sizeof(prof_stats_t));
56 	prof_stats_leave(tsd);
57 }
58