From 76f0c8fafed9f0d43a40c94d099fce2a6d4b05f4 Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Mon, 30 Apr 2018 03:54:09 +0200 Subject: [PATCH] Sort source location zones on a separate thread. --- server/TracyView.cpp | 21 +++++++++++++++++++++ server/TracyWorker.cpp | 24 +++++++++++++++++------- server/TracyWorker.hpp | 6 +++++- 3 files changed, 43 insertions(+), 8 deletions(-) diff --git a/server/TracyView.cpp b/server/TracyView.cpp index ac769bf0..a55c8b9f 100644 --- a/server/TracyView.cpp +++ b/server/TracyView.cpp @@ -3085,6 +3085,13 @@ void View::DrawFindZone() ImGui::TextWrapped( "Collection of statistical data is disabled in this build." ); ImGui::TextWrapped( "Rebuild without the TRACY_NO_STATISTICS macro to enable zone search." ); #else + if( !m_worker.AreSourceLocationZonesReady() ) + { + ImGui::TextWrapped( "Please wait, computing data..." ); + ImGui::End(); + return; + } + ImGui::InputText( "", m_findZone.pattern, 1024 ); ImGui::SameLine(); @@ -3849,6 +3856,13 @@ void View::DrawCompare() return; } + if( !m_worker.AreSourceLocationZonesReady() || !m_compare.second->AreSourceLocationZonesReady() ) + { + ImGui::TextWrapped( "Please wait, computing data..." ); + ImGui::End(); + return; + } + ImGui::TextDisabled( "This trace:" ); ImGui::SameLine(); ImGui::Text( "%s", m_worker.GetCaptureName().c_str() ); @@ -4371,6 +4385,13 @@ void View::DrawStatistics() ImGui::TextWrapped( "Collection of statistical data is disabled in this build." ); ImGui::TextWrapped( "Rebuild without the TRACY_NO_STATISTICS macro to enable statistics view." ); #else + if( !m_worker.AreSourceLocationZonesReady() ) + { + ImGui::TextWrapped( "Please wait, computing data..." ); + ImGui::End(); + return; + } + auto& slz = m_worker.GetSourceLocationZones(); Vector srcloc; srcloc.reserve( slz.size() ); diff --git a/server/TracyWorker.cpp b/server/TracyWorker.cpp index 62fa1366..a3f65cbe 100644 --- a/server/TracyWorker.cpp +++ b/server/TracyWorker.cpp @@ -184,6 +184,10 @@ Worker::Worker( const char* addr ) { m_data.sourceLocationExpand.push_back( 0 ); +#ifndef TRACY_NO_STATISTICS + m_data.sourceLocationZonesReady = true; +#endif + m_thread = std::thread( [this] { Exec(); } ); SetThreadName( m_thread, "Tracy Worker" ); } @@ -293,6 +297,7 @@ Worker::Worker( FileRead& f, EventType::Type eventMask ) } #ifndef TRACY_NO_STATISTICS + m_data.sourceLocationZonesReady = false; m_data.sourceLocationZones.reserve( sle + sz ); for( uint64_t i=1; istart < rhs.zone->start; } ); - } + m_threadZones = std::thread( [this] { + for( auto& v : m_data.sourceLocationZones ) + { + auto& zones = v.second.zones; + pdqsort_branchless( zones.begin(), zones.end(), []( const auto& lhs, const auto& rhs ) { return lhs.zone->start < rhs.zone->start; } ); + } + std::lock_guard lock( m_data.lock ); + m_data.sourceLocationZonesReady = true; + } ); #endif f.Read( &sz, sizeof( sz ) ); @@ -532,7 +541,7 @@ Worker::Worker( FileRead& f, EventType::Type eventMask ) f.Read( &m_data.memory.low, sizeof( m_data.memory.low ) ); f.Read( &m_data.memory.usage, sizeof( m_data.memory.usage ) ); - m_loadThread = std::thread( [this] { ReconstructMemAllocPlot(); } ); + m_threadMemory = std::thread( [this] { ReconstructMemAllocPlot(); } ); } else { @@ -562,7 +571,8 @@ Worker::~Worker() Shutdown(); if( m_thread.joinable() ) m_thread.join(); - if( m_loadThread.joinable() ) m_loadThread.join(); + if( m_threadMemory.joinable() ) m_threadMemory.join(); + if( m_threadZones.joinable() ) m_threadZones.join(); delete[] m_buffer; LZ4_freeStreamDecode( m_stream ); diff --git a/server/TracyWorker.hpp b/server/TracyWorker.hpp index 6e4b932d..82a0f188 100644 --- a/server/TracyWorker.hpp +++ b/server/TracyWorker.hpp @@ -93,6 +93,7 @@ class Worker Vector sourceLocationExpand; #ifndef TRACY_NO_STATISTICS flat_hash_map> sourceLocationZones; + bool sourceLocationZonesReady; #endif std::map lockMap; @@ -157,6 +158,7 @@ public: #ifndef TRACY_NO_STATISTICS const SourceLocationZones& GetZonesForSourceLocation( int32_t srcloc ) const; const flat_hash_map>& GetSourceLocationZones() const { return m_data.sourceLocationZones; } + bool AreSourceLocationZonesReady() const { return m_data.sourceLocationZonesReady; } #endif tracy_force_inline uint16_t CompressThread( uint64_t thread ); @@ -254,11 +256,13 @@ private: Socket m_sock; std::string m_addr; - std::thread m_thread, m_loadThread; + std::thread m_thread; std::atomic m_connected; std::atomic m_hasData; std::atomic m_shutdown; + std::thread m_threadMemory, m_threadZones; + int64_t m_delay; int64_t m_resolution; double m_timerMul;