mirror of
https://github.com/wolfpld/tracy.git
synced 2025-03-20 07:40:02 +08:00
[NOMERGE] sample reformatted files to get a sense of the changes
This commit is contained in:
parent
1307dbf4bc
commit
4ee0c1e7b1
@ -1,8 +1,8 @@
|
|||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
# include <windows.h>
|
# include <io.h>
|
||||||
# include <io.h>
|
# include <windows.h>
|
||||||
#else
|
#else
|
||||||
# include <unistd.h>
|
# include <unistd.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
@ -25,28 +25,28 @@
|
|||||||
#include "../../server/TracyWorker.hpp"
|
#include "../../server/TracyWorker.hpp"
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
# include "../../getopt/getopt.h"
|
# include "../../getopt/getopt.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
// This atomic is written by a signal handler (SigInt). Traditionally that would
|
// This atomic is written by a signal handler (SigInt). Traditionally that would
|
||||||
// have had to be `volatile sig_atomic_t`, and annoyingly, `bool` was
|
// have had to be `volatile sig_atomic_t`, and annoyingly, `bool` was
|
||||||
// technically not allowed there, even though in practice it would work.
|
// technically not allowed there, even though in practice it would work.
|
||||||
// The good thing with C++11 atomics is that we can use atomic<bool> instead
|
// The good thing with C++11 atomics is that we can use atomic<bool> instead
|
||||||
// here and be on the actually supported path.
|
// here and be on the actually supported path.
|
||||||
static std::atomic<bool> s_disconnect { false };
|
static std::atomic<bool> s_disconnect{ false };
|
||||||
|
|
||||||
void SigInt( int )
|
void SigInt( int )
|
||||||
{
|
{
|
||||||
// Relaxed order is closest to a traditional `volatile` write.
|
// Relaxed order is closest to a traditional `volatile` write.
|
||||||
// We don't need stronger ordering since this signal handler doesn't do
|
// We don't need stronger ordering since this signal handler doesn't do
|
||||||
// anything else that would need to be ordered relatively to this.
|
// anything else that would need to be ordered relatively to this.
|
||||||
s_disconnect.store(true, std::memory_order_relaxed);
|
s_disconnect.store( true, std::memory_order_relaxed );
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool s_isStdoutATerminal = false;
|
static bool s_isStdoutATerminal = false;
|
||||||
|
|
||||||
void InitIsStdoutATerminal() {
|
void InitIsStdoutATerminal()
|
||||||
|
{
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
s_isStdoutATerminal = _isatty( fileno( stdout ) );
|
s_isStdoutATerminal = _isatty( fileno( stdout ) );
|
||||||
#else
|
#else
|
||||||
@ -69,7 +69,8 @@ bool IsStdoutATerminal() { return s_isStdoutATerminal; }
|
|||||||
|
|
||||||
// Like printf, but if stdout is a terminal, prepends the output with
|
// Like printf, but if stdout is a terminal, prepends the output with
|
||||||
// the given `ansiEscape` and appends ANSI_RESET.
|
// the given `ansiEscape` and appends ANSI_RESET.
|
||||||
void AnsiPrintf( const char* ansiEscape, const char* format, ... ) {
|
void AnsiPrintf( const char* ansiEscape, const char* format, ... )
|
||||||
|
{
|
||||||
if( IsStdoutATerminal() )
|
if( IsStdoutATerminal() )
|
||||||
{
|
{
|
||||||
// Prepend ansiEscape and append ANSI_RESET.
|
// Prepend ansiEscape and append ANSI_RESET.
|
||||||
@ -133,7 +134,7 @@ int main( int argc, char** argv )
|
|||||||
overwrite = true;
|
overwrite = true;
|
||||||
break;
|
break;
|
||||||
case 's':
|
case 's':
|
||||||
seconds = atoi(optarg);
|
seconds = atoi( optarg );
|
||||||
break;
|
break;
|
||||||
case 'm':
|
case 'm':
|
||||||
memoryLimit = std::clamp( atoll( optarg ), 1ll, 999ll ) * tracy::GetPhysicalMemorySize() / 100;
|
memoryLimit = std::clamp( atoll( optarg ), 1ll, 999ll ) * tracy::GetPhysicalMemorySize() / 100;
|
||||||
@ -170,22 +171,26 @@ int main( int argc, char** argv )
|
|||||||
const auto handshake = worker.GetHandshakeStatus();
|
const auto handshake = worker.GetHandshakeStatus();
|
||||||
if( handshake == tracy::HandshakeProtocolMismatch )
|
if( handshake == tracy::HandshakeProtocolMismatch )
|
||||||
{
|
{
|
||||||
printf( "\nThe client you are trying to connect to uses incompatible protocol version.\nMake sure you are using the same Tracy version on both client and server.\n" );
|
printf(
|
||||||
|
"\nThe client you are trying to connect to uses incompatible protocol version.\nMake sure you are using the same Tracy version on both client and server.\n" );
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
if( handshake == tracy::HandshakeNotAvailable )
|
if( handshake == tracy::HandshakeNotAvailable )
|
||||||
{
|
{
|
||||||
printf( "\nThe client you are trying to connect to is no longer able to sent profiling data,\nbecause another server was already connected to it.\nYou can do the following:\n\n 1. Restart the client application.\n 2. Rebuild the client application with on-demand mode enabled.\n" );
|
printf(
|
||||||
|
"\nThe client you are trying to connect to is no longer able to sent profiling data,\nbecause another server was already connected to it.\nYou can do the following:\n\n 1. Restart the client application.\n 2. Rebuild the client application with on-demand mode enabled.\n" );
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
if( handshake == tracy::HandshakeDropped )
|
if( handshake == tracy::HandshakeDropped )
|
||||||
{
|
{
|
||||||
printf( "\nThe client you are trying to connect to has disconnected during the initial\nconnection handshake. Please check your network configuration.\n" );
|
printf(
|
||||||
|
"\nThe client you are trying to connect to has disconnected during the initial\nconnection handshake. Please check your network configuration.\n" );
|
||||||
return 3;
|
return 3;
|
||||||
}
|
}
|
||||||
std::this_thread::sleep_for( std::chrono::milliseconds( 100 ) );
|
std::this_thread::sleep_for( std::chrono::milliseconds( 100 ) );
|
||||||
}
|
}
|
||||||
printf( "\nQueue delay: %s\nTimer resolution: %s\n", tracy::TimeToString( worker.GetDelay() ), tracy::TimeToString( worker.GetResolution() ) );
|
printf( "\nQueue delay: %s\nTimer resolution: %s\n", tracy::TimeToString( worker.GetDelay() ),
|
||||||
|
tracy::TimeToString( worker.GetResolution() ) );
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
signal( SIGINT, SigInt );
|
signal( SIGINT, SigInt );
|
||||||
@ -210,7 +215,7 @@ int main( int argc, char** argv )
|
|||||||
worker.Disconnect();
|
worker.Disconnect();
|
||||||
// Relaxed order is sufficient because only this thread ever reads
|
// Relaxed order is sufficient because only this thread ever reads
|
||||||
// this value.
|
// this value.
|
||||||
s_disconnect.store(false, std::memory_order_relaxed );
|
s_disconnect.store( false, std::memory_order_relaxed );
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -232,21 +237,22 @@ int main( int argc, char** argv )
|
|||||||
unitsPerMbps = 1000.f;
|
unitsPerMbps = 1000.f;
|
||||||
}
|
}
|
||||||
AnsiPrintf( ANSI_ERASE_LINE ANSI_CYAN ANSI_BOLD, "\r%7.2f %s", mbps * unitsPerMbps, unit );
|
AnsiPrintf( ANSI_ERASE_LINE ANSI_CYAN ANSI_BOLD, "\r%7.2f %s", mbps * unitsPerMbps, unit );
|
||||||
printf( " /");
|
printf( " /" );
|
||||||
AnsiPrintf( ANSI_CYAN ANSI_BOLD, "%5.1f%%", compRatio * 100.f );
|
AnsiPrintf( ANSI_CYAN ANSI_BOLD, "%5.1f%%", compRatio * 100.f );
|
||||||
printf( " =");
|
printf( " =" );
|
||||||
AnsiPrintf( ANSI_YELLOW ANSI_BOLD, "%7.2f Mbps", mbps / compRatio );
|
AnsiPrintf( ANSI_YELLOW ANSI_BOLD, "%7.2f Mbps", mbps / compRatio );
|
||||||
printf( " | ");
|
printf( " | " );
|
||||||
AnsiPrintf( ANSI_YELLOW, "Tx: ");
|
AnsiPrintf( ANSI_YELLOW, "Tx: " );
|
||||||
AnsiPrintf( ANSI_GREEN, "%s", tracy::MemSizeToString( netTotal ) );
|
AnsiPrintf( ANSI_GREEN, "%s", tracy::MemSizeToString( netTotal ) );
|
||||||
printf( " | ");
|
printf( " | " );
|
||||||
AnsiPrintf( ANSI_RED ANSI_BOLD, "%s", tracy::MemSizeToString( tracy::memUsage.load( std::memory_order_relaxed ) ) );
|
AnsiPrintf( ANSI_RED ANSI_BOLD, "%s",
|
||||||
|
tracy::MemSizeToString( tracy::memUsage.load( std::memory_order_relaxed ) ) );
|
||||||
if( memoryLimit > 0 )
|
if( memoryLimit > 0 )
|
||||||
{
|
{
|
||||||
printf( " / " );
|
printf( " / " );
|
||||||
AnsiPrintf( ANSI_BLUE ANSI_BOLD, "%s", tracy::MemSizeToString( memoryLimit ) );
|
AnsiPrintf( ANSI_BLUE ANSI_BOLD, "%s", tracy::MemSizeToString( memoryLimit ) );
|
||||||
}
|
}
|
||||||
printf( " | ");
|
printf( " | " );
|
||||||
AnsiPrintf( ANSI_RED, "%s", tracy::TimeToString( worker.GetLastTime() - firstTime ) );
|
AnsiPrintf( ANSI_RED, "%s", tracy::TimeToString( worker.GetLastTime() - firstTime ) );
|
||||||
fflush( stdout );
|
fflush( stdout );
|
||||||
}
|
}
|
||||||
@ -255,11 +261,11 @@ int main( int argc, char** argv )
|
|||||||
if( seconds != -1 )
|
if( seconds != -1 )
|
||||||
{
|
{
|
||||||
const auto dur = std::chrono::high_resolution_clock::now() - t0;
|
const auto dur = std::chrono::high_resolution_clock::now() - t0;
|
||||||
if( std::chrono::duration_cast<std::chrono::seconds>(dur).count() >= seconds )
|
if( std::chrono::duration_cast<std::chrono::seconds>( dur ).count() >= seconds )
|
||||||
{
|
{
|
||||||
// Relaxed order is sufficient because only this thread ever reads
|
// Relaxed order is sufficient because only this thread ever reads
|
||||||
// this value.
|
// this value.
|
||||||
s_disconnect.store(true, std::memory_order_relaxed );
|
s_disconnect.store( true, std::memory_order_relaxed );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -289,12 +295,12 @@ int main( int argc, char** argv )
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
const auto fsz = frameData->size;
|
const auto fsz = frameData->size;
|
||||||
for( uint8_t f=0; f<fsz; f++ )
|
for( uint8_t f = 0; f < fsz; f++ )
|
||||||
{
|
{
|
||||||
const auto& frame = frameData->data[f];
|
const auto& frame = frameData->data[f];
|
||||||
auto txt = worker.GetString( frame.name );
|
auto txt = worker.GetString( frame.name );
|
||||||
|
|
||||||
if( fidx == 0 && f != fsz-1 )
|
if( fidx == 0 && f != fsz - 1 )
|
||||||
{
|
{
|
||||||
auto test = tracy::s_tracyStackFrames;
|
auto test = tracy::s_tracyStackFrames;
|
||||||
bool match = false;
|
bool match = false;
|
||||||
@ -305,12 +311,11 @@ int main( int argc, char** argv )
|
|||||||
match = true;
|
match = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
} while( *++test );
|
||||||
while( *++test );
|
|
||||||
if( match ) continue;
|
if( match ) continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( f == fsz-1 )
|
if( f == fsz - 1 )
|
||||||
{
|
{
|
||||||
printf( "%3i. ", fidx++ );
|
printf( "%3i. ", fidx++ );
|
||||||
}
|
}
|
||||||
@ -343,8 +348,9 @@ int main( int argc, char** argv )
|
|||||||
}
|
}
|
||||||
|
|
||||||
printf( "\nFrames: %" PRIu64 "\nTime span: %s\nZones: %s\nElapsed time: %s\nSaving trace...",
|
printf( "\nFrames: %" PRIu64 "\nTime span: %s\nZones: %s\nElapsed time: %s\nSaving trace...",
|
||||||
worker.GetFrameCount( *worker.GetFramesBase() ), tracy::TimeToString( worker.GetLastTime() - firstTime ), tracy::RealToString( worker.GetZoneCount() ),
|
worker.GetFrameCount( *worker.GetFramesBase() ), tracy::TimeToString( worker.GetLastTime() - firstTime ),
|
||||||
tracy::TimeToString( std::chrono::duration_cast<std::chrono::nanoseconds>( t1 - t0 ).count() ) );
|
tracy::RealToString( worker.GetZoneCount() ),
|
||||||
|
tracy::TimeToString( std::chrono::duration_cast<std::chrono::nanoseconds>( t1 - t0 ).count() ) );
|
||||||
fflush( stdout );
|
fflush( stdout );
|
||||||
auto f = std::unique_ptr<tracy::FileWrite>( tracy::FileWrite::Open( output, tracy::FileCompression::Zstd, 3, 4 ) );
|
auto f = std::unique_ptr<tracy::FileWrite>( tracy::FileWrite::Open( output, tracy::FileCompression::Zstd, 3, 4 ) );
|
||||||
if( f )
|
if( f )
|
||||||
@ -353,11 +359,12 @@ int main( int argc, char** argv )
|
|||||||
AnsiPrintf( ANSI_GREEN ANSI_BOLD, " done!\n" );
|
AnsiPrintf( ANSI_GREEN ANSI_BOLD, " done!\n" );
|
||||||
f->Finish();
|
f->Finish();
|
||||||
const auto stats = f->GetCompressionStatistics();
|
const auto stats = f->GetCompressionStatistics();
|
||||||
printf( "Trace size %s (%.2f%% ratio)\n", tracy::MemSizeToString( stats.second ), 100.f * stats.second / stats.first );
|
printf( "Trace size %s (%.2f%% ratio)\n", tracy::MemSizeToString( stats.second ),
|
||||||
|
100.f * stats.second / stats.first );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
AnsiPrintf( ANSI_RED ANSI_BOLD, " failed!\n");
|
AnsiPrintf( ANSI_RED ANSI_BOLD, " failed!\n" );
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
@ -9,17 +9,32 @@ namespace tracy
|
|||||||
|
|
||||||
constexpr unsigned Lz4CompressBound( unsigned isize ) { return isize + ( isize / 255 ) + 16; }
|
constexpr unsigned Lz4CompressBound( unsigned isize ) { return isize + ( isize / 255 ) + 16; }
|
||||||
|
|
||||||
enum : uint32_t { ProtocolVersion = 66 };
|
enum : uint32_t
|
||||||
enum : uint16_t { BroadcastVersion = 3 };
|
{
|
||||||
|
ProtocolVersion = 66
|
||||||
|
};
|
||||||
|
enum : uint16_t
|
||||||
|
{
|
||||||
|
BroadcastVersion = 3
|
||||||
|
};
|
||||||
|
|
||||||
using lz4sz_t = uint32_t;
|
using lz4sz_t = uint32_t;
|
||||||
|
|
||||||
enum { TargetFrameSize = 256 * 1024 };
|
enum
|
||||||
enum { LZ4Size = Lz4CompressBound( TargetFrameSize ) };
|
{
|
||||||
static_assert( LZ4Size <= (std::numeric_limits<lz4sz_t>::max)(), "LZ4Size greater than lz4sz_t" );
|
TargetFrameSize = 256 * 1024
|
||||||
|
};
|
||||||
|
enum
|
||||||
|
{
|
||||||
|
LZ4Size = Lz4CompressBound( TargetFrameSize )
|
||||||
|
};
|
||||||
|
static_assert( LZ4Size <= ( std::numeric_limits<lz4sz_t>::max )(), "LZ4Size greater than lz4sz_t" );
|
||||||
static_assert( TargetFrameSize * 2 >= 64 * 1024, "Not enough space for LZ4 stream buffer" );
|
static_assert( TargetFrameSize * 2 >= 64 * 1024, "Not enough space for LZ4 stream buffer" );
|
||||||
|
|
||||||
enum { HandshakeShibbolethSize = 8 };
|
enum
|
||||||
|
{
|
||||||
|
HandshakeShibbolethSize = 8
|
||||||
|
};
|
||||||
static const char HandshakeShibboleth[HandshakeShibbolethSize] = { 'T', 'r', 'a', 'c', 'y', 'P', 'r', 'f' };
|
static const char HandshakeShibboleth[HandshakeShibbolethSize] = { 'T', 'r', 'a', 'c', 'y', 'P', 'r', 'f' };
|
||||||
|
|
||||||
enum HandshakeStatus : uint8_t
|
enum HandshakeStatus : uint8_t
|
||||||
@ -31,8 +46,14 @@ enum HandshakeStatus : uint8_t
|
|||||||
HandshakeDropped
|
HandshakeDropped
|
||||||
};
|
};
|
||||||
|
|
||||||
enum { WelcomeMessageProgramNameSize = 64 };
|
enum
|
||||||
enum { WelcomeMessageHostInfoSize = 1024 };
|
{
|
||||||
|
WelcomeMessageProgramNameSize = 64
|
||||||
|
};
|
||||||
|
enum
|
||||||
|
{
|
||||||
|
WelcomeMessageHostInfoSize = 1024
|
||||||
|
};
|
||||||
|
|
||||||
#pragma pack( push, 1 )
|
#pragma pack( push, 1 )
|
||||||
|
|
||||||
@ -65,8 +86,10 @@ struct ServerQueryPacket
|
|||||||
uint32_t extra;
|
uint32_t extra;
|
||||||
};
|
};
|
||||||
|
|
||||||
enum { ServerQueryPacketSize = sizeof( ServerQueryPacket ) };
|
enum
|
||||||
|
{
|
||||||
|
ServerQueryPacketSize = sizeof( ServerQueryPacket )
|
||||||
|
};
|
||||||
|
|
||||||
enum CpuArchitecture : uint8_t
|
enum CpuArchitecture : uint8_t
|
||||||
{
|
{
|
||||||
@ -77,15 +100,14 @@ enum CpuArchitecture : uint8_t
|
|||||||
CpuArchArm64
|
CpuArchArm64
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
struct WelcomeFlag
|
struct WelcomeFlag
|
||||||
{
|
{
|
||||||
enum _t : uint8_t
|
enum _t : uint8_t
|
||||||
{
|
{
|
||||||
OnDemand = 1 << 0,
|
OnDemand = 1 << 0,
|
||||||
IsApple = 1 << 1,
|
IsApple = 1 << 1,
|
||||||
CodeTransfer = 1 << 2,
|
CodeTransfer = 1 << 2,
|
||||||
CombineSamples = 1 << 3,
|
CombineSamples = 1 << 3,
|
||||||
IdentifySamples = 1 << 4,
|
IdentifySamples = 1 << 4,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
@ -109,8 +131,10 @@ struct WelcomeMessage
|
|||||||
char hostInfo[WelcomeMessageHostInfoSize];
|
char hostInfo[WelcomeMessageHostInfoSize];
|
||||||
};
|
};
|
||||||
|
|
||||||
enum { WelcomeMessageSize = sizeof( WelcomeMessage ) };
|
enum
|
||||||
|
{
|
||||||
|
WelcomeMessageSize = sizeof( WelcomeMessage )
|
||||||
|
};
|
||||||
|
|
||||||
struct OnDemandPayloadMessage
|
struct OnDemandPayloadMessage
|
||||||
{
|
{
|
||||||
@ -118,8 +142,10 @@ struct OnDemandPayloadMessage
|
|||||||
uint64_t currentTime;
|
uint64_t currentTime;
|
||||||
};
|
};
|
||||||
|
|
||||||
enum { OnDemandPayloadMessageSize = sizeof( OnDemandPayloadMessage ) };
|
enum
|
||||||
|
{
|
||||||
|
OnDemandPayloadMessageSize = sizeof( OnDemandPayloadMessage )
|
||||||
|
};
|
||||||
|
|
||||||
struct BroadcastMessage
|
struct BroadcastMessage
|
||||||
{
|
{
|
||||||
@ -127,7 +153,7 @@ struct BroadcastMessage
|
|||||||
uint16_t listenPort;
|
uint16_t listenPort;
|
||||||
uint32_t protocolVersion;
|
uint32_t protocolVersion;
|
||||||
uint64_t pid;
|
uint64_t pid;
|
||||||
int32_t activeTime; // in seconds
|
int32_t activeTime; // in seconds
|
||||||
char programName[WelcomeMessageProgramNameSize];
|
char programName[WelcomeMessageProgramNameSize];
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -157,10 +183,22 @@ struct BroadcastMessage_v0
|
|||||||
char programName[WelcomeMessageProgramNameSize];
|
char programName[WelcomeMessageProgramNameSize];
|
||||||
};
|
};
|
||||||
|
|
||||||
enum { BroadcastMessageSize = sizeof( BroadcastMessage ) };
|
enum
|
||||||
enum { BroadcastMessageSize_v2 = sizeof( BroadcastMessage_v2 ) };
|
{
|
||||||
enum { BroadcastMessageSize_v1 = sizeof( BroadcastMessage_v1 ) };
|
BroadcastMessageSize = sizeof( BroadcastMessage )
|
||||||
enum { BroadcastMessageSize_v0 = sizeof( BroadcastMessage_v0 ) };
|
};
|
||||||
|
enum
|
||||||
|
{
|
||||||
|
BroadcastMessageSize_v2 = sizeof( BroadcastMessage_v2 )
|
||||||
|
};
|
||||||
|
enum
|
||||||
|
{
|
||||||
|
BroadcastMessageSize_v1 = sizeof( BroadcastMessage_v1 )
|
||||||
|
};
|
||||||
|
enum
|
||||||
|
{
|
||||||
|
BroadcastMessageSize_v0 = sizeof( BroadcastMessage_v0 )
|
||||||
|
};
|
||||||
|
|
||||||
#pragma pack( pop )
|
#pragma pack( pop )
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user