mirror of
https://github.com/wolfpld/tracy.git
synced 2024-11-10 02:31:48 +00:00
Adding ZoneColor to set a dynamic color override to an existing zone.
This commit is contained in:
parent
dfdf70aea3
commit
7dfdad2e02
@ -23,6 +23,8 @@
|
||||
#define ZoneTextV(x,y,z)
|
||||
#define ZoneName(x,y)
|
||||
#define ZoneNameV(x,y,z)
|
||||
#define ZoneColor(x)
|
||||
#define ZoneColorV(x,y)
|
||||
#define ZoneValue(x)
|
||||
#define ZoneValueV(x,y)
|
||||
|
||||
@ -128,6 +130,8 @@
|
||||
#define ZoneTextV( varname, txt, size ) varname.Text( txt, size );
|
||||
#define ZoneName( txt, size ) ___tracy_scoped_zone.Name( txt, size );
|
||||
#define ZoneNameV( varname, txt, size ) varname.Name( txt, size );
|
||||
#define ZoneColor( color ) __trace_scoped_zone.Color( color );
|
||||
#define ZoneColorV( varname, color ) varname.Color( color );
|
||||
#define ZoneValue( value ) ___tracy_scoped_zone.Value( value );
|
||||
#define ZoneValueV( varname, value ) varname.Value( value );
|
||||
|
||||
|
3
TracyC.h
3
TracyC.h
@ -27,6 +27,7 @@ typedef const void* TracyCZoneCtx;
|
||||
#define TracyCZoneEnd(c)
|
||||
#define TracyCZoneText(c,x,y)
|
||||
#define TracyCZoneName(c,x,y)
|
||||
#define TracyCZoneColor(c,x)
|
||||
#define TracyCZoneValue(c,x)
|
||||
|
||||
#define TracyCAlloc(x,y)
|
||||
@ -111,6 +112,7 @@ TRACY_API TracyCZoneCtx ___tracy_emit_zone_begin_alloc_callstack( uint64_t srclo
|
||||
TRACY_API void ___tracy_emit_zone_end( TracyCZoneCtx ctx );
|
||||
TRACY_API void ___tracy_emit_zone_text( TracyCZoneCtx ctx, const char* txt, size_t size );
|
||||
TRACY_API void ___tracy_emit_zone_name( TracyCZoneCtx ctx, const char* txt, size_t size );
|
||||
TRACY_API void ___tracy_emit_zone_color( TracyCZoneCtx ctx, uint32_t color );
|
||||
TRACY_API void ___tracy_emit_zone_value( TracyCZoneCtx ctx, uint64_t value );
|
||||
|
||||
#if defined TRACY_HAS_CALLSTACK && defined TRACY_CALLSTACK
|
||||
@ -129,6 +131,7 @@ TRACY_API void ___tracy_emit_zone_value( TracyCZoneCtx ctx, uint64_t value );
|
||||
|
||||
#define TracyCZoneText( ctx, txt, size ) ___tracy_emit_zone_text( ctx, txt, size );
|
||||
#define TracyCZoneName( ctx, txt, size ) ___tracy_emit_zone_name( ctx, txt, size );
|
||||
#define TracyCZoneColor( ctx, color ) ___tracy_emit_zone_color( ctx, color );
|
||||
#define TracyCZoneValue( ctx, value ) ___tracy_emit_zone_value( ctx, value );
|
||||
|
||||
|
||||
|
@ -3290,6 +3290,24 @@ TRACY_API void ___tracy_emit_zone_name( TracyCZoneCtx ctx, const char* txt, size
|
||||
}
|
||||
}
|
||||
|
||||
TRACY_API void ___tracy_emit_zone_color( TracyCZoneCtx ctx, uint32_t color ) {
|
||||
if( !ctx.active ) return;
|
||||
#ifndef TRACY_NO_VERIFY
|
||||
{
|
||||
TracyLfqPrepareC( tracy::QueueType::ZoneValidation );
|
||||
tracy::MemWrite( &item->zoneValidation.id, ctx.id );
|
||||
TracyLfqCommitC;
|
||||
}
|
||||
#endif
|
||||
{
|
||||
TracyLfqPrepareC( tracy::QueueType::ZoneColor );
|
||||
tracy::MemWrite( &item->zoneColor.r, uint8_t( ( color ) & 0xFF ) );
|
||||
tracy::MemWrite( &item->zoneColor.g, uint8_t( ( color >> 8 ) & 0xFF ) );
|
||||
tracy::MemWrite( &item->zoneColor.b, uint8_t( ( color >> 16 ) & 0xFF ) );
|
||||
TracyLfqCommitC;
|
||||
}
|
||||
}
|
||||
|
||||
TRACY_API void ___tracy_emit_zone_value( TracyCZoneCtx ctx, uint64_t value )
|
||||
{
|
||||
if( !ctx.active ) return;
|
||||
|
@ -136,6 +136,19 @@ public:
|
||||
TracyLfqCommit;
|
||||
}
|
||||
|
||||
tracy_force_inline void Color( uint32_t color )
|
||||
{
|
||||
if( !m_active ) return;
|
||||
#ifdef TRACY_ON_DEMAND
|
||||
if( GetProfiler().ConnectionId() != m_connectionId ) return;
|
||||
#endif
|
||||
TracyLfqPrepare( QueueType::ZoneColor );
|
||||
MemWrite( &item->zoneColor.r, uint8_t( ( color ) & 0xFF ) );
|
||||
MemWrite( &item->zoneColor.g, uint8_t( ( color >> 8 ) & 0xFF ) );
|
||||
MemWrite( &item->zoneColor.b, uint8_t( ( color >> 16 ) & 0xFF ) );
|
||||
TracyLfqCommit;
|
||||
}
|
||||
|
||||
tracy_force_inline void Value( uint64_t value )
|
||||
{
|
||||
if( !m_active ) return;
|
||||
|
@ -9,7 +9,7 @@ namespace tracy
|
||||
|
||||
constexpr unsigned Lz4CompressBound( unsigned isize ) { return isize + ( isize / 255 ) + 16; }
|
||||
|
||||
enum : uint32_t { ProtocolVersion = 42 };
|
||||
enum : uint32_t { ProtocolVersion = 43 };
|
||||
enum : uint16_t { BroadcastVersion = 2 };
|
||||
|
||||
using lz4sz_t = uint32_t;
|
||||
|
@ -57,6 +57,7 @@ enum class QueueType : uint8_t
|
||||
Crash,
|
||||
CrashReport,
|
||||
ZoneValidation,
|
||||
ZoneColor,
|
||||
ZoneValue,
|
||||
FrameMarkMsg,
|
||||
FrameMarkMsgStart,
|
||||
@ -124,6 +125,13 @@ struct QueueZoneValidation
|
||||
uint32_t id;
|
||||
};
|
||||
|
||||
struct QueueZoneColor
|
||||
{
|
||||
uint8_t r;
|
||||
uint8_t g;
|
||||
uint8_t b;
|
||||
};
|
||||
|
||||
struct QueueZoneValue
|
||||
{
|
||||
uint64_t value;
|
||||
@ -489,6 +497,7 @@ struct QueueItem
|
||||
QueueZoneBeginLean zoneBeginLean;
|
||||
QueueZoneEnd zoneEnd;
|
||||
QueueZoneValidation zoneValidation;
|
||||
QueueZoneColor zoneColor;
|
||||
QueueZoneValue zoneValue;
|
||||
QueueStringTransfer stringTransfer;
|
||||
QueueFrameMark frameMark;
|
||||
@ -593,6 +602,7 @@ static constexpr size_t QueueDataSize[] = {
|
||||
sizeof( QueueHeader ), // crash
|
||||
sizeof( QueueHeader ) + sizeof( QueueCrashReport ),
|
||||
sizeof( QueueHeader ) + sizeof( QueueZoneValidation ),
|
||||
sizeof( QueueHeader ) + sizeof( QueueZoneColor ),
|
||||
sizeof( QueueHeader ) + sizeof( QueueZoneValue ),
|
||||
sizeof( QueueHeader ) + sizeof( QueueFrameMark ), // continuous frames
|
||||
sizeof( QueueHeader ) + sizeof( QueueFrameMark ), // start
|
||||
|
@ -1027,7 +1027,7 @@ $2560\times1440$ & 23~FPS & 3300~FPS & 1600~FPS
|
||||
|
||||
To record a zone's\footnote{A \texttt{zone} represents the lifetime of a special on-stack profiler variable. Typically it would exist for the duration of a whole scope of the profiled function, but you also can measure time spent in scopes of a for-loop, or an if-branch.} execution time add the \texttt{ZoneScoped} macro at the beginning of the scope you want to measure. This will automatically record function name, source file name and location. Optionally you may use the \texttt{ZoneScopedC(color)} macro to set a custom color for the zone. Note that the color value will be constant in the recording (don't try to parametrize it). You may also set a custom name for the zone, using the \texttt{ZoneScopedN(name)} macro. Color and name may be combined by using the \texttt{ZoneScopedNC(name, color)} macro.
|
||||
|
||||
Use the \texttt{ZoneText(text, size)} macro to add a custom text string that will be displayed along the zone information (for example, name of the file you are opening). Multiple text strings can be attached to any single zone. If you want to send a numeric value and don't want to pay the cost of converting it to a string, you may use the \texttt{ZoneValue(uint64\_t)} macro.
|
||||
Use the \texttt{ZoneText(text, size)} macro to add a custom text string that will be displayed along the zone information (for example, name of the file you are opening). Multiple text strings can be attached to any single zone. The dynamic color of a zone can be specified with the \texttt{ZoneColor(uint32\_t)} macro to override the source location color. If you want to send a numeric value and don't want to pay the cost of converting it to a string, you may use the \texttt{ZoneValue(uint64\_t)} macro.
|
||||
|
||||
If you want to set zone name on a per-call basis, you may do so using the \texttt{ZoneName(text, size)} macro. This name won't be used in the process of grouping the zones for statistical purposes (sections~\ref{statistics} and~\ref{findzone}).
|
||||
|
||||
@ -1050,7 +1050,7 @@ The zone markup macros automatically report when they end, through the RAII mech
|
||||
|
||||
Using the \texttt{ZoneScoped} family of macros creates a stack variable named \texttt{\_\_\_tracy\_scoped\_zone}. If you want to measure more than one zone in the same scope, you will need to use the \texttt{ZoneNamed} macros, which require that you provide a name for the created variable. For example, instead of \texttt{ZoneScopedN("Zone name")}, you would use \texttt{ZoneNamedN(variableName, "Zone name", true)}\footnote{The last parameter is explained in section~\ref{filteringzones}.}.
|
||||
|
||||
The \texttt{ZoneText}, \texttt{ZoneValue} and \texttt{ZoneName} macros apply to the zones created using the \texttt{ZoneScoped} macros. For zones created using the \texttt{ZoneNamed} macros, you can use the \texttt{ZoneTextV(variableName, text, size)}, \texttt{ZoneValueV(variableName, uint64\_t)}, or \texttt{ZoneNameV(variableName, text, size)} macros, or invoke the methods \texttt{Text}, \texttt{Value} or \texttt{Name} directly on the variable you have created.
|
||||
The \texttt{ZoneText}, \texttt{ZoneColor}, \texttt{ZoneValue}, and \texttt{ZoneName} macros apply to the zones created using the \texttt{ZoneScoped} macros. For zones created using the \texttt{ZoneNamed} macros, you can use the \texttt{ZoneTextV(variableName, text, size)}, \texttt{ZoneColorV(variableName, uint32\_t)}, \texttt{ZoneValueV(variableName, uint64\_t)}, or \texttt{ZoneNameV(variableName, text, size)} macros, or invoke the methods \texttt{Text}, \texttt{Color}, \texttt{Value}, or \texttt{Name} directly on the variable you have created.
|
||||
|
||||
Zone objects can't be moved or copied.
|
||||
|
||||
|
@ -207,6 +207,7 @@ struct ZoneExtra
|
||||
Int24 callstack;
|
||||
StringIdx text;
|
||||
StringIdx name;
|
||||
Int24 color;
|
||||
};
|
||||
|
||||
enum { ZoneExtraSize = sizeof( ZoneExtra ) };
|
||||
|
@ -7,7 +7,7 @@ namespace Version
|
||||
{
|
||||
enum { Major = 0 };
|
||||
enum { Minor = 7 };
|
||||
enum { Patch = 4 };
|
||||
enum { Patch = 5 };
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -16561,8 +16561,16 @@ uint32_t View::GetRawZoneColor( const ZoneEvent& ev, uint64_t thread, int depth
|
||||
{
|
||||
const auto sl = ev.SrcLoc();
|
||||
const auto& srcloc = m_worker.GetSourceLocation( sl );
|
||||
const auto color = srcloc.color;
|
||||
if( color != 0 && !m_vd.forceColors ) return color | 0xFF000000;
|
||||
if( !m_vd.forceColors )
|
||||
{
|
||||
if( m_worker.HasZoneExtra( ev ) )
|
||||
{
|
||||
const auto custom_color = m_worker.GetZoneExtra( ev ).color.Val();
|
||||
if( custom_color != 0 ) return custom_color | 0xFF000000;
|
||||
}
|
||||
const auto color = srcloc.color;
|
||||
if( color != 0 ) return color | 0xFF000000;
|
||||
}
|
||||
switch( m_vd.dynamicColors )
|
||||
{
|
||||
case 0:
|
||||
|
@ -822,13 +822,25 @@ Worker::Worker( FileRead& f, EventType::Type eventMask, bool bgTasks )
|
||||
f.Skip( sz * ( sizeof( uint64_t ) + sizeof( MessageData::time ) + sizeof( MessageData::ref ) + sizeof( MessageData::color ) + sizeof( MessageData::callstack ) ) );
|
||||
}
|
||||
|
||||
if( fileVer >= FileVersion( 0, 6, 3 ) )
|
||||
if( fileVer >= FileVersion( 0, 7, 5 ) )
|
||||
{
|
||||
f.Read( sz );
|
||||
assert( sz != 0 );
|
||||
m_data.zoneExtra.reserve_exact( sz, m_slab );
|
||||
f.Read( m_data.zoneExtra.data(), sz * sizeof( ZoneExtra ) );
|
||||
}
|
||||
else if( fileVer >= FileVersion( 0, 6, 3 ) )
|
||||
{
|
||||
f.Read( sz );
|
||||
assert( sz != 0 );
|
||||
m_data.zoneExtra.reserve_exact( sz, m_slab );
|
||||
for( uint64_t i=0; i<sz; i++ )
|
||||
{
|
||||
auto* zoneExtra = &m_data.zoneExtra[i];
|
||||
f.Read3( zoneExtra->callstack, zoneExtra->text, zoneExtra->name );
|
||||
zoneExtra->color = 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
m_data.zoneExtra.push_back( ZoneExtra {} );
|
||||
@ -4116,6 +4128,9 @@ bool Worker::Process( const QueueItem& ev )
|
||||
case QueueType::ZoneName:
|
||||
ProcessZoneName();
|
||||
break;
|
||||
case QueueType::ZoneColor:
|
||||
ProcessZoneColor( ev.zoneColor );
|
||||
break;
|
||||
case QueueType::ZoneValue:
|
||||
ProcessZoneValue( ev.zoneValue );
|
||||
break;
|
||||
@ -4506,6 +4521,12 @@ void Worker::ZoneTextFailure( uint64_t thread )
|
||||
m_failureData.thread = thread;
|
||||
}
|
||||
|
||||
void Worker::ZoneColorFailure( uint64_t thread )
|
||||
{
|
||||
m_failure = Failure::ZoneColor;
|
||||
m_failureData.thread = thread;
|
||||
}
|
||||
|
||||
void Worker::ZoneNameFailure( uint64_t thread )
|
||||
{
|
||||
m_failure = Failure::ZoneName;
|
||||
@ -4738,6 +4759,23 @@ void Worker::ProcessZoneName()
|
||||
extra.name = StringIdx( GetSingleStringIdx() );
|
||||
}
|
||||
|
||||
void Worker::ProcessZoneColor( const QueueZoneColor& ev )
|
||||
{
|
||||
auto td = RetrieveThread( m_threadCtx );
|
||||
if( !td || td->stack.empty() || td->nextZoneId != td->zoneIdStack.back() )
|
||||
{
|
||||
ZoneColorFailure( m_threadCtx );
|
||||
return;
|
||||
}
|
||||
|
||||
td->nextZoneId = 0;
|
||||
auto& stack = td->stack;
|
||||
auto zone = stack.back();
|
||||
auto& extra = RequestZoneExtra( *zone );
|
||||
const uint32_t color = ( ev.b << 16 ) | ( ev.g << 8 ) | ev.r;
|
||||
extra.color = color;
|
||||
}
|
||||
|
||||
void Worker::ProcessZoneValue( const QueueZoneValue& ev )
|
||||
{
|
||||
char tmp[32];
|
||||
@ -7221,6 +7259,7 @@ static const char* s_failureReasons[] = {
|
||||
"Invalid order of zone begin and end events.",
|
||||
"Zone is ended twice.",
|
||||
"Zone text transfer destination doesn't match active zone.",
|
||||
"Zone color transfer destination doesn't match active zone.",
|
||||
"Zone name transfer destination doesn't match active zone.",
|
||||
"Memory free event without a matching allocation.",
|
||||
"Discontinuous frame begin/end mismatch.",
|
||||
|
@ -383,6 +383,7 @@ public:
|
||||
ZoneStack,
|
||||
ZoneDoubleEnd,
|
||||
ZoneText,
|
||||
ZoneColor,
|
||||
ZoneName,
|
||||
MemFree,
|
||||
FrameEnd,
|
||||
@ -608,6 +609,7 @@ private:
|
||||
tracy_force_inline void ProcessFrameImage( const QueueFrameImage& ev );
|
||||
tracy_force_inline void ProcessZoneText();
|
||||
tracy_force_inline void ProcessZoneName();
|
||||
tracy_force_inline void ProcessZoneColor( const QueueZoneColor& ev );
|
||||
tracy_force_inline void ProcessZoneValue( const QueueZoneValue& ev );
|
||||
tracy_force_inline void ProcessLockAnnounce( const QueueLockAnnounce& ev );
|
||||
tracy_force_inline void ProcessLockTerminate( const QueueLockTerminate& ev );
|
||||
@ -670,6 +672,7 @@ private:
|
||||
void ZoneStackFailure( uint64_t thread, const ZoneEvent* ev );
|
||||
void ZoneDoubleEndFailure( uint64_t thread, const ZoneEvent* ev );
|
||||
void ZoneTextFailure( uint64_t thread );
|
||||
void ZoneColorFailure( uint64_t thread );
|
||||
void ZoneNameFailure( uint64_t thread );
|
||||
void MemFreeFailure( uint64_t thread );
|
||||
void FrameEndFailure();
|
||||
|
Loading…
Reference in New Issue
Block a user