1 #include "jemalloc/internal/jemalloc_preamble.h" 2 #include "jemalloc/internal/jemalloc_internal_includes.h" 3 4 #include "jemalloc/internal/peak_event.h" 5 6 #include "jemalloc/internal/activity_callback.h" 7 #include "jemalloc/internal/peak.h" 8 9 /* 10 * Update every 64K by default. We're not exposing this as a configuration 11 * option for now; we don't want to bind ourselves too tightly to any particular 12 * performance requirements for small values, or guarantee that we'll even be 13 * able to provide fine-grained accuracy. 14 */ 15 #define PEAK_EVENT_WAIT (64 * 1024) 16 17 /* Update the peak with current tsd state. */ 18 void 19 peak_event_update(tsd_t *tsd) { 20 uint64_t alloc = tsd_thread_allocated_get(tsd); 21 uint64_t dalloc = tsd_thread_deallocated_get(tsd); 22 peak_t *peak = tsd_peakp_get(tsd); 23 peak_update(peak, alloc, dalloc); 24 } 25 26 static void 27 peak_event_activity_callback(tsd_t *tsd) { 28 activity_callback_thunk_t *thunk = tsd_activity_callback_thunkp_get( 29 tsd); 30 uint64_t alloc = tsd_thread_allocated_get(tsd); 31 uint64_t dalloc = tsd_thread_deallocated_get(tsd); 32 if (thunk->callback != NULL) { 33 thunk->callback(thunk->uctx, alloc, dalloc); 34 } 35 } 36 37 /* Set current state to zero. */ 38 void 39 peak_event_zero(tsd_t *tsd) { 40 uint64_t alloc = tsd_thread_allocated_get(tsd); 41 uint64_t dalloc = tsd_thread_deallocated_get(tsd); 42 peak_t *peak = tsd_peakp_get(tsd); 43 peak_set_zero(peak, alloc, dalloc); 44 } 45 46 uint64_t 47 peak_event_max(tsd_t *tsd) { 48 peak_t *peak = tsd_peakp_get(tsd); 49 return peak_max(peak); 50 } 51 52 uint64_t 53 peak_alloc_new_event_wait(tsd_t *tsd) { 54 return PEAK_EVENT_WAIT; 55 } 56 57 uint64_t 58 peak_alloc_postponed_event_wait(tsd_t *tsd) { 59 return TE_MIN_START_WAIT; 60 } 61 62 void 63 peak_alloc_event_handler(tsd_t *tsd, uint64_t elapsed) { 64 peak_event_update(tsd); 65 peak_event_activity_callback(tsd); 66 } 67 68 uint64_t 69 peak_dalloc_new_event_wait(tsd_t *tsd) { 70 return PEAK_EVENT_WAIT; 71 } 72 73 uint64_t 74 peak_dalloc_postponed_event_wait(tsd_t *tsd) { 75 return TE_MIN_START_WAIT; 76 } 77 78 void 79 peak_dalloc_event_handler(tsd_t *tsd, uint64_t elapsed) { 80 peak_event_update(tsd); 81 peak_event_activity_callback(tsd); 82 } 83