From 4372ad1bc31bd8a09a1cdd41e7461539bc7ca32b Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Tue, 15 Oct 2019 21:37:16 +0200 Subject: [PATCH] Allow disabling CPU usage graph. --- server/TracyUserData.cpp | 4 ++- server/TracyView.cpp | 62 ++++++++++++++++++++++++---------------- server/TracyViewData.hpp | 1 + 3 files changed, 41 insertions(+), 26 deletions(-) diff --git a/server/TracyUserData.cpp b/server/TracyUserData.cpp index 7a9aaeac..94984751 100644 --- a/server/TracyUserData.cpp +++ b/server/TracyUserData.cpp @@ -20,7 +20,7 @@ constexpr auto FileOptions = "options"; constexpr auto FileAnnotations = "annotations"; enum : uint32_t { VersionTimeline = 0 }; -enum : uint32_t { VersionOptions = 2 }; +enum : uint32_t { VersionOptions = 3 }; enum : uint32_t { VersionAnnotations = 0 }; UserData::UserData() @@ -103,6 +103,7 @@ void UserData::LoadState( ViewData& data ) 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.drawCpuUsageGraph, 1, sizeof( data.drawCpuUsageGraph ), f ); fread( &data.dynamicColors, 1, sizeof( data.dynamicColors ), f ); } fclose( f ); @@ -141,6 +142,7 @@ void UserData::SaveState( const ViewData& data ) 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.drawCpuUsageGraph, 1, sizeof( data.drawCpuUsageGraph ), f ); fwrite( &data.dynamicColors, 1, sizeof( data.dynamicColors ), f ); fclose( f ); } diff --git a/server/TracyView.cpp b/server/TracyView.cpp index 934b632f..2aee0b7e 100644 --- a/server/TracyView.cpp +++ b/server/TracyView.cpp @@ -4408,35 +4408,38 @@ int View::DrawCpuData( int offset, double pxns, const ImVec2& wpos, bool hover, const auto cpuCnt = m_worker.GetCpuDataCpuCount(); assert( cpuCnt != 0 ); - const auto cpuUsageHeight = floor( 40.f * ImGui::GetTextLineHeight() / 15.f ); - if( wpos.y + offset + cpuUsageHeight + 3 >= yMin && wpos.y + offset <= yMax ) + if( m_vd.drawCpuUsageGraph ) { - const float cpuCntRev = 1.f / cpuCnt; - float pos = 0; - int usageOwn, usageOther; - while( pos < w ) + const auto cpuUsageHeight = floor( 40.f * ImGui::GetTextLineHeight() / 15.f ); + if( wpos.y + offset + cpuUsageHeight + 3 >= yMin && wpos.y + offset <= yMax ) { - m_worker.GetCpuUsageAtTime( m_vd.zvStart + pos * nspx, usageOwn, usageOther ); - float base; - if( usageOwn != 0 ) + const float cpuCntRev = 1.f / cpuCnt; + float pos = 0; + int usageOwn, usageOther; + while( pos < w ) { - base = wpos.y + offset + ( 1.f - usageOwn * cpuCntRev ) * cpuUsageHeight; - draw->AddLine( ImVec2( wpos.x + pos, wpos.y + offset + cpuUsageHeight ), ImVec2( wpos.x + pos, base ), 0xFF55BB55 ); + m_worker.GetCpuUsageAtTime( m_vd.zvStart + pos * nspx, usageOwn, usageOther ); + float base; + if( usageOwn != 0 ) + { + base = wpos.y + offset + ( 1.f - usageOwn * cpuCntRev ) * cpuUsageHeight; + draw->AddLine( ImVec2( wpos.x + pos, wpos.y + offset + cpuUsageHeight ), ImVec2( wpos.x + pos, base ), 0xFF55BB55 ); + } + else + { + base = wpos.y + offset + cpuUsageHeight; + } + if( usageOther != 0 ) + { + int usageTotal = usageOwn + usageOther; + draw->AddLine( ImVec2( wpos.x + pos, base ), ImVec2( wpos.x + pos, wpos.y + offset + ( 1.f - usageTotal * cpuCntRev ) * cpuUsageHeight ), 0xFF666666 ); + } + pos++; } - else - { - base = wpos.y + offset + cpuUsageHeight; - } - if( usageOther != 0 ) - { - int usageTotal = usageOwn + usageOther; - draw->AddLine( ImVec2( wpos.x + pos, base ), ImVec2( wpos.x + pos, wpos.y + offset + ( 1.f - usageTotal * cpuCntRev ) * cpuUsageHeight ), 0xFF666666 ); - } - pos++; + draw->AddLine( wpos + ImVec2( 0, offset+cpuUsageHeight+2 ), wpos + ImVec2( w, offset+cpuUsageHeight+2 ), 0x22DD88DD ); } - draw->AddLine( wpos + ImVec2( 0, offset+cpuUsageHeight+2 ), wpos + ImVec2( w, offset+cpuUsageHeight+2 ), 0x22DD88DD ); + offset += cpuUsageHeight + 3; } - offset += cpuUsageHeight + 3; const auto origOffset = offset; for( int i=0; i