From 053284b1c7c9fe730ae3867693a9e215b1036d75 Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Fri, 29 Jun 2018 16:12:17 +0200 Subject: [PATCH] Process custom free-form zone names. --- NEWS | 2 +- server/TracyEvent.hpp | 1 + server/TracyWorker.cpp | 46 +++++++++++++++++++++++++++++++++--------- server/TracyWorker.hpp | 5 +++-- 4 files changed, 42 insertions(+), 12 deletions(-) diff --git a/NEWS b/NEWS index 70b942ae..0982ffd8 100644 --- a/NEWS +++ b/NEWS @@ -7,7 +7,7 @@ Note: Release numbers are nothing more than numbers. There are some a mistake. -v0.3.2 (xxxx-xx-xx) +v0.3.3 (xxxx-xx-xx) ------------------- - Breaking change: the format of trace files has changed. diff --git a/server/TracyEvent.hpp b/server/TracyEvent.hpp index 000f20bd..157b82e4 100644 --- a/server/TracyEvent.hpp +++ b/server/TracyEvent.hpp @@ -81,6 +81,7 @@ struct ZoneEvent int8_t cpu_end; StringIdx text; uint32_t callstack; + StringIdx name; // This must be last. All above is read/saved as-is. Vector child; diff --git a/server/TracyWorker.cpp b/server/TracyWorker.cpp index 1cbb3fa8..7e3580da 100644 --- a/server/TracyWorker.cpp +++ b/server/TracyWorker.cpp @@ -31,7 +31,7 @@ static constexpr int FileVersion( uint8_t h5, uint8_t h6, uint8_t h7 ) return ( h5 << 16 ) | ( h6 << 8 ) | h7; } -static const uint8_t FileHeader[8] { 't', 'r', 'a', 'c', 'y', 0, 3, 2 }; +static const uint8_t FileHeader[8] { 't', 'r', 'a', 'c', 'y', 0, 3, 3 }; enum { FileHeaderMagic = 5 }; static const int CurrentVersion = FileVersion( FileHeader[FileHeaderMagic], FileHeader[FileHeaderMagic+1], FileHeader[FileHeaderMagic+2] ); @@ -456,9 +456,9 @@ Worker::Worker( FileRead& f, EventType::Type eventMask ) f.Read( tid ); td->id = tid; f.Read( td->count ); - if( fileVer <= FileVersion( 0, 3, 1 ) ) + if( fileVer <= FileVersion( 0, 3, 2 ) ) { - ReadTimelinePre032( f, td->timeline, CompressThread( tid ) ); + ReadTimelinePre033( f, td->timeline, CompressThread( tid ), fileVer ); } else { @@ -1560,6 +1560,9 @@ void Worker::Process( const QueueItem& ev ) case QueueType::ZoneText: ProcessZoneText( ev.zoneText ); break; + case QueueType::ZoneName: + ProcessZoneName( ev.zoneText ); + break; case QueueType::LockAnnounce: ProcessLockAnnounce( ev.lockAnnounce ); break; @@ -1752,6 +1755,21 @@ void Worker::ProcessZoneText( const QueueZoneText& ev ) m_pendingCustomStrings.erase( it ); } +void Worker::ProcessZoneName( const QueueZoneText& ev ) +{ + auto tit = m_threadMap.find( ev.thread ); + assert( tit != m_threadMap.end() ); + + auto td = tit->second; + auto& stack = td->stack; + assert( !stack.empty() ); + auto zone = stack.back(); + auto it = m_pendingCustomStrings.find( ev.text ); + assert( it != m_pendingCustomStrings.end() ); + zone->name = StringIdx( it->second.idx ); + m_pendingCustomStrings.erase( it ); +} + void Worker::ProcessLockAnnounce( const QueueLockAnnounce& ev ) { auto it = m_data.lockMap.find( ev.id ); @@ -2376,13 +2394,13 @@ void Worker::ReadTimeline( FileRead& f, Vector& vec, uint16_t thread } } -void Worker::ReadTimelinePre032( FileRead& f, Vector& vec, uint16_t thread ) +void Worker::ReadTimelinePre033( FileRead& f, Vector& vec, uint16_t thread, int fileVer ) { uint64_t sz; f.Read( sz ); if( sz != 0 ) { - ReadTimelinePre032( f, vec, thread, sz ); + ReadTimelinePre033( f, vec, thread, sz, fileVer ); } } @@ -2452,7 +2470,7 @@ void Worker::ReadTimeline( FileRead& f, Vector& vec, uint16_t thread } } -void Worker::ReadTimelinePre032( FileRead& f, Vector& vec, uint16_t thread, uint64_t size ) +void Worker::ReadTimelinePre033( FileRead& f, Vector& vec, uint16_t thread, uint64_t size, int fileVer ) { assert( size != 0 ); vec.reserve_non_zero( size ); @@ -2464,9 +2482,19 @@ void Worker::ReadTimelinePre032( FileRead& f, Vector& vec, uint16_t vec.push_back_no_space_check( zone ); new( &zone->child ) decltype( zone->child ); - f.Read( zone, 26 ); - zone->callstack = 0; - ReadTimelinePre032( f, zone->child, thread ); + if( fileVer <= FileVersion( 0, 3, 1 ) ) + { + f.Read( zone, 26 ); + zone->callstack = 0; + zone->name.__data = 0; + } + else + { + assert( fileVer <= FileVersion( 0, 3, 2 ) ); + f.Read( zone, 30 ); + zone->name.__data = 0; + } + ReadTimelinePre033( f, zone->child, thread, fileVer ); ReadTimelineUpdateStatistics( zone, thread ); } } diff --git a/server/TracyWorker.hpp b/server/TracyWorker.hpp index a713a280..2ac600f6 100644 --- a/server/TracyWorker.hpp +++ b/server/TracyWorker.hpp @@ -223,6 +223,7 @@ private: tracy_force_inline void ProcessZoneEnd( const QueueZoneEnd& ev ); tracy_force_inline void ProcessFrameMark( const QueueFrameMark& ev ); tracy_force_inline void ProcessZoneText( const QueueZoneText& ev ); + tracy_force_inline void ProcessZoneName( const QueueZoneText& ev ); tracy_force_inline void ProcessLockAnnounce( const QueueLockAnnounce& ev ); tracy_force_inline void ProcessLockWait( const QueueLockWait& ev ); tracy_force_inline void ProcessLockObtain( const QueueLockObtain& ev ); @@ -290,14 +291,14 @@ private: uint16_t CompressThreadNew( uint64_t thread ); tracy_force_inline void ReadTimeline( FileRead& f, Vector& vec, uint16_t thread ); - tracy_force_inline void ReadTimelinePre032( FileRead& f, Vector& vec, uint16_t thread ); + tracy_force_inline void ReadTimelinePre033( FileRead& f, Vector& vec, uint16_t thread, int fileVer ); tracy_force_inline void ReadTimeline( FileRead& f, Vector& vec ); tracy_force_inline void ReadTimelinePre032( FileRead& f, Vector& vec ); tracy_force_inline void ReadTimelineUpdateStatistics( ZoneEvent* zone, uint16_t thread ); void ReadTimeline( FileRead& f, Vector& vec, uint16_t thread, uint64_t size ); - void ReadTimelinePre032( FileRead& f, Vector& vec, uint16_t thread, uint64_t size ); + void ReadTimelinePre033( FileRead& f, Vector& vec, uint16_t thread, uint64_t size, int fileVer ); void ReadTimeline( FileRead& f, Vector& vec, uint64_t size ); void ReadTimelinePre032( FileRead& f, Vector& vec, uint64_t size );