prof_backtrace: use unw_backtrace
unw_backtrace: - does internal per-thread caching - doesn't acquire an internal lock
This commit is contained in:
parent
3541a904d6
commit
9d4e13f45a
@ -352,9 +352,9 @@ static const bool config_ivsalloc =
|
|||||||
# endif
|
# endif
|
||||||
# endif
|
# endif
|
||||||
# define VARIABLE_ARRAY(type, name, count) \
|
# define VARIABLE_ARRAY(type, name, count) \
|
||||||
type *name = alloca(sizeof(type) * count)
|
type *name = alloca(sizeof(type) * (count))
|
||||||
#else
|
#else
|
||||||
# define VARIABLE_ARRAY(type, name, count) type name[count]
|
# define VARIABLE_ARRAY(type, name, count) type name[(count)]
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "jemalloc/internal/valgrind.h"
|
#include "jemalloc/internal/valgrind.h"
|
||||||
|
31
src/prof.c
31
src/prof.c
@ -160,36 +160,21 @@ prof_leave(prof_tdata_t *prof_tdata)
|
|||||||
void
|
void
|
||||||
prof_backtrace(prof_bt_t *bt, unsigned nignore)
|
prof_backtrace(prof_bt_t *bt, unsigned nignore)
|
||||||
{
|
{
|
||||||
unw_context_t uc;
|
|
||||||
unw_cursor_t cursor;
|
|
||||||
unsigned i;
|
|
||||||
int err;
|
|
||||||
|
|
||||||
cassert(config_prof);
|
cassert(config_prof);
|
||||||
assert(bt->len == 0);
|
assert(bt->len == 0);
|
||||||
assert(bt->vec != NULL);
|
assert(bt->vec != NULL);
|
||||||
|
|
||||||
unw_getcontext(&uc);
|
VARIABLE_ARRAY(void *, frames, nignore + PROF_BT_MAX);
|
||||||
unw_init_local(&cursor, &uc);
|
int n = unw_backtrace(frames, nignore + PROF_BT_MAX);
|
||||||
|
if (n <= 0)
|
||||||
|
return;
|
||||||
|
|
||||||
/* Throw away (nignore+1) stack frames, if that many exist. */
|
/* Throw away (nignore+1) stack frames, if that many exist. */
|
||||||
for (i = 0; i < nignore + 1; i++) {
|
nignore++;
|
||||||
err = unw_step(&cursor);
|
if (nignore >= n)
|
||||||
if (err <= 0)
|
|
||||||
return;
|
return;
|
||||||
}
|
memcpy(bt->vec, &frames[nignore], sizeof(frames[0]) * (n - nignore));
|
||||||
|
bt->len = n - nignore;
|
||||||
/*
|
|
||||||
* 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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
#elif (defined(JEMALLOC_PROF_LIBGCC))
|
#elif (defined(JEMALLOC_PROF_LIBGCC))
|
||||||
static _Unwind_Reason_Code
|
static _Unwind_Reason_Code
|
||||||
|
Loading…
Reference in New Issue
Block a user