Store thread id next to zone ptr in source location zone list.

This commit is contained in:
Bartosz Taudul 2018-03-18 20:45:49 +01:00
parent 777d672e05
commit d0519499f4
4 changed files with 30 additions and 22 deletions

View File

@ -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). 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).

View File

@ -2805,7 +2805,7 @@ void View::DrawFindZone()
const auto idt = numBins / ( log10( tmax ) - tMinLog ); const auto idt = numBins / ( log10( tmax ) - tMinLog );
for( auto& ev : zones ) 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 ) if( timeSpan != 0 )
{ {
const auto bin = std::min( numBins - 1, int64_t( ( log10( timeSpan ) - tMinLog ) * idt ) ); 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; const auto idt = numBins / dt;
for( auto& ev : zones ) 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 ) if( timeSpan != 0 )
{ {
const auto bin = std::min( numBins - 1, int64_t( ( timeSpan - tmin ) * idt ) ); 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 ); const auto idt = numBins / ( log10( tmax ) - tMinLog );
for( auto& ev : zones ) 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 ) if( timeSpan != 0 )
{ {
const auto bin = std::min( numBins - 1, int64_t( ( log10( timeSpan ) - tMinLog ) * idt ) ); 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; const auto idt = numBins / dt;
for( auto& ev : zones ) 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 ) if( timeSpan != 0 )
{ {
const auto bin = std::min( numBins - 1, int64_t( ( timeSpan - tmin ) * idt ) ); const auto bin = std::min( numBins - 1, int64_t( ( timeSpan - tmin ) * idt ) );
@ -3138,8 +3138,8 @@ void View::DrawFindZone()
{ {
auto& ev = zones[i]; auto& ev = zones[i];
const auto end = m_worker.GetZoneEndDirect( *ev ); const auto end = m_worker.GetZoneEndDirect( *ev.zone );
const auto timespan = end - ev->start; const auto timespan = end - ev.zone->start;
if( m_findZone.highlight.active ) if( m_findZone.highlight.active )
{ {
@ -3148,10 +3148,9 @@ void View::DrawFindZone()
if( timespan < s || timespan > e ) continue; if( timespan < s || timespan > e ) continue;
} }
auto thread = GetZoneThread( *ev ); if( ev.thread != 0 )
if( thread != 0 )
{ {
m_findZone.threads[thread].emplace_back( ev ); m_findZone.threads[ev.thread].emplace_back( ev.zone );
} }
} }
m_findZone.processed = sz; m_findZone.processed = sz;
@ -3159,15 +3158,16 @@ void View::DrawFindZone()
int idx = 0; int idx = 0;
for( auto& v : m_findZone.threads ) for( auto& v : m_findZone.threads )
{ {
auto threadString = m_worker.GetThreadString( m_worker.DecompressThread( v.first ) );
ImGui::PushID( idx++ ); ImGui::PushID( idx++ );
const bool expand = ImGui::TreeNode( m_worker.GetThreadString( v.first ) ); const bool expand = ImGui::TreeNode( threadString );
ImGui::PopID(); ImGui::PopID();
ImGui::SameLine(); ImGui::SameLine();
ImGui::TextColored( ImVec4( 0.5f, 0.5f, 0.5f, 1.0f ), "(%s)", RealToString( v.second.size(), true ) ); ImGui::TextColored( ImVec4( 0.5f, 0.5f, 0.5f, 1.0f ), "(%s)", RealToString( v.second.size(), true ) );
if( expand ) if( expand )
{ {
ImGui::Columns( 3, m_worker.GetThreadString( v.first ) ); ImGui::Columns( 3, threadString );
ImGui::Separator(); ImGui::Separator();
ImGui::Text( "Name" ); ImGui::Text( "Name" );
ImGui::NextColumn(); ImGui::NextColumn();

View File

@ -193,7 +193,7 @@ Worker::Worker( FileRead& f )
auto td = m_slab.AllocInit<ThreadData>(); auto td = m_slab.AllocInit<ThreadData>();
f.Read( &td->id, sizeof( td->id ) ); f.Read( &td->id, sizeof( td->id ) );
f.Read( &td->count, sizeof( td->count ) ); f.Read( &td->count, sizeof( td->count ) );
ReadTimeline( f, td->timeline ); ReadTimeline( f, td->timeline, CompressThread( td->id ) );
uint64_t msz; uint64_t msz;
f.Read( &msz, sizeof( msz ) ); f.Read( &msz, sizeof( msz ) );
td->messages.reserve( msz ); td->messages.reserve( msz );
@ -723,7 +723,7 @@ void Worker::NewZone( ZoneEvent* zone, uint64_t thread )
#ifndef TRACY_NO_STATISTICS #ifndef TRACY_NO_STATISTICS
auto it = m_data.sourceLocationZones.find( zone->srcloc ); auto it = m_data.sourceLocationZones.find( zone->srcloc );
assert( it != m_data.sourceLocationZones.end() ); assert( it != m_data.sourceLocationZones.end() );
it->second.zones.push_back( zone ); it->second.zones.push_back( ZoneThreadData { zone, CompressThread( thread ) } );
#endif #endif
auto td = NoticeThread( thread ); auto td = NoticeThread( thread );
@ -1623,13 +1623,13 @@ void Worker::ProcessGpuResync( const QueueGpuResync& ev )
} }
} }
void Worker::ReadTimeline( FileRead& f, Vector<ZoneEvent*>& vec ) void Worker::ReadTimeline( FileRead& f, Vector<ZoneEvent*>& vec, uint16_t thread )
{ {
uint64_t sz; uint64_t sz;
f.Read( &sz, sizeof( sz ) ); f.Read( &sz, sizeof( sz ) );
if( sz != 0 ) if( sz != 0 )
{ {
ReadTimeline( f, vec, sz ); ReadTimeline( f, vec, thread, sz );
} }
} }
@ -1643,7 +1643,7 @@ void Worker::ReadTimeline( FileRead& f, Vector<GpuEvent*>& vec )
} }
} }
void Worker::ReadTimeline( FileRead& f, Vector<ZoneEvent*>& vec, uint64_t size ) void Worker::ReadTimeline( FileRead& f, Vector<ZoneEvent*>& vec, uint16_t thread, uint64_t size )
{ {
assert( size != 0 ); assert( size != 0 );
vec.reserve_non_zero( size ); vec.reserve_non_zero( size );
@ -1659,7 +1659,7 @@ void Worker::ReadTimeline( FileRead& f, Vector<ZoneEvent*>& vec, uint64_t size )
#ifndef TRACY_NO_STATISTICS #ifndef TRACY_NO_STATISTICS
auto it = m_data.sourceLocationZones.find( zone->srcloc ); auto it = m_data.sourceLocationZones.find( zone->srcloc );
assert( it != m_data.sourceLocationZones.end() ); assert( it != m_data.sourceLocationZones.end() );
it->second.zones.push_back( zone ); it->second.zones.push_back( ZoneThreadData { zone, thread } );
if( zone->end != -1 ) if( zone->end != -1 )
{ {
@ -1672,7 +1672,7 @@ void Worker::ReadTimeline( FileRead& f, Vector<ZoneEvent*>& vec, uint64_t size )
} }
#endif #endif
ReadTimeline( f, zone->child ); ReadTimeline( f, zone->child, thread );
} }
} }

