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.
This commit is contained in:
Bartosz Taudul 2018-03-18 12:55:54 +01:00
parent 4baea4a74f
commit 7a4e7cbf86
4 changed files with 25 additions and 0 deletions

View File

@ -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
}

View File

@ -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 <typename T>
bool& Visible( const T* ptr )

View File

@ -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<sle; i++ )
{
@ -129,6 +130,7 @@ Worker::Worker( FileRead& f )
{
m_data.sourceLocationZones.emplace( -int32_t( i + 1 ), Vector<ZoneEvent*>() );
}
#endif
f.Read( &sz, sizeof( sz ) );
for( uint64_t i=0; i<sz; i++ )
@ -415,12 +417,14 @@ std::vector<int32_t> Worker::GetMatchingSourceLocation( const char* query ) cons
return match;
}
#ifndef TRACY_NO_STATISTICS
const Vector<ZoneEvent*>& Worker::GetZonesForSourceLocation( int32_t srcloc ) const
{
static const Vector<ZoneEvent*> 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<ZoneEvent*>() );
#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<ZoneEvent*>() );
#endif
}
else
{
@ -1613,9 +1623,11 @@ void Worker::ReadTimeline( FileRead& f, Vector<ZoneEvent*>& 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 );
}

View File

@ -54,7 +54,9 @@ class Worker
Vector<SourceLocation*> sourceLocationPayload;
flat_hash_map<SourceLocation*, uint32_t, SourceLocationHasher, SourceLocationComparator> sourceLocationPayloadMap;
Vector<uint64_t> sourceLocationExpand;
#ifndef TRACY_NO_STATISTICS
flat_hash_map<int32_t, Vector<ZoneEvent*>, nohash<int32_t>> sourceLocationZones;
#endif
std::map<uint32_t, LockMap> lockMap;
};
@ -110,7 +112,9 @@ public:
const SourceLocation& GetSourceLocation( int32_t srcloc ) const;
std::vector<int32_t> GetMatchingSourceLocation( const char* query ) const;
#ifndef TRACY_NO_STATISTICS
const Vector<ZoneEvent*>& GetZonesForSourceLocation( int32_t srcloc ) const;
#endif
NonRecursiveBenaphore& GetMbpsDataLock() { return m_mbpsData.lock; }
const std::vector<float>& GetMbpsData() const { return m_mbpsData.mbps; }