summaryrefslogtreecommitdiff
path: root/deps/jemalloc/include/jemalloc/internal/peak.h
blob: 59da3e41b6b78b35a249381287f019232c48d706 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#ifndef JEMALLOC_INTERNAL_PEAK_H
#define JEMALLOC_INTERNAL_PEAK_H

typedef struct peak_s peak_t;
struct peak_s {
	/* The highest recorded peak value, after adjustment (see below). */
	uint64_t cur_max;
	/*
	 * The difference between alloc and dalloc at the last set_zero call;
	 * this lets us cancel out the appropriate amount of excess.
	 */
	uint64_t adjustment;
};

#define PEAK_INITIALIZER {0, 0}

static inline uint64_t
peak_max(peak_t *peak) {
	return peak->cur_max;
}

static inline void
peak_update(peak_t *peak, uint64_t alloc, uint64_t dalloc) {
	int64_t candidate_max = (int64_t)(alloc - dalloc - peak->adjustment);
	if (candidate_max > (int64_t)peak->cur_max) {
		peak->cur_max = candidate_max;
	}
}

/* Resets the counter to zero; all peaks are now relative to this point. */
static inline void
peak_set_zero(peak_t *peak, uint64_t alloc, uint64_t dalloc) {
	peak->cur_max = 0;
	peak->adjustment = alloc - dalloc;
}

#endif /* JEMALLOC_INTERNAL_PEAK_H */