From 5733b420a11d86e9a286aeffeb2d934929ee60fd Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Sun, 2 Sep 2018 03:17:05 +0200 Subject: [PATCH] Use the same algorithm for selection group binning. --- server/TracyView.cpp | 128 +++++++++++++++++++++++++++---------------- server/TracyView.hpp | 12 +++- 2 files changed, 92 insertions(+), 48 deletions(-) diff --git a/server/TracyView.cpp b/server/TracyView.cpp index e8c67a04..718bee47 100644 --- a/server/TracyView.cpp +++ b/server/TracyView.cpp @@ -4628,6 +4628,34 @@ void View::DrawFindZone() m_findZone.sortedNum = i; } + if( m_findZone.selGroup != m_findZone.Unselected ) + { + if( m_findZone.selSortNum != m_findZone.sortedNum ) + { + const auto selGroup = m_findZone.selGroup; + const auto groupBy = m_findZone.groupBy; + + auto& vec = m_findZone.selSort; + vec.reserve( zsz ); + auto act = m_findZone.selSortActive; + size_t i; + for( i=m_findZone.selSortNum; iend - ev.zone->start ); + act++; + } + } + auto mid = vec.begin() + m_findZone.selSortActive; + pdqsort_branchless( mid, vec.end() ); + std::inplace_merge( vec.begin(), mid, vec.end() ); + m_findZone.selSortNum = m_findZone.sortedNum; + m_findZone.selSortActive = act; + } + } + if( tmin != std::numeric_limits::max() ) { ImGui::Checkbox( "Log values", &m_findZone.logVal ); @@ -4649,8 +4677,6 @@ void View::DrawFindZone() ImGui::Text( "%s - %s (%s)", TimeToString( tmin ), TimeToString( tmax ), TimeToString( tmax - tmin ) ); const auto dt = double( tmax - tmin ); - const auto selGroup = m_findZone.selGroup; - const auto groupBy = m_findZone.groupBy; const auto cumulateTime = m_findZone.cumulateTime; if( dt > 0 ) @@ -4686,42 +4712,47 @@ void View::DrawFindZone() { const auto tMinLog = log10( tmin ); const auto zmax = ( log10( tmax ) - tMinLog ) / numBins; - auto zit = sorted.begin(); - while( zit != sorted.end() && *zit == 0 ) zit++; - for( int64_t i=0; i= s && *end <= e ) selectionTime += timeSum; - } - zit = nit; - } - const auto timeSum = std::accumulate( zit, sorted.end(), int64_t( 0 ) ); - bins[numBins-1] += std::distance( zit, sorted.end() ); - binTime[numBins-1] += timeSum; - if( m_findZone.highlight.active && *zit >= s && *(sorted.end()-1) <= e ) selectionTime += timeSum; - - if( selGroup != m_findZone.Unselected ) - { - const auto idt = numBins / ( log10( tmax ) - tMinLog ); - for( auto& ev : zones ) - { - if( selGroup == GetSelectionTarget( ev, groupBy ) ) + const auto nextBinVal = int64_t( pow( 10.0, tMinLog + ( i+1 ) * zmax ) ); + auto nit = std::lower_bound( zit, sorted.end(), nextBinVal ); + const auto distance = std::distance( zit, nit ); + const auto timeSum = std::accumulate( zit, nit, int64_t( 0 ) ); + bins[i] = distance; + binTime[i] = timeSum; + if( m_findZone.highlight.active ) { - const auto timeSpan = m_worker.GetZoneEndDirect( *ev.zone ) - ev.zone->start; - if( timeSpan != 0 ) - { - const auto bin = std::min( numBins - 1, int64_t( ( log10( timeSpan ) - tMinLog ) * idt ) ); - if( cumulateTime ) selBin[bin] += timeSpan; else selBin[bin]++; - } + auto end = nit == zit ? zit : nit-1; + if( *zit >= s && *end <= e ) selectionTime += timeSum; } + zit = nit; + } + const auto timeSum = std::accumulate( zit, sorted.end(), int64_t( 0 ) ); + bins[numBins-1] += std::distance( zit, sorted.end() ); + binTime[numBins-1] += timeSum; + if( m_findZone.highlight.active && *zit >= s && *(sorted.end()-1) <= e ) selectionTime += timeSum; + } + + if( m_findZone.selGroup != m_findZone.Unselected ) + { + auto zit = m_findZone.selSort.begin(); + while( zit != m_findZone.selSort.end() && *zit == 0 ) zit++; + for( int64_t i=0; i= s && *(sorted.end()-1) <= e ) selectionTime += timeSum; - if( selGroup != m_findZone.Unselected ) + if( m_findZone.selGroup != m_findZone.Unselected ) { - const auto idt = numBins / dt; - for( auto& ev : zones ) + auto zit = m_findZone.selSort.begin(); + while( zit != m_findZone.selSort.end() && *zit == 0 ) zit++; + for( int64_t i=0; istart; - if( timeSpan != 0 ) - { - const auto bin = std::min( numBins - 1, int64_t( ( timeSpan - tmin ) * idt ) ); - if( cumulateTime ) selBin[bin] += timeSpan; else selBin[bin]++; - } + selBin[i] = std::accumulate( zit, nit, int64_t( 0 ) ); } + else + { + selBin[i] = std::distance( zit, nit ); + } + zit = nit; } } } @@ -4825,9 +4859,9 @@ void View::DrawFindZone() { TextFocused( "Selection time:", "none" ); } - if( selGroup != m_findZone.Unselected ) + if( m_findZone.selGroup != m_findZone.Unselected ) { - TextFocused( "Zone group time:", TimeToString( m_findZone.groups[selGroup].time ) ); + TextFocused( "Zone group time:", TimeToString( m_findZone.groups[m_findZone.selGroup].time ) ); } else { @@ -5257,6 +5291,7 @@ void View::DrawFindZone() if( ImGui::IsItemClicked() ) { m_findZone.selGroup = v->first; + m_findZone.ResetSelection(); } ImGui::PopID(); ImGui::SameLine(); @@ -5327,6 +5362,7 @@ void View::DrawFindZone() if( ImGui::IsItemHovered() && ImGui::IsMouseClicked( 1 ) ) { m_findZone.selGroup = m_findZone.Unselected; + m_findZone.ResetSelection(); } } #endif diff --git a/server/TracyView.hpp b/server/TracyView.hpp index d3791a3e..b450a23b 100644 --- a/server/TracyView.hpp +++ b/server/TracyView.hpp @@ -292,8 +292,8 @@ private: int64_t hlOrig_t0, hlOrig_t1; int64_t numBins = -1; std::unique_ptr bins, binTime, selBin; - std::vector sorted; - size_t sortedNum; + std::vector sorted, selSort; + size_t sortedNum, selSortNum, selSortActive; float average; float median; int64_t total; @@ -314,10 +314,18 @@ private: void ResetGroups() { + ResetSelection(); groups.clear(); processed = 0; } + void ResetSelection() + { + selSort.clear(); + selSortNum = 0; + selSortActive = 0; + } + void ShowZone( int32_t srcloc, const char* name ) { show = true;