From d0519499f47e931ab41f5a90be1e8e41015389e6 Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Sun, 18 Mar 2018 20:45:49 +0100 Subject: [PATCH] Store thread id next to zone ptr in source location zone list. --- README.md | 2 +- server/TracyView.cpp | 22 +++++++++++----------- server/TracyWorker.cpp | 14 +++++++------- server/TracyWorker.hpp | 14 +++++++++++--- 4 files changed, 30 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index a6c7aab2..40946760 100644 --- a/README.md +++ b/README.md @@ -129,4 +129,4 @@ Lua instrumentation needs to perform additional work (including memory allocatio You may use named colors predefined in `common/TracyColor.hpp` (included by `Tracy.hpp`). Visual reference: [wikipedia](https://en.wikipedia.org/wiki/X11_color_names). -Tracy server will perform statistical data collection on the fly, if the macro `TRACY_NO_STATISTICS` is not defined. This allows extended analysis of the trace (for example, you can perform a live search for matching zones) at a small CPU processing cost and a considerable memory usage increase (at least 8 bytes per zone). +Tracy server will perform statistical data collection on the fly, if the macro `TRACY_NO_STATISTICS` is not defined. This allows extended analysis of the trace (for example, you can perform a live search for matching zones) at a small CPU processing cost and a considerable memory usage increase (at least 10 bytes per zone). diff --git a/server/TracyView.cpp b/server/TracyView.cpp index 3a4f6cdb..1be92cd1 100644 --- a/server/TracyView.cpp +++ b/server/TracyView.cpp @@ -2805,7 +2805,7 @@ void View::DrawFindZone() const auto idt = numBins / ( log10( tmax ) - tMinLog ); for( auto& ev : zones ) { - const auto timeSpan = m_worker.GetZoneEndDirect( *ev ) - ev->start; + 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 ) ); @@ -2820,7 +2820,7 @@ void View::DrawFindZone() const auto idt = numBins / dt; for( auto& ev : zones ) { - const auto timeSpan = m_worker.GetZoneEndDirect( *ev ) - ev->start; + const auto timeSpan = m_worker.GetZoneEndDirect( *ev.zone ) - ev.zone->start; if( timeSpan != 0 ) { const auto bin = std::min( numBins - 1, int64_t( ( timeSpan - tmin ) * idt ) ); @@ -2839,7 +2839,7 @@ void View::DrawFindZone() const auto idt = numBins / ( log10( tmax ) - tMinLog ); for( auto& ev : zones ) { - const auto timeSpan = m_worker.GetZoneEndDirect( *ev ) - ev->start; + 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 ) ); @@ -2853,7 +2853,7 @@ void View::DrawFindZone() const auto idt = numBins / dt; for( auto& ev : zones ) { - const auto timeSpan = m_worker.GetZoneEndDirect( *ev ) - ev->start; + const auto timeSpan = m_worker.GetZoneEndDirect( *ev.zone ) - ev.zone->start; if( timeSpan != 0 ) { const auto bin = std::min( numBins - 1, int64_t( ( timeSpan - tmin ) * idt ) ); @@ -3138,8 +3138,8 @@ void View::DrawFindZone() { auto& ev = zones[i]; - const auto end = m_worker.GetZoneEndDirect( *ev ); - const auto timespan = end - ev->start; + const auto end = m_worker.GetZoneEndDirect( *ev.zone ); + const auto timespan = end - ev.zone->start; if( m_findZone.highlight.active ) { @@ -3148,10 +3148,9 @@ void View::DrawFindZone() if( timespan < s || timespan > e ) continue; } - auto thread = GetZoneThread( *ev ); - if( thread != 0 ) + if( ev.thread != 0 ) { - m_findZone.threads[thread].emplace_back( ev ); + m_findZone.threads[ev.thread].emplace_back( ev.zone ); } } m_findZone.processed = sz; @@ -3159,15 +3158,16 @@ void View::DrawFindZone() int idx = 0; for( auto& v : m_findZone.threads ) { + auto threadString = m_worker.GetThreadString( m_worker.DecompressThread( v.first ) ); ImGui::PushID( idx++ ); - const bool expand = ImGui::TreeNode( m_worker.GetThreadString( v.first ) ); + const bool expand = ImGui::TreeNode( threadString ); ImGui::PopID(); ImGui::SameLine(); ImGui::TextColored( ImVec4( 0.5f, 0.5f, 0.5f, 1.0f ), "(%s)", RealToString( v.second.size(), true ) ); if( expand ) { - ImGui::Columns( 3, m_worker.GetThreadString( v.first ) ); + ImGui::Columns( 3, threadString ); ImGui::Separator(); ImGui::Text( "Name" ); ImGui::NextColumn(); diff --git a/server/TracyWorker.cpp b/server/TracyWorker.cpp index e9273711..480c669d 100644 --- a/server/TracyWorker.cpp +++ b/server/TracyWorker.cpp @@ -193,7 +193,7 @@ Worker::Worker( FileRead& f ) auto td = m_slab.AllocInit(); f.Read( &td->id, sizeof( td->id ) ); f.Read( &td->count, sizeof( td->count ) ); - ReadTimeline( f, td->timeline ); + ReadTimeline( f, td->timeline, CompressThread( td->id ) ); uint64_t msz; f.Read( &msz, sizeof( msz ) ); td->messages.reserve( msz ); @@ -723,7 +723,7 @@ void Worker::NewZone( ZoneEvent* zone, uint64_t thread ) #ifndef TRACY_NO_STATISTICS auto it = m_data.sourceLocationZones.find( zone->srcloc ); assert( it != m_data.sourceLocationZones.end() ); - it->second.zones.push_back( zone ); + it->second.zones.push_back( ZoneThreadData { zone, CompressThread( thread ) } ); #endif auto td = NoticeThread( thread ); @@ -1623,13 +1623,13 @@ void Worker::ProcessGpuResync( const QueueGpuResync& ev ) } } -void Worker::ReadTimeline( FileRead& f, Vector& vec ) +void Worker::ReadTimeline( FileRead& f, Vector& vec, uint16_t thread ) { uint64_t sz; f.Read( &sz, sizeof( sz ) ); if( sz != 0 ) { - ReadTimeline( f, vec, sz ); + ReadTimeline( f, vec, thread, sz ); } } @@ -1643,7 +1643,7 @@ void Worker::ReadTimeline( FileRead& f, Vector& vec ) } } -void Worker::ReadTimeline( FileRead& f, Vector& vec, uint64_t size ) +void Worker::ReadTimeline( FileRead& f, Vector& vec, uint16_t thread, uint64_t size ) { assert( size != 0 ); vec.reserve_non_zero( size ); @@ -1659,7 +1659,7 @@ void Worker::ReadTimeline( FileRead& f, Vector& vec, uint64_t size ) #ifndef TRACY_NO_STATISTICS auto it = m_data.sourceLocationZones.find( zone->srcloc ); assert( it != m_data.sourceLocationZones.end() ); - it->second.zones.push_back( zone ); + it->second.zones.push_back( ZoneThreadData { zone, thread } ); if( zone->end != -1 ) { @@ -1672,7 +1672,7 @@ void Worker::ReadTimeline( FileRead& f, Vector& vec, uint64_t size ) } #endif - ReadTimeline( f, zone->child ); + ReadTimeline( f, zone->child, thread ); } } diff --git a/server/TracyWorker.hpp b/server/TracyWorker.hpp index 7e862682..4ea69f11 100644 --- a/server/TracyWorker.hpp +++ b/server/TracyWorker.hpp @@ -33,11 +33,19 @@ struct nohash class Worker { +#pragma pack( 1 ) + struct ZoneThreadData + { + ZoneEvent* zone; + uint16_t thread; + }; +#pragma pack() + struct SourceLocationZones { SourceLocationZones() : min( std::numeric_limits::max() ), max( std::numeric_limits::min() ) {} - Vector zones; + Vector zones; int64_t min; int64_t max; }; @@ -200,10 +208,10 @@ private: StringLocation StoreString( char* str, size_t sz ); - tracy_force_inline void ReadTimeline( FileRead& f, Vector& vec ); + tracy_force_inline void ReadTimeline( FileRead& f, Vector& vec, uint16_t thread ); tracy_force_inline void ReadTimeline( FileRead& f, Vector& vec ); - void ReadTimeline( FileRead& f, Vector& vec, uint64_t size ); + void ReadTimeline( FileRead& f, Vector& vec, uint16_t thread, uint64_t size ); void ReadTimeline( FileRead& f, Vector& vec, uint64_t size ); void WriteTimeline( FileWrite& f, const Vector& vec );