prof_backtrace: use unw_backtrace

unw_backtrace:
- does internal per-thread caching
- doesn't acquire an internal lock
This commit is contained in:
Lucian Adrian Grijincu 2014-04-21 20:52:35 -07:00
parent 3541a904d6
commit 9d4e13f45a
2 changed files with 11 additions and 26 deletions

View File

@ -352,9 +352,9 @@ static const bool config_ivsalloc =
# endif
# endif
# define VARIABLE_ARRAY(type, name, count) \
type *name = alloca(sizeof(type) * count)
type *name = alloca(sizeof(type) * (count))
#else
# define VARIABLE_ARRAY(type, name, count) type name[count]
# define VARIABLE_ARRAY(type, name, count) type name[(count)]
#endif
#include "jemalloc/internal/valgrind.h"

View File

@ -160,36 +160,21 @@ prof_leave(prof_tdata_t *prof_tdata)
void
prof_backtrace(prof_bt_t *bt, unsigned nignore)
{
unw_context_t uc;
unw_cursor_t cursor;
unsigned i;
int err;
cassert(config_prof);
assert(bt->len == 0);
assert(bt->vec != NULL);
unw_getcontext(&uc);
unw_init_local(&cursor, &uc);
VARIABLE_ARRAY(void *, frames, nignore + PROF_BT_MAX);
int n = unw_backtrace(frames, nignore + PROF_BT_MAX);
if (n <= 0)
return;
/* Throw away (nignore+1) stack frames, if that many exist. */
for (i = 0; i < nignore + 1; i++) {
err = unw_step(&cursor);
if (err <= 0)
return;
}
/*
* Iterate over stack frames until there are no more, or until no space
* remains in bt.
*/
for (i = 0; i < PROF_BT_MAX; i++) {
unw_get_reg(&cursor, UNW_REG_IP, (unw_word_t *)&bt->vec[i]);
bt->len++;
err = unw_step(&cursor);
if (err <= 0)
break;
}
nignore++;
if (nignore >= n)
return;
memcpy(bt->vec, &frames[nignore], sizeof(frames[0]) * (n - nignore));
bt->len = n - nignore;
}
#elif (defined(JEMALLOC_PROF_LIBGCC))
static _Unwind_Reason_Code