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.
This commit is contained in:
David McCloskey
2026-07-09 12:16:17 -05:00
parent ac4defb4f3
commit 655b8295cf

View File

@@ -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<float>( 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 );