From 92c872dfc085400b93bce0635813a9577b151094 Mon Sep 17 00:00:00 2001 From: Dedmen Miller Date: Thu, 7 Feb 2019 12:25:03 +0100 Subject: [PATCH 1/3] Added sorting for findZone zonelist --- server/TracyView.cpp | 38 ++++++++++++++++++++++++++++++++++---- server/TracyView.hpp | 1 + 2 files changed, 35 insertions(+), 4 deletions(-) diff --git a/server/TracyView.cpp b/server/TracyView.cpp index 310e53bc..65271d8a 100644 --- a/server/TracyView.cpp +++ b/server/TracyView.cpp @@ -5669,11 +5669,11 @@ void View::DrawFindZone() { ImGui::Columns( 3, hdrString ); ImGui::Separator(); - ImGui::Text( "Time from start" ); + if( ImGui::SmallButton( "Time from start" ) ) m_findZoneSort = 0; ImGui::NextColumn(); - ImGui::Text( "Execution time" ); + if( ImGui::SmallButton( "Execution time" ) ) m_findZoneSort = 1; ImGui::NextColumn(); - ImGui::Text( "Name" ); + if( ImGui::SmallButton( "Name" ) ) m_findZoneSort = 2; ImGui::SameLine(); ImGui::TextDisabled( "(?)" ); if( ImGui::IsItemHovered() ) @@ -5685,7 +5685,37 @@ void View::DrawFindZone() ImGui::NextColumn(); ImGui::Separator(); - for( auto& ev : v->second.zones ) + Vector sortedZones; + sortedZones.reserve_and_use( v->second.zones.size() ); + std::copy(v->second.zones.begin(), v->second.zones.end(), sortedZones.begin()); + + + switch( m_findZoneSort ) + { + case 0: + //Already sorted by time from start + 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 - GetZoneChildTimeFast( *lhs )) > (m_worker.GetZoneEndDirect( *rhs ) - rhs->start - GetZoneChildTimeFast( *rhs )); } ); + 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: + pdqsort_branchless( sortedZones.begin(), sortedZones.end(), [this]( const auto& lhs, const auto& rhs ) + { + if (lhs->name.active != rhs->name.active) return lhs->name.active > rhs->name.active; + + return strcmp(m_worker.GetString( lhs->name ), m_worker.GetString( rhs->name )) < 0; + } ); + break; + default: + assert( false ); + break; + } + + + for( auto& ev : sortedZones ) { const auto end = m_worker.GetZoneEndDirect( *ev ); auto timespan = end - ev->start; diff --git a/server/TracyView.hpp b/server/TracyView.hpp index 362a0b2d..37cbc82f 100644 --- a/server/TracyView.hpp +++ b/server/TracyView.hpp @@ -267,6 +267,7 @@ private: bool m_goToFrame = false; int m_statSort = 0; + int m_findZoneSort = 0; bool m_statSelf = false; bool m_showCallstackFrameAddress = false; bool m_showUnknownFrames = true; From 59ae188a7ffe95d704b53eda3ee68c227ac1ecba Mon Sep 17 00:00:00 2001 From: Dedmen Miller Date: Thu, 7 Feb 2019 14:51:34 +0100 Subject: [PATCH 2/3] Cleanup --- server/TracyView.cpp | 64 +++++++++++++++++++++++++------------------- server/TracyView.hpp | 3 ++- 2 files changed, 38 insertions(+), 29 deletions(-) diff --git a/server/TracyView.cpp b/server/TracyView.cpp index 65271d8a..73f55d40 100644 --- a/server/TracyView.cpp +++ b/server/TracyView.cpp @@ -5669,11 +5669,11 @@ void View::DrawFindZone() { ImGui::Columns( 3, hdrString ); ImGui::Separator(); - if( ImGui::SmallButton( "Time from start" ) ) m_findZoneSort = 0; + if( ImGui::SmallButton( "Time from start" ) ) m_findZone.tableSortBy = FindZone::TableSortBy::Starttime; ImGui::NextColumn(); - if( ImGui::SmallButton( "Execution time" ) ) m_findZoneSort = 1; + if( ImGui::SmallButton( "Execution time" ) ) m_findZone.tableSortBy = FindZone::TableSortBy::Runtime; ImGui::NextColumn(); - if( ImGui::SmallButton( "Name" ) ) m_findZoneSort = 2; + if( ImGui::SmallButton( "Name" ) ) m_findZone.tableSortBy = FindZone::TableSortBy::Name; ImGui::SameLine(); ImGui::TextDisabled( "(?)" ); if( ImGui::IsItemHovered() ) @@ -5685,37 +5685,45 @@ void View::DrawFindZone() ImGui::NextColumn(); ImGui::Separator(); + Vector* zonesToIterate = &v->second.zones; Vector sortedZones; - sortedZones.reserve_and_use( v->second.zones.size() ); - std::copy(v->second.zones.begin(), v->second.zones.end(), sortedZones.begin()); - - switch( m_findZoneSort ) + if ( m_findZone.tableSortBy != FindZone::TableSortBy::Starttime ) { - case 0: - //Already sorted by time from start - 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 - GetZoneChildTimeFast( *lhs )) > (m_worker.GetZoneEndDirect( *rhs ) - rhs->start - GetZoneChildTimeFast( *rhs )); } ); - 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: - pdqsort_branchless( sortedZones.begin(), sortedZones.end(), [this]( const auto& lhs, const auto& rhs ) - { - if (lhs->name.active != rhs->name.active) return lhs->name.active > rhs->name.active; + zonesToIterate = &sortedZones; + sortedZones.reserve_and_use( v->second.zones.size() ); + std::copy(v->second.zones.begin(), v->second.zones.end(), sortedZones.begin()); - return strcmp(m_worker.GetString( lhs->name ), m_worker.GetString( rhs->name )) < 0; - } ); - break; - default: - assert( false ); - break; + + switch( m_findZone.tableSortBy ) + { + case FindZone::TableSortBy::Runtime: + if( m_findZone.selfTime ) + pdqsort_branchless( sortedZones.begin(), sortedZones.end(), [this]( const auto& lhs, const auto& rhs ) + { + return (m_worker.GetZoneEndDirect( *lhs ) - lhs->start - GetZoneChildTimeFast( *lhs )) + > + (m_worker.GetZoneEndDirect( *rhs ) - rhs->start - GetZoneChildTimeFast( *rhs )); + } ); + 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 FindZone::TableSortBy::Name: + pdqsort_branchless( sortedZones.begin(), sortedZones.end(), [this]( const auto& lhs, const auto& rhs ) + { + if (lhs->name.active != rhs->name.active) return lhs->name.active > rhs->name.active; + + return strcmp(m_worker.GetString( lhs->name ), m_worker.GetString( rhs->name )) < 0; + } ); + break; + default: + assert( false ); + break; + } + } - - for( auto& ev : sortedZones ) + for( auto& ev : *zonesToIterate ) { const auto end = m_worker.GetZoneEndDirect( *ev ); auto timespan = end - ev->start; diff --git a/server/TracyView.hpp b/server/TracyView.hpp index 37cbc82f..8cff0eb0 100644 --- a/server/TracyView.hpp +++ b/server/TracyView.hpp @@ -267,7 +267,6 @@ private: bool m_goToFrame = false; int m_statSort = 0; - int m_findZoneSort = 0; bool m_statSelf = false; bool m_showCallstackFrameAddress = false; bool m_showUnknownFrames = true; @@ -303,6 +302,7 @@ private: enum : uint64_t { Unselected = std::numeric_limits::max() - 1 }; enum class GroupBy : int { Thread, UserText, Callstack }; enum class SortBy : int { Order, Count, Time, Mtpc }; + enum class TableSortBy : int { Starttime, Runtime, Name }; struct Group { @@ -324,6 +324,7 @@ private: bool selfTime = 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; From ab0dc0da11d3308a85ae9e4237a25e346106708c Mon Sep 17 00:00:00 2001 From: Dedmen Miller Date: Thu, 7 Feb 2019 16:10:28 +0100 Subject: [PATCH 3/3] Use memcpy --- server/TracyView.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/server/TracyView.cpp b/server/TracyView.cpp index 73f55d40..247a146b 100644 --- a/server/TracyView.cpp +++ b/server/TracyView.cpp @@ -5692,8 +5692,7 @@ void View::DrawFindZone() { zonesToIterate = &sortedZones; sortedZones.reserve_and_use( v->second.zones.size() ); - std::copy(v->second.zones.begin(), v->second.zones.end(), sortedZones.begin()); - + memcpy(sortedZones.data(), v->second.zones.data(), sizeof(ZoneEvent*)*v->second.zones.size()); switch( m_findZone.tableSortBy ) {