Skip to content
Snippets Groups Projects
Commit 6db3a806 authored by Nadav Har'El's avatar Nadav Har'El
Browse files

In leak detector, remember most recent functions

As Avi suggested, add an option (turned on by default) to remember only
the most recent function calls - instead of the most high-level function
calls like I did until now - in an allocation's stack trace.

In our project, where we often don't care about the top-level
functions (various Java stuff), it is more useful.
parent 1c6c395a
No related branches found
No related tags found
No related merge requests found
......@@ -45,11 +45,11 @@ void alloc_tracker::remember(void *addr, int size)
a->size = size;
// Do the backtrace. If we ask for only a small number of call levels
// we'll get only the deepest (most recent) levels, but we are more
// interested in the highest level functions, so we ask for 1024 levels
// (assuming we'll never have deeper recursion than that), and later only
// save the highest levels.
static void *bt[1024];
// we'll get only the deepest (most recent) levels, but when
// !POLICY_DEEPEST we are more interested in the highest level functions,
// so we ask for 1024 levels (assuming we'll never have deeper recursion than
// that), and later only save the highest levels.
static void *bt[POLICY_DEEPEST ? MAX_BACKTRACE : 1024];
int n = backtrace(bt, sizeof(bt)/sizeof(*bt));
// When backtrace is too deep, save only the MAX_BACKTRACE most high
......@@ -58,7 +58,7 @@ void alloc_tracker::remember(void *addr, int size)
// and then malloc/alloc_page) and and at the end (typically some assembly
// code or ununderstood address).
static constexpr int N_USELESS_FUNCS_START = 2;
static constexpr int N_USELESS_FUNCS_END = 1;
static constexpr int N_USELESS_FUNCS_END = 0;
void **bt_from = bt + N_USELESS_FUNCS_START;
n -= N_USELESS_FUNCS_START+N_USELESS_FUNCS_END;
if(n > MAX_BACKTRACE) {
......
......@@ -19,7 +19,13 @@ public:
void remember(void *addr, int size);
void forget(void *addr);
private:
static constexpr int MAX_BACKTRACE = 30;
// For each allocation we remember MAX_BACKTRACE functions (or rather,
// instruction pointers) on the call chain. We remember either the
// deepest (newest) calls, if POLICY_DEEPEST, else the shallowest
// (top-level calls).
static constexpr int MAX_BACKTRACE = 20;
static constexpr bool POLICY_DEEPEST = true;
struct alloc_info {
// sequential number of allocation (to know how "old" this allocation
// is):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment