From c2797a4cc705c071dba81e94dcc4f91ae4b0aee1 Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Sat, 11 Nov 2017 15:08:03 +0100 Subject: [PATCH] Data packets can't cross data buffer boundary. --- client/TracyProfiler.cpp | 22 +++++++++++++++++++--- client/TracyProfiler.hpp | 1 + 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/client/TracyProfiler.cpp b/client/TracyProfiler.cpp index 1105115a..775e76cc 100644 --- a/client/TracyProfiler.cpp +++ b/client/TracyProfiler.cpp @@ -276,7 +276,7 @@ Profiler::DequeueStatus Profiler::Dequeue( moodycamel::ConsumerToken& token ) bool Profiler::AppendData( const void* data, size_t len ) { auto ret = true; - if( m_bufferOffset - m_bufferStart + len > TargetFrameSize ) ret = CommitData(); + ret = NeedDataSize( len ); memcpy( m_buffer + m_bufferOffset, data, len ); m_bufferOffset += int( len ); return ret; @@ -290,6 +290,16 @@ bool Profiler::CommitData() return ret; } +bool Profiler::NeedDataSize( size_t len ) +{ + bool ret = true; + if( m_bufferOffset - m_bufferStart + len > TargetFrameSize ) + { + ret = CommitData(); + } + return ret; +} + bool Profiler::SendData( const char* data, size_t len ) { const lz4sz_t lz4sz = LZ4_compress_fast_continue( m_stream, data, m_lz4Buf + sizeof( lz4sz_t ), (int)len, LZ4Size, 1 ); @@ -304,11 +314,14 @@ bool Profiler::SendString( uint64_t str, const char* ptr, QueueType type ) QueueItem item; item.hdr.type = type; item.stringTransfer.ptr = str; - AppendData( &item, QueueDataSize[item.hdr.idx] ); auto len = strlen( ptr ); assert( len <= std::numeric_limits::max() ); auto l16 = uint16_t( len ); + + NeedDataSize( QueueDataSize[item.hdr.idx] + sizeof( l16 ) + l16 ); + + AppendData( &item, QueueDataSize[item.hdr.idx] ); AppendData( &l16, sizeof( l16 ) ); AppendData( ptr, l16 ); @@ -337,12 +350,15 @@ bool Profiler::SendSourceLocationPayload( uint64_t _ptr ) QueueItem item; item.hdr.type = QueueType::SourceLocationPayload; item.stringTransfer.ptr = _ptr; - AppendData( &item, QueueDataSize[item.hdr.idx] ); const auto len = *((uint32_t*)ptr); assert( len <= std::numeric_limits::max() ); assert( len > 4 ); const auto l16 = uint16_t( len - 4 ); + + NeedDataSize( QueueDataSize[item.hdr.idx] + sizeof( l16 ) + l16 ); + + AppendData( &item, QueueDataSize[item.hdr.idx] ); AppendData( &l16, sizeof( l16 ) ); AppendData( ptr + 4, l16 ); diff --git a/client/TracyProfiler.hpp b/client/TracyProfiler.hpp index 906a5507..43cf1432 100644 --- a/client/TracyProfiler.hpp +++ b/client/TracyProfiler.hpp @@ -188,6 +188,7 @@ private: DequeueStatus Dequeue( moodycamel::ConsumerToken& token ); bool AppendData( const void* data, size_t len ); bool CommitData(); + bool NeedDataSize( size_t len ); bool SendData( const char* data, size_t len ); bool SendString( uint64_t ptr, const char* str, QueueType type );