From 655b8295cf35a0fb72eaecaeb988db515da2a9b0 Mon Sep 17 00:00:00 2001 From: David McCloskey Date: Thu, 9 Jul 2026 12:16:17 -0500 Subject: [PATCH 1/2] Enhance Flame Graph View with Sorting Functionality Added a "Sort" button to the Flame Graph view, allowing users to sort threads based on group hints, thread names, and IDs. Updated the child window to always show a vertical scrollbar for better usability. --- profiler/src/profiler/TracyView_FlameGraph.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/profiler/src/profiler/TracyView_FlameGraph.cpp b/profiler/src/profiler/TracyView_FlameGraph.cpp index 5db2f369..adcebda8 100644 --- a/profiler/src/profiler/TracyView_FlameGraph.cpp +++ b/profiler/src/profiler/TracyView_FlameGraph.cpp @@ -1069,6 +1069,16 @@ void View::DrawFlameGraph() m_flameGraphViewEnd = 0; m_flameGraphPan = 0; } + ImGui::SameLine(); + if( ImGui::SmallButton( "Sort" ) ) + { + pdqsort_branchless( m_threadOrder.begin(), m_threadOrder.end(), [this] ( const auto& lhs, const auto& rhs ) { + if( lhs->groupHint != rhs->groupHint ) return lhs->groupHint < rhs->groupHint; + const auto cmp = strcmp( m_worker.GetThreadName( lhs->id ), m_worker.GetThreadName( rhs->id ) ); + if( cmp != 0 ) return cmp < 0; + return lhs->id < rhs->id; + } ); + } const auto& style = ImGui::GetStyle(); float probe = 0; @@ -1084,7 +1094,7 @@ void View::DrawFlameGraph() const auto rows = ( tsz + cols - 1 ) / cols; const auto rowsVisible = std::min( rows, 7.5f ); const auto rowsHeight = ImGui::GetTextLineHeightWithSpacing() * rowsVisible; - ImGui::BeginChild( "###flamegraphthreadrows", ImVec2( -1, rowsHeight ) ); + ImGui::BeginChild( "###flamegraphthreadrows", ImVec2( -1, rowsHeight ), false, ImGuiWindowFlags_AlwaysVerticalScrollbar ); int idx = 0; ImGui::BeginTable( "##flamegraphthreadcols", cols, ImGuiTableFlags_NoSavedSettings ); From 7d1a37de2df05a377e2967eb71084d8bb341c867 Mon Sep 17 00:00:00 2001 From: David McCloskey Date: Fri, 10 Jul 2026 12:00:48 -0500 Subject: [PATCH 2/2] Pulling implementation in to a separate function. --- profiler/src/profiler/TracyView.hpp | 11 +++++++++++ profiler/src/profiler/TracyView_FlameGraph.cpp | 7 +------ profiler/src/profiler/TracyView_Options.cpp | 7 +------ 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/profiler/src/profiler/TracyView.hpp b/profiler/src/profiler/TracyView.hpp index c9d7dbdf..1b15884b 100644 --- a/profiler/src/profiler/TracyView.hpp +++ b/profiler/src/profiler/TracyView.hpp @@ -31,6 +31,7 @@ #include "../server/TracyWorker.hpp" #include "../server/tracy_robin_hood.h" #include "../server/TracyVector.hpp" +#include "../server/tracy_pdqsort.h" #ifndef __EMSCRIPTEN__ # include "TracyLlm.hpp" @@ -517,6 +518,16 @@ private: return it->second; } + tracy_force_inline void SortThreads() + { + pdqsort_branchless( m_threadOrder.begin(), m_threadOrder.end(), [this] ( const auto& lhs, const auto& rhs ) { + if( lhs->groupHint != rhs->groupHint ) return lhs->groupHint < rhs->groupHint; + const auto cmp = strcmp( m_worker.GetThreadName( lhs->id ), m_worker.GetThreadName( rhs->id ) ); + if( cmp != 0 ) return cmp < 0; + return lhs->id < rhs->id; + } ); + } + static int64_t AdjustGpuTime( int64_t time, int64_t begin, int drift ); static const char* DecodeContextSwitchState( uint8_t state ); diff --git a/profiler/src/profiler/TracyView_FlameGraph.cpp b/profiler/src/profiler/TracyView_FlameGraph.cpp index adcebda8..77d234af 100644 --- a/profiler/src/profiler/TracyView_FlameGraph.cpp +++ b/profiler/src/profiler/TracyView_FlameGraph.cpp @@ -1072,12 +1072,7 @@ void View::DrawFlameGraph() ImGui::SameLine(); if( ImGui::SmallButton( "Sort" ) ) { - pdqsort_branchless( m_threadOrder.begin(), m_threadOrder.end(), [this] ( const auto& lhs, const auto& rhs ) { - if( lhs->groupHint != rhs->groupHint ) return lhs->groupHint < rhs->groupHint; - const auto cmp = strcmp( m_worker.GetThreadName( lhs->id ), m_worker.GetThreadName( rhs->id ) ); - if( cmp != 0 ) return cmp < 0; - return lhs->id < rhs->id; - } ); + SortThreads(); } const auto& style = ImGui::GetStyle(); diff --git a/profiler/src/profiler/TracyView_Options.cpp b/profiler/src/profiler/TracyView_Options.cpp index 8ad879bb..c9c341cd 100644 --- a/profiler/src/profiler/TracyView_Options.cpp +++ b/profiler/src/profiler/TracyView_Options.cpp @@ -698,12 +698,7 @@ void View::DrawOptions() ImGui::SameLine(); if( ImGui::SmallButton( "Sort" ) ) { - pdqsort_branchless( m_threadOrder.begin(), m_threadOrder.end(), [this] ( const auto& lhs, const auto& rhs ) { - if( lhs->groupHint != rhs->groupHint ) return lhs->groupHint < rhs->groupHint; - const auto cmp = strcmp( m_worker.GetThreadName( lhs->id ), m_worker.GetThreadName( rhs->id ) ); - if( cmp != 0 ) return cmp < 0; - return lhs->id < rhs->id; - } ); + SortThreads(); } const auto wposx = ImGui::GetCursorScreenPos().x;