28 void *trace[ALLOC_TRACE_DEPTH];
30 backtrace(
const backtrace &) =
default;
31 explicit backtrace(
void **bt) { memcpy(trace, bt,
sizeof(trace)); }
32 bool operator<(
const backtrace &a)
const {
33 for (
int i = 0; i < ALLOC_TRACE_DEPTH; ++i)
34 if (trace[i] != a.trace[i])
return trace[i] < a.trace[i];
37 bool operator==(
const backtrace &a)
const {
38 for (
int i = 0; i < ALLOC_TRACE_DEPTH; ++i)
39 if (trace[i] != a.trace[i])
return false;
43 std::map<backtrace, std::map<size_t, int>> data;
44 void count(
void **,
size_t);
45 static void callback(
void *t,
void **bt,
size_t sz) {
50 void clear() { data.clear(); }
54 auto tmp = set_alloc_trace(old);
55 BUG_CHECK(tmp.fn == callback && tmp.arg ==
this,
"AllocTrace stopped when not running");
59 BUG(
"Can't trace allocations without garbage collection");
64 friend std::ostream &operator<<(std::ostream &,
const AllocTrace &);