View File

@ -33,11 +33,19 @@ struct nohash
class Worker class Worker
{ {
#pragma pack( 1 )
struct ZoneThreadData
{
ZoneEvent* zone;
uint16_t thread;
};
#pragma pack()
struct SourceLocationZones struct SourceLocationZones
{ {
SourceLocationZones() : min( std::numeric_limits<int64_t>::max() ), max( std::numeric_limits<int64_t>::min() ) {} SourceLocationZones() : min( std::numeric_limits<int64_t>::max() ), max( std::numeric_limits<int64_t>::min() ) {}
Vector<ZoneEvent*> zones; Vector<ZoneThreadData> zones;
int64_t min; int64_t min;
int64_t max; int64_t max;
}; };
@ -200,10 +208,10 @@ private:
StringLocation StoreString( char* str, size_t sz ); StringLocation StoreString( char* str, size_t sz );
tracy_force_inline void ReadTimeline( FileRead& f, Vector<ZoneEvent*>& vec ); tracy_force_inline void ReadTimeline( FileRead& f, Vector<ZoneEvent*>& vec, uint16_t thread );
tracy_force_inline void ReadTimeline( FileRead& f, Vector<GpuEvent*>& vec ); tracy_force_inline void ReadTimeline( FileRead& f, Vector<GpuEvent*>& vec );
void ReadTimeline( FileRead& f, Vector<ZoneEvent*>& vec, uint64_t size ); void ReadTimeline( FileRead& f, Vector<ZoneEvent*>& vec, uint16_t thread, uint64_t size );
void ReadTimeline( FileRead& f, Vector<GpuEvent*>& vec, uint64_t size ); void ReadTimeline( FileRead& f, Vector<GpuEvent*>& vec, uint64_t size );
void WriteTimeline( FileWrite& f, const Vector<ZoneEvent*>& vec ); void WriteTimeline( FileWrite& f, const Vector<ZoneEvent*>& vec );