From 474383b65651d44c6ac0cece14173c1e96ba15ca Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Thu, 27 Feb 2020 13:17:26 +0100 Subject: [PATCH] Only copy symbol strings, if needed. --- client/TracyCallstack.cpp | 17 +++++++++-------- client/TracyCallstack.hpp | 1 + client/TracyProfiler.cpp | 2 +- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/client/TracyCallstack.cpp b/client/TracyCallstack.cpp index 1b705e6b..ae4898b0 100644 --- a/client/TracyCallstack.cpp +++ b/client/TracyCallstack.cpp @@ -237,18 +237,17 @@ SymbolData DecodeSymbolAddress( uint64_t ptr ) IMAGEHLP_LINE64 line; DWORD displacement = 0; line.SizeOfStruct = sizeof(IMAGEHLP_LINE64); - const char* filename; if( SymGetLineFromAddr64( GetCurrentProcess(), ptr, &displacement, &line ) == 0 ) { - filename = "[unknown]"; + sym.file = "[unknown]"; sym.line = 0; } else { - filename = line.FileName; + sym.file = line.FileName; sym.line = line.LineNumber; } - sym.file = CopyString( filename ); + sym.needFree = false; return sym; } @@ -397,16 +396,18 @@ static int SymbolAddressDataCb( void* data, uintptr_t pc, const char* fn, int li if( !fn ) { const char* symloc = nullptr; - Dl_info dlinfo; + static Dl_info dlinfo; if( dladdr( (void*)ptr, &dlinfo ) ) symloc = dlinfo.dli_fname; if( !symloc ) symloc = "[unknown]"; - sym.file = CopyString( symloc ); + sym.file = symloc; sym.line = 0; + sym.needFree = false; } else { sym.file = CopyString( fn ); sym.line = lineno; + sym.needFree = true; } return 1; @@ -597,10 +598,10 @@ const char* DecodeCallstackPtrFast( uint64_t ptr ) SymbolData DecodeSymbolAddress( uint64_t ptr ) { const char* symloc = nullptr; - Dl_info dlinfo; + static Dl_info dlinfo; if( dladdr( (void*)ptr, &dlinfo ) ) symloc = dlinfo.dli_fname; if( !symloc ) symloc = "[unknown]"; - return SymbolData { CopyString( symloc ), 0 }; + return SymbolData { symloc, 0, false }; } CallstackEntryData DecodeCallstackPtr( uint64_t ptr ) diff --git a/client/TracyCallstack.hpp b/client/TracyCallstack.hpp index 243aaf01..a3ee9a39 100644 --- a/client/TracyCallstack.hpp +++ b/client/TracyCallstack.hpp @@ -26,6 +26,7 @@ struct SymbolData { const char* file; uint32_t line; + bool needFree; }; struct CallstackEntry diff --git a/client/TracyProfiler.cpp b/client/TracyProfiler.cpp index 66f66c41..0e9a36e1 100644 --- a/client/TracyProfiler.cpp +++ b/client/TracyProfiler.cpp @@ -2695,7 +2695,7 @@ void Profiler::HandleSymbolQuery( uint64_t symbol ) AppendData( &item, QueueDataSize[(int)QueueType::SymbolInformation] ); - tracy_free( (void*)sym.file ); + if( sym.needFree ) tracy_free( (void*)sym.file ); #endif }