From 7a4e7cbf86d12ec139a7de1af065f4ee27c2e472 Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Sun, 18 Mar 2018 12:55:54 +0100 Subject: [PATCH] Reduce data collection if TRACY_NO_STATISTICS is defined. Statistical data collection is only useful if it's meant to be used. Otherwise it only incurs CPU and memory cost. --- server/TracyView.cpp | 7 +++++++ server/TracyView.hpp | 2 ++ server/TracyWorker.cpp | 12 ++++++++++++ server/TracyWorker.hpp | 4 ++++ 4 files changed, 25 insertions(+) diff --git a/server/TracyView.cpp b/server/TracyView.cpp index 075257e1..e618927f 100644 --- a/server/TracyView.cpp +++ b/server/TracyView.cpp @@ -2703,6 +2703,10 @@ void View::DrawMessages() void View::DrawFindZone() { ImGui::Begin( "Find Zone", &m_findZone.show ); +#ifdef TRACY_NO_STATISTICS + 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 ImGui::InputText( "", m_findZone.pattern, 1024 ); ImGui::SameLine(); @@ -3243,6 +3247,7 @@ void View::DrawFindZone() } #endif } +#endif ImGui::End(); } @@ -3480,6 +3485,7 @@ const GpuEvent* View::GetZoneParent( const GpuEvent& zone ) const return nullptr; } +#ifndef TRACY_NO_STATISTICS void View::FindZones() { const auto match = m_worker.GetMatchingSourceLocation( m_findZone.pattern ); @@ -3494,5 +3500,6 @@ void View::FindZones() } } } +#endif } diff --git a/server/TracyView.hpp b/server/TracyView.hpp index 83923d2b..0bb89a64 100644 --- a/server/TracyView.hpp +++ b/server/TracyView.hpp @@ -97,7 +97,9 @@ private: const ZoneEvent* GetZoneParent( const ZoneEvent& zone ) const; const GpuEvent* GetZoneParent( const GpuEvent& zone ) const; +#ifndef TRACY_NO_STATISTICS void FindZones(); +#endif template bool& Visible( const T* ptr ) diff --git a/server/TracyWorker.cpp b/server/TracyWorker.cpp index b0264789..761b4586 100644 --- a/server/TracyWorker.cpp +++ b/server/TracyWorker.cpp @@ -120,6 +120,7 @@ Worker::Worker( FileRead& f ) m_data.sourceLocationPayloadMap.emplace( srcloc, uint32_t( i ) ); } +#ifndef TRACY_NO_STATISTICS m_data.sourceLocationZones.reserve( sle + sz ); for( uint64_t i=1; i() ); } +#endif f.Read( &sz, sizeof( sz ) ); for( uint64_t i=0; i Worker::GetMatchingSourceLocation( const char* query ) cons return match; } +#ifndef TRACY_NO_STATISTICS const Vector& Worker::GetZonesForSourceLocation( int32_t srcloc ) const { static const Vector empty; auto it = m_data.sourceLocationZones.find( srcloc ); return it != m_data.sourceLocationZones.end() ? it->second : empty; } +#endif void Worker::Exec() { @@ -627,7 +631,9 @@ uint32_t Worker::NewShrinkedSourceLocation( uint64_t srcloc ) { const auto sz = m_data.sourceLocationExpand.size(); m_data.sourceLocationExpand.push_back( srcloc ); +#ifndef TRACY_NO_STATISTICS m_data.sourceLocationZones.emplace( sz, Vector() ); +#endif m_sourceLocationShrink.emplace( srcloc, sz ); return sz; } @@ -692,9 +698,11 @@ void Worker::NewZone( ZoneEvent* zone, uint64_t thread ) { m_data.zonesCnt++; +#ifndef TRACY_NO_STATISTICS auto it = m_data.sourceLocationZones.find( zone->srcloc ); assert( it != m_data.sourceLocationZones.end() ); it->second.push_back( zone ); +#endif auto td = NoticeThread( thread ); td->count++; @@ -960,7 +968,9 @@ void Worker::AddSourceLocationPayload( uint64_t ptr, char* data, size_t sz ) m_data.sourceLocationPayloadMap.emplace( slptr, idx ); m_pendingSourceLocationPayload.emplace( ptr, -int32_t( idx + 1 ) ); m_data.sourceLocationPayload.push_back( slptr ); +#ifndef TRACY_NO_STATISTICS m_data.sourceLocationZones.emplace( -int32_t( idx + 1 ), Vector() ); +#endif } else { @@ -1613,9 +1623,11 @@ void Worker::ReadTimeline( FileRead& f, Vector& vec, uint64_t size ) vec.push_back_no_space_check( zone ); f.Read( zone, sizeof( ZoneEvent ) - sizeof( ZoneEvent::child ) ); +#ifndef TRACY_NO_STATISTICS auto it = m_data.sourceLocationZones.find( zone->srcloc ); assert( it != m_data.sourceLocationZones.end() ); it->second.push_back( zone ); +#endif ReadTimeline( f, zone->child ); } diff --git a/server/TracyWorker.hpp b/server/TracyWorker.hpp index 68b77aec..a5c517a2 100644 --- a/server/TracyWorker.hpp +++ b/server/TracyWorker.hpp @@ -54,7 +54,9 @@ class Worker Vector sourceLocationPayload; flat_hash_map sourceLocationPayloadMap; Vector sourceLocationExpand; +#ifndef TRACY_NO_STATISTICS flat_hash_map, nohash> sourceLocationZones; +#endif std::map lockMap; }; @@ -110,7 +112,9 @@ public: const SourceLocation& GetSourceLocation( int32_t srcloc ) const; std::vector GetMatchingSourceLocation( const char* query ) const; +#ifndef TRACY_NO_STATISTICS const Vector& GetZonesForSourceLocation( int32_t srcloc ) const; +#endif NonRecursiveBenaphore& GetMbpsDataLock() { return m_mbpsData.lock; } const std::vector& GetMbpsData() const { return m_mbpsData.mbps; }