1
0
mirror of https://github.com/wolfpld/tracy synced 2025-04-29 12:23:53 +00:00

Decorate source scroll bar with line hotness.

This commit is contained in:
Bartosz Taudul 2020-04-10 16:56:31 +02:00
parent e51844eba3
commit bcfd32e49f

View File

@ -660,6 +660,49 @@ void SourceView::RenderSymbolSourceView( uint32_t iptotal, unordered_flat_map<ui
const auto ly = round( rect.Min.y + ( m_hoveredLine - 0.5f ) / m_lines.size() * rect.GetHeight() );
draw->AddLine( ImVec2( rect.Min.x, ly ), ImVec2( rect.Max.x, ly ), 0x88888888, 3 );
}
uint32_t maxIpCount = 0;
std::vector<std::pair<uint64_t, uint32_t>> ipData;
ipData.reserve( ipcount.size() );
for( auto& v : ipcount )
{
if( v.second > maxIpCount ) maxIpCount = v.second;
ipData.emplace_back( v.first, v.second );
}
pdqsort_branchless( ipData.begin(), ipData.end(), []( const auto& l, const auto& r ) { return l.first < r.first; } );
const auto step = uint32_t( m_lines.size() * 2 / rect.GetHeight() );
const auto x14 = round( rect.Min.x + rect.GetWidth() * 0.4f );
const auto x34 = round( rect.Min.x + rect.GetWidth() * 0.6f );
auto it = ipData.begin();
while( it != ipData.end() )
{
const auto firstLine = it->first;
auto ipSum = 0;
while( it != ipData.end() && it->first <= firstLine + step )
{
ipSum += it->second;
++it;
}
const auto ly = round( rect.Min.y + float( firstLine ) / m_lines.size() * rect.GetHeight() );
const auto ipPercent = float( ipSum ) / maxIpCount;
if( ipPercent <= 0.5f )
{
const auto a = int( ( ipPercent * 1.5f + 0.25f ) * 255 );
draw->AddRectFilled( ImVec2( x14, ly ), ImVec2( x34, ly+3 ), 0x000000FF | ( a << 24 ) );
}
else if( ipPercent <= 1.f )
{
const auto g = int( ( ipPercent - 0.5f ) * 511 );
draw->AddRectFilled( ImVec2( x14, ly ), ImVec2( x34, ly+3 ), 0xFF0000FF | ( g << 8 ) );
}
else
{
draw->AddRectFilled( ImVec2( x14, ly ), ImVec2( x34, ly+3 ), 0xFF00FFFF );
}
}
ImGui::PopClipRect();
}