Compare commits

...

1 Commits

Author SHA1 Message Date
Marcos Slomp
75499a4944 public API to query symbols 2026-07-01 12:40:07 -07:00
2 changed files with 32 additions and 0 deletions

View File

@@ -10,6 +10,9 @@
#include "../common/TracyAlloc.hpp"
#include "../common/TracySystem.hpp"
#include <shared_mutex>
#include <string>
#include <unordered_map>
#ifdef TRACY_HAS_CALLSTACK
@@ -1952,6 +1955,33 @@ CallstackEntryData DecodeCallstackPtr( uint64_t ptr )
#endif
TRACY_API const char* QuerySymbolName(void* ptr)
{
#ifndef TRACY_HAS_CALLSTACK
return "[unavailable]";
#else
uint64_t address = uint64_t(ptr);
static std::unordered_map<uint64_t, std::string> s_cache;
static std::shared_mutex s_mutex;
{
std::shared_lock lock(s_mutex);
auto it = s_cache.find(address);
if (it != s_cache.end()) return it->second.c_str();
}
std::unique_lock lock(s_mutex);
auto [it, inserted] = s_cache.try_emplace(address);
if (inserted)
{
const char* symbol = DecodeCallstackPtrFast(address);
it->second = symbol;
}
return it->second.c_str();
#endif
}
}
#endif

View File

@@ -26,6 +26,7 @@ namespace tracy
{
static constexpr bool has_callstack() { return false; }
static tracy_force_inline void* Callstack( int32_t /*depth*/ ) { return nullptr; }
TRACY_API const char* QuerySymbolName(void* address);
}
#else
@@ -87,6 +88,7 @@ void InitCallstack();
void InitCallstackCritical();
void EndCallstack();
const char* GetKernelModulePath( uint64_t addr );
TRACY_API const char* QuerySymbolName(void* address);
#ifdef __linux__
void InitExternalImageCache( pid_t pid );