From 6300f5918306a753159bd001c184b78bda77831d Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Wed, 9 Dec 2020 02:13:14 +0100 Subject: [PATCH] Use tables in find zone zones list. --- server/TracyView.cpp | 125 +++++++++++++++++++++++++++++-------------- server/TracyView.hpp | 2 - 2 files changed, 86 insertions(+), 41 deletions(-) diff --git a/server/TracyView.cpp b/server/TracyView.cpp index a82ca7c3..22ac6257 100644 --- a/server/TracyView.cpp +++ b/server/TracyView.cpp @@ -10863,64 +10863,110 @@ void View::DrawFindZone() void View::DrawZoneList( const Vector>& zones ) { - ImGui::Columns( 3 ); - ImGui::Separator(); - if( ImGui::SmallButton( "Time from start" ) ) m_findZone.tableSortBy = FindZone::TableSortBy::Starttime; - ImGui::NextColumn(); - if( ImGui::SmallButton( "Execution time" ) ) m_findZone.tableSortBy = FindZone::TableSortBy::Runtime; - ImGui::NextColumn(); - if( ImGui::SmallButton( "Name" ) ) m_findZone.tableSortBy = FindZone::TableSortBy::Name; - ImGui::SameLine(); - DrawHelpMarker( "Only displayed if custom zone name is set." ); - ImGui::NextColumn(); - ImGui::Separator(); + if( !ImGui::BeginTable( "##zonelist", 3, ImGuiTableFlags_Resizable | ImGuiTableFlags_Hideable | ImGuiTableFlags_BordersInnerV | ImGuiTableFlags_Sortable | ImGuiTableFlags_ScrollY ) ) return; + ImGui::TableSetupScrollFreeze( 0, 1 ); + ImGui::TableSetupColumn( "Time from start" ); + ImGui::TableSetupColumn( "Execution time", ImGuiTableColumnFlags_PreferSortDescending ); + ImGui::TableSetupColumn( "Name", ImGuiTableColumnFlags_NoSort ); + ImGui::TableHeadersRow(); const Vector>* zonesToIterate = &zones; Vector> sortedZones; - if( m_findZone.tableSortBy != FindZone::TableSortBy::Starttime ) + const auto& sortspec = *ImGui::TableGetSortSpecs()->Specs; + if( sortspec.ColumnIndex != 0 || sortspec.SortDirection != ImGuiSortDirection_Ascending ) { zonesToIterate = &sortedZones; sortedZones.reserve_and_use( zones.size() ); memcpy( sortedZones.data(), zones.data(), zones.size() * sizeof( decltype( *zones.begin() ) ) ); - switch( m_findZone.tableSortBy ) + switch( sortspec.ColumnIndex ) { - case FindZone::TableSortBy::Runtime: + case 0: + assert( sortspec.SortDirection != ImGuiSortDirection_Descending ); + std::reverse( sortedZones.begin(), sortedZones.end() ); + break; + case 1: if( m_findZone.selfTime ) { - pdqsort_branchless( sortedZones.begin(), sortedZones.end(), [this]( const auto& lhs, const auto& rhs ) { - return m_worker.GetZoneEndDirect( *lhs ) - lhs->Start() - this->GetZoneChildTimeFast( *lhs ) > - m_worker.GetZoneEndDirect( *rhs ) - rhs->Start() - this->GetZoneChildTimeFast( *rhs ); - } ); + if( sortspec.SortDirection == ImGuiSortDirection_Descending ) + { + pdqsort_branchless( sortedZones.begin(), sortedZones.end(), [this]( const auto& lhs, const auto& rhs ) { + return m_worker.GetZoneEndDirect( *lhs ) - lhs->Start() - this->GetZoneChildTimeFast( *lhs ) > + m_worker.GetZoneEndDirect( *rhs ) - rhs->Start() - this->GetZoneChildTimeFast( *rhs ); + } ); + } + else + { + pdqsort_branchless( sortedZones.begin(), sortedZones.end(), [this]( const auto& lhs, const auto& rhs ) { + return m_worker.GetZoneEndDirect( *lhs ) - lhs->Start() - this->GetZoneChildTimeFast( *lhs ) < + m_worker.GetZoneEndDirect( *rhs ) - rhs->Start() - this->GetZoneChildTimeFast( *rhs ); + } ); + } } else if( m_findZone.runningTime ) + { + if( sortspec.SortDirection == ImGuiSortDirection_Descending ) + { + pdqsort_branchless( sortedZones.begin(), sortedZones.end(), [this]( const auto& lhs, const auto& rhs ) { + const auto ctx0 = m_worker.GetContextSwitchData( GetZoneThread( *lhs ) ); + const auto ctx1 = m_worker.GetContextSwitchData( GetZoneThread( *rhs ) ); + int64_t t0, t1; + uint64_t c0, c1; + GetZoneRunningTime( ctx0, *lhs, t0, c0 ); + GetZoneRunningTime( ctx1, *rhs, t1, c1 ); + return t0 > t1; + } ); + } + else + { + pdqsort_branchless( sortedZones.begin(), sortedZones.end(), [this]( const auto& lhs, const auto& rhs ) { + const auto ctx0 = m_worker.GetContextSwitchData( GetZoneThread( *lhs ) ); + const auto ctx1 = m_worker.GetContextSwitchData( GetZoneThread( *rhs ) ); + int64_t t0, t1; + uint64_t c0, c1; + GetZoneRunningTime( ctx0, *lhs, t0, c0 ); + GetZoneRunningTime( ctx1, *rhs, t1, c1 ); + return t0 < t1; + } ); + } + } + else + { + if( sortspec.SortDirection == ImGuiSortDirection_Descending ) + { + pdqsort_branchless( sortedZones.begin(), sortedZones.end(), [this]( const auto& lhs, const auto& rhs ) { + return m_worker.GetZoneEndDirect( *lhs ) - lhs->Start() > m_worker.GetZoneEndDirect( *rhs ) - rhs->Start(); + } ); + } + else + { + pdqsort_branchless( sortedZones.begin(), sortedZones.end(), [this]( const auto& lhs, const auto& rhs ) { + return m_worker.GetZoneEndDirect( *lhs ) - lhs->Start() < m_worker.GetZoneEndDirect( *rhs ) - rhs->Start(); + } ); + } + } + break; + case 2: + if( sortspec.SortDirection == ImGuiSortDirection_Descending ) { pdqsort_branchless( sortedZones.begin(), sortedZones.end(), [this]( const auto& lhs, const auto& rhs ) { - const auto ctx0 = m_worker.GetContextSwitchData( GetZoneThread( *lhs ) ); - const auto ctx1 = m_worker.GetContextSwitchData( GetZoneThread( *rhs ) ); - int64_t t0, t1; - uint64_t c0, c1; - GetZoneRunningTime( ctx0, *lhs, t0, c0 ); - GetZoneRunningTime( ctx1, *rhs, t1, c1 ); - return t0 > t1; + const auto hle = m_worker.HasZoneExtra( *lhs ); + const auto hre = m_worker.HasZoneExtra( *rhs ); + if( !( hle & hre ) ) return hle > hre; + return strcmp( m_worker.GetString( m_worker.GetZoneExtra( *lhs ).name ), m_worker.GetString( m_worker.GetZoneExtra( *rhs ).name ) ) < 0; } ); } else { pdqsort_branchless( sortedZones.begin(), sortedZones.end(), [this]( const auto& lhs, const auto& rhs ) { - return m_worker.GetZoneEndDirect( *lhs ) - lhs->Start() > m_worker.GetZoneEndDirect( *rhs ) - rhs->Start(); + const auto hle = m_worker.HasZoneExtra( *lhs ); + const auto hre = m_worker.HasZoneExtra( *rhs ); + if( !( hle & hre ) ) return hle < hre; + return strcmp( m_worker.GetString( m_worker.GetZoneExtra( *lhs ).name ), m_worker.GetString( m_worker.GetZoneExtra( *rhs ).name ) ) > 0; } ); } break; - case FindZone::TableSortBy::Name: - pdqsort_branchless( sortedZones.begin(), sortedZones.end(), [this]( const auto& lhs, const auto& rhs ) { - const auto hle = m_worker.HasZoneExtra( *lhs ); - const auto hre = m_worker.HasZoneExtra( *rhs ); - if( !( hle & hre ) ) return hle > hre; - return strcmp( m_worker.GetString( m_worker.GetZoneExtra( *lhs ).name ), m_worker.GetString( m_worker.GetZoneExtra( *rhs ).name ) ) < 0; - } ); - break; default: assert( false ); break; @@ -10933,6 +10979,9 @@ void View::DrawZoneList( const Vector>& zones ) { for( auto i=clipper.DisplayStart; i>& zones ) m_zoneHover2 = ev; } - ImGui::NextColumn(); + ImGui::TableNextColumn(); ImGui::TextUnformatted( TimeToString( timespan ) ); - ImGui::NextColumn(); + ImGui::TableNextColumn(); if( m_worker.HasZoneExtra( *ev ) ) { const auto& extra = m_worker.GetZoneExtra( *ev ); @@ -10976,13 +11025,11 @@ void View::DrawZoneList( const Vector>& zones ) ImGui::TextUnformatted( m_worker.GetString( extra.name ) ); } } - ImGui::NextColumn(); if( m_zoneHover == ev ) ImGui::PopStyleColor(); ImGui::PopID(); } } - ImGui::Columns( 1 ); - ImGui::Separator(); + ImGui::EndTable(); ImGui::TreePop(); } diff --git a/server/TracyView.hpp b/server/TracyView.hpp index 781d1937..438955dc 100644 --- a/server/TracyView.hpp +++ b/server/TracyView.hpp @@ -488,7 +488,6 @@ private: enum : uint64_t { Unselected = std::numeric_limits::max() - 1 }; enum class GroupBy : int { Thread, UserText, ZoneName, Callstack, Parent, NoGrouping }; enum class SortBy : int { Order, Count, Time, Mtpc }; - enum class TableSortBy : int { Starttime, Runtime, Name }; struct Group { @@ -513,7 +512,6 @@ private: bool runningTime = false; GroupBy groupBy = GroupBy::Thread; SortBy sortBy = SortBy::Count; - TableSortBy tableSortBy = TableSortBy::Starttime; Region highlight; int64_t hlOrig_t0, hlOrig_t1; int64_t numBins = -1;