Extract rendering hw samples line part.

This commit is contained in:
Bartosz Taudul 2021-06-09 00:17:37 +02:00
parent 18cace42ca
commit def9570eda
No known key found for this signature in database
GPG Key ID: B7FE2008B7575DF3
2 changed files with 143 additions and 137 deletions

View File

@ -2971,143 +2971,7 @@ void SourceView::RenderAsmLine( AsmLine& line, const AddrStat& ipcnt, const Addr
{
if( hw )
{
if( cycles )
{
const bool unreliable = cycles < 10 || retired < 10;
const float ipc = float( retired ) / cycles;
uint32_t col = unreliable ? 0x44FFFFFF : GetGoodnessColor( ipc * 0.25f );
if( ipc >= 10 )
{
TextColoredUnformatted( col, " 10+ " );
}
else
{
char buf[16];
*buf = ' ';
const auto end = PrintFloat( buf+1, buf+16, ipc, 2 );
assert( end == buf + 5 );
memcpy( end, " ", 3 );
TextColoredUnformatted( col, buf );
}
if( ImGui::IsItemHovered() )
{
if( m_font ) ImGui::PopFont();
ImGui::BeginTooltip();
ImGui::TextUnformatted( "Instructions Per Cycle (IPC)" );
ImGui::SameLine();
TextDisabledUnformatted( "Higher is better" );
ImGui::Separator();
TextFocused( "Cycles:", RealToString( cycles ) );
TextFocused( "Retirements:", RealToString( retired ) );
if( unreliable ) TextColoredUnformatted( 0xFF4444FF, "Not enough samples for reliable data!" );
ImGui::EndTooltip();
if( m_font ) ImGui::PushFont( m_font );
}
}
else
{
ImGui::ItemSize( ImVec2( 7 * ts.x, ts.y ) );
}
ImGui::SameLine( 0, 0 );
if( branchRetired )
{
const bool unreliable = branchRetired < 10;
const float rate = float( branchMiss ) / branchRetired;
uint32_t col = unreliable ? 0x44FFFFFF : GetGoodnessColor( 1.f - rate * 3.f );
if( branchMiss == 0 )
{
TextColoredUnformatted( col, " 0% " );
}
else if( rate >= 1.f )
{
TextColoredUnformatted( col, " 100% " );
}
else
{
char buf[16];
if( rate >= 0.1f )
{
const auto end = PrintFloat( buf, buf+16, rate * 100, 1 );
assert( end == buf+4 );
}
else
{
*buf = ' ';
const auto end = PrintFloat( buf+1, buf+16, rate * 100, 1 );
assert( end == buf+4 );
}
memcpy( buf+4, "% ", 4 );
TextColoredUnformatted( col, buf );
}
if( ImGui::IsItemHovered() )
{
if( m_font ) ImGui::PopFont();
ImGui::BeginTooltip();
ImGui::TextUnformatted( "Branch mispredictions rate" );
ImGui::SameLine();
TextDisabledUnformatted( "Lower is better" );
ImGui::Separator();
TextFocused( "Retired branches:", RealToString( branchRetired ) );
TextFocused( "Branch mispredictions:", RealToString( branchMiss ) );
if( unreliable ) TextColoredUnformatted( 0xFF4444FF, "Not enough samples for reliable data!" );
ImGui::EndTooltip();
if( m_font ) ImGui::PushFont( m_font );
}
}
else
{
ImGui::ItemSize( ImVec2( 7 * ts.x, ts.y ) );
}
ImGui::SameLine( 0, 0 );
if( cacheRef )
{
const bool unreliable = cacheRef < 10;
const float rate = float( cacheMiss ) / cacheRef;
uint32_t col = unreliable ? 0x44FFFFFF : GetGoodnessColor( 1.f - rate * 3.f );
if( cacheMiss == 0 )
{
TextColoredUnformatted( col, " 0%" );
}
else if( rate >= 1.f )
{
TextColoredUnformatted( col, " 100%" );
}
else
{
char buf[16];
if( rate >= 0.1f )
{
const auto end = PrintFloat( buf, buf+16, rate * 100, 1 );
assert( end == buf+4 );
}
else
{
*buf = ' ';
const auto end = PrintFloat( buf+1, buf+16, rate * 100, 1 );
assert( end == buf+4 );
}
memcpy( buf+4, "%", 2 );
TextColoredUnformatted( col, buf );
}
if( ImGui::IsItemHovered() )
{
if( m_font ) ImGui::PopFont();
ImGui::BeginTooltip();
ImGui::TextUnformatted( "Cache miss rate" );
ImGui::SameLine();
TextDisabledUnformatted( "Lower is better" );
ImGui::Separator();
TextFocused( "Cache references:", RealToString( cacheRef ) );
TextFocused( "Cache misses:", RealToString( cacheMiss ) );
if( unreliable ) TextColoredUnformatted( 0xFF4444FF, "Not enough samples for reliable data!" );
ImGui::EndTooltip();
if( m_font ) ImGui::PushFont( m_font );
}
}
else
{
ImGui::ItemSize( ImVec2( 5 * ts.x, ts.y ) );
}
RenderHwLinePart( cycles, retired, branchRetired, branchMiss, cacheRef, cacheMiss, ts );
}
else
{
@ -3810,6 +3674,147 @@ void SourceView::RenderAsmLine( AsmLine& line, const AddrStat& ipcnt, const Addr
DrawLine( draw, dpos + ImVec2( 0, ty+2 ), dpos + ImVec2( w, ty+2 ), 0x08FFFFFF );
}
void SourceView::RenderHwLinePart( size_t cycles, size_t retired, size_t branchRetired, size_t branchMiss, size_t cacheRef, size_t cacheMiss, const ImVec2& ts )
{
if( cycles )
{
const bool unreliable = cycles < 10 || retired < 10;
const float ipc = float( retired ) / cycles;
uint32_t col = unreliable ? 0x44FFFFFF : GetGoodnessColor( ipc * 0.25f );
if( ipc >= 10 )
{
TextColoredUnformatted( col, " 10+ " );
}
else
{
char buf[16];
*buf = ' ';
const auto end = PrintFloat( buf+1, buf+16, ipc, 2 );
assert( end == buf + 5 );
memcpy( end, " ", 3 );
TextColoredUnformatted( col, buf );
}
if( ImGui::IsItemHovered() )
{
if( m_font ) ImGui::PopFont();
ImGui::BeginTooltip();
ImGui::TextUnformatted( "Instructions Per Cycle (IPC)" );
ImGui::SameLine();
TextDisabledUnformatted( "Higher is better" );
ImGui::Separator();
TextFocused( "Cycles:", RealToString( cycles ) );
TextFocused( "Retirements:", RealToString( retired ) );
if( unreliable ) TextColoredUnformatted( 0xFF4444FF, "Not enough samples for reliable data!" );
ImGui::EndTooltip();
if( m_font ) ImGui::PushFont( m_font );
}
}
else
{
ImGui::ItemSize( ImVec2( 7 * ts.x, ts.y ) );
}
ImGui::SameLine( 0, 0 );
if( branchRetired )
{
const bool unreliable = branchRetired < 10;
const float rate = float( branchMiss ) / branchRetired;
uint32_t col = unreliable ? 0x44FFFFFF : GetGoodnessColor( 1.f - rate * 3.f );
if( branchMiss == 0 )
{
TextColoredUnformatted( col, " 0% " );
}
else if( rate >= 1.f )
{
TextColoredUnformatted( col, " 100% " );
}
else
{
char buf[16];
if( rate >= 0.1f )
{
const auto end = PrintFloat( buf, buf+16, rate * 100, 1 );
assert( end == buf+4 );
}
else
{
*buf = ' ';
const auto end = PrintFloat( buf+1, buf+16, rate * 100, 1 );
assert( end == buf+4 );
}
memcpy( buf+4, "% ", 4 );
TextColoredUnformatted( col, buf );
}
if( ImGui::IsItemHovered() )
{
if( m_font ) ImGui::PopFont();
ImGui::BeginTooltip();
ImGui::TextUnformatted( "Branch mispredictions rate" );
ImGui::SameLine();
TextDisabledUnformatted( "Lower is better" );
ImGui::Separator();
TextFocused( "Retired branches:", RealToString( branchRetired ) );
TextFocused( "Branch mispredictions:", RealToString( branchMiss ) );
if( unreliable ) TextColoredUnformatted( 0xFF4444FF, "Not enough samples for reliable data!" );
ImGui::EndTooltip();
if( m_font ) ImGui::PushFont( m_font );
}
}
else
{
ImGui::ItemSize( ImVec2( 7 * ts.x, ts.y ) );
}
ImGui::SameLine( 0, 0 );
if( cacheRef )
{
const bool unreliable = cacheRef < 10;
const float rate = float( cacheMiss ) / cacheRef;
uint32_t col = unreliable ? 0x44FFFFFF : GetGoodnessColor( 1.f - rate * 3.f );
if( cacheMiss == 0 )
{
TextColoredUnformatted( col, " 0%" );
}
else if( rate >= 1.f )
{
TextColoredUnformatted( col, " 100%" );
}
else
{
char buf[16];
if( rate >= 0.1f )
{
const auto end = PrintFloat( buf, buf+16, rate * 100, 1 );
assert( end == buf+4 );
}
else
{
*buf = ' ';
const auto end = PrintFloat( buf+1, buf+16, rate * 100, 1 );
assert( end == buf+4 );
}
memcpy( buf+4, "%", 2 );
TextColoredUnformatted( col, buf );
}
if( ImGui::IsItemHovered() )
{
if( m_font ) ImGui::PopFont();
ImGui::BeginTooltip();
ImGui::TextUnformatted( "Cache miss rate" );
ImGui::SameLine();
TextDisabledUnformatted( "Lower is better" );
ImGui::Separator();
TextFocused( "Cache references:", RealToString( cacheRef ) );
TextFocused( "Cache misses:", RealToString( cacheMiss ) );
if( unreliable ) TextColoredUnformatted( 0xFF4444FF, "Not enough samples for reliable data!" );
ImGui::EndTooltip();
if( m_font ) ImGui::PushFont( m_font );
}
}
else
{
ImGui::ItemSize( ImVec2( 5 * ts.x, ts.y ) );
}
}
void SourceView::SelectLine( uint32_t line, const Worker* worker, bool changeAsmLine, uint64_t targetAddr )
{
m_selectedLine = line;

View File

@ -141,6 +141,7 @@ private:
void RenderLine( const Tokenizer::Line& line, int lineNum, const AddrStat& ipcnt, const AddrStat& iptotal, const AddrStat& ipmax, Worker* worker, const View* view );
void RenderAsmLine( AsmLine& line, const AddrStat& ipcnt, const AddrStat& iptotal, const AddrStat& ipmax, Worker& worker, uint64_t& jumpOut, int maxAddrLen, View& view );
void RenderHwLinePart( size_t cycles, size_t retired, size_t branchRetired, size_t branchMiss, size_t cacheRef, size_t cacheMiss, const ImVec2& ts );
void SelectLine( uint32_t line, const Worker* worker, bool changeAsmLine = true, uint64_t targetAddr = 0 );
void SelectAsmLines( uint32_t file, uint32_t line, const Worker& worker, bool changeAsmLine = true, uint64_t targetAddr = 0 );