1
0
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:
Grégoire Roussel 2024-07-17 23:47:09 +02:00
parent 1307dbf4bc
commit 4ee0c1e7b1
2 changed files with 102 additions and 57 deletions

View File

@ -1,6 +1,6 @@
#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
@ -28,7 +28,6 @@
# 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.
@ -46,7 +45,8 @@ void SigInt( int )
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.
@ -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 );
@ -240,7 +245,8 @@ int main( int argc, char** argv )
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( " / " );
@ -305,8 +311,7 @@ int main( int argc, char** argv )
match = true; match = true;
break; break;
} }
} } while( *++test );
while( *++test );
if( match ) continue; if( match ) continue;
} }
@ -343,7 +348,8 @@ 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::RealToString( worker.GetZoneCount() ),
tracy::TimeToString( std::chrono::duration_cast<std::chrono::nanoseconds>( t1 - t0 ).count() ) ); 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 ) );
@ -353,7 +359,8 @@ 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
{ {

View File

@ -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 ) }; {
TargetFrameSize = 256 * 1024
};
enum
{
LZ4Size = Lz4CompressBound( TargetFrameSize )
};
static_assert( LZ4Size <= ( std::numeric_limits<lz4sz_t>::max )(), "LZ4Size greater than lz4sz_t" ); 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,7 +100,6 @@ enum CpuArchitecture : uint8_t
CpuArchArm64 CpuArchArm64
}; };
struct WelcomeFlag struct WelcomeFlag
{ {
enum _t : uint8_t enum _t : uint8_t
@ -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
{ {
@ -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 )