From 0e566829644f57b322b7408e62860eafef8ea84a Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Mon, 30 Sep 2019 23:37:36 +0200 Subject: [PATCH] Darkening of inactive thread regions. --- server/TracyUserData.cpp | 4 +++- server/TracyView.cpp | 36 ++++++++++++++++++++++++++---------- server/TracyView.hpp | 2 +- server/TracyViewData.hpp | 1 + 4 files changed, 31 insertions(+), 12 deletions(-) diff --git a/server/TracyUserData.cpp b/server/TracyUserData.cpp index a8f288be..d2f81003 100644 --- a/server/TracyUserData.cpp +++ b/server/TracyUserData.cpp @@ -13,7 +13,7 @@ constexpr auto FileTimeline = "timeline"; constexpr auto FileOptions = "options"; enum : uint32_t { VersionTimeline = 0 }; -enum : uint32_t { VersionOptions = 1 }; +enum : uint32_t { VersionOptions = 2 }; UserData::UserData() : m_preserveState( false ) @@ -93,6 +93,7 @@ void UserData::LoadState( ViewData& data ) fread( &data.onlyContendedLocks, 1, sizeof( data.onlyContendedLocks ), f ); fread( &data.drawEmptyLabels, 1, sizeof( data.drawEmptyLabels ), f ); fread( &data.drawContextSwitches, 1, sizeof( data.drawContextSwitches ), f ); + fread( &data.darkenContextSwitches, 1, sizeof( data.darkenContextSwitches ), f ); fread( &data.drawCpuData, 1, sizeof( data.drawCpuData ), f ); fread( &data.dynamicColors, 1, sizeof( data.dynamicColors ), f ); } @@ -130,6 +131,7 @@ void UserData::SaveState( const ViewData& data ) fwrite( &data.onlyContendedLocks, 1, sizeof( data.onlyContendedLocks ), f ); fwrite( &data.drawEmptyLabels, 1, sizeof( data.drawEmptyLabels ), f ); fwrite( &data.drawContextSwitches, 1, sizeof( data.drawContextSwitches ), f ); + fwrite( &data.darkenContextSwitches, 1, sizeof( data.darkenContextSwitches ), f ); fwrite( &data.drawCpuData, 1, sizeof( data.drawCpuData ), f ); fwrite( &data.dynamicColors, 1, sizeof( data.dynamicColors ), f ); fclose( f ); diff --git a/server/TracyView.cpp b/server/TracyView.cpp index d13c1491..bc6b365d 100644 --- a/server/TracyView.cpp +++ b/server/TracyView.cpp @@ -2242,14 +2242,10 @@ void View::DrawZones() offset += ostep; if( showFull ) { + const auto ctxOffset = offset; if( m_vd.drawContextSwitches ) { - auto ctxSwitch = m_worker.GetContextSwitchData( v->id ); - if( ctxSwitch ) - { - DrawContextSwitches( ctxSwitch, hover, pxns, int64_t( nspx ), wpos, offset ); - offset += round( ostep * 0.75f ); - } + offset += round( ostep * 0.75f ); } if( m_vd.drawZones ) @@ -2258,6 +2254,15 @@ void View::DrawZones() offset += ostep * depth; } + if( m_vd.drawContextSwitches ) + { + auto ctxSwitch = m_worker.GetContextSwitchData( v->id ); + if( ctxSwitch ) + { + DrawContextSwitches( ctxSwitch, hover, pxns, int64_t( nspx ), wpos, ctxOffset, offset ); + } + } + if( m_vd.drawLocks ) { const auto lockDepth = DrawLocks( v->id, hover, pxns, wpos, offset, nextLockHighlight, yMin, yMax ); @@ -2704,7 +2709,7 @@ static const char* DecodeContextSwitchState( uint8_t state ) } } -void View::DrawContextSwitches( const ContextSwitch* ctx, bool hover, double pxns, int64_t nspx, const ImVec2& wpos, int offset ) +void View::DrawContextSwitches( const ContextSwitch* ctx, bool hover, double pxns, int64_t nspx, const ImVec2& wpos, int offset, int endOffset ) { auto& vec = ctx->v; auto it = std::lower_bound( vec.begin(), vec.end(), std::max( 0, m_vd.zvStart ), [] ( const auto& l, const auto& r ) { return (uint64_t)l.End() < (uint64_t)r; } ); @@ -2732,6 +2737,10 @@ void View::DrawContextSwitches( const ContextSwitch* ctx, bool hover, double pxn const auto pxw = ( ev.wakeup - m_vd.zvStart ) * pxns; const auto px1 = std::min( ( ev.Start() - m_vd.zvStart ) * pxns, w + 10.0 ); const auto color = migration ? 0xFFEE7711 : 0xFF2222AA; + if( m_vd.darkenContextSwitches ) + { + draw->AddRectFilled( wpos + ImVec2( px0, round( offset + ty * 0.5 ) ), wpos + ImVec2( px1, endOffset ), 0x44000000 ); + } draw->AddLine( wpos + ImVec2( px0, round( offset + ty * 0.5 ) - 0.5 ), wpos + ImVec2( std::min( pxw, w+10.0 ), round( offset + ty * 0.5 ) - 0.5 ), color, 2 ); if( ev.wakeup != ev.Start() ) { @@ -2749,11 +2758,11 @@ void View::DrawContextSwitches( const ContextSwitch* ctx, bool hover, double pxn { TextFocused( "CPU:", RealToString( pit->Cpu(), true ) ); ImGui::SameLine(); - #ifdef TRACY_EXTENDED_FONT +#ifdef TRACY_EXTENDED_FONT TextFocused( ICON_FA_LONG_ARROW_ALT_RIGHT, RealToString( ev.Cpu(), true ) ); - #else +#else TextFocused( "->", RealToString( ev.Cpu(), true ) ); - #endif +#endif } else { @@ -6476,6 +6485,13 @@ void View::DrawOptions() ImGui::Checkbox( "Draw context switches", &val ); #endif m_vd.drawContextSwitches = val; + val = m_vd.darkenContextSwitches; +#ifdef TRACY_EXTENDED_FONT + ImGui::Checkbox( ICON_FA_MOON " Darken inactive threads", &val ); +#else + ImGui::Checkbox( "Darken inactive threads", &val ); +#endif + m_vd.darkenContextSwitches = val; val = m_vd.drawCpuData; #ifdef TRACY_EXTENDED_FONT ImGui::Checkbox( ICON_FA_SLIDERS_H " Draw CPU data", &val ); diff --git a/server/TracyView.hpp b/server/TracyView.hpp index aca4fbac..23783079 100644 --- a/server/TracyView.hpp +++ b/server/TracyView.hpp @@ -110,7 +110,7 @@ private: bool DrawZoneFramesHeader(); bool DrawZoneFrames( const FrameData& frames ); void DrawZones(); - void DrawContextSwitches( const ContextSwitch* ctx, bool hover, double pxns, int64_t nspx, const ImVec2& wpos, int offset ); + void DrawContextSwitches( const ContextSwitch* ctx, bool hover, double pxns, int64_t nspx, const ImVec2& wpos, int offset, int endOffset ); int DispatchZoneLevel( const Vector& vec, bool hover, double pxns, int64_t nspx, const ImVec2& wpos, int offset, int depth, float yMin, float yMax, uint64_t tid ); int DrawZoneLevel( const Vector& vec, bool hover, double pxns, int64_t nspx, const ImVec2& wpos, int offset, int depth, float yMin, float yMax, uint64_t tid ); int SkipZoneLevel( const Vector& vec, bool hover, double pxns, int64_t nspx, const ImVec2& wpos, int offset, int depth, float yMin, float yMax, uint64_t tid ); diff --git a/server/TracyViewData.hpp b/server/TracyViewData.hpp index f08aa491..172eae23 100644 --- a/server/TracyViewData.hpp +++ b/server/TracyViewData.hpp @@ -22,6 +22,7 @@ struct ViewData uint8_t onlyContendedLocks = true; uint8_t drawEmptyLabels = false; uint8_t drawContextSwitches = true; + uint8_t darkenContextSwitches = true; uint8_t drawCpuData = true; uint8_t dynamicColors = true; };