Skip to content

Commit

Permalink
Normalize flame graph sample frame names, to mach callstack list beha…
Browse files Browse the repository at this point in the history
…vior.
  • Loading branch information
wolfpld committed Oct 27, 2024
1 parent 8471810 commit 2097e3c
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions profiler/src/profiler/TracyView_FlameGraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,7 @@ void View::DrawFlameGraphItem( const FlameGraphItem& item, FlameGraphContext& ct
const SourceLocation* srcloc;
uint32_t color;
const char* name;
const char* normalized;
const char* slName;

uint32_t textColor = 0xFFFFFFFF;
Expand Down Expand Up @@ -363,9 +364,26 @@ void View::DrawFlameGraphItem( const FlameGraphItem& item, FlameGraphContext& ct
const auto zsz = x1 - x0;

auto tsz = ImGui::CalcTextSize( name );
if( m_vd.shortenName == ShortenName::Always || ( ( m_vd.shortenName == ShortenName::NoSpace || m_vd.shortenName == ShortenName::NoSpaceAndNormalize ) && tsz.x > zsz ) )
if( m_vd.shortenName == ShortenName::Never )
{
name = ShortenZoneName( m_vd.shortenName, name, tsz, zsz );
normalized = name;
}
else if( samples )
{
normalized = ShortenZoneName( ShortenName::OnlyNormalize, name );
tsz = ImGui::CalcTextSize( normalized );
if( tsz.x > zsz && ( m_vd.shortenName == ShortenName::NoSpace || m_vd.shortenName == ShortenName::NoSpaceAndNormalize ) )
{
normalized = ShortenZoneName( m_vd.shortenName, normalized, tsz, zsz );
}
}
else if( m_vd.shortenName == ShortenName::Always || ( ( m_vd.shortenName == ShortenName::NoSpace || m_vd.shortenName == ShortenName::NoSpaceAndNormalize ) && tsz.x > zsz ) )
{
normalized = ShortenZoneName( m_vd.shortenName, name, tsz, zsz );
}
else
{
normalized = name;
}

const bool hover = ImGui::IsWindowHovered() && ImGui::IsMouseHoveringRect( ImVec2( x0, y0 ), ImVec2( x1, y1 ) );
Expand All @@ -384,12 +402,12 @@ void View::DrawFlameGraphItem( const FlameGraphItem& item, FlameGraphContext& ct
if( tsz.x < zsz )
{
const auto x = ( x1 + x0 - tsz.x ) * 0.5;
DrawTextContrast( ctx.draw, ImVec2( x, y0 ), textColor, name );
DrawTextContrast( ctx.draw, ImVec2( x, y0 ), textColor, normalized );
}
else
{
ImGui::PushClipRect( ImVec2( x0, y0 ), ImVec2( x1, y1 ), true );
DrawTextContrast( ctx.draw, ImVec2( x0, y0 ), textColor, name );
DrawTextContrast( ctx.draw, ImVec2( x0, y0 ), textColor, normalized );
ImGui::PopClipRect();
}

Expand All @@ -405,7 +423,6 @@ void View::DrawFlameGraphItem( const FlameGraphItem& item, FlameGraphContext& ct
auto sym = m_worker.GetSymbolData( symAddr );
if( sym )
{
auto normalized = m_vd.shortenName == ShortenName::Never ? name : ShortenZoneName( ShortenName::OnlyNormalize, name );
TextFocused( "Name:", normalized );
if( sym->isInline )
{
Expand Down

0 comments on commit 2097e3c

Please sign in to comment.