From 00ce66313622945fedfb1d9f0046324f78f96eb3 Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Thu, 15 Jan 2026 22:14:10 +0100 Subject: [PATCH] Allow attaching symbol source code to LLM, with execution costs. --- profiler/src/profiler/TracySourceView.cpp | 39 ++++++++++++++++++++++- profiler/src/profiler/TracySourceView.hpp | 2 +- 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/profiler/src/profiler/TracySourceView.cpp b/profiler/src/profiler/TracySourceView.cpp index e4186dac..09596a06 100644 --- a/profiler/src/profiler/TracySourceView.cpp +++ b/profiler/src/profiler/TracySourceView.cpp @@ -1865,7 +1865,7 @@ static uint32_t GetGoodnessColor( float inRatio ) return GoodnessColor[ratio]; } -void SourceView::RenderSymbolSourceView( const AddrStatData& as, Worker& worker, const View& view, bool hasInlines ) +void SourceView::RenderSymbolSourceView( const AddrStatData& as, Worker& worker, View& view, bool hasInlines ) { const auto scale = GetScale(); if( hasInlines && !m_calcInlineStats && ( ( as.ipTotalAsm.local + as.ipTotalAsm.ext ) > 0 || ( view.m_statRange.active && worker.GetSamplesForSymbol( m_baseAddr ) ) ) ) @@ -1929,6 +1929,43 @@ void SourceView::RenderSymbolSourceView( const AddrStatData& as, Worker& worker, ImGui::EndTooltip(); } } + if( s_config.llm ) + { + ImGui::SameLine(); + if( ImGui::SmallButton( ICON_FA_ROBOT "##src" ) ) + { + nlohmann::json json = { + { "type", "source", }, + { "file", m_source.filename() }, + { "code", nlohmann::json::array() } + }; + + auto& code = json["code"]; + auto& lines = m_source.get(); + + int idx = 1; + for( auto& line : lines ) + { + nlohmann::json l = { + { "line", idx }, + { "text", std::string( line.begin, line.end ) } + }; + + auto it = as.ipCountSrc.find( idx ); + if( it != as.ipCountSrc.end() ) + { + char buf[32]; + snprintf( buf, sizeof(buf), "%.4f%%", 100.f * it->second.local / as.ipTotalSrc.local ); + l["cost"] = buf; + } + + code.push_back( l ); + idx++; + } + + view.AddLlmAttachment( json ); + } + } ImGui::SameLine(); TextDisabledUnformatted( ICON_FA_FILE " File:" ); ImGui::SameLine(); diff --git a/profiler/src/profiler/TracySourceView.hpp b/profiler/src/profiler/TracySourceView.hpp index c8e467b8..82e85815 100644 --- a/profiler/src/profiler/TracySourceView.hpp +++ b/profiler/src/profiler/TracySourceView.hpp @@ -183,7 +183,7 @@ private: void RenderSimpleSourceView(); void RenderSymbolView( Worker& worker, View& view ); - void RenderSymbolSourceView( const AddrStatData& as, Worker& worker, const View& view, bool hasInlines ); + void RenderSymbolSourceView( const AddrStatData& as, Worker& worker, View& view, bool hasInlines ); uint64_t RenderSymbolAsmView( const AddrStatData& as, Worker& worker, View& view ); void RenderLine( const Tokenizer::Line& line, int lineNum, const AddrStat& ipcnt, const AddrStatData& as, Worker* worker, const View* view );