Make GetCallstackJson available via View.

This commit is contained in:
Bartosz Taudul
2026-01-08 22:34:45 +01:00
parent d9200351ef
commit 723bdc71dc
3 changed files with 74 additions and 72 deletions

View File

@@ -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<CallstackFrameId>& cs );
void SetViewToLastFrames();
int64_t GetZoneChildTime( const ZoneEvent& zone );
int64_t GetZoneChildTime( const GpuEvent& zone );

View File

@@ -28,75 +28,6 @@ void View::DrawCallstackWindow()
if( !show ) m_callstackInfoWindow = 0;
}
static nlohmann::json GetCallstackJson( Worker& worker, const VarArray<CallstackFrameId>& 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; f<fsz; f++ )
{
const auto& frame = frameData->data[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();
}

View File

@@ -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<CallstackFrameId>& 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; f<fsz; f++ )
{
const auto& frame = frameData->data[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;
}
}