Remove ability to disable LZ4 compression.

This commit is contained in:
Bartosz Taudul 2017-11-10 17:34:11 +01:00
parent 44ee282b6e
commit f6af913fd3
4 changed files with 19 additions and 92 deletions

View File

@ -176,12 +176,6 @@ void Profiler::Worker()
while( m_timeBegin.load( std::memory_order_relaxed ) == 0 ) std::this_thread::sleep_for( std::chrono::milliseconds( 10 ) );
WelcomeMessage welcome;
#ifdef TRACY_DISABLE_LZ4
// notify client that lz4 compression is disabled
welcome.lz4 = 0;
#else
welcome.lz4 = 1;
#endif
welcome.timerMul = m_timerMul;
welcome.initBegin = s_initTime.val;
welcome.initEnd = m_timeBegin.load( std::memory_order_relaxed );
@ -274,14 +268,9 @@ Profiler::DequeueStatus Profiler::Dequeue( moodycamel::ConsumerToken& token )
bool Profiler::SendData( const char* data, size_t len )
{
#ifdef TRACY_DISABLE_LZ4
if( m_sock->Send( data, (int)len ) == -1 ) return false;
#else
const lz4sz_t lz4sz = LZ4_compress_fast_continue( m_stream, data, m_lz4Buf + sizeof( lz4sz_t ), (int)len, LZ4Size, 1 );
memcpy( m_lz4Buf, &lz4sz, sizeof( lz4sz ) );
if( m_sock->Send( m_lz4Buf, lz4sz + sizeof( lz4sz_t ) ) == -1 ) return false;
#endif
return true;
return m_sock->Send( m_lz4Buf, lz4sz + sizeof( lz4sz_t ) ) != -1;
}
bool Profiler::SendString( uint64_t str, const char* ptr, QueueType type )

View File

@ -33,7 +33,6 @@ enum { WelcomeMessageProgramNameSize = 64 };
#pragma pack( 1 )
struct WelcomeMessage
{
uint8_t lz4;
double timerMul;
uint64_t initBegin;
uint64_t initEnd;

View File

@ -433,13 +433,11 @@ void View::Worker()
std::chrono::time_point<std::chrono::high_resolution_clock> t0;
uint8_t lz4;
uint64_t bytes = 0;
{
WelcomeMessage welcome;
if( !m_sock.Read( &welcome, sizeof( welcome ), &tv, ShouldExit ) ) goto close;
lz4 = welcome.lz4;
m_timerMul = welcome.timerMul;
m_frames.push_back( welcome.initBegin * m_timerMul );
m_frames.push_back( welcome.initEnd * m_timerMul );
@ -466,42 +464,27 @@ void View::Worker()
{
if( m_shutdown.load( std::memory_order_relaxed ) ) return;
if( lz4 )
auto buf = m_buffer + m_bufferOffset;
char lz4buf[LZ4Size];
lz4sz_t lz4sz;
if( !m_sock.Read( &lz4sz, sizeof( lz4sz ), &tv, ShouldExit ) ) goto close;
if( !m_sock.Read( lz4buf, lz4sz, &tv, ShouldExit ) ) goto close;
bytes += sizeof( lz4sz ) + lz4sz;
auto sz = LZ4_decompress_safe_continue( m_stream, lz4buf, buf, lz4sz, TargetFrameSize );
assert( sz >= 0 );
const char* ptr = buf;
const char* end = buf + sz;
while( ptr < end )
{
auto buf = m_buffer + m_bufferOffset;
char lz4buf[LZ4Size];
lz4sz_t lz4sz;
if( !m_sock.Read( &lz4sz, sizeof( lz4sz ), &tv, ShouldExit ) ) goto close;
if( !m_sock.Read( lz4buf, lz4sz, &tv, ShouldExit ) ) goto close;
bytes += sizeof( lz4sz ) + lz4sz;
auto sz = LZ4_decompress_safe_continue( m_stream, lz4buf, buf, lz4sz, TargetFrameSize );
assert( sz >= 0 );
const char* ptr = buf;
const char* end = buf + sz;
while( ptr < end )
{
auto ev = (QueueItem*)ptr;
DispatchProcess( *ev, ptr );
}
m_bufferOffset += sz;
if( m_bufferOffset > TargetFrameSize * 2 ) m_bufferOffset = 0;
}
else
{
QueueItem ev;
if( !m_sock.Read( &ev.hdr, sizeof( QueueHeader ), &tv, ShouldExit ) ) goto close;
const auto payload = QueueDataSize[ev.hdr.idx] - sizeof( QueueHeader );
if( payload > 0 )
{
if( !m_sock.Read( ((char*)&ev) + sizeof( QueueHeader ), payload, &tv, ShouldExit ) ) goto close;
}
bytes += sizeof( QueueHeader ) + payload; // ignores string transfer
DispatchProcess( ev );
auto ev = (QueueItem*)ptr;
DispatchProcess( *ev, ptr );
}
m_bufferOffset += sz;
if( m_bufferOffset > TargetFrameSize * 2 ) m_bufferOffset = 0;
HandlePostponedPlots();
auto t1 = std::chrono::high_resolution_clock::now();
@ -544,49 +527,6 @@ close:
}
}
void View::DispatchProcess( const QueueItem& ev )
{
if( ev.hdr.type == QueueType::CustomStringData || ev.hdr.type == QueueType::StringData || ev.hdr.type == QueueType::ThreadName || ev.hdr.type == QueueType::PlotName || ev.hdr.type == QueueType::MessageData || ev.hdr.type == QueueType::SourceLocationPayload )
{
timeval tv;
tv.tv_sec = 0;
tv.tv_usec = 10000;
char buf[TargetFrameSize];
uint16_t sz;
m_sock.Read( &sz, sizeof( sz ), &tv, ShouldExit );
m_sock.Read( buf, sz, &tv, ShouldExit );
switch( ev.hdr.type )
{
case QueueType::CustomStringData:
AddCustomString( ev.stringTransfer.ptr, std::string( buf, buf+sz ) );
break;
case QueueType::StringData:
AddString( ev.stringTransfer.ptr, std::string( buf, buf+sz ) );
break;
case QueueType::ThreadName:
AddThreadString( ev.stringTransfer.ptr, std::string( buf, buf+sz ) );
break;
case QueueType::PlotName:
HandlePlotName( ev.stringTransfer.ptr, std::string( buf, buf+sz ) );
break;
case QueueType::MessageData:
AddMessageData( ev.stringTransfer.ptr, buf, sz );
break;
case QueueType::SourceLocationPayload:
AddSourceLocationPayload( ev.stringTransfer.ptr, buf, sz );
break;
default:
assert( false );
break;
}
}
else
{
Process( ev );
}
}
void View::DispatchProcess( const QueueItem& ev, const char*& ptr )
{
ptr += QueueDataSize[ev.hdr.idx];

View File

@ -117,7 +117,6 @@ private:
void Worker();
void DispatchProcess( const QueueItem& ev );
void DispatchProcess( const QueueItem& ev, const char*& ptr );
void ServerQuery( uint8_t type, uint64_t data );