8 typedef int (*
mallctl_t)(
const char *
name,
void *oldp,
size_t *oldlenp,
void *newp,
size_t newlen);
10 typedef int (*
mallctlbymib_t)(
const size_t *mib,
size_t miblen,
void *oldp,
size_t *oldlenp,
void *newp,
size_t newlen);
15 bool initialise_peak();
16 const uint64_t *initialise_thread_allocated_p();
17 const uint64_t *initialise_thread_deallocated_p();
20 size_t mib_peak_read[3];
21 size_t mib_peak_reset[3];
22 thread_local
const uint64_t *thread_allocated_p = initialise_thread_allocated_p();
23 thread_local
const uint64_t *thread_deallocated_p = initialise_thread_deallocated_p();
28 const bool have_jemalloc_and_stats = initialise();
29 const bool have_jemalloc_and_peak = have_jemalloc_and_stats and initialise_peak();
33 mallctl = (
mallctl_t)::dlsym(RTLD_DEFAULT,
"mallctl");
34 if (mallctl ==
nullptr)
37 if (mallctlnametomib ==
nullptr)
39 mallctlbymib = (
mallctlbymib_t)::dlsym(RTLD_DEFAULT,
"mallctlbymib");
40 if (mallctlbymib ==
nullptr)
44 bool enable_stats =
false;
45 size_t bool_s =
sizeof(bool);
46 mallctl(
"config.stats", &enable_stats, &bool_s,
nullptr, 0);
50 bool initialise_peak() {
53 if (mallctlnametomib(
"thread.peak.read", mib_peak_read, &miblen) != 0)
55 if (mallctlnametomib(
"thread.peak.reset", mib_peak_reset, &miblen) != 0)
60 const uint64_t *initialise_thread_allocated_p() {
64 if (have_jemalloc_and_stats)
66 mallctl(
"thread.allocatedp", &stats, &ptr_s,
nullptr, 0);
71 const uint64_t *initialise_thread_deallocated_p() {
75 if (have_jemalloc_and_stats)
77 mallctl(
"thread.deallocatedp", &stats, &ptr_s,
nullptr, 0);
93 if (have_jemalloc_and_peak)
94 mallctlbymib(mib_peak_read, 3, &peak, &size,
nullptr, 0);
99 if (have_jemalloc_and_peak)
100 mallctlbymib(mib_peak_reset, 3,
nullptr,
nullptr,
nullptr, 0);
int(* mallctlbymib_t)(const size_t *mib, size_t miblen, void *oldp, size_t *oldlenp, void *newp, size_t newlen)
static uint64_t deallocated()
int(* mallctlnametomib_t)(const char *name, size_t *mibp, size_t *miblenp)
static bool is_available()
unsigned long long uint64_t
static uint64_t allocated()
tuple size
Write out results.
int(* mallctl_t)(const char *name, void *oldp, size_t *oldlenp, void *newp, size_t newlen)