From c6a7bcb0861a2357c1a80af0d372c58e210f8081 Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Sun, 5 Nov 2017 21:24:50 +0100 Subject: [PATCH] Store source location payloads. No saving yet. No detection of duplicate entries. --- server/TracyEvent.hpp | 7 ++++--- server/TracyView.cpp | 49 ++++++++++++++++++++++++++++++++++--------- server/TracyView.hpp | 3 ++- 3 files changed, 45 insertions(+), 14 deletions(-) diff --git a/server/TracyEvent.hpp b/server/TracyEvent.hpp index fa9f7f31..9609a034 100644 --- a/server/TracyEvent.hpp +++ b/server/TracyEvent.hpp @@ -21,7 +21,8 @@ struct SourceLocation uint64_t function; // ptr uint64_t file; // ptr uint32_t line; - uint32_t color; + uint32_t color : 31; + uint32_t stringsAllocated : 1; }; enum { SourceLocationSize = sizeof( SourceLocation ) }; @@ -31,7 +32,7 @@ struct ZoneEvent { int64_t start; int64_t end; - uint32_t srcloc; + int32_t srcloc; int8_t cpu_start; int8_t cpu_end; @@ -52,7 +53,7 @@ struct LockEvent }; int64_t time; - uint32_t srcloc; + int32_t srcloc; uint64_t waitList; uint16_t thread : 6; uint16_t lockingThread : 6; diff --git a/server/TracyView.cpp b/server/TracyView.cpp index f9af6fe7..7a0aab51 100644 --- a/server/TracyView.cpp +++ b/server/TracyView.cpp @@ -983,7 +983,7 @@ void View::AddSourceLocation( const QueueSourceLocation& srcloc ) CheckString( srcloc.function ); uint32_t color = ( srcloc.r << 16 ) | ( srcloc.g << 8 ) | srcloc.b; std::lock_guard lock( m_lock ); - m_sourceLocation.emplace( srcloc.ptr, SourceLocation { srcloc.function, srcloc.file, srcloc.line, color } ); + m_sourceLocation.emplace( srcloc.ptr, SourceLocation { srcloc.function, srcloc.file, srcloc.line, color, 0 } ); } void View::AddSourceLocationPayload( uint64_t ptr, const char* data, size_t sz ) @@ -1007,10 +1007,18 @@ void View::AddSourceLocationPayload( uint64_t ptr, const char* data, size_t sz ) memcpy( source, end, ssz ); source[ssz] = '\0'; - std::unique_lock lock( m_lock ); + auto srcloc = m_slab.Alloc(); + srcloc->function = (uint64_t)func; + srcloc->file = (uint64_t)source; + srcloc->line = line; + srcloc->color = color; + srcloc->stringsAllocated = 1; + std::unique_lock lock( m_lock ); + pit->second->srcloc = -int32_t( m_sourceLocationPayload.size() + 1 ); + m_sourceLocationPayload.push_back( srcloc ); lock.unlock(); - m_pendingSourceLocationPayload.erase( ptr ); + m_pendingSourceLocationPayload.erase( pit ); } void View::AddMessageData( uint64_t ptr, const char* str, size_t sz ) @@ -1367,12 +1375,19 @@ const char* View::GetThreadString( uint64_t id ) const } } -const SourceLocation& View::GetSourceLocation( uint32_t srcloc ) const +const SourceLocation& View::GetSourceLocation( int32_t srcloc ) const { - static const SourceLocation empty = {}; - const auto it = m_sourceLocation.find( m_sourceLocationExpand[srcloc] ); - if( it == m_sourceLocation.end() ) return empty; - return it->second; + if( srcloc < 0 ) + { + return *m_sourceLocationPayload[-srcloc-1]; + } + else + { + static const SourceLocation empty = {}; + const auto it = m_sourceLocation.find( m_sourceLocationExpand[srcloc] ); + if( it == m_sourceLocation.end() ) return empty; + return it->second; + } } const char* View::ShortenNamespace( const char* name ) const @@ -3041,12 +3056,26 @@ void View::DrawMessages() const char* View::GetSrcLocFunction( const SourceLocation& srcloc ) { - return GetString( srcloc.function ); + if( srcloc.stringsAllocated ) + { + return (const char*)srcloc.function; + } + else + { + return GetString( srcloc.function ); + } } const char* View::GetSrcLocFile( const SourceLocation& srcloc ) { - return GetString( srcloc.file ); + if( srcloc.stringsAllocated ) + { + return (const char*)srcloc.file; + } + else + { + return GetString( srcloc.file ); + } } uint32_t View::GetZoneColor( const ZoneEvent& ev ) diff --git a/server/TracyView.hpp b/server/TracyView.hpp index e3be10ce..9f7eb716 100644 --- a/server/TracyView.hpp +++ b/server/TracyView.hpp @@ -176,7 +176,7 @@ private: int64_t GetZoneEnd( const ZoneEvent& ev ) const; const char* GetString( uint64_t ptr ) const; const char* GetThreadString( uint64_t id ) const; - const SourceLocation& GetSourceLocation( uint32_t srcloc ) const; + const SourceLocation& GetSourceLocation( int32_t srcloc ) const; const char* ShortenNamespace( const char* name ) const; @@ -230,6 +230,7 @@ private: Vector m_plots; Vector m_messages; Vector m_textData; + Vector m_sourceLocationPayload; std::unordered_map m_strings; std::unordered_map m_threadNames; std::unordered_set m_customStrings;