Path: blob/main/contrib/jemalloc/src/peak_event.c
104186 views
#include "jemalloc/internal/jemalloc_preamble.h"1#include "jemalloc/internal/jemalloc_internal_includes.h"23#include "jemalloc/internal/peak_event.h"45#include "jemalloc/internal/activity_callback.h"6#include "jemalloc/internal/peak.h"78/*9* Update every 64K by default. We're not exposing this as a configuration10* option for now; we don't want to bind ourselves too tightly to any particular11* performance requirements for small values, or guarantee that we'll even be12* able to provide fine-grained accuracy.13*/14#define PEAK_EVENT_WAIT (64 * 1024)1516/* Update the peak with current tsd state. */17void18peak_event_update(tsd_t *tsd) {19uint64_t alloc = tsd_thread_allocated_get(tsd);20uint64_t dalloc = tsd_thread_deallocated_get(tsd);21peak_t *peak = tsd_peakp_get(tsd);22peak_update(peak, alloc, dalloc);23}2425static void26peak_event_activity_callback(tsd_t *tsd) {27activity_callback_thunk_t *thunk = tsd_activity_callback_thunkp_get(28tsd);29uint64_t alloc = tsd_thread_allocated_get(tsd);30uint64_t dalloc = tsd_thread_deallocated_get(tsd);31if (thunk->callback != NULL) {32thunk->callback(thunk->uctx, alloc, dalloc);33}34}3536/* Set current state to zero. */37void38peak_event_zero(tsd_t *tsd) {39uint64_t alloc = tsd_thread_allocated_get(tsd);40uint64_t dalloc = tsd_thread_deallocated_get(tsd);41peak_t *peak = tsd_peakp_get(tsd);42peak_set_zero(peak, alloc, dalloc);43}4445uint64_t46peak_event_max(tsd_t *tsd) {47peak_t *peak = tsd_peakp_get(tsd);48return peak_max(peak);49}5051uint64_t52peak_alloc_new_event_wait(tsd_t *tsd) {53return PEAK_EVENT_WAIT;54}5556uint64_t57peak_alloc_postponed_event_wait(tsd_t *tsd) {58return TE_MIN_START_WAIT;59}6061void62peak_alloc_event_handler(tsd_t *tsd, uint64_t elapsed) {63peak_event_update(tsd);64peak_event_activity_callback(tsd);65}6667uint64_t68peak_dalloc_new_event_wait(tsd_t *tsd) {69return PEAK_EVENT_WAIT;70}7172uint64_t73peak_dalloc_postponed_event_wait(tsd_t *tsd) {74return TE_MIN_START_WAIT;75}7677void78peak_dalloc_event_handler(tsd_t *tsd, uint64_t elapsed) {79peak_event_update(tsd);80peak_event_activity_callback(tsd);81}828384