mudgangster

Tiny, scriptable MUD client
Log | Files | Refs | README

TracyQueue.hpp (11826B)


      1 #ifndef __TRACYQUEUE_HPP__
      2 #define __TRACYQUEUE_HPP__
      3 
      4 #include <stdint.h>
      5 
      6 namespace tracy
      7 {
      8 
      9 enum class QueueType : uint8_t
     10 {
     11     ZoneText,
     12     ZoneName,
     13     Message,
     14     MessageColor,
     15     MessageCallstack,
     16     MessageColorCallstack,
     17     MessageAppInfo,
     18     ZoneBeginAllocSrcLoc,
     19     ZoneBeginAllocSrcLocCallstack,
     20     CallstackMemory,
     21     Callstack,
     22     CallstackAlloc,
     23     FrameImage,
     24     ZoneBegin,
     25     ZoneBeginCallstack,
     26     ZoneEnd,
     27     LockWait,
     28     LockObtain,
     29     LockRelease,
     30     LockSharedWait,
     31     LockSharedObtain,
     32     LockSharedRelease,
     33     MemAlloc,
     34     MemFree,
     35     MemAllocCallstack,
     36     MemFreeCallstack,
     37     GpuZoneBegin,
     38     GpuZoneBeginCallstack,
     39     GpuZoneEnd,
     40     GpuZoneBeginSerial,
     41     GpuZoneBeginCallstackSerial,
     42     GpuZoneEndSerial,
     43     PlotData,
     44     ContextSwitch,
     45     ThreadWakeup,
     46     GpuTime,
     47     Terminate,
     48     KeepAlive,
     49     ThreadContext,
     50     Crash,
     51     CrashReport,
     52     ZoneValidation,
     53     FrameMarkMsg,
     54     FrameMarkMsgStart,
     55     FrameMarkMsgEnd,
     56     SourceLocation,
     57     LockAnnounce,
     58     LockTerminate,
     59     LockMark,
     60     MessageLiteral,
     61     MessageLiteralColor,
     62     MessageLiteralCallstack,
     63     MessageLiteralColorCallstack,
     64     GpuNewContext,
     65     CallstackFrameSize,
     66     CallstackFrame,
     67     SysTimeReport,
     68     TidToPid,
     69     PlotConfig,
     70     ParamSetup,
     71     StringData,
     72     ThreadName,
     73     CustomStringData,
     74     PlotName,
     75     SourceLocationPayload,
     76     CallstackPayload,
     77     CallstackAllocPayload,
     78     FrameName,
     79     FrameImageData,
     80     ExternalName,
     81     ExternalThreadName,
     82     NUM_TYPES
     83 };
     84 
     85 #pragma pack( 1 )
     86 
     87 struct QueueThreadContext
     88 {
     89     uint64_t thread;
     90 };
     91 
     92 struct QueueZoneBegin
     93 {
     94     int64_t time;
     95     uint64_t srcloc;    // ptr
     96 };
     97 
     98 struct QueueZoneEnd
     99 {
    100     int64_t time;
    101 };
    102 
    103 struct QueueZoneValidation
    104 {
    105     uint32_t id;
    106 };
    107 
    108 struct QueueStringTransfer
    109 {
    110     uint64_t ptr;
    111 };
    112 
    113 struct QueueFrameMark
    114 {
    115     int64_t time;
    116     uint64_t name;      // ptr
    117 };
    118 
    119 struct QueueFrameImage
    120 {
    121     uint64_t image;     // ptr
    122     uint64_t frame;
    123     uint16_t w;
    124     uint16_t h;
    125     uint8_t flip;
    126 };
    127 
    128 struct QueueSourceLocation
    129 {
    130     uint64_t name;
    131     uint64_t function;  // ptr
    132     uint64_t file;      // ptr
    133     uint32_t line;
    134     uint8_t r;
    135     uint8_t g;
    136     uint8_t b;
    137 };
    138 
    139 struct QueueZoneText
    140 {
    141     uint64_t text;      // ptr
    142 };
    143 
    144 enum class LockType : uint8_t
    145 {
    146     Lockable,
    147     SharedLockable
    148 };
    149 
    150 struct QueueLockAnnounce
    151 {
    152     uint32_t id;
    153     int64_t time;
    154     uint64_t lckloc;    // ptr
    155     LockType type;
    156 };
    157 
    158 struct QueueLockTerminate
    159 {
    160     uint32_t id;
    161     int64_t time;
    162     LockType type;
    163 };
    164 
    165 struct QueueLockWait
    166 {
    167     uint64_t thread;
    168     uint32_t id;
    169     int64_t time;
    170     LockType type;
    171 };
    172 
    173 struct QueueLockObtain
    174 {
    175     uint64_t thread;
    176     uint32_t id;
    177     int64_t time;
    178 };
    179 
    180 struct QueueLockRelease
    181 {
    182     uint64_t thread;
    183     uint32_t id;
    184     int64_t time;
    185 };
    186 
    187 struct QueueLockMark
    188 {
    189     uint64_t thread;
    190     uint32_t id;
    191     uint64_t srcloc;    // ptr
    192 };
    193 
    194 enum class PlotDataType : uint8_t
    195 {
    196     Float,
    197     Double,
    198     Int
    199 };
    200 
    201 struct QueuePlotData
    202 {
    203     uint64_t name;      // ptr
    204     int64_t time;
    205     PlotDataType type;
    206     union
    207     {
    208         double d;
    209         float f;
    210         int64_t i;
    211     } data;
    212 };
    213 
    214 struct QueueMessage
    215 {
    216     int64_t time;
    217     uint64_t text;      // ptr
    218 };
    219 
    220 struct QueueMessageColor : public QueueMessage
    221 {
    222     uint8_t r;
    223     uint8_t g;
    224     uint8_t b;
    225 };
    226 
    227 struct QueueGpuNewContext
    228 {
    229     int64_t cpuTime;
    230     int64_t gpuTime;
    231     uint64_t thread;
    232     float period;
    233     uint8_t context;
    234     uint8_t accuracyBits;
    235 };
    236 
    237 struct QueueGpuZoneBegin
    238 {
    239     int64_t cpuTime;
    240     uint64_t srcloc;
    241     uint64_t thread;
    242     uint16_t queryId;
    243     uint8_t context;
    244 };
    245 
    246 struct QueueGpuZoneEnd
    247 {
    248     int64_t cpuTime;
    249     uint64_t thread;
    250     uint16_t queryId;
    251     uint8_t context;
    252 };
    253 
    254 struct QueueGpuTime
    255 {
    256     int64_t gpuTime;
    257     uint16_t queryId;
    258     uint8_t context;
    259 };
    260 
    261 struct QueueMemAlloc
    262 {
    263     int64_t time;
    264     uint64_t thread;
    265     uint64_t ptr;
    266     char size[6];
    267 };
    268 
    269 struct QueueMemFree
    270 {
    271     int64_t time;
    272     uint64_t thread;
    273     uint64_t ptr;
    274 };
    275 
    276 struct QueueCallstackMemory
    277 {
    278     uint64_t ptr;
    279 };
    280 
    281 struct QueueCallstack
    282 {
    283     uint64_t ptr;
    284 };
    285 
    286 struct QueueCallstackAlloc
    287 {
    288     uint64_t ptr;
    289     uint64_t nativePtr;
    290 };
    291 
    292 struct QueueCallstackFrameSize
    293 {
    294     uint64_t ptr;
    295     uint8_t size;
    296 };
    297 
    298 struct QueueCallstackFrame
    299 {
    300     uint64_t name;
    301     uint64_t file;
    302     uint32_t line;
    303 };
    304 
    305 struct QueueCrashReport
    306 {
    307     int64_t time;
    308     uint64_t text;      // ptr
    309 };
    310 
    311 struct QueueSysTime
    312 {
    313     int64_t time;
    314     float sysTime;
    315 };
    316 
    317 struct QueueContextSwitch
    318 {
    319     int64_t time;
    320     uint64_t oldThread;
    321     uint64_t newThread;
    322     uint8_t cpu;
    323     uint8_t reason;
    324     uint8_t state;
    325 };
    326 
    327 struct QueueThreadWakeup
    328 {
    329     int64_t time;
    330     uint64_t thread;
    331 };
    332 
    333 struct QueueTidToPid
    334 {
    335     uint64_t tid;
    336     uint64_t pid;
    337 };
    338 
    339 enum class PlotFormatType : uint8_t
    340 {
    341     Number,
    342     Memory,
    343     Percentage
    344 };
    345 
    346 struct QueuePlotConfig
    347 {
    348     uint64_t name;      // ptr
    349     uint8_t type;
    350 };
    351 
    352 struct QueueParamSetup
    353 {
    354     uint32_t idx;
    355     uint64_t name;      // ptr
    356     uint8_t isBool;
    357     int32_t val;
    358 };
    359 
    360 struct QueueHeader
    361 {
    362     union
    363     {
    364         QueueType type;
    365         uint8_t idx;
    366     };
    367 };
    368 
    369 struct QueueItem
    370 {
    371     QueueHeader hdr;
    372     union
    373     {
    374         QueueThreadContext threadCtx;
    375         QueueZoneBegin zoneBegin;
    376         QueueZoneEnd zoneEnd;
    377         QueueZoneValidation zoneValidation;
    378         QueueStringTransfer stringTransfer;
    379         QueueFrameMark frameMark;
    380         QueueFrameImage frameImage;
    381         QueueSourceLocation srcloc;
    382         QueueZoneText zoneText;
    383         QueueLockAnnounce lockAnnounce;
    384         QueueLockTerminate lockTerminate;
    385         QueueLockWait lockWait;
    386         QueueLockObtain lockObtain;
    387         QueueLockRelease lockRelease;
    388         QueueLockMark lockMark;
    389         QueuePlotData plotData;
    390         QueueMessage message;
    391         QueueMessageColor messageColor;
    392         QueueGpuNewContext gpuNewContext;
    393         QueueGpuZoneBegin gpuZoneBegin;
    394         QueueGpuZoneEnd gpuZoneEnd;
    395         QueueGpuTime gpuTime;
    396         QueueMemAlloc memAlloc;
    397         QueueMemFree memFree;
    398         QueueCallstackMemory callstackMemory;
    399         QueueCallstack callstack;
    400         QueueCallstackAlloc callstackAlloc;
    401         QueueCallstackFrameSize callstackFrameSize;
    402         QueueCallstackFrame callstackFrame;
    403         QueueCrashReport crashReport;
    404         QueueSysTime sysTime;
    405         QueueContextSwitch contextSwitch;
    406         QueueThreadWakeup threadWakeup;
    407         QueueTidToPid tidToPid;
    408         QueuePlotConfig plotConfig;
    409         QueueParamSetup paramSetup;
    410     };
    411 };
    412 #pragma pack()
    413 
    414 
    415 enum { QueueItemSize = sizeof( QueueItem ) };
    416 
    417 static const size_t QueueDataSize[] = {
    418     sizeof( QueueHeader ) + sizeof( QueueZoneText ),
    419     sizeof( QueueHeader ) + sizeof( QueueZoneText ),        // zone name
    420     sizeof( QueueHeader ) + sizeof( QueueMessage ),
    421     sizeof( QueueHeader ) + sizeof( QueueMessageColor ),
    422     sizeof( QueueHeader ) + sizeof( QueueMessage ),         // callstack
    423     sizeof( QueueHeader ) + sizeof( QueueMessageColor ),    // callstack
    424     sizeof( QueueHeader ) + sizeof( QueueMessage ),         // app info
    425     sizeof( QueueHeader ) + sizeof( QueueZoneBegin ),       // allocated source location
    426     sizeof( QueueHeader ) + sizeof( QueueZoneBegin ),       // allocated source location, callstack
    427     sizeof( QueueHeader ) + sizeof( QueueCallstackMemory ),
    428     sizeof( QueueHeader ) + sizeof( QueueCallstack ),
    429     sizeof( QueueHeader ) + sizeof( QueueCallstackAlloc ),
    430     sizeof( QueueHeader ) + sizeof( QueueFrameImage ),
    431     sizeof( QueueHeader ) + sizeof( QueueZoneBegin ),
    432     sizeof( QueueHeader ) + sizeof( QueueZoneBegin ),       // callstack
    433     sizeof( QueueHeader ) + sizeof( QueueZoneEnd ),
    434     sizeof( QueueHeader ) + sizeof( QueueLockWait ),
    435     sizeof( QueueHeader ) + sizeof( QueueLockObtain ),
    436     sizeof( QueueHeader ) + sizeof( QueueLockRelease ),
    437     sizeof( QueueHeader ) + sizeof( QueueLockWait ),        // shared
    438     sizeof( QueueHeader ) + sizeof( QueueLockObtain ),      // shared
    439     sizeof( QueueHeader ) + sizeof( QueueLockRelease ),     // shared
    440     sizeof( QueueHeader ) + sizeof( QueueMemAlloc ),
    441     sizeof( QueueHeader ) + sizeof( QueueMemFree ),
    442     sizeof( QueueHeader ) + sizeof( QueueMemAlloc ),        // callstack
    443     sizeof( QueueHeader ) + sizeof( QueueMemFree ),         // callstack
    444     sizeof( QueueHeader ) + sizeof( QueueGpuZoneBegin ),
    445     sizeof( QueueHeader ) + sizeof( QueueGpuZoneBegin ),    // callstack
    446     sizeof( QueueHeader ) + sizeof( QueueGpuZoneEnd ),
    447     sizeof( QueueHeader ) + sizeof( QueueGpuZoneBegin ),    // serial
    448     sizeof( QueueHeader ) + sizeof( QueueGpuZoneBegin ),    // serial, callstack
    449     sizeof( QueueHeader ) + sizeof( QueueGpuZoneEnd ),      // serial
    450     sizeof( QueueHeader ) + sizeof( QueuePlotData ),
    451     sizeof( QueueHeader ) + sizeof( QueueContextSwitch ),
    452     sizeof( QueueHeader ) + sizeof( QueueThreadWakeup ),
    453     sizeof( QueueHeader ) + sizeof( QueueGpuTime ),
    454     // above items must be first
    455     sizeof( QueueHeader ),                                  // terminate
    456     sizeof( QueueHeader ),                                  // keep alive
    457     sizeof( QueueHeader ) + sizeof( QueueThreadContext ),
    458     sizeof( QueueHeader ),                                  // crash
    459     sizeof( QueueHeader ) + sizeof( QueueCrashReport ),
    460     sizeof( QueueHeader ) + sizeof( QueueZoneValidation ),
    461     sizeof( QueueHeader ) + sizeof( QueueFrameMark ),       // continuous frames
    462     sizeof( QueueHeader ) + sizeof( QueueFrameMark ),       // start
    463     sizeof( QueueHeader ) + sizeof( QueueFrameMark ),       // end
    464     sizeof( QueueHeader ) + sizeof( QueueSourceLocation ),
    465     sizeof( QueueHeader ) + sizeof( QueueLockAnnounce ),
    466     sizeof( QueueHeader ) + sizeof( QueueLockTerminate ),
    467     sizeof( QueueHeader ) + sizeof( QueueLockMark ),
    468     sizeof( QueueHeader ) + sizeof( QueueMessage ),         // literal
    469     sizeof( QueueHeader ) + sizeof( QueueMessageColor ),    // literal
    470     sizeof( QueueHeader ) + sizeof( QueueMessage ),         // literal, callstack
    471     sizeof( QueueHeader ) + sizeof( QueueMessageColor ),    // literal, callstack
    472     sizeof( QueueHeader ) + sizeof( QueueGpuNewContext ),
    473     sizeof( QueueHeader ) + sizeof( QueueCallstackFrameSize ),
    474     sizeof( QueueHeader ) + sizeof( QueueCallstackFrame ),
    475     sizeof( QueueHeader ) + sizeof( QueueSysTime ),
    476     sizeof( QueueHeader ) + sizeof( QueueTidToPid ),
    477     sizeof( QueueHeader ) + sizeof( QueuePlotConfig ),
    478     sizeof( QueueHeader ) + sizeof( QueueParamSetup ),
    479     // keep all QueueStringTransfer below
    480     sizeof( QueueHeader ) + sizeof( QueueStringTransfer ),  // string data
    481     sizeof( QueueHeader ) + sizeof( QueueStringTransfer ),  // thread name
    482     sizeof( QueueHeader ) + sizeof( QueueStringTransfer ),  // custom string data
    483     sizeof( QueueHeader ) + sizeof( QueueStringTransfer ),  // plot name
    484     sizeof( QueueHeader ) + sizeof( QueueStringTransfer ),  // allocated source location payload
    485     sizeof( QueueHeader ) + sizeof( QueueStringTransfer ),  // callstack payload
    486     sizeof( QueueHeader ) + sizeof( QueueStringTransfer ),  // callstack alloc payload
    487     sizeof( QueueHeader ) + sizeof( QueueStringTransfer ),  // frame name
    488     sizeof( QueueHeader ) + sizeof( QueueStringTransfer ),  // frame image data
    489     sizeof( QueueHeader ) + sizeof( QueueStringTransfer ),  // external name
    490     sizeof( QueueHeader ) + sizeof( QueueStringTransfer ),  // external thread name
    491 };
    492 
    493 static_assert( QueueItemSize == 32, "Queue item size not 32 bytes" );
    494 static_assert( sizeof( QueueDataSize ) / sizeof( size_t ) == (uint8_t)QueueType::NUM_TYPES, "QueueDataSize mismatch" );
    495 static_assert( sizeof( void* ) <= sizeof( uint64_t ), "Pointer size > 8 bytes" );
    496 static_assert( sizeof( void* ) == sizeof( uintptr_t ), "Pointer size != uintptr_t" );
    497 
    498 };
    499 
    500 #endif