mirror of
https://github.com/wolfpld/tracy.git
synced 2024-11-26 16:04:34 +00:00
Move sending data to a separate function.
This commit is contained in:
parent
cd9218e952
commit
76df000467
@ -80,22 +80,21 @@ void Profiler::Worker()
|
||||
|
||||
for(;;)
|
||||
{
|
||||
std::unique_ptr<Socket> sock;
|
||||
for(;;)
|
||||
{
|
||||
if( m_shutdown.load( std::memory_order_relaxed ) ) return;
|
||||
sock = listen.Accept();
|
||||
if( sock ) break;
|
||||
m_sock = listen.Accept();
|
||||
if( m_sock ) break;
|
||||
}
|
||||
|
||||
sock->Send( &m_timeBegin, sizeof( m_timeBegin ) );
|
||||
m_sock->Send( &m_timeBegin, sizeof( m_timeBegin ) );
|
||||
#ifdef _DEBUG
|
||||
// notify client that lz4 compression is disabled (too slow in debug builds)
|
||||
char val = 0;
|
||||
sock->Send( &val, 1 );
|
||||
m_sock->Send( &val, 1 );
|
||||
#else
|
||||
char val = 1;
|
||||
sock->Send( &val, 1 );
|
||||
m_sock->Send( &val, 1 );
|
||||
#endif
|
||||
|
||||
for(;;)
|
||||
@ -114,14 +113,7 @@ void Profiler::Worker()
|
||||
memcpy( ptr, item+i, dsz );
|
||||
ptr += dsz;
|
||||
}
|
||||
#ifdef _DEBUG
|
||||
if( sock->Send( buf, ptr - buf ) == -1 ) break;
|
||||
#else
|
||||
char lz4[LZ4Size + sizeof( lz4sz_t )];
|
||||
const lz4sz_t lz4sz = LZ4_compress_default( buf, lz4 + sizeof( lz4sz_t ), ptr - buf, LZ4Size );
|
||||
memcpy( lz4, &lz4sz, sizeof( lz4sz ) );
|
||||
if( sock->Send( lz4, lz4sz + sizeof( lz4sz_t ) ) == -1 ) break;
|
||||
#endif
|
||||
if( !SendData( buf, ptr - buf ) ) break;
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -131,4 +123,17 @@ void Profiler::Worker()
|
||||
}
|
||||
}
|
||||
|
||||
bool Profiler::SendData( const char* data, size_t len )
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
if( m_sock->Send( data, len ) == -1 ) return false;
|
||||
#else
|
||||
char lz4[LZ4Size + sizeof( lz4sz_t )];
|
||||
const lz4sz_t lz4sz = LZ4_compress_default( data, lz4 + sizeof( lz4sz_t ), len, LZ4Size );
|
||||
memcpy( lz4, &lz4sz, sizeof( lz4sz ) );
|
||||
if( m_sock->Send( lz4, lz4sz + sizeof( lz4sz_t ) ) == -1 ) return false;
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -12,6 +12,8 @@
|
||||
namespace tracy
|
||||
{
|
||||
|
||||
class Socket;
|
||||
|
||||
static inline int64_t GetTime()
|
||||
{
|
||||
return std::chrono::duration_cast<std::chrono::nanoseconds>( std::chrono::high_resolution_clock::now().time_since_epoch() ).count();
|
||||
@ -31,6 +33,8 @@ public:
|
||||
private:
|
||||
void Worker();
|
||||
|
||||
bool SendData( const char* data, size_t len );
|
||||
|
||||
static Profiler* Instance();
|
||||
static moodycamel::ProducerToken& GetToken()
|
||||
{
|
||||
@ -43,6 +47,7 @@ private:
|
||||
std::atomic<bool> m_shutdown;
|
||||
moodycamel::ConcurrentQueue<QueueItem> m_queue;
|
||||
std::atomic<uint64_t> m_id;
|
||||
std::unique_ptr<Socket> m_sock;
|
||||
};
|
||||
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user