Use tables for instrumented zones statistics.

This commit is contained in:
Bartosz Taudul 2020-12-09 20:55:00 +01:00
parent 6300f59183
commit f1a641a838
2 changed files with 129 additions and 97 deletions

View File

@ -12202,36 +12202,6 @@ void View::DrawStatistics()
}
}
switch( m_statSort )
{
case 0:
if( m_statSelf )
{
pdqsort_branchless( srcloc.begin(), srcloc.end(), []( const auto& lhs, const auto& rhs ) { return lhs.selfTotal > rhs.selfTotal; } );
}
else
{
pdqsort_branchless( srcloc.begin(), srcloc.end(), []( const auto& lhs, const auto& rhs ) { return lhs.total > rhs.total; } );
}
break;
case 1:
pdqsort_branchless( srcloc.begin(), srcloc.end(), []( const auto& lhs, const auto& rhs ) { return lhs.numZones > rhs.numZones; } );
break;
case 2:
if( m_statSelf )
{
pdqsort_branchless( srcloc.begin(), srcloc.end(), []( const auto& lhs, const auto& rhs ) { return lhs.selfTotal / lhs.numZones > rhs.selfTotal / rhs.numZones; } );
}
else
{
pdqsort_branchless( srcloc.begin(), srcloc.end(), []( const auto& lhs, const auto& rhs ) { return lhs.total / lhs.numZones > rhs.total / rhs.numZones; } );
}
break;
default:
assert( false );
break;
}
TextFocused( "Total zone count:", RealToString( slzcnt ) );
ImGui::SameLine();
ImGui::Spacing();
@ -12367,34 +12337,97 @@ void View::DrawStatistics()
else
{
ImGui::BeginChild( "##statistics" );
const auto w = ImGui::GetWindowWidth();
static bool widthSet = false;
ImGui::Columns( 5 );
if( !widthSet )
if( ImGui::BeginTable( "##statistics", 5, ImGuiTableFlags_Resizable | ImGuiTableFlags_Reorderable | ImGuiTableFlags_Hideable | ImGuiTableFlags_Sortable | ImGuiTableFlags_BordersInnerV | ImGuiTableFlags_ScrollY ) )
{
widthSet = true;
ImGui::SetColumnWidth( 0, w * 0.325f );
ImGui::SetColumnWidth( 1, w * 0.425f );
ImGui::SetColumnWidth( 2, w * 0.1f );
ImGui::SetColumnWidth( 3, w * 0.075f );
ImGui::SetColumnWidth( 4, w * 0.075f );
ImGui::TableSetupScrollFreeze( 0, 1 );
ImGui::TableSetupColumn( "Name", ImGuiTableColumnFlags_NoHide );
ImGui::TableSetupColumn( "Location", ImGuiTableColumnFlags_NoSort );
ImGui::TableSetupColumn( "Total time", ImGuiTableColumnFlags_DefaultSort | ImGuiTableColumnFlags_PreferSortDescending | ImGuiTableColumnFlags_WidthAutoResize );
ImGui::TableSetupColumn( "Counts", ImGuiTableColumnFlags_PreferSortDescending | ImGuiTableColumnFlags_WidthAutoResize );
ImGui::TableSetupColumn( "MTPC", ImGuiTableColumnFlags_PreferSortDescending | ImGuiTableColumnFlags_WidthAutoResize );
ImGui::TableHeadersRow();
const auto& sortspec = *ImGui::TableGetSortSpecs()->Specs;
switch( sortspec.ColumnIndex )
{
case 0:
if( sortspec.SortDirection == ImGuiSortDirection_Ascending )
{
pdqsort_branchless( srcloc.begin(), srcloc.end(), [this]( const auto& lhs, const auto& rhs ) { return strcmp( m_worker.GetZoneName( m_worker.GetSourceLocation( lhs.srcloc ) ), m_worker.GetZoneName( m_worker.GetSourceLocation( rhs.srcloc ) ) ) < 0; } );
}
else
{
pdqsort_branchless( srcloc.begin(), srcloc.end(), [this]( const auto& lhs, const auto& rhs ) { return strcmp( m_worker.GetZoneName( m_worker.GetSourceLocation( lhs.srcloc ) ), m_worker.GetZoneName( m_worker.GetSourceLocation( rhs.srcloc ) ) ) > 0; } );
}
break;
case 2:
if( m_statSelf )
{
if( sortspec.SortDirection == ImGuiSortDirection_Ascending )
{
pdqsort_branchless( srcloc.begin(), srcloc.end(), []( const auto& lhs, const auto& rhs ) { return lhs.selfTotal < rhs.selfTotal; } );
}
else
{
pdqsort_branchless( srcloc.begin(), srcloc.end(), []( const auto& lhs, const auto& rhs ) { return lhs.selfTotal > rhs.selfTotal; } );
}
}
else
{
if( sortspec.SortDirection == ImGuiSortDirection_Ascending )
{
pdqsort_branchless( srcloc.begin(), srcloc.end(), []( const auto& lhs, const auto& rhs ) { return lhs.total < rhs.total; } );
}
else
{
pdqsort_branchless( srcloc.begin(), srcloc.end(), []( const auto& lhs, const auto& rhs ) { return lhs.total > rhs.total; } );
}
}
break;
case 3:
if( sortspec.SortDirection == ImGuiSortDirection_Ascending )
{
pdqsort_branchless( srcloc.begin(), srcloc.end(), []( const auto& lhs, const auto& rhs ) { return lhs.numZones < rhs.numZones; } );
}
else
{
pdqsort_branchless( srcloc.begin(), srcloc.end(), []( const auto& lhs, const auto& rhs ) { return lhs.numZones > rhs.numZones; } );
}
break;
case 4:
if( m_statSelf )
{
if( sortspec.SortDirection == ImGuiSortDirection_Ascending )
{
pdqsort_branchless( srcloc.begin(), srcloc.end(), []( const auto& lhs, const auto& rhs ) { return lhs.selfTotal / lhs.numZones < rhs.selfTotal / rhs.numZones; } );
}
else
{
pdqsort_branchless( srcloc.begin(), srcloc.end(), []( const auto& lhs, const auto& rhs ) { return lhs.selfTotal / lhs.numZones > rhs.selfTotal / rhs.numZones; } );
}
}
else
{
if( sortspec.SortDirection == ImGuiSortDirection_Ascending )
{
pdqsort_branchless( srcloc.begin(), srcloc.end(), []( const auto& lhs, const auto& rhs ) { return lhs.total / lhs.numZones < rhs.total / rhs.numZones; } );
}
else
{
pdqsort_branchless( srcloc.begin(), srcloc.end(), []( const auto& lhs, const auto& rhs ) { return lhs.total / lhs.numZones > rhs.total / rhs.numZones; } );
}
}
break;
default:
assert( false );
break;
}
ImGui::TextUnformatted( "Name" );
ImGui::NextColumn();
ImGui::TextUnformatted( "Location" );
ImGui::NextColumn();
if( ImGui::SmallButton( "Total time" ) ) m_statSort = 0;
ImGui::NextColumn();
if( ImGui::SmallButton( "Counts" ) ) m_statSort = 1;
ImGui::NextColumn();
if( ImGui::SmallButton( "MTPC" ) ) m_statSort = 2;
ImGui::SameLine();
DrawHelpMarker( "Mean time per call" );
ImGui::NextColumn();
ImGui::Separator();
for( auto& v : srcloc )
{
ImGui::TableNextRow();
ImGui::TableNextColumn();
ImGui::PushID( v.srcloc );
auto& srcloc = m_worker.GetSourceLocation( v.srcloc );
auto name = m_worker.GetString( srcloc.name.active ? srcloc.name : srcloc.function );
@ -12404,7 +12437,7 @@ void View::DrawStatistics()
{
m_findZone.ShowZone( v.srcloc, name );
}
ImGui::NextColumn();
ImGui::TableNextColumn();
float indentVal = 0.f;
if( m_statBuzzAnim.Match( v.srcloc ) )
{
@ -12430,21 +12463,21 @@ void View::DrawStatistics()
{
ImGui::Unindent( indentVal );
}
ImGui::NextColumn();
ImGui::TableNextColumn();
const auto time = m_statSelf ? v.selfTotal : v.total;
ImGui::TextUnformatted( TimeToString( time ) );
ImGui::SameLine();
char buf[64];
PrintStringPercent( buf, 100. * time / timeRange );
TextDisabledUnformatted( buf );
ImGui::NextColumn();
ImGui::TableNextColumn();
ImGui::TextUnformatted( RealToString( v.numZones ) );
ImGui::NextColumn();
ImGui::TableNextColumn();
ImGui::TextUnformatted( TimeToString( ( m_statSelf ? v.selfTotal : v.total ) / v.numZones ) );
ImGui::NextColumn();
ImGui::PopID();
}
ImGui::EndColumns();
ImGui::EndTable();
}
ImGui::EndChild();
}
}

View File

@ -397,7 +397,6 @@ private:
CpuDataSortBy m_cpuDataSort = CpuDataSortBy::Pid;
int m_statSort = 0;
bool m_statSelf = true;
bool m_statSampleTime = true;
int m_statMode = 0;