mirror of
https://github.com/varun-r-mallya/sysprof.git
synced 2026-02-12 16:10:54 +00:00
preload: use unw_backtrace()
This seems to be significantly faster than doing the manual stepping. A quick look shows that it has a number of special cases which we'd have to duplicate, so best to just use it directly.
This commit is contained in:
@ -76,29 +76,15 @@ backtrace_func (SysprofCaptureAddress *addrs,
|
|||||||
gpointer user_data)
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
#if defined(ENABLE_LIBUNWIND)
|
#if defined(ENABLE_LIBUNWIND)
|
||||||
unw_context_t uc;
|
# if GLIB_SIZEOF_VOID_P == 8
|
||||||
unw_cursor_t cursor;
|
return unw_backtrace ((void **)addrs, n_addrs);
|
||||||
unw_word_t ip;
|
# else
|
||||||
|
void **stack = alloca (n_addrs * sizeof (gpointer));
|
||||||
unw_getcontext (&uc);
|
guint n = unw_backtrace (stack, n_addrs);
|
||||||
unw_init_local (&cursor, &uc);
|
for (guint i = 0; i < n; i++)
|
||||||
|
addrs[i] = GPOINTER_TO_SIZE (stack[i]);
|
||||||
/* Skip past caller frames */
|
return n;
|
||||||
if (unw_step (&cursor) > 0 && unw_step (&cursor) > 0)
|
# endif
|
||||||
{
|
|
||||||
guint n = 0;
|
|
||||||
|
|
||||||
/* Now walk the stack frames back */
|
|
||||||
while (n < n_addrs && unw_step (&cursor) > 0)
|
|
||||||
{
|
|
||||||
unw_get_reg (&cursor, UNW_REG_IP, &ip);
|
|
||||||
addrs[n++] = ip;
|
|
||||||
}
|
|
||||||
|
|
||||||
return n;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
#elif defined(HAVE_EXECINFO_H)
|
#elif defined(HAVE_EXECINFO_H)
|
||||||
# if GLIB_SIZEOF_VOID_P == 8
|
# if GLIB_SIZEOF_VOID_P == 8
|
||||||
return backtrace ((void **)addrs, n_addrs);
|
return backtrace ((void **)addrs, n_addrs);
|
||||||
|
|||||||
Reference in New Issue
Block a user