Allow disabling CPU usage graph.

This commit is contained in:
Bartosz Taudul 2019-10-15 21:37:16 +02:00
parent c28bab59b5
commit 4372ad1bc3
3 changed files with 41 additions and 26 deletions

View File

@ -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 );
}

View File

@ -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<cpuCnt; i++ )
@ -6789,15 +6792,15 @@ void View::DrawOptions()
ImGui::Checkbox( "Draw context switches", &val );
#endif
m_vd.drawContextSwitches = val;
val = m_vd.darkenContextSwitches;
ImGui::Indent();
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
ImGui::Unindent();
m_vd.darkenContextSwitches = val;
ImGui::Unindent();
val = m_vd.drawCpuData;
#ifdef TRACY_EXTENDED_FONT
ImGui::Checkbox( ICON_FA_SLIDERS_H " Draw CPU data", &val );
@ -6805,6 +6808,15 @@ void View::DrawOptions()
ImGui::Checkbox( "Draw CPU data", &val );
#endif
m_vd.drawCpuData = val;
ImGui::Indent();
val = m_vd.drawCpuUsageGraph;
#ifdef TRACY_EXTENDED_FONT
ImGui::Checkbox( ICON_FA_SIGNATURE " Draw CPU usage graph", &val );
#else
ImGui::Checkbox( "Draw CPU usage graph", &val );
#endif
m_vd.drawCpuUsageGraph = val;
ImGui::Unindent();
}
ImGui::Separator();

View File

@ -24,6 +24,7 @@ struct ViewData
uint8_t drawContextSwitches = true;
uint8_t darkenContextSwitches = true;
uint8_t drawCpuData = true;
uint8_t drawCpuUsageGraph = true;
uint8_t dynamicColors = true;
};