TracyC.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. #ifndef __TRACYC_HPP__
  2. #define __TRACYC_HPP__
  3. #include <stddef.h>
  4. #include <stdint.h>
  5. #include "client/TracyCallstack.h"
  6. #include "common/TracyApi.h"
  7. #ifdef __cplusplus
  8. extern "C" {
  9. #endif
  10. TRACY_API void ___tracy_set_thread_name( const char* name );
  11. #define TracyCSetThreadName( name ) ___tracy_set_thread_name( name );
  12. #ifndef TRACY_ENABLE
  13. typedef const void* TracyCZoneCtx;
  14. #define TracyCZone(c,x)
  15. #define TracyCZoneN(c,x,y)
  16. #define TracyCZoneC(c,x,y)
  17. #define TracyCZoneNC(c,x,y,z)
  18. #define TracyCZoneEnd(c)
  19. #define TracyCZoneText(c,x,y)
  20. #define TracyCZoneName(c,x,y)
  21. #define TracyCZoneColor(c,x)
  22. #define TracyCZoneValue(c,x)
  23. #define TracyCAlloc(x,y)
  24. #define TracyCFree(x)
  25. #define TracyCSecureAlloc(x,y)
  26. #define TracyCSecureFree(x)
  27. #define TracyCAllocN(x,y,z)
  28. #define TracyCFreeN(x,y)
  29. #define TracyCSecureAllocN(x,y,z)
  30. #define TracyCSecureFreeN(x,y)
  31. #define TracyCFrameMark
  32. #define TracyCFrameMarkNamed(x)
  33. #define TracyCFrameMarkStart(x)
  34. #define TracyCFrameMarkEnd(x)
  35. #define TracyCFrameImage(x,y,z,w,a)
  36. #define TracyCPlot(x,y)
  37. #define TracyCMessage(x,y)
  38. #define TracyCMessageL(x)
  39. #define TracyCMessageC(x,y,z)
  40. #define TracyCMessageLC(x,y)
  41. #define TracyCAppInfo(x,y)
  42. #define TracyCZoneS(x,y,z)
  43. #define TracyCZoneNS(x,y,z,w)
  44. #define TracyCZoneCS(x,y,z,w)
  45. #define TracyCZoneNCS(x,y,z,w,a)
  46. #define TracyCAllocS(x,y,z)
  47. #define TracyCFreeS(x,y)
  48. #define TracyCSecureAllocS(x,y,z)
  49. #define TracyCSecureFreeS(x,y)
  50. #define TracyCAllocNS(x,y,z,w)
  51. #define TracyCFreeNS(x,y,z)
  52. #define TracyCSecureAllocNS(x,y,z,w)
  53. #define TracyCSecureFreeNS(x,y,z)
  54. #define TracyCMessageS(x,y,z)
  55. #define TracyCMessageLS(x,y)
  56. #define TracyCMessageCS(x,y,z,w)
  57. #define TracyCMessageLCS(x,y,z)
  58. #else
  59. #ifndef TracyConcat
  60. # define TracyConcat(x,y) TracyConcatIndirect(x,y)
  61. #endif
  62. #ifndef TracyConcatIndirect
  63. # define TracyConcatIndirect(x,y) x##y
  64. #endif
  65. struct ___tracy_source_location_data
  66. {
  67. const char* name;
  68. const char* function;
  69. const char* file;
  70. uint32_t line;
  71. uint32_t color;
  72. };
  73. struct ___tracy_c_zone_context
  74. {
  75. uint32_t id;
  76. int active;
  77. };
  78. // Some containers don't support storing const types.
  79. // This struct, as visible to user, is immutable, so treat it as if const was declared here.
  80. typedef /*const*/ struct ___tracy_c_zone_context TracyCZoneCtx;
  81. TRACY_API void ___tracy_init_thread(void);
  82. TRACY_API uint64_t ___tracy_alloc_srcloc( uint32_t line, const char* source, size_t sourceSz, const char* function, size_t functionSz );
  83. TRACY_API uint64_t ___tracy_alloc_srcloc_name( uint32_t line, const char* source, size_t sourceSz, const char* function, size_t functionSz, const char* name, size_t nameSz );
  84. TRACY_API TracyCZoneCtx ___tracy_emit_zone_begin( const struct ___tracy_source_location_data* srcloc, int active );
  85. TRACY_API TracyCZoneCtx ___tracy_emit_zone_begin_callstack( const struct ___tracy_source_location_data* srcloc, int depth, int active );
  86. TRACY_API TracyCZoneCtx ___tracy_emit_zone_begin_alloc( uint64_t srcloc, int active );
  87. TRACY_API TracyCZoneCtx ___tracy_emit_zone_begin_alloc_callstack( uint64_t srcloc, int depth, int active );
  88. TRACY_API void ___tracy_emit_zone_end( TracyCZoneCtx ctx );
  89. TRACY_API void ___tracy_emit_zone_text( TracyCZoneCtx ctx, const char* txt, size_t size );
  90. TRACY_API void ___tracy_emit_zone_name( TracyCZoneCtx ctx, const char* txt, size_t size );
  91. TRACY_API void ___tracy_emit_zone_color( TracyCZoneCtx ctx, uint32_t color );
  92. TRACY_API void ___tracy_emit_zone_value( TracyCZoneCtx ctx, uint64_t value );
  93. #if defined TRACY_HAS_CALLSTACK && defined TRACY_CALLSTACK
  94. # define TracyCZone( ctx, active ) static const struct ___tracy_source_location_data TracyConcat(__tracy_source_location,__LINE__) = { NULL, __FUNCTION__, __FILE__, (uint32_t)__LINE__, 0 }; TracyCZoneCtx ctx = ___tracy_emit_zone_begin_callstack( &TracyConcat(__tracy_source_location,__LINE__), TRACY_CALLSTACK, active );
  95. # define TracyCZoneN( ctx, name, active ) static const struct ___tracy_source_location_data TracyConcat(__tracy_source_location,__LINE__) = { name, __FUNCTION__, __FILE__, (uint32_t)__LINE__, 0 }; TracyCZoneCtx ctx = ___tracy_emit_zone_begin_callstack( &TracyConcat(__tracy_source_location,__LINE__), TRACY_CALLSTACK, active );
  96. # define TracyCZoneC( ctx, color, active ) static const struct ___tracy_source_location_data TracyConcat(__tracy_source_location,__LINE__) = { NULL, __FUNCTION__, __FILE__, (uint32_t)__LINE__, color }; TracyCZoneCtx ctx = ___tracy_emit_zone_begin_callstack( &TracyConcat(__tracy_source_location,__LINE__), TRACY_CALLSTACK, active );
  97. # define TracyCZoneNC( ctx, name, color, active ) static const struct ___tracy_source_location_data TracyConcat(__tracy_source_location,__LINE__) = { name, __FUNCTION__, __FILE__, (uint32_t)__LINE__, color }; TracyCZoneCtx ctx = ___tracy_emit_zone_begin_callstack( &TracyConcat(__tracy_source_location,__LINE__), TRACY_CALLSTACK, active );
  98. #else
  99. # define TracyCZone( ctx, active ) static const struct ___tracy_source_location_data TracyConcat(__tracy_source_location,__LINE__) = { NULL, __FUNCTION__, __FILE__, (uint32_t)__LINE__, 0 }; TracyCZoneCtx ctx = ___tracy_emit_zone_begin( &TracyConcat(__tracy_source_location,__LINE__), active );
  100. # define TracyCZoneN( ctx, name, active ) static const struct ___tracy_source_location_data TracyConcat(__tracy_source_location,__LINE__) = { name, __FUNCTION__, __FILE__, (uint32_t)__LINE__, 0 }; TracyCZoneCtx ctx = ___tracy_emit_zone_begin( &TracyConcat(__tracy_source_location,__LINE__), active );
  101. # define TracyCZoneC( ctx, color, active ) static const struct ___tracy_source_location_data TracyConcat(__tracy_source_location,__LINE__) = { NULL, __FUNCTION__, __FILE__, (uint32_t)__LINE__, color }; TracyCZoneCtx ctx = ___tracy_emit_zone_begin( &TracyConcat(__tracy_source_location,__LINE__), active );
  102. # define TracyCZoneNC( ctx, name, color, active ) static const struct ___tracy_source_location_data TracyConcat(__tracy_source_location,__LINE__) = { name, __FUNCTION__, __FILE__, (uint32_t)__LINE__, color }; TracyCZoneCtx ctx = ___tracy_emit_zone_begin( &TracyConcat(__tracy_source_location,__LINE__), active );
  103. #endif
  104. #define TracyCZoneEnd( ctx ) ___tracy_emit_zone_end( ctx );
  105. #define TracyCZoneText( ctx, txt, size ) ___tracy_emit_zone_text( ctx, txt, size );
  106. #define TracyCZoneName( ctx, txt, size ) ___tracy_emit_zone_name( ctx, txt, size );
  107. #define TracyCZoneColor( ctx, color ) ___tracy_emit_zone_color( ctx, color );
  108. #define TracyCZoneValue( ctx, value ) ___tracy_emit_zone_value( ctx, value );
  109. TRACY_API void ___tracy_emit_memory_alloc( const void* ptr, size_t size, int secure );
  110. TRACY_API void ___tracy_emit_memory_alloc_callstack( const void* ptr, size_t size, int depth, int secure );
  111. TRACY_API void ___tracy_emit_memory_free( const void* ptr, int secure );
  112. TRACY_API void ___tracy_emit_memory_free_callstack( const void* ptr, int depth, int secure );
  113. TRACY_API void ___tracy_emit_message( const char* txt, size_t size, int callstack );
  114. TRACY_API void ___tracy_emit_messageL( const char* txt, int callstack );
  115. TRACY_API void ___tracy_emit_messageC( const char* txt, size_t size, uint32_t color, int callstack );
  116. TRACY_API void ___tracy_emit_messageLC( const char* txt, uint32_t color, int callstack );
  117. #if defined TRACY_HAS_CALLSTACK && defined TRACY_CALLSTACK
  118. # define TracyCAlloc( ptr, size ) ___tracy_emit_memory_alloc_callstack( ptr, size, TRACY_CALLSTACK, 0 )
  119. # define TracyCFree( ptr ) ___tracy_emit_memory_free_callstack( ptr, TRACY_CALLSTACK, 0 )
  120. # define TracyCSecureAlloc( ptr, size ) ___tracy_emit_memory_alloc_callstack( ptr, size, TRACY_CALLSTACK, 1 )
  121. # define TracyCSecureFree( ptr ) ___tracy_emit_memory_free_callstack( ptr, TRACY_CALLSTACK, 1 )
  122. # define TracyCAllocN( ptr, size, name ) ___tracy_emit_memory_alloc_callstack_named( ptr, size, TRACY_CALLSTACK, 0, name )
  123. # define TracyCFreeN( ptr, name ) ___tracy_emit_memory_free_callstack_named( ptr, TRACY_CALLSTACK, 0, name )
  124. # define TracyCSecureAllocN( ptr, size, name ) ___tracy_emit_memory_alloc_callstack_named( ptr, size, TRACY_CALLSTACK, 1, name )
  125. # define TracyCSecureFreeN( ptr, name ) ___tracy_emit_memory_free_callstack_named( ptr, TRACY_CALLSTACK, 1, name )
  126. # define TracyCMessage( txt, size ) ___tracy_emit_message( txt, size, TRACY_CALLSTACK );
  127. # define TracyCMessageL( txt ) ___tracy_emit_messageL( txt, TRACY_CALLSTACK );
  128. # define TracyCMessageC( txt, size, color ) ___tracy_emit_messageC( txt, size, color, TRACY_CALLSTACK );
  129. # define TracyCMessageLC( txt, color ) ___tracy_emit_messageLC( txt, color, TRACY_CALLSTACK );
  130. #else
  131. # define TracyCAlloc( ptr, size ) ___tracy_emit_memory_alloc( ptr, size, 0 );
  132. # define TracyCFree( ptr ) ___tracy_emit_memory_free( ptr, 0 );
  133. # define TracyCSecureAlloc( ptr, size ) ___tracy_emit_memory_alloc( ptr, size, 1 );
  134. # define TracyCSecureFree( ptr ) ___tracy_emit_memory_free( ptr, 1 );
  135. # define TracyCAllocN( ptr, size, name ) ___tracy_emit_memory_alloc_named( ptr, size, 0, name );
  136. # define TracyCFreeN( ptr, name ) ___tracy_emit_memory_free_named( ptr, 0, name );
  137. # define TracyCSecureAllocN( ptr, size, name ) ___tracy_emit_memory_alloc_named( ptr, size, 1, name );
  138. # define TracyCSecureFreeN( ptr, name ) ___tracy_emit_memory_free_named( ptr, 1, name );
  139. # define TracyCMessage( txt, size ) ___tracy_emit_message( txt, size, 0 );
  140. # define TracyCMessageL( txt ) ___tracy_emit_messageL( txt, 0 );
  141. # define TracyCMessageC( txt, size, color ) ___tracy_emit_messageC( txt, size, color, 0 );
  142. # define TracyCMessageLC( txt, color ) ___tracy_emit_messageLC( txt, color, 0 );
  143. #endif
  144. TRACY_API void ___tracy_emit_frame_mark( const char* name );
  145. TRACY_API void ___tracy_emit_frame_mark_start( const char* name );
  146. TRACY_API void ___tracy_emit_frame_mark_end( const char* name );
  147. TRACY_API void ___tracy_emit_frame_image( const void* image, uint16_t w, uint16_t h, uint8_t offset, int flip );
  148. #define TracyCFrameMark ___tracy_emit_frame_mark( 0 );
  149. #define TracyCFrameMarkNamed( name ) ___tracy_emit_frame_mark( name );
  150. #define TracyCFrameMarkStart( name ) ___tracy_emit_frame_mark_start( name );
  151. #define TracyCFrameMarkEnd( name ) ___tracy_emit_frame_mark_end( name );
  152. #define TracyCFrameImage( image, width, height, offset, flip ) ___tracy_emit_frame_image( image, width, height, offset, flip );
  153. TRACY_API void ___tracy_emit_plot( const char* name, double val );
  154. TRACY_API void ___tracy_emit_message_appinfo( const char* txt, size_t size );
  155. #define TracyCPlot( name, val ) ___tracy_emit_plot( name, val );
  156. #define TracyCAppInfo( txt, color ) ___tracy_emit_message_appinfo( txt, color );
  157. #ifdef TRACY_HAS_CALLSTACK
  158. # define TracyCZoneS( ctx, depth, active ) static const struct ___tracy_source_location_data TracyConcat(__tracy_source_location,__LINE__) = { NULL, __FUNCTION__, __FILE__, (uint32_t)__LINE__, 0 }; TracyCZoneCtx ctx = ___tracy_emit_zone_begin_callstack( &TracyConcat(__tracy_source_location,__LINE__), depth, active );
  159. # define TracyCZoneNS( ctx, name, depth, active ) static const struct ___tracy_source_location_data TracyConcat(__tracy_source_location,__LINE__) = { name, __FUNCTION__, __FILE__, (uint32_t)__LINE__, 0 }; TracyCZoneCtx ctx = ___tracy_emit_zone_begin_callstack( &TracyConcat(__tracy_source_location,__LINE__), depth, active );
  160. # define TracyCZoneCS( ctx, color, depth, active ) static const struct ___tracy_source_location_data TracyConcat(__tracy_source_location,__LINE__) = { NULL, __FUNCTION__, __FILE__, (uint32_t)__LINE__, color }; TracyCZoneCtx ctx = ___tracy_emit_zone_begin_callstack( &TracyConcat(__tracy_source_location,__LINE__), depth, active );
  161. # define TracyCZoneNCS( ctx, name, color, depth, active ) static const struct ___tracy_source_location_data TracyConcat(__tracy_source_location,__LINE__) = { name, __FUNCTION__, __FILE__, (uint32_t)__LINE__, color }; TracyCZoneCtx ctx = ___tracy_emit_zone_begin_callstack( &TracyConcat(__tracy_source_location,__LINE__), depth, active );
  162. # define TracyCAllocS( ptr, size, depth ) ___tracy_emit_memory_alloc_callstack( ptr, size, depth, 0 )
  163. # define TracyCFreeS( ptr, depth ) ___tracy_emit_memory_free_callstack( ptr, depth, 0 )
  164. # define TracyCSecureAllocS( ptr, size, depth ) ___tracy_emit_memory_alloc_callstack( ptr, size, depth, 1 )
  165. # define TracyCSecureFreeS( ptr, depth ) ___tracy_emit_memory_free_callstack( ptr, depth, 1 )
  166. # define TracyCAllocNS( ptr, size, depth, name ) ___tracy_emit_memory_alloc_callstack_named( ptr, size, depth, 0, name )
  167. # define TracyCFreeNS( ptr, depth, name ) ___tracy_emit_memory_free_callstack_named( ptr, depth, 0, name )
  168. # define TracyCSecureAllocNS( ptr, size, depth, name ) ___tracy_emit_memory_alloc_callstack_named( ptr, size, depth, 1, name )
  169. # define TracyCSecureFreeNS( ptr, depth, name ) ___tracy_emit_memory_free_callstack_named( ptr, depth, 1, name )
  170. # define TracyCMessageS( txt, size, depth ) ___tracy_emit_message( txt, size, depth );
  171. # define TracyCMessageLS( txt, depth ) ___tracy_emit_messageL( txt, depth );
  172. # define TracyCMessageCS( txt, size, color, depth ) ___tracy_emit_messageC( txt, size, color, depth );
  173. # define TracyCMessageLCS( txt, color, depth ) ___tracy_emit_messageLC( txt, color, depth );
  174. #else
  175. # define TracyCZoneS( ctx, depth, active ) TracyCZone( ctx, active )
  176. # define TracyCZoneNS( ctx, name, depth, active ) TracyCZoneN( ctx, name, active )
  177. # define TracyCZoneCS( ctx, color, depth, active ) TracyCZoneC( ctx, color, active )
  178. # define TracyCZoneNCS( ctx, name, color, depth, active ) TracyCZoneNC( ctx, name, color, active )
  179. # define TracyCAllocS( ptr, size, depth ) TracyCAlloc( ptr, size )
  180. # define TracyCFreeS( ptr, depth ) TracyCFree( ptr )
  181. # define TracyCSecureAllocS( ptr, size, depth ) TracyCSecureAlloc( ptr, size )
  182. # define TracyCSecureFreeS( ptr, depth ) TracyCSecureFree( ptr )
  183. # define TracyCAllocNS( ptr, size, depth, name ) TracyCAllocN( ptr, size, name )
  184. # define TracyCFreeNS( ptr, depth, name ) TracyCFreeN( ptr, name )
  185. # define TracyCSecureAllocNS( ptr, size, depth, name ) TracyCSecureAllocN( ptr, size, name )
  186. # define TracyCSecureFreeNS( ptr, depth, name ) TracyCSecureFreeN( ptr, name )
  187. # define TracyCMessageS( txt, size, depth ) TracyCMessage( txt, size )
  188. # define TracyCMessageLS( txt, depth ) TracyCMessageL( txt )
  189. # define TracyCMessageCS( txt, size, color, depth ) TracyCMessageC( txt, size, color )
  190. # define TracyCMessageLCS( txt, color, depth ) TracyCMessageLC( txt, color )
  191. #endif
  192. #endif
  193. #ifdef __cplusplus
  194. }
  195. #endif
  196. #endif