Add child samples to source view percentages.

This commit is contained in:
Bartosz Taudul 2021-04-18 22:23:55 +02:00
parent cba72859e9
commit fb872fa088
No known key found for this signature in database
GPG Key ID: B7FE2008B7575DF3
2 changed files with 90 additions and 30 deletions

View File

@ -864,6 +864,7 @@ void SourceView::RenderSimpleSourceView()
const auto lx = ts * maxLine + ty + round( ts*0.4f ); const auto lx = ts * maxLine + ty + round( ts*0.4f );
draw->AddLine( wpos + ImVec2( lx, 0 ), wpos + ImVec2( lx, wh ), 0x08FFFFFF ); draw->AddLine( wpos + ImVec2( lx, 0 ), wpos + ImVec2( lx, wh ), 0x08FFFFFF );
const AddrStat zero = {};
if( m_targetLine != 0 ) if( m_targetLine != 0 )
{ {
int lineNum = 1; int lineNum = 1;
@ -874,7 +875,7 @@ void SourceView::RenderSimpleSourceView()
m_targetLine = 0; m_targetLine = 0;
ImGui::SetScrollHereY(); ImGui::SetScrollHereY();
} }
RenderLine( line, lineNum++, 0, 0, 0, nullptr ); RenderLine( line, lineNum++, zero, zero, zero, nullptr );
} }
const auto win = ImGui::GetCurrentWindowRead(); const auto win = ImGui::GetCurrentWindowRead();
m_srcWidth = win->DC.CursorMaxPos.x - win->DC.CursorStartPos.x; m_srcWidth = win->DC.CursorMaxPos.x - win->DC.CursorStartPos.x;
@ -887,7 +888,7 @@ void SourceView::RenderSimpleSourceView()
{ {
for( auto i=clipper.DisplayStart; i<clipper.DisplayEnd; i++ ) for( auto i=clipper.DisplayStart; i<clipper.DisplayEnd; i++ )
{ {
RenderLine( lines[i], i+1, 0, 0, 0, nullptr ); RenderLine( lines[i], i+1, zero, zero, zero, nullptr );
} }
} }
} }
@ -1220,14 +1221,14 @@ void SourceView::RenderSymbolView( const Worker& worker, View& view )
switch( m_displayMode ) switch( m_displayMode )
{ {
case DisplaySource: case DisplaySource:
RenderSymbolSourceView( iptotalSrc.local, ipcountSrc, ipcountAsm, ipmaxSrc.local, worker, view ); RenderSymbolSourceView( iptotalSrc, ipcountSrc, ipcountAsm, ipmaxSrc, worker, view );
break; break;
case DisplayAsm: case DisplayAsm:
jumpOut = RenderSymbolAsmView( iptotalAsm, ipcountAsm, ipmaxAsm, worker, view ); jumpOut = RenderSymbolAsmView( iptotalAsm, ipcountAsm, ipmaxAsm, worker, view );
break; break;
case DisplayMixed: case DisplayMixed:
ImGui::Columns( 2 ); ImGui::Columns( 2 );
RenderSymbolSourceView( iptotalSrc.local, ipcountSrc, ipcountAsm, ipmaxSrc.local, worker, view ); RenderSymbolSourceView( iptotalSrc, ipcountSrc, ipcountAsm, ipmaxSrc, worker, view );
ImGui::NextColumn(); ImGui::NextColumn();
jumpOut = RenderSymbolAsmView( iptotalAsm, ipcountAsm, ipmaxAsm, worker, view ); jumpOut = RenderSymbolAsmView( iptotalAsm, ipcountAsm, ipmaxAsm, worker, view );
ImGui::EndColumns(); ImGui::EndColumns();
@ -1281,7 +1282,7 @@ static uint32_t GetHotnessColor( uint32_t ipSum, uint32_t maxIpCount )
} }
} }
void SourceView::RenderSymbolSourceView( uint32_t iptotal, const unordered_flat_map<uint64_t, AddrStat>& ipcount, const unordered_flat_map<uint64_t, AddrStat>& ipcountAsm, uint32_t ipmax, const Worker& worker, const View& view ) void SourceView::RenderSymbolSourceView( const AddrStat& iptotal, const unordered_flat_map<uint64_t, AddrStat>& ipcount, const unordered_flat_map<uint64_t, AddrStat>& ipcountAsm, const AddrStat& ipmax, const Worker& worker, const View& view )
{ {
if( m_sourceFiles.empty() ) if( m_sourceFiles.empty() )
{ {
@ -1512,7 +1513,7 @@ void SourceView::RenderSymbolSourceView( uint32_t iptotal, const unordered_flat_
const auto tmp = RealToString( lineCount ); const auto tmp = RealToString( lineCount );
const auto maxLine = strlen( tmp ); const auto maxLine = strlen( tmp );
auto lx = ts * maxLine + ty + round( ts*0.4f ); auto lx = ts * maxLine + ty + round( ts*0.4f );
if( iptotal != 0 ) lx += ts * 7 + ty; if( iptotal.local + iptotal.ext != 0 ) lx += ts * 7 + ty;
if( !m_asm.empty() ) if( !m_asm.empty() )
{ {
const auto tmp = RealToString( m_asm.size() ); const auto tmp = RealToString( m_asm.size() );
@ -1521,6 +1522,7 @@ void SourceView::RenderSymbolSourceView( uint32_t iptotal, const unordered_flat_
} }
draw->AddLine( wpos + ImVec2( lx, 0 ), wpos + ImVec2( lx, wh ), 0x08FFFFFF ); draw->AddLine( wpos + ImVec2( lx, 0 ), wpos + ImVec2( lx, wh ), 0x08FFFFFF );
const AddrStat zero = {};
m_selectedAddressesHover.clear(); m_selectedAddressesHover.clear();
if( m_targetLine != 0 ) if( m_targetLine != 0 )
{ {
@ -1532,7 +1534,7 @@ void SourceView::RenderSymbolSourceView( uint32_t iptotal, const unordered_flat_
m_targetLine = 0; m_targetLine = 0;
ImGui::SetScrollHereY(); ImGui::SetScrollHereY();
} }
RenderLine( line, lineNum++, 0, iptotal, ipmax, &worker ); RenderLine( line, lineNum++, zero, iptotal, ipmax, &worker );
} }
const auto win = ImGui::GetCurrentWindowRead(); const auto win = ImGui::GetCurrentWindowRead();
m_srcWidth = win->DC.CursorMaxPos.x - win->DC.CursorStartPos.x; m_srcWidth = win->DC.CursorMaxPos.x - win->DC.CursorStartPos.x;
@ -1543,11 +1545,11 @@ void SourceView::RenderSymbolSourceView( uint32_t iptotal, const unordered_flat_
clipper.Begin( (int)lines.size() ); clipper.Begin( (int)lines.size() );
while( clipper.Step() ) while( clipper.Step() )
{ {
if( iptotal == 0 ) if( iptotal.local + iptotal.ext == 0 )
{ {
for( auto i=clipper.DisplayStart; i<clipper.DisplayEnd; i++ ) for( auto i=clipper.DisplayStart; i<clipper.DisplayEnd; i++ )
{ {
RenderLine( lines[i], i+1, 0, 0, 0, &worker ); RenderLine( lines[i], i+1, zero, zero, zero, &worker );
} }
} }
else else
@ -1555,7 +1557,7 @@ void SourceView::RenderSymbolSourceView( uint32_t iptotal, const unordered_flat_
for( auto i=clipper.DisplayStart; i<clipper.DisplayEnd; i++ ) for( auto i=clipper.DisplayStart; i<clipper.DisplayEnd; i++ )
{ {
auto it = ipcount.find( i+1 ); auto it = ipcount.find( i+1 );
const auto ipcnt = it == ipcount.end() ? 0 : it->second.local; const auto ipcnt = it == ipcount.end() ? zero : it->second;
RenderLine( lines[i], i+1, ipcnt, iptotal, ipmax, &worker ); RenderLine( lines[i], i+1, ipcnt, iptotal, ipmax, &worker );
} }
} }
@ -1579,9 +1581,9 @@ void SourceView::RenderSymbolSourceView( uint32_t iptotal, const unordered_flat_
draw->AddLine( ImVec2( rect.Min.x, ly ), ImVec2( rect.Max.x, ly ), 0x88888888, 3 ); draw->AddLine( ImVec2( rect.Min.x, ly ), ImVec2( rect.Max.x, ly ), 0x88888888, 3 );
} }
std::vector<std::pair<uint64_t, uint32_t>> ipData; std::vector<std::pair<uint64_t, AddrStat>> ipData;
ipData.reserve( ipcount.size() ); ipData.reserve( ipcount.size() );
for( auto& v : ipcount ) ipData.emplace_back( v.first, v.second.local ); for( auto& v : ipcount ) ipData.emplace_back( v.first, v.second );
for( uint32_t lineNum = 1; lineNum <= lines.size(); lineNum++ ) for( uint32_t lineNum = 1; lineNum <= lines.size(); lineNum++ )
{ {
if( ipcount.find( lineNum ) == ipcount.end() ) if( ipcount.find( lineNum ) == ipcount.end() )
@ -1593,7 +1595,7 @@ void SourceView::RenderSymbolSourceView( uint32_t iptotal, const unordered_flat_
{ {
if( addr >= m_baseAddr && addr < m_baseAddr + m_codeLen ) if( addr >= m_baseAddr && addr < m_baseAddr + m_codeLen )
{ {
ipData.emplace_back( lineNum, 0 ); ipData.emplace_back( lineNum, AddrStat {} );
break; break;
} }
} }
@ -1610,16 +1612,24 @@ void SourceView::RenderSymbolSourceView( uint32_t iptotal, const unordered_flat_
while( it != ipData.end() ) while( it != ipData.end() )
{ {
const auto firstLine = it->first; const auto firstLine = it->first;
uint32_t ipSum = 0; AddrStat ipSum = {};
while( it != ipData.end() && it->first <= firstLine + step ) while( it != ipData.end() && it->first <= firstLine + step )
{ {
ipSum += it->second; ipSum += it->second;
++it; ++it;
} }
const auto ly = round( rect.Min.y + float( firstLine ) / lines.size() * rect.GetHeight() ); const auto ly = round( rect.Min.y + float( firstLine ) / lines.size() * rect.GetHeight() );
const uint32_t color = ipSum == 0 ? 0x22FFFFFF : GetHotnessColor( ipSum, ipmax ); if( m_childCalls )
{
const auto color = ( ipSum.local + ipSum.ext == 0 ) ? 0x22FFFFFF : GetHotnessColor( ipSum.local + ipSum.ext, ipmax.local + ipmax.ext );
draw->AddRectFilled( ImVec2( x14, ly ), ImVec2( x34, ly+3 ), color ); draw->AddRectFilled( ImVec2( x14, ly ), ImVec2( x34, ly+3 ), color );
} }
else
{
const auto color = ipSum.local == 0 ? 0x22FFFFFF : GetHotnessColor( ipSum.local, ipmax.local );
draw->AddRectFilled( ImVec2( x14, ly ), ImVec2( x34, ly+3 ), color );
}
}
ImGui::PopClipRect(); ImGui::PopClipRect();
} }
@ -1629,14 +1639,14 @@ void SourceView::RenderSymbolSourceView( uint32_t iptotal, const unordered_flat_
if( !m_srcSampleSelect.empty() ) if( !m_srcSampleSelect.empty() )
{ {
uint32_t count = 0; AddrStat count = {};
uint32_t numLines = 0; uint32_t numLines = 0;
for( auto& idx : m_srcSampleSelect ) for( auto& idx : m_srcSampleSelect )
{ {
auto it = ipcount.find( idx ); auto it = ipcount.find( idx );
if( it != ipcount.end() ) if( it != ipcount.end() )
{ {
count += it->second.local; count += it->second;
numLines++; numLines++;
} }
} }
@ -1649,17 +1659,43 @@ void SourceView::RenderSymbolSourceView( uint32_t iptotal, const unordered_flat_
} }
ImGui::SameLine(); ImGui::SameLine();
char buf[16]; char buf[16];
auto end = PrintFloat( buf, buf+16, 100.f * count / iptotal, 2 ); char* end;
if( m_childCalls )
{
end = PrintFloat( buf, buf+16, 100.f * ( count.local + count.ext ) / ( iptotal.local + iptotal.ext ), 2 );
}
else if( iptotal.local != 0 )
{
end = PrintFloat( buf, buf+16, 100.f * count.local / iptotal.local, 2 );
}
else
{
end = PrintFloat( buf, buf+16, 0.f, 2 );
}
memcpy( end, "%", 2 ); memcpy( end, "%", 2 );
TextFocused( "Selected:", buf ); TextFocused( "Selected:", buf );
ImGui::SameLine(); ImGui::SameLine();
ImGui::Spacing(); ImGui::Spacing();
ImGui::SameLine(); ImGui::SameLine();
TextFocused( "Time:", TimeToString( count * worker.GetSamplingPeriod() ) ); if( m_childCalls )
{
TextFocused( "Time:", TimeToString( ( count.local + count.ext ) * worker.GetSamplingPeriod() ) );
}
else
{
TextFocused( "Time:", TimeToString( count.local * worker.GetSamplingPeriod() ) );
}
ImGui::SameLine(); ImGui::SameLine();
ImGui::Spacing(); ImGui::Spacing();
ImGui::SameLine(); ImGui::SameLine();
TextFocused( "Sample count:", RealToString( count ) ); if( m_childCalls )
{
TextFocused( "Sample count:", RealToString( count.local + count.ext ) );
}
else
{
TextFocused( "Sample count:", RealToString( count.local ) );
}
ImGui::SameLine(); ImGui::SameLine();
ImGui::Spacing(); ImGui::Spacing();
ImGui::SameLine(); ImGui::SameLine();
@ -2290,7 +2326,7 @@ static bool PrintPercentage( float val, uint32_t col = 0xFFFFFFFF )
return ImGui::IsWindowHovered() && ImGui::IsMouseHoveringRect( wpos, wpos + ImVec2( stw * 7, ty ) ); return ImGui::IsWindowHovered() && ImGui::IsMouseHoveringRect( wpos, wpos + ImVec2( stw * 7, ty ) );
} }
void SourceView::RenderLine( const Tokenizer::Line& line, int lineNum, uint32_t ipcnt, uint32_t iptotal, uint32_t ipmax, const Worker* worker ) void SourceView::RenderLine( const Tokenizer::Line& line, int lineNum, const AddrStat& ipcnt, const AddrStat& iptotal, const AddrStat& ipmax, const Worker* worker )
{ {
const auto ty = ImGui::GetFontSize(); const auto ty = ImGui::GetFontSize();
auto draw = ImGui::GetWindowDrawList(); auto draw = ImGui::GetWindowDrawList();
@ -2306,9 +2342,9 @@ void SourceView::RenderLine( const Tokenizer::Line& line, int lineNum, uint32_t
} }
bool mouseHandled = false; bool mouseHandled = false;
if( iptotal != 0 ) if( iptotal.local + iptotal.ext != 0 )
{ {
if( ipcnt == 0 ) if( ( m_childCalls && ipcnt.local + ipcnt.ext == 0 ) || ( !m_childCalls && ipcnt.local == 0 ) )
{ {
const auto ts = ImGui::CalcTextSize( " " ); const auto ts = ImGui::CalcTextSize( " " );
ImGui::ItemSize( ImVec2( 7 * ts.x, ts.y ) ); ImGui::ItemSize( ImVec2( 7 * ts.x, ts.y ) );
@ -2316,12 +2352,29 @@ void SourceView::RenderLine( const Tokenizer::Line& line, int lineNum, uint32_t
else else
{ {
auto sit = m_srcSampleSelect.find( lineNum ); auto sit = m_srcSampleSelect.find( lineNum );
if( PrintPercentage( 100.f * ipcnt / iptotal, sit == m_srcSampleSelect.end() ? 0xFFFFFFFF : 0xFF8888FF ) ) bool hover;
if( m_childCalls )
{
hover = PrintPercentage( 100.f * ( ipcnt.local + ipcnt.ext ) / ( iptotal.local + iptotal.ext ), sit == m_srcSampleSelect.end() ? 0xFFFFFFFF : 0xFF8888FF );
}
else
{
hover = PrintPercentage( 100.f * ipcnt.local / iptotal.local, sit == m_srcSampleSelect.end() ? 0xFFFFFFFF : 0xFF8888FF );
}
if( hover )
{ {
if( m_font ) ImGui::PopFont(); if( m_font ) ImGui::PopFont();
ImGui::BeginTooltip(); ImGui::BeginTooltip();
if( worker ) TextFocused( "Time:", TimeToString( ipcnt * worker->GetSamplingPeriod() ) ); if( ipcnt.local )
TextFocused( "Sample count:", RealToString( ipcnt ) ); {
if( worker ) TextFocused( "Local time:", TimeToString( ipcnt.local * worker->GetSamplingPeriod() ) );
TextFocused( "Local samples:", RealToString( ipcnt.local ) );
}
if( ipcnt.ext )
{
if( worker ) TextFocused( "Child time:", TimeToString( ipcnt.ext * worker->GetSamplingPeriod() ) );
TextFocused( "Child samples:", RealToString( ipcnt.ext ) );
}
ImGui::EndTooltip(); ImGui::EndTooltip();
if( m_font ) ImGui::PushFont( m_font ); if( m_font ) ImGui::PushFont( m_font );
@ -2381,7 +2434,14 @@ void SourceView::RenderLine( const Tokenizer::Line& line, int lineNum, uint32_t
m_srcGroupSelect = -1; m_srcGroupSelect = -1;
} }
} }
draw->AddLine( wpos + ImVec2( 0, 1 ), wpos + ImVec2( 0, ty-2 ), GetHotnessColor( ipcnt, ipmax ) ); if( m_childCalls )
{
draw->AddLine( wpos + ImVec2( 0, 1 ), wpos + ImVec2( 0, ty-2 ), GetHotnessColor( ipcnt.local + ipcnt.ext, ipmax.local + ipmax.ext ) );
}
else
{
draw->AddLine( wpos + ImVec2( 0, 1 ), wpos + ImVec2( 0, ty-2 ), GetHotnessColor( ipcnt.local, ipmax.local ) );
}
} }
ImGui::SameLine( 0, ty ); ImGui::SameLine( 0, ty );
} }

View File

@ -136,10 +136,10 @@ private:
void RenderSimpleSourceView(); void RenderSimpleSourceView();
void RenderSymbolView( const Worker& worker, View& view ); void RenderSymbolView( const Worker& worker, View& view );
void RenderSymbolSourceView( uint32_t iptotal, const unordered_flat_map<uint64_t, AddrStat>& ipcount, const unordered_flat_map<uint64_t, AddrStat>& ipcountAsm, uint32_t ipmax, const Worker& worker, const View& view ); void RenderSymbolSourceView( const AddrStat& iptotal, const unordered_flat_map<uint64_t, AddrStat>& ipcount, const unordered_flat_map<uint64_t, AddrStat>& ipcountAsm, const AddrStat& ipmax, const Worker& worker, const View& view );
uint64_t RenderSymbolAsmView( const AddrStat& iptotal, const unordered_flat_map<uint64_t, AddrStat>& ipcount, const AddrStat& ipmax, const Worker& worker, View& view ); uint64_t RenderSymbolAsmView( const AddrStat& iptotal, const unordered_flat_map<uint64_t, AddrStat>& ipcount, const AddrStat& ipmax, const Worker& worker, View& view );
void RenderLine( const Tokenizer::Line& line, int lineNum, uint32_t ipcnt, uint32_t iptotal, uint32_t ipmax, const Worker* worker ); void RenderLine( const Tokenizer::Line& line, int lineNum, const AddrStat& ipcnt, const AddrStat& iptotal, const AddrStat& ipmax, const Worker* worker );
void RenderAsmLine( AsmLine& line, const AddrStat& ipcnt, const AddrStat& iptotal, const AddrStat& ipmax, const Worker& worker, uint64_t& jumpOut, int maxAddrLen, View& view ); void RenderAsmLine( AsmLine& line, const AddrStat& ipcnt, const AddrStat& iptotal, const AddrStat& ipmax, const Worker& worker, uint64_t& jumpOut, int maxAddrLen, View& view );
void SelectLine( uint32_t line, const Worker* worker, bool changeAsmLine = true, uint64_t targetAddr = 0 ); void SelectLine( uint32_t line, const Worker* worker, bool changeAsmLine = true, uint64_t targetAddr = 0 );