mirror of
https://github.com/wolfpld/tracy.git
synced 2024-11-27 00:04:35 +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(;;)
|
for(;;)
|
||||||
{
|
{
|
||||||
std::unique_ptr<Socket> sock;
|
|
||||||
for(;;)
|
for(;;)
|
||||||
{
|
{
|
||||||
if( m_shutdown.load( std::memory_order_relaxed ) ) return;
|
if( m_shutdown.load( std::memory_order_relaxed ) ) return;
|
||||||
sock = listen.Accept();
|
m_sock = listen.Accept();
|
||||||
if( sock ) break;
|
if( m_sock ) break;
|
||||||
}
|
}
|
||||||
|
|
||||||
sock->Send( &m_timeBegin, sizeof( m_timeBegin ) );
|
m_sock->Send( &m_timeBegin, sizeof( m_timeBegin ) );
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
// notify client that lz4 compression is disabled (too slow in debug builds)
|
// notify client that lz4 compression is disabled (too slow in debug builds)
|
||||||
char val = 0;
|
char val = 0;
|
||||||
sock->Send( &val, 1 );
|
m_sock->Send( &val, 1 );
|
||||||
#else
|
#else
|
||||||
char val = 1;
|
char val = 1;
|
||||||
sock->Send( &val, 1 );
|
m_sock->Send( &val, 1 );
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
for(;;)
|
for(;;)
|
||||||
@ -114,14 +113,7 @@ void Profiler::Worker()
|
|||||||
memcpy( ptr, item+i, dsz );
|
memcpy( ptr, item+i, dsz );
|
||||||
ptr += dsz;
|
ptr += dsz;
|
||||||
}
|
}
|
||||||
#ifdef _DEBUG
|
if( !SendData( buf, ptr - buf ) ) break;
|
||||||
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
|
|
||||||
}
|
}
|
||||||
else
|
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
|
namespace tracy
|
||||||
{
|
{
|
||||||
|
|
||||||
|
class Socket;
|
||||||
|
|
||||||
static inline int64_t GetTime()
|
static inline int64_t GetTime()
|
||||||
{
|
{
|
||||||
return std::chrono::duration_cast<std::chrono::nanoseconds>( std::chrono::high_resolution_clock::now().time_since_epoch() ).count();
|
return std::chrono::duration_cast<std::chrono::nanoseconds>( std::chrono::high_resolution_clock::now().time_since_epoch() ).count();
|
||||||
@ -31,6 +33,8 @@ public:
|
|||||||
private:
|
private:
|
||||||
void Worker();
|
void Worker();
|
||||||
|
|
||||||
|
bool SendData( const char* data, size_t len );
|
||||||
|
|
||||||
static Profiler* Instance();
|
static Profiler* Instance();
|
||||||
static moodycamel::ProducerToken& GetToken()
|
static moodycamel::ProducerToken& GetToken()
|
||||||
{
|
{
|
||||||
@ -43,6 +47,7 @@ private:
|
|||||||
std::atomic<bool> m_shutdown;
|
std::atomic<bool> m_shutdown;
|
||||||
moodycamel::ConcurrentQueue<QueueItem> m_queue;
|
moodycamel::ConcurrentQueue<QueueItem> m_queue;
|
||||||
std::atomic<uint64_t> m_id;
|
std::atomic<uint64_t> m_id;
|
||||||
|
std::unique_ptr<Socket> m_sock;
|
||||||
};
|
};
|
||||||
|
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user