From 723bdc71dc7db02416c7302eafaa339b0bfa392e Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Thu, 8 Jan 2026 22:34:45 +0100 Subject: [PATCH] Make GetCallstackJson available via View. --- profiler/src/profiler/TracyView.hpp | 1 + profiler/src/profiler/TracyView_Callstack.cpp | 75 +------------------ profiler/src/profiler/TracyView_Utility.cpp | 70 +++++++++++++++++ 3 files changed, 74 insertions(+), 72 deletions(-) diff --git a/profiler/src/profiler/TracyView.hpp b/profiler/src/profiler/TracyView.hpp index 9dc438c1..86384690 100644 --- a/profiler/src/profiler/TracyView.hpp +++ b/profiler/src/profiler/TracyView.hpp @@ -387,6 +387,7 @@ private: void SmallCallstackButton( const char* name, uint32_t callstack, int& idx, bool tooltip = true ); void DrawCallstackCalls( uint32_t callstack, uint16_t limit ) const; + nlohmann::json GetCallstackJson( const VarArray& cs ); void SetViewToLastFrames(); int64_t GetZoneChildTime( const ZoneEvent& zone ); int64_t GetZoneChildTime( const GpuEvent& zone ); diff --git a/profiler/src/profiler/TracyView_Callstack.cpp b/profiler/src/profiler/TracyView_Callstack.cpp index 0af9cd27..06d51063 100644 --- a/profiler/src/profiler/TracyView_Callstack.cpp +++ b/profiler/src/profiler/TracyView_Callstack.cpp @@ -28,75 +28,6 @@ void View::DrawCallstackWindow() if( !show ) m_callstackInfoWindow = 0; } -static nlohmann::json GetCallstackJson( Worker& worker, const VarArray& cs ) -{ - nlohmann::json json = { - { "type", "callstack" }, - { "frames", nlohmann::json::array() } - }; - auto& frames = json["frames"]; - - int fidx = 0; - for( auto& entry : cs ) - { - auto frameData = worker.GetCallstackFrame( entry ); - if( !frameData ) - { - frames.push_back( { "pointer", worker.GetCanonicalPointer( entry ) } ); - } - else - { - const auto fsz = frameData->size; - for( uint8_t f=0; fdata[f]; - auto txt = worker.GetString( frame.name ); - - if( fidx == 0 && f != fsz-1 ) - { - auto test = tracy::s_tracyStackFrames; - bool match = false; - do - { - if( strcmp( txt, *test ) == 0 ) - { - match = true; - break; - } - } - while( *++test ); - if( match ) continue; - } - - frames.push_back( { - { "function", txt }, - { "source", worker.GetString( frame.file ) }, - } ); - auto& frameJson = frames.back(); - - if( f == fsz-1 ) - { - frameJson["frame"] = fidx++; - } - else - { - frameJson["frame"] = fidx; - frameJson["inline"] = f; - } - if( frame.line != 0 ) - { - frameJson["line"] = frame.line; - } - if( frameData->imageName.Active() ) - { - frameJson["executable"] = worker.GetString( frameData->imageName ); - } - } - } - } - return json; -} - void View::DrawCallstackTable( uint32_t callstack, bool globalEntriesButton ) { auto& cs = m_worker.GetCallstack( callstack ); @@ -174,7 +105,7 @@ void View::DrawCallstackTable( uint32_t callstack, bool globalEntriesButton ) ImGui::SameLine(); if( ImGui::SmallButton( ICON_FA_ROBOT ) ) { - AddLlmAttachment( GetCallstackJson( m_worker, cs ) ); + AddLlmAttachment( GetCallstackJson( cs ) ); } if( ImGui::IsItemHovered() && IsMouseClicked( ImGuiMouseButton_Right ) ) { @@ -184,13 +115,13 @@ void View::DrawCallstackTable( uint32_t callstack, bool globalEntriesButton ) { if( ImGui::Selectable( "What is program doing at this moment?" ) ) { - AddLlmAttachment( GetCallstackJson( m_worker, cs ) ); + AddLlmAttachment( GetCallstackJson( cs ) ); AddLlmQuery( "What is program doing at this moment?" ); ImGui::CloseCurrentPopup(); } if( ImGui::Selectable( "Walk me through the details of this callstack, step by step, explaining the code." ) ) { - AddLlmAttachment( GetCallstackJson( m_worker, cs ) ); + AddLlmAttachment( GetCallstackJson( cs ) ); AddLlmQuery( "Walk me through the details of this callstack, step by step, explaining the code." ); ImGui::CloseCurrentPopup(); } diff --git a/profiler/src/profiler/TracyView_Utility.cpp b/profiler/src/profiler/TracyView_Utility.cpp index dbdfeaeb..bc864f3f 100644 --- a/profiler/src/profiler/TracyView_Utility.cpp +++ b/profiler/src/profiler/TracyView_Utility.cpp @@ -4,6 +4,7 @@ #include "TracyPrint.hpp" #include "TracyUtility.hpp" #include "TracyView.hpp" +#include "../common/TracyStackFrames.hpp" namespace tracy { @@ -925,4 +926,73 @@ void View::UpdateTitle() } } +nlohmann::json View::GetCallstackJson( const VarArray& cs ) +{ + nlohmann::json json = { + { "type", "callstack" }, + { "frames", nlohmann::json::array() } + }; + auto& frames = json["frames"]; + + int fidx = 0; + for( auto& entry : cs ) + { + auto frameData = m_worker.GetCallstackFrame( entry ); + if( !frameData ) + { + frames.push_back( { "pointer", m_worker.GetCanonicalPointer( entry ) } ); + } + else + { + const auto fsz = frameData->size; + for( uint8_t f=0; fdata[f]; + auto txt = m_worker.GetString( frame.name ); + + if( fidx == 0 && f != fsz-1 ) + { + auto test = tracy::s_tracyStackFrames; + bool match = false; + do + { + if( strcmp( txt, *test ) == 0 ) + { + match = true; + break; + } + } + while( *++test ); + if( match ) continue; + } + + frames.push_back( { + { "function", txt }, + { "source", m_worker.GetString( frame.file ) }, + } ); + auto& frameJson = frames.back(); + + if( f == fsz-1 ) + { + frameJson["frame"] = fidx++; + } + else + { + frameJson["frame"] = fidx; + frameJson["inline"] = f; + } + if( frame.line != 0 ) + { + frameJson["line"] = frame.line; + } + if( frameData->imageName.Active() ) + { + frameJson["executable"] = m_worker.GetString( frameData->imageName ); + } + } + } + } + return json; +} + }