From 4c94b3eff7c212e431a117c6c10ee60bb2a8e875 Mon Sep 17 00:00:00 2001 From: Tiago Rodrigues Date: Fri, 10 Nov 2023 17:00:39 -0500 Subject: [PATCH] Add support to use libunwind for backtrace capturing on linux platforms (which is ~ 4x faster than execinfo) --- public/client/TracyCallstack.hpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/public/client/TracyCallstack.hpp b/public/client/TracyCallstack.hpp index 0b522b73..36e295a1 100644 --- a/public/client/TracyCallstack.hpp +++ b/public/client/TracyCallstack.hpp @@ -8,9 +8,15 @@ #if TRACY_HAS_CALLSTACK == 2 || TRACY_HAS_CALLSTACK == 5 # include #elif TRACY_HAS_CALLSTACK >= 3 -# include -#endif + #ifdef USE_LIB_UNWIND_BACKTRACE + // libunwind is in general significantly faster than execinfo based backtraces + #define UNW_LOCAL_ONLY + # include + #else + # include + #endif +#endif #ifndef TRACY_HAS_CALLSTACK @@ -127,7 +133,13 @@ static tracy_force_inline void* Callstack( int depth ) assert( depth >= 1 ); auto trace = (uintptr_t*)tracy_malloc( ( 1 + (size_t)depth ) * sizeof( uintptr_t ) ); + +#ifdef USE_LIB_UNWIND_BACKTRACE + size_t num = unw_backtrace( (void**)(trace+1), depth ); +#else const auto num = (size_t)backtrace( (void**)(trace+1), depth ); +#endif + *trace = num; return trace;