1 #ifndef JEMALLOC_INTERNAL_PEAK_H 2 #define JEMALLOC_INTERNAL_PEAK_H 3 4 typedef struct peak_s peak_t; 5 struct peak_s { 6 /* The highest recorded peak value, after adjustment (see below). */ 7 uint64_t cur_max; 8 /* 9 * The difference between alloc and dalloc at the last set_zero call; 10 * this lets us cancel out the appropriate amount of excess. 11 */ 12 uint64_t adjustment; 13 }; 14 15 #define PEAK_INITIALIZER {0, 0} 16 17 static inline uint64_t 18 peak_max(peak_t *peak) { 19 return peak->cur_max; 20 } 21 22 static inline void 23 peak_update(peak_t *peak, uint64_t alloc, uint64_t dalloc) { 24 int64_t candidate_max = (int64_t)(alloc - dalloc - peak->adjustment); 25 if (candidate_max > (int64_t)peak->cur_max) { 26 peak->cur_max = candidate_max; 27 } 28 } 29 30 /* Resets the counter to zero; all peaks are now relative to this point. */ 31 static inline void 32 peak_set_zero(peak_t *peak, uint64_t alloc, uint64_t dalloc) { 33 peak->cur_max = 0; 34 peak->adjustment = alloc - dalloc; 35 } 36 37 #endif /* JEMALLOC_INTERNAL_PEAK_H */ 38