Skip to content

Commit

Permalink
Thread selection in flame graph.
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfpld committed Sep 8, 2024
1 parent 504b9d2 commit 48763ef
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 2 deletions.
11 changes: 11 additions & 0 deletions profiler/src/profiler/TracyView.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,7 @@ class View

unordered_flat_map<uint64_t, bool> m_visibleMsgThread;
unordered_flat_map<uint64_t, bool> m_waitStackThread;
unordered_flat_map<uint64_t, bool> m_flameGraphThread;
unordered_flat_map<const void*, int> m_gpuDrift;
unordered_flat_map<const PlotData*, PlotView> m_plotView;
Vector<const ThreadData*> m_threadOrder;
Expand All @@ -406,6 +407,16 @@ class View
return it->second;
}

tracy_force_inline bool& FlameGraphThread( uint64_t thread )
{
auto it = m_flameGraphThread.find( thread );
if( it == m_flameGraphThread.end() )
{
it = m_flameGraphThread.emplace( thread, true ).first;
}
return it->second;
}

tracy_force_inline int& GpuDrift( const void* ptr )
{
auto it = m_gpuDrift.find( ptr );
Expand Down
64 changes: 62 additions & 2 deletions profiler/src/profiler/TracyView_FlameGraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -291,18 +291,78 @@ void View::DrawFlameGraph()
ImGui::RadioButton( ICON_FA_EYE_DROPPER " Sampling", &m_flameMode, 1 );
}

auto expand = ImGui::TreeNode( ICON_FA_SHUFFLE " Visible threads:" );
ImGui::SameLine();
size_t visibleThreads = 0;
size_t tsz = 0;
for( const auto& t : m_threadOrder )
{
if( FlameGraphThread( t->id ) ) visibleThreads++;
tsz++;
}
if( visibleThreads == tsz )
{
ImGui::TextDisabled( "(%zu)", tsz );
}
else
{
ImGui::TextDisabled( "(%zu/%zu)", visibleThreads, tsz );
}
if( expand )
{
ImGui::SameLine();
if( ImGui::SmallButton( "Select all" ) )
{
for( const auto& t : m_threadOrder )
{
FlameGraphThread( t->id ) = true;
}
}
ImGui::SameLine();
if( ImGui::SmallButton( "Unselect all" ) )
{
for( const auto& t : m_threadOrder )
{
FlameGraphThread( t->id ) = false;
}
}

int idx = 0;
for( const auto& t : m_threadOrder )
{
ImGui::PushID( idx++ );
const auto threadColor = GetThreadColor( t->id, 0 );
SmallColorBox( threadColor );
ImGui::SameLine();
SmallCheckbox( m_worker.GetThreadName( t->id ), &FlameGraphThread( t->id ) );
ImGui::PopID();
if( t->isFiber )
{
ImGui::SameLine();
TextColoredUnformatted( ImVec4( 0.2f, 0.6f, 0.2f, 1.f ), "Fiber" );
}
}
ImGui::TreePop();
}

ImGui::Separator();
ImGui::PopStyleVar();

Vector<FlameGraphItem> data;

if( m_flameMode == 0 )
{
for( auto& thread : m_worker.GetThreadData() ) BuildFlameGraph( m_worker, data, thread->timeline );
for( auto& thread : m_worker.GetThreadData() )
{
if( FlameGraphThread( thread->id ) ) BuildFlameGraph( m_worker, data, thread->timeline );
}
}
else
{
for( auto& thread : m_worker.GetThreadData() ) BuildFlameGraph( m_worker, data, thread->samples );
for( auto& thread : m_worker.GetThreadData() )
{
if( FlameGraphThread( thread->id ) ) BuildFlameGraph( m_worker, data, thread->samples );
}
}
SortFlameGraph( data );

Expand Down

0 comments on commit 48763ef

Please sign in to comment.