Tracy.hpp (10952B)
1 #ifndef __TRACY_HPP__ 2 #define __TRACY_HPP__ 3 4 #include "common/TracyColor.hpp" 5 #include "common/TracySystem.hpp" 6 7 #ifndef TRACY_ENABLE 8 9 #define ZoneNamed(x,y) 10 #define ZoneNamedN(x,y,z) 11 #define ZoneNamedC(x,y,z) 12 #define ZoneNamedNC(x,y,z,w) 13 14 #define ZoneScoped 15 #define ZoneScopedN(x) 16 #define ZoneScopedC(x) 17 #define ZoneScopedNC(x,y) 18 19 #define ZoneText(x,y) 20 #define ZoneName(x,y) 21 22 #define FrameMark 23 #define FrameMarkNamed(x) 24 #define FrameMarkStart(x) 25 #define FrameMarkEnd(x) 26 27 #define FrameImage(x,y,z,w,a) 28 29 #define TracyLockable( type, varname ) type varname; 30 #define TracyLockableN( type, varname, desc ) type varname; 31 #define TracySharedLockable( type, varname ) type varname; 32 #define TracySharedLockableN( type, varname, desc ) type varname; 33 #define LockableBase( type ) type 34 #define SharedLockableBase( type ) type 35 #define LockMark(x) (void)x; 36 37 #define TracyPlot(x,y) 38 #define TracyPlotConfig(x,y) 39 40 #define TracyMessage(x,y) 41 #define TracyMessageL(x) 42 #define TracyMessageC(x,y,z) 43 #define TracyMessageLC(x,y) 44 #define TracyAppInfo(x,y) 45 46 #define TracyAlloc(x,y) 47 #define TracyFree(x) 48 49 #define ZoneNamedS(x,y,z) 50 #define ZoneNamedNS(x,y,z,w) 51 #define ZoneNamedCS(x,y,z,w) 52 #define ZoneNamedNCS(x,y,z,w,a) 53 54 #define ZoneScopedS(x) 55 #define ZoneScopedNS(x,y) 56 #define ZoneScopedCS(x,y) 57 #define ZoneScopedNCS(x,y,z) 58 59 #define TracyAllocS(x,y,z) 60 #define TracyFreeS(x,y) 61 62 #define TracyMessageS(x,y,z) 63 #define TracyMessageLS(x,y) 64 #define TracyMessageCS(x,y,z,w) 65 #define TracyMessageLCS(x,y,z) 66 67 #define TracyParameterRegister(x) 68 #define TracyParameterSetup(x,y,z,w) 69 70 #else 71 72 #include "client/TracyLock.hpp" 73 #include "client/TracyProfiler.hpp" 74 #include "client/TracyScoped.hpp" 75 76 #if defined TRACY_HAS_CALLSTACK && defined TRACY_CALLSTACK 77 # define ZoneNamed( varname, active ) static const tracy::SourceLocationData TracyConcat(__tracy_source_location,__LINE__) { nullptr, __FUNCTION__, __FILE__, (uint32_t)__LINE__, 0 }; tracy::ScopedZone varname( &TracyConcat(__tracy_source_location,__LINE__), TRACY_CALLSTACK, active ); 78 # define ZoneNamedN( varname, name, active ) static const tracy::SourceLocationData TracyConcat(__tracy_source_location,__LINE__) { name, __FUNCTION__, __FILE__, (uint32_t)__LINE__, 0 }; tracy::ScopedZone varname( &TracyConcat(__tracy_source_location,__LINE__), TRACY_CALLSTACK, active ); 79 # define ZoneNamedC( varname, color, active ) static const tracy::SourceLocationData TracyConcat(__tracy_source_location,__LINE__) { nullptr, __FUNCTION__, __FILE__, (uint32_t)__LINE__, color }; tracy::ScopedZone varname( &TracyConcat(__tracy_source_location,__LINE__), TRACY_CALLSTACK, active ); 80 # define ZoneNamedNC( varname, name, color, active ) static const tracy::SourceLocationData TracyConcat(__tracy_source_location,__LINE__) { name, __FUNCTION__, __FILE__, (uint32_t)__LINE__, color }; tracy::ScopedZone varname( &TracyConcat(__tracy_source_location,__LINE__), TRACY_CALLSTACK, active ); 81 #else 82 # define ZoneNamed( varname, active ) static const tracy::SourceLocationData TracyConcat(__tracy_source_location,__LINE__) { nullptr, __FUNCTION__, __FILE__, (uint32_t)__LINE__, 0 }; tracy::ScopedZone varname( &TracyConcat(__tracy_source_location,__LINE__), active ); 83 # define ZoneNamedN( varname, name, active ) static const tracy::SourceLocationData TracyConcat(__tracy_source_location,__LINE__) { name, __FUNCTION__, __FILE__, (uint32_t)__LINE__, 0 }; tracy::ScopedZone varname( &TracyConcat(__tracy_source_location,__LINE__), active ); 84 # define ZoneNamedC( varname, color, active ) static const tracy::SourceLocationData TracyConcat(__tracy_source_location,__LINE__) { nullptr, __FUNCTION__, __FILE__, (uint32_t)__LINE__, color }; tracy::ScopedZone varname( &TracyConcat(__tracy_source_location,__LINE__), active ); 85 # define ZoneNamedNC( varname, name, color, active ) static const tracy::SourceLocationData TracyConcat(__tracy_source_location,__LINE__) { name, __FUNCTION__, __FILE__, (uint32_t)__LINE__, color }; tracy::ScopedZone varname( &TracyConcat(__tracy_source_location,__LINE__), active ); 86 #endif 87 88 #define ZoneScoped ZoneNamed( ___tracy_scoped_zone, true ) 89 #define ZoneScopedN( name ) ZoneNamedN( ___tracy_scoped_zone, name, true ) 90 #define ZoneScopedC( color ) ZoneNamedC( ___tracy_scoped_zone, color, true ) 91 #define ZoneScopedNC( name, color ) ZoneNamedNC( ___tracy_scoped_zone, name, color, true ) 92 93 #define ZoneText( txt, size ) ___tracy_scoped_zone.Text( txt, size ); 94 #define ZoneName( txt, size ) ___tracy_scoped_zone.Name( txt, size ); 95 96 #define FrameMark tracy::Profiler::SendFrameMark( nullptr ); 97 #define FrameMarkNamed( name ) tracy::Profiler::SendFrameMark( name ); 98 #define FrameMarkStart( name ) tracy::Profiler::SendFrameMark( name, tracy::QueueType::FrameMarkMsgStart ); 99 #define FrameMarkEnd( name ) tracy::Profiler::SendFrameMark( name, tracy::QueueType::FrameMarkMsgEnd ); 100 101 #define FrameImage( image, width, height, offset, flip ) tracy::Profiler::SendFrameImage( image, width, height, offset, flip ); 102 103 #define TracyLockable( type, varname ) tracy::Lockable<type> varname { [] () -> const tracy::SourceLocationData* { static const tracy::SourceLocationData srcloc { nullptr, #type " " #varname, __FILE__, __LINE__, 0 }; return &srcloc; }() }; 104 #define TracyLockableN( type, varname, desc ) tracy::Lockable<type> varname { [] () -> const tracy::SourceLocationData* { static const tracy::SourceLocationData srcloc { nullptr, desc, __FILE__, __LINE__, 0 }; return &srcloc; }() }; 105 #define TracySharedLockable( type, varname ) tracy::SharedLockable<type> varname { [] () -> const tracy::SourceLocationData* { static const tracy::SourceLocationData srcloc { nullptr, #type " " #varname, __FILE__, __LINE__, 0 }; return &srcloc; }() }; 106 #define TracySharedLockableN( type, varname, desc ) tracy::SharedLockable<type> varname { [] () -> const tracy::SourceLocationData* { static const tracy::SourceLocationData srcloc { nullptr, desc, __FILE__, __LINE__, 0 }; return &srcloc; }() }; 107 #define LockableBase( type ) tracy::Lockable<type> 108 #define SharedLockableBase( type ) tracy::SharedLockable<type> 109 #define LockMark( varname ) static const tracy::SourceLocationData __tracy_lock_location_##varname { nullptr, __FUNCTION__, __FILE__, (uint32_t)__LINE__, 0 }; varname.Mark( &__tracy_lock_location_##varname ); 110 111 #define TracyPlot( name, val ) tracy::Profiler::PlotData( name, val ); 112 #define TracyPlotConfig( name, type ) tracy::Profiler::ConfigurePlot( name, type ); 113 114 #define TracyAppInfo( txt, size ) tracy::Profiler::MessageAppInfo( txt, size ); 115 116 #if defined TRACY_HAS_CALLSTACK && defined TRACY_CALLSTACK 117 # define TracyMessage( txt, size ) tracy::Profiler::Message( txt, size, TRACY_CALLSTACK ); 118 # define TracyMessageL( txt ) tracy::Profiler::Message( txt, TRACY_CALLSTACK ); 119 # define TracyMessageC( txt, size, color ) tracy::Profiler::MessageColor( txt, size, color, TRACY_CALLSTACK ); 120 # define TracyMessageLC( txt, color ) tracy::Profiler::MessageColor( txt, color, TRACY_CALLSTACK ); 121 122 # define TracyAlloc( ptr, size ) tracy::Profiler::MemAllocCallstack( ptr, size, TRACY_CALLSTACK ); 123 # define TracyFree( ptr ) tracy::Profiler::MemFreeCallstack( ptr, TRACY_CALLSTACK ); 124 #else 125 # define TracyMessage( txt, size ) tracy::Profiler::Message( txt, size, 0 ); 126 # define TracyMessageL( txt ) tracy::Profiler::Message( txt, 0 ); 127 # define TracyMessageC( txt, size, color ) tracy::Profiler::MessageColor( txt, size, color, 0 ); 128 # define TracyMessageLC( txt, color ) tracy::Profiler::MessageColor( txt, color, 0 ); 129 130 # define TracyAlloc( ptr, size ) tracy::Profiler::MemAlloc( ptr, size ); 131 # define TracyFree( ptr ) tracy::Profiler::MemFree( ptr ); 132 #endif 133 134 #ifdef TRACY_HAS_CALLSTACK 135 # define ZoneNamedS( varname, depth, active ) static const tracy::SourceLocationData TracyConcat(__tracy_source_location,__LINE__) { nullptr, __FUNCTION__, __FILE__, (uint32_t)__LINE__, 0 }; tracy::ScopedZone varname( &TracyConcat(__tracy_source_location,__LINE__), depth, active ); 136 # define ZoneNamedNS( varname, name, depth, active ) static const tracy::SourceLocationData TracyConcat(__tracy_source_location,__LINE__) { name, __FUNCTION__, __FILE__, (uint32_t)__LINE__, 0 }; tracy::ScopedZone varname( &TracyConcat(__tracy_source_location,__LINE__), depth, active ); 137 # define ZoneNamedCS( varname, color, depth, active ) static const tracy::SourceLocationData TracyConcat(__tracy_source_location,__LINE__) { nullptr, __FUNCTION__, __FILE__, (uint32_t)__LINE__, color }; tracy::ScopedZone varname( &TracyConcat(__tracy_source_location,__LINE__), depth, active ); 138 # define ZoneNamedNCS( varname, name, color, depth, active ) static const tracy::SourceLocationData TracyConcat(__tracy_source_location,__LINE__) { name, __FUNCTION__, __FILE__, (uint32_t)__LINE__, color }; tracy::ScopedZone varname( &TracyConcat(__tracy_source_location,__LINE__), depth, active ); 139 140 # define ZoneScopedS( depth ) ZoneNamedS( ___tracy_scoped_zone, depth, true ) 141 # define ZoneScopedNS( name, depth ) ZoneNamedNS( ___tracy_scoped_zone, name, depth, true ) 142 # define ZoneScopedCS( color, depth ) ZoneNamedCS( ___tracy_scoped_zone, color, depth, true ) 143 # define ZoneScopedNCS( name, color, depth ) ZoneNamedNCS( ___tracy_scoped_zone, name, color depth, true ) 144 145 # define TracyAllocS( ptr, size, depth ) tracy::Profiler::MemAllocCallstack( ptr, size, depth ); 146 # define TracyFreeS( ptr, depth ) tracy::Profiler::MemFreeCallstack( ptr, depth ); 147 148 # define TracyMessageS( txt, size, depth ) tracy::Profiler::Message( txt, size, depth ); 149 # define TracyMessageLS( txt, depth ) tracy::Profiler::Message( txt, depth ); 150 # define TracyMessageCS( txt, size, color, depth ) tracy::Profiler::MessageColor( txt, size, color, depth ); 151 # define TracyMessageLCS( txt, color, depth ) tracy::Profiler::MessageColor( txt, color, depth ); 152 #else 153 # define ZoneNamedS( varname, depth, active ) ZoneNamed( varname, active ) 154 # define ZoneNamedNS( varname, name, depth, active ) ZoneNamedN( varname, name, active ) 155 # define ZoneNamedCS( varname, color, depth, active ) ZoneNamedC( varname, color, active ) 156 # define ZoneNamedNCS( varname, name, color, depth, active ) ZoneNamedNC( varname, name, color, active ) 157 158 # define ZoneScopedS( depth ) ZoneScoped 159 # define ZoneScopedNS( name, depth ) ZoneScopedN( name ) 160 # define ZoneScopedCS( color, depth ) ZoneScopedC( color ) 161 # define ZoneScopedNCS( name, color, depth ) ZoneScopedNC( name, color ) 162 163 # define TracyAllocS( ptr, size, depth ) TracyAlloc( ptr, size ) 164 # define TracyFreeS( ptr, depth ) TracyFree( ptr ) 165 166 # define TracyMessageS( txt, size, depth ) TracyMessage( txt, size ) 167 # define TracyMessageLS( txt, depth ) TracyMessageL( txt ) 168 # define TracyMessageCS( txt, size, color, depth ) TracyMessageC( txt, size, color ) 169 # define TracyMessageLCS( txt, color, depth ) TracyMessageLC( txt, color ) 170 #endif 171 172 #define TracyParameterRegister( cb ) tracy::Profiler::ParameterRegister( cb ); 173 #define TracyParameterSetup( idx, name, isBool, val ) tracy::Profiler::ParameterSetup( idx, name, isBool, val ); 174 175 #endif 176 177 #endif