diff --git a/server/TracyView.cpp b/server/TracyView.cpp index 45177e75..64a8db46 100755 --- a/server/TracyView.cpp +++ b/server/TracyView.cpp @@ -60,10 +60,13 @@ void View::Worker() uint8_t lz4; uint64_t bytes = 0; + uint64_t timeStart; - if( !m_sock.Read( &m_timeBegin, sizeof( m_timeBegin ), &tv, ShouldExit ) ) goto close; + if( !m_sock.Read( &timeStart, sizeof( timeStart ), &tv, ShouldExit ) ) goto close; if( !m_sock.Read( &lz4, sizeof( lz4 ), &tv, ShouldExit ) ) goto close; + m_frames.push_back( timeStart ); + t0 = std::chrono::high_resolution_clock::now(); for(;;) @@ -169,6 +172,7 @@ void View::Process( const QueueItem& ev ) ProcessZoneEnd( ev.hdr.id, ev.zoneEnd ); break; case QueueType::FrameMark: + ProcessFrameMark( ev.hdr.id ); break; default: assert( false ); @@ -220,6 +224,23 @@ void View::ProcessZoneEnd( uint64_t id, const QueueZoneEnd& ev ) } } +void View::ProcessFrameMark( uint64_t id ) +{ + assert( !m_frames.empty() ); + const auto lastframe = m_frames.back(); + if( lastframe < id ) + { + std::unique_lock lock( m_lock ); + m_frames.push_back( id ); + } + else + { + auto it = std::lower_bound( m_frames.begin(), m_frames.end(), id ); + std::unique_lock lock( m_lock ); + m_frames.insert( it, id ); + } +} + void View::CheckString( uint64_t ptr ) { if( m_strings.find( ptr ) != m_strings.end() ) return; diff --git a/server/TracyView.hpp b/server/TracyView.hpp index cb43bdc9..e4ec6afa 100755 --- a/server/TracyView.hpp +++ b/server/TracyView.hpp @@ -39,6 +39,7 @@ private: void Process( const QueueItem& ev ); void ProcessZoneBegin( uint64_t id, const QueueZoneBegin& ev ); void ProcessZoneEnd( uint64_t id, const QueueZoneEnd& ev ); + void ProcessFrameMark( uint64_t id ); void CheckString( uint64_t ptr ); void AddString( uint64_t ptr, std::string&& str ); @@ -54,11 +55,10 @@ private: std::thread m_thread; std::atomic m_shutdown; - int64_t m_timeBegin; - // this block must be locked std::mutex m_lock; Vector m_timeline; + Vector m_frames; std::unordered_map m_strings; std::mutex m_mbpslock;