From b7800be6270b891886054b3a4c816c6186bc2c8e Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Thu, 19 Oct 2017 23:26:21 +0200 Subject: [PATCH] Perform bulk insertion of plot points. --- server/TracyView.cpp | 25 +++++++++++++++++++++++-- server/TracyView.hpp | 2 ++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/server/TracyView.cpp b/server/TracyView.cpp index 4c525bf7..19e06686 100644 --- a/server/TracyView.cpp +++ b/server/TracyView.cpp @@ -381,6 +381,8 @@ void View::Worker() DispatchProcess( ev ); } + HandlePostponedPlots(); + auto t1 = std::chrono::high_resolution_clock::now(); auto td = std::chrono::duration_cast( t1 - t0 ).count(); enum { MbpsUpdateTime = 200 }; @@ -1038,8 +1040,7 @@ void View::InsertPlot( PlotData* plot, PlotItem* item ) { if( plot->min > val ) plot->min = val; else if( plot->max < val ) plot->max = val; - auto it = std::lower_bound( plot->data.begin(), plot->data.end(), time, [] ( const auto& lhs, const auto& rhs ) { return lhs->time < rhs; } ); - plot->data.insert( it, item ); + plot->postpone.push_back( item ); } } @@ -1073,6 +1074,26 @@ void View::HandlePlotName( uint64_t name, std::string&& str ) m_pendingPlots.erase( pit ); } +void View::HandlePostponedPlots() +{ + for( auto& plot : m_plots ) + { + auto& src = plot->postpone; + if( src.empty() ) continue; + auto& dst = plot->data; + std::sort( src.begin(), src.end(), [] ( const auto& l, const auto& r ) { return l->time < r->time; } ); + const auto ds = std::lower_bound( dst.begin(), dst.end(), src.front()->time, [] ( const auto& l, const auto& r ) { return l->time < r; } ); + const auto dsd = std::distance( dst.begin(), ds ) ; + const auto de = std::lower_bound( ds, dst.end(), src.back()->time, [] ( const auto& l, const auto& r ) { return l->time < r; } ); + const auto ded = std::distance( dst.begin(), de ); + std::unique_lock lock( m_lock ); + dst.insert( de, src.begin(), src.end() ); + std::inplace_merge( dst.begin() + dsd, dst.begin() + ded, dst.begin() + ded + src.size(), [] ( const auto& l, const auto& r ) { return l->time < r->time; } ); + lock.unlock(); + src.clear(); + } +} + uint64_t View::GetFrameTime( size_t idx ) const { if( idx < m_frames.size() - 1 ) diff --git a/server/TracyView.hpp b/server/TracyView.hpp index d9bf25c1..6acb980d 100644 --- a/server/TracyView.hpp +++ b/server/TracyView.hpp @@ -88,6 +88,7 @@ private: double max; bool enabled; Vector data; + Vector postpone; }; void Worker(); @@ -132,6 +133,7 @@ private: void InsertPlot( PlotData* plot, int64_t time, double val ); void InsertPlot( PlotData* plot, PlotItem* item ); void HandlePlotName( uint64_t name, std::string&& str ); + void HandlePostponedPlots(); uint64_t GetFrameTime( size_t idx ) const; uint64_t GetFrameBegin( size_t idx ) const;