Allow adding custom colors to zones.

This commit is contained in:
Bartosz Taudul 2017-09-25 22:46:14 +02:00
parent 93fc85a639
commit 519cb8dff3
6 changed files with 17 additions and 9 deletions

View File

@ -4,6 +4,8 @@
#ifdef TRACY_DISABLE
#define ZoneScoped
#define ZoneScopedC(x)
#define FrameMark
#else
@ -11,7 +13,9 @@
#include "TracyProfiler.hpp"
#include "TracyScoped.hpp"
#define ZoneScoped tracy::ScopedZone ___tracy_scoped_zone( __FILE__, __FUNCTION__, __LINE__ );
#define ZoneScoped tracy::ScopedZone ___tracy_scoped_zone( __FILE__, __FUNCTION__, __LINE__, 0 );
#define ZoneScopedC( color ) tracy::ScopedZone ___tracy_scoped_zone( __FILE__, __FUNCTION__, __LINE__, color );
#define FrameMark tracy::Profiler::FrameMark();
#endif

View File

@ -288,7 +288,7 @@ void Profiler::CalibrateTimer()
class FakeZone
{
public:
FakeZone( const char* file, const char* function, uint32_t line ) {}
FakeZone( const char* file, const char* function, uint32_t line, uint32_t color ) {}
~FakeZone() {}
private:
@ -302,17 +302,17 @@ void Profiler::CalibrateDelay()
static_assert( Events * 2 < QueuePrealloc, "Delay calibration loop will allocate memory in queue" );
for( int i=0; i<Iterations; i++ )
{
ScopedZone ___tracy_scoped_zone( __FILE__, __FUNCTION__, __LINE__ );
ScopedZone ___tracy_scoped_zone( __FILE__, __FUNCTION__, __LINE__, 0 );
}
const auto f0 = GetTime();
for( int i=0; i<Iterations; i++ )
{
FakeZone ___tracy_scoped_zone( __FILE__, __FUNCTION__, __LINE__ );
FakeZone ___tracy_scoped_zone( __FILE__, __FUNCTION__, __LINE__, 0 );
}
const auto t0 = GetTime();
for( int i=0; i<Iterations; i++ )
{
ScopedZone ___tracy_scoped_zone( __FILE__, __FUNCTION__, __LINE__ );
ScopedZone ___tracy_scoped_zone( __FILE__, __FUNCTION__, __LINE__, 0 );
}
const auto t1 = GetTime();
const auto dt = t1 - t0;

View File

@ -12,8 +12,8 @@ namespace tracy
class ScopedZone
{
public:
ScopedZone( const char* file, const char* function, uint32_t line )
: m_id( Profiler::ZoneBegin( QueueZoneBegin { Profiler::GetTime(), (uint64_t)file, (uint64_t)function, line, GetThreadHandle() } ) )
ScopedZone( const char* file, const char* function, uint32_t line, uint32_t color )
: m_id( Profiler::ZoneBegin( QueueZoneBegin { Profiler::GetTime(), (uint64_t)file, (uint64_t)function, line, GetThreadHandle(), color } ) )
{
}

View File

@ -25,6 +25,7 @@ struct QueueZoneBegin
uint64_t function; // ptr
uint32_t line;
uint64_t thread;
uint32_t color;
};
struct QueueZoneEnd

View File

@ -11,6 +11,7 @@ struct Event
int64_t start;
int64_t end;
uint32_t srcloc;
uint32_t color;
Event* parent;
Vector<Event*> child;

View File

@ -232,6 +232,7 @@ void View::ProcessZoneBegin( uint64_t id, const QueueZoneBegin& ev )
CheckString( ev.function );
CheckThreadString( ev.thread );
zone->start = ev.time;
zone->color = ev.color;
SourceLocation srcloc { ev.filename, ev.function, ev.line };
auto lit = m_locationRef.find( srcloc );
@ -1007,6 +1008,7 @@ int View::DrawZoneLevel( const Vector<Event*>& vec, bool hover, double pxns, con
while( it < zitend )
{
auto& ev = **it;
const auto color = ev.color != 0 ? ( ev.color | 0xFF000000 ) : 0xDDDD6666;
const auto end = GetZoneEnd( ev );
const auto zsz = ( ev.end - ev.start ) * pxns;
if( zsz < MinVisSize )
@ -1026,7 +1028,7 @@ int View::DrawZoneLevel( const Vector<Event*>& vec, bool hover, double pxns, con
rend = nend;
num++;
}
draw->AddRectFilled( wpos + ImVec2( std::max( px0, -10.0 ), offset ), wpos + ImVec2( std::min( px1, double( w + 10 ) ), offset + ostep ), 0xDDDD6666, 2.f );
draw->AddRectFilled( wpos + ImVec2( std::max( px0, -10.0 ), offset ), wpos + ImVec2( std::min( px1, double( w + 10 ) ), offset + ostep ), color, 2.f );
if( hover && ImGui::IsMouseHoveringRect( wpos + ImVec2( std::max( px0, -10.0 ), offset ), wpos + ImVec2( std::min( px1, double( w + 10 ) ), offset + ostep ) ) )
{
ImGui::BeginTooltip();
@ -1044,7 +1046,7 @@ int View::DrawZoneLevel( const Vector<Event*>& vec, bool hover, double pxns, con
const auto pr1 = ( end - m_zvStart ) * pxns;
const auto px0 = std::max( pr0, -10.0 );
const auto px1 = std::min( pr1, double( w + 10 ) );
draw->AddRectFilled( wpos + ImVec2( px0, offset ), wpos + ImVec2( px1, offset + tsz.y ), 0xDDDD6666, 2.f );
draw->AddRectFilled( wpos + ImVec2( px0, offset ), wpos + ImVec2( px1, offset + tsz.y ), color, 2.f );
draw->AddRect( wpos + ImVec2( px0, offset ), wpos + ImVec2( px1, offset + tsz.y ), 0xAAAAAAAA, 2.f );
if( dsz >= MinVisSize )
{