From 519cb8dff35a83bc4a877f2c77c3759b460d2754 Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Mon, 25 Sep 2017 22:46:14 +0200 Subject: [PATCH] Allow adding custom colors to zones. --- client/Tracy.hpp | 6 +++++- client/TracyProfiler.cpp | 8 ++++---- client/TracyScoped.hpp | 4 ++-- common/TracyQueue.hpp | 1 + server/TracyEvent.hpp | 1 + server/TracyView.cpp | 6 ++++-- 6 files changed, 17 insertions(+), 9 deletions(-) diff --git a/client/Tracy.hpp b/client/Tracy.hpp index c8b87937..653fa619 100755 --- a/client/Tracy.hpp +++ b/client/Tracy.hpp @@ -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 diff --git a/client/TracyProfiler.cpp b/client/TracyProfiler.cpp index 07e7be69..41dcd3d8 100755 --- a/client/TracyProfiler.cpp +++ b/client/TracyProfiler.cpp @@ -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 child; diff --git a/server/TracyView.cpp b/server/TracyView.cpp index e7df770b..0c5dc4eb 100755 --- a/server/TracyView.cpp +++ b/server/TracyView.cpp @@ -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& 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& 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& 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 ) {