Process frame marks.

This commit is contained in:
Bartosz Taudul 2017-09-16 00:40:51 +02:00
parent 03ece0ac48
commit 3d0ddb960a
2 changed files with 24 additions and 3 deletions

View File

@ -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<std::mutex> lock( m_lock );
m_frames.push_back( id );
}
else
{
auto it = std::lower_bound( m_frames.begin(), m_frames.end(), id );
std::unique_lock<std::mutex> lock( m_lock );
m_frames.insert( it, id );
}
}
void View::CheckString( uint64_t ptr )
{
if( m_strings.find( ptr ) != m_strings.end() ) return;

View File

@ -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<bool> m_shutdown;
int64_t m_timeBegin;
// this block must be locked
std::mutex m_lock;
Vector<Event*> m_timeline;
Vector<uint64_t> m_frames;
std::unordered_map<uint64_t, std::string> m_strings;
std::mutex m_mbpslock;