TracyProtocol.hpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. #ifndef __TRACYPROTOCOL_HPP__
  2. #define __TRACYPROTOCOL_HPP__
  3. #include <limits>
  4. #include <stdint.h>
  5. namespace tracy
  6. {
  7. constexpr unsigned Lz4CompressBound( unsigned isize ) { return isize + ( isize / 255 ) + 16; }
  8. enum : uint32_t { ProtocolVersion = 46 };
  9. enum : uint16_t { BroadcastVersion = 2 };
  10. using lz4sz_t = uint32_t;
  11. enum { TargetFrameSize = 256 * 1024 };
  12. enum { LZ4Size = Lz4CompressBound( TargetFrameSize ) };
  13. static_assert( LZ4Size <= std::numeric_limits<lz4sz_t>::max(), "LZ4Size greater than lz4sz_t" );
  14. static_assert( TargetFrameSize * 2 >= 64 * 1024, "Not enough space for LZ4 stream buffer" );
  15. enum { HandshakeShibbolethSize = 8 };
  16. static const char HandshakeShibboleth[HandshakeShibbolethSize] = { 'T', 'r', 'a', 'c', 'y', 'P', 'r', 'f' };
  17. enum HandshakeStatus : uint8_t
  18. {
  19. HandshakePending,
  20. HandshakeWelcome,
  21. HandshakeProtocolMismatch,
  22. HandshakeNotAvailable,
  23. HandshakeDropped
  24. };
  25. enum { WelcomeMessageProgramNameSize = 64 };
  26. enum { WelcomeMessageHostInfoSize = 1024 };
  27. #pragma pack( 1 )
  28. // Must increase left query space after handling!
  29. enum ServerQuery : uint8_t
  30. {
  31. ServerQueryTerminate,
  32. ServerQueryString,
  33. ServerQueryThreadString,
  34. ServerQuerySourceLocation,
  35. ServerQueryPlotName,
  36. ServerQueryCallstackFrame,
  37. ServerQueryFrameName,
  38. ServerQueryDisconnect,
  39. ServerQueryExternalName,
  40. ServerQueryParameter,
  41. ServerQuerySymbol,
  42. ServerQuerySymbolCode,
  43. ServerQueryCodeLocation,
  44. ServerQuerySourceCode,
  45. ServerQueryDataTransfer,
  46. ServerQueryDataTransferPart
  47. };
  48. struct ServerQueryPacket
  49. {
  50. ServerQuery type;
  51. uint64_t ptr;
  52. uint32_t extra;
  53. };
  54. enum { ServerQueryPacketSize = sizeof( ServerQueryPacket ) };
  55. enum CpuArchitecture : uint8_t
  56. {
  57. CpuArchUnknown,
  58. CpuArchX86,
  59. CpuArchX64,
  60. CpuArchArm32,
  61. CpuArchArm64
  62. };
  63. struct WelcomeMessage
  64. {
  65. double timerMul;
  66. int64_t initBegin;
  67. int64_t initEnd;
  68. uint64_t delay;
  69. uint64_t resolution;
  70. uint64_t epoch;
  71. uint64_t exectime;
  72. uint64_t pid;
  73. int64_t samplingPeriod;
  74. uint8_t onDemand;
  75. uint8_t isApple;
  76. uint8_t cpuArch;
  77. uint8_t codeTransfer;
  78. char cpuManufacturer[12];
  79. uint32_t cpuId;
  80. char programName[WelcomeMessageProgramNameSize];
  81. char hostInfo[WelcomeMessageHostInfoSize];
  82. };
  83. enum { WelcomeMessageSize = sizeof( WelcomeMessage ) };
  84. struct OnDemandPayloadMessage
  85. {
  86. uint64_t frames;
  87. uint64_t currentTime;
  88. };
  89. enum { OnDemandPayloadMessageSize = sizeof( OnDemandPayloadMessage ) };
  90. struct BroadcastMessage
  91. {
  92. uint16_t broadcastVersion;
  93. uint16_t listenPort;
  94. uint32_t protocolVersion;
  95. int32_t activeTime; // in seconds
  96. char programName[WelcomeMessageProgramNameSize];
  97. };
  98. enum { BroadcastMessageSize = sizeof( BroadcastMessage ) };
  99. #pragma pack()
  100. }
  101. #endif