1
0
mirror of https://github.com/wolfpld/tracy synced 2025-05-04 06:13:53 +00:00

Use tables in find zone zones list.

This commit is contained in:
Bartosz Taudul 2020-12-09 02:13:14 +01:00
parent c437ecfcf5
commit 6300f59183
2 changed files with 86 additions and 41 deletions

View File

@ -10863,38 +10863,50 @@ void View::DrawFindZone()
void View::DrawZoneList( const Vector<short_ptr<ZoneEvent>>& zones ) void View::DrawZoneList( const Vector<short_ptr<ZoneEvent>>& zones )
{ {
ImGui::Columns( 3 ); if( !ImGui::BeginTable( "##zonelist", 3, ImGuiTableFlags_Resizable | ImGuiTableFlags_Hideable | ImGuiTableFlags_BordersInnerV | ImGuiTableFlags_Sortable | ImGuiTableFlags_ScrollY ) ) return;
ImGui::Separator(); ImGui::TableSetupScrollFreeze( 0, 1 );
if( ImGui::SmallButton( "Time from start" ) ) m_findZone.tableSortBy = FindZone::TableSortBy::Starttime; ImGui::TableSetupColumn( "Time from start" );
ImGui::NextColumn(); ImGui::TableSetupColumn( "Execution time", ImGuiTableColumnFlags_PreferSortDescending );
if( ImGui::SmallButton( "Execution time" ) ) m_findZone.tableSortBy = FindZone::TableSortBy::Runtime; ImGui::TableSetupColumn( "Name", ImGuiTableColumnFlags_NoSort );
ImGui::NextColumn(); ImGui::TableHeadersRow();
if( ImGui::SmallButton( "Name" ) ) m_findZone.tableSortBy = FindZone::TableSortBy::Name;
ImGui::SameLine();
DrawHelpMarker( "Only displayed if custom zone name is set." );
ImGui::NextColumn();
ImGui::Separator();
const Vector<short_ptr<ZoneEvent>>* zonesToIterate = &zones; const Vector<short_ptr<ZoneEvent>>* zonesToIterate = &zones;
Vector<short_ptr<ZoneEvent>> sortedZones; Vector<short_ptr<ZoneEvent>> sortedZones;
if( m_findZone.tableSortBy != FindZone::TableSortBy::Starttime ) const auto& sortspec = *ImGui::TableGetSortSpecs()->Specs;
if( sortspec.ColumnIndex != 0 || sortspec.SortDirection != ImGuiSortDirection_Ascending )
{ {
zonesToIterate = &sortedZones; zonesToIterate = &sortedZones;
sortedZones.reserve_and_use( zones.size() ); sortedZones.reserve_and_use( zones.size() );
memcpy( sortedZones.data(), zones.data(), zones.size() * sizeof( decltype( *zones.begin() ) ) ); memcpy( sortedZones.data(), zones.data(), zones.size() * sizeof( decltype( *zones.begin() ) ) );
switch( m_findZone.tableSortBy ) switch( sortspec.ColumnIndex )
{ {
case FindZone::TableSortBy::Runtime: case 0:
assert( sortspec.SortDirection != ImGuiSortDirection_Descending );
std::reverse( sortedZones.begin(), sortedZones.end() );
break;
case 1:
if( m_findZone.selfTime ) if( m_findZone.selfTime )
{
if( sortspec.SortDirection == ImGuiSortDirection_Descending )
{ {
pdqsort_branchless( sortedZones.begin(), sortedZones.end(), [this]( const auto& lhs, const auto& rhs ) { pdqsort_branchless( sortedZones.begin(), sortedZones.end(), [this]( const auto& lhs, const auto& rhs ) {
return m_worker.GetZoneEndDirect( *lhs ) - lhs->Start() - this->GetZoneChildTimeFast( *lhs ) > return m_worker.GetZoneEndDirect( *lhs ) - lhs->Start() - this->GetZoneChildTimeFast( *lhs ) >
m_worker.GetZoneEndDirect( *rhs ) - rhs->Start() - this->GetZoneChildTimeFast( *rhs ); m_worker.GetZoneEndDirect( *rhs ) - rhs->Start() - this->GetZoneChildTimeFast( *rhs );
} ); } );
} }
else
{
pdqsort_branchless( sortedZones.begin(), sortedZones.end(), [this]( const auto& lhs, const auto& rhs ) {
return m_worker.GetZoneEndDirect( *lhs ) - lhs->Start() - this->GetZoneChildTimeFast( *lhs ) <
m_worker.GetZoneEndDirect( *rhs ) - rhs->Start() - this->GetZoneChildTimeFast( *rhs );
} );
}
}
else if( m_findZone.runningTime ) else if( m_findZone.runningTime )
{
if( sortspec.SortDirection == ImGuiSortDirection_Descending )
{ {
pdqsort_branchless( sortedZones.begin(), sortedZones.end(), [this]( const auto& lhs, const auto& rhs ) { pdqsort_branchless( sortedZones.begin(), sortedZones.end(), [this]( const auto& lhs, const auto& rhs ) {
const auto ctx0 = m_worker.GetContextSwitchData( GetZoneThread( *lhs ) ); const auto ctx0 = m_worker.GetContextSwitchData( GetZoneThread( *lhs ) );
@ -10907,19 +10919,53 @@ void View::DrawZoneList( const Vector<short_ptr<ZoneEvent>>& zones )
} ); } );
} }
else else
{
pdqsort_branchless( sortedZones.begin(), sortedZones.end(), [this]( const auto& lhs, const auto& rhs ) {
const auto ctx0 = m_worker.GetContextSwitchData( GetZoneThread( *lhs ) );
const auto ctx1 = m_worker.GetContextSwitchData( GetZoneThread( *rhs ) );
int64_t t0, t1;
uint64_t c0, c1;
GetZoneRunningTime( ctx0, *lhs, t0, c0 );
GetZoneRunningTime( ctx1, *rhs, t1, c1 );
return t0 < t1;
} );
}
}
else
{
if( sortspec.SortDirection == ImGuiSortDirection_Descending )
{ {
pdqsort_branchless( sortedZones.begin(), sortedZones.end(), [this]( const auto& lhs, const auto& rhs ) { pdqsort_branchless( sortedZones.begin(), sortedZones.end(), [this]( const auto& lhs, const auto& rhs ) {
return m_worker.GetZoneEndDirect( *lhs ) - lhs->Start() > m_worker.GetZoneEndDirect( *rhs ) - rhs->Start(); return m_worker.GetZoneEndDirect( *lhs ) - lhs->Start() > m_worker.GetZoneEndDirect( *rhs ) - rhs->Start();
} ); } );
} }
else
{
pdqsort_branchless( sortedZones.begin(), sortedZones.end(), [this]( const auto& lhs, const auto& rhs ) {
return m_worker.GetZoneEndDirect( *lhs ) - lhs->Start() < m_worker.GetZoneEndDirect( *rhs ) - rhs->Start();
} );
}
}
break; break;
case FindZone::TableSortBy::Name: case 2:
if( sortspec.SortDirection == ImGuiSortDirection_Descending )
{
pdqsort_branchless( sortedZones.begin(), sortedZones.end(), [this]( const auto& lhs, const auto& rhs ) { pdqsort_branchless( sortedZones.begin(), sortedZones.end(), [this]( const auto& lhs, const auto& rhs ) {
const auto hle = m_worker.HasZoneExtra( *lhs ); const auto hle = m_worker.HasZoneExtra( *lhs );
const auto hre = m_worker.HasZoneExtra( *rhs ); const auto hre = m_worker.HasZoneExtra( *rhs );
if( !( hle & hre ) ) return hle > hre; if( !( hle & hre ) ) return hle > hre;
return strcmp( m_worker.GetString( m_worker.GetZoneExtra( *lhs ).name ), m_worker.GetString( m_worker.GetZoneExtra( *rhs ).name ) ) < 0; return strcmp( m_worker.GetString( m_worker.GetZoneExtra( *lhs ).name ), m_worker.GetString( m_worker.GetZoneExtra( *rhs ).name ) ) < 0;
} ); } );
}
else
{
pdqsort_branchless( sortedZones.begin(), sortedZones.end(), [this]( const auto& lhs, const auto& rhs ) {
const auto hle = m_worker.HasZoneExtra( *lhs );
const auto hre = m_worker.HasZoneExtra( *rhs );
if( !( hle & hre ) ) return hle < hre;
return strcmp( m_worker.GetString( m_worker.GetZoneExtra( *lhs ).name ), m_worker.GetString( m_worker.GetZoneExtra( *rhs ).name ) ) > 0;
} );
}
break; break;
default: default:
assert( false ); assert( false );
@ -10933,6 +10979,9 @@ void View::DrawZoneList( const Vector<short_ptr<ZoneEvent>>& zones )
{ {
for( auto i=clipper.DisplayStart; i<clipper.DisplayEnd; i++ ) for( auto i=clipper.DisplayStart; i<clipper.DisplayEnd; i++ )
{ {
ImGui::TableNextRow();
ImGui::TableNextColumn();
auto ev = (*zonesToIterate)[i].get(); auto ev = (*zonesToIterate)[i].get();
const auto end = m_worker.GetZoneEndDirect( *ev ); const auto end = m_worker.GetZoneEndDirect( *ev );
int64_t timespan; int64_t timespan;
@ -10965,9 +11014,9 @@ void View::DrawZoneList( const Vector<short_ptr<ZoneEvent>>& zones )
m_zoneHover2 = ev; m_zoneHover2 = ev;
} }
ImGui::NextColumn(); ImGui::TableNextColumn();
ImGui::TextUnformatted( TimeToString( timespan ) ); ImGui::TextUnformatted( TimeToString( timespan ) );
ImGui::NextColumn(); ImGui::TableNextColumn();
if( m_worker.HasZoneExtra( *ev ) ) if( m_worker.HasZoneExtra( *ev ) )
{ {
const auto& extra = m_worker.GetZoneExtra( *ev ); const auto& extra = m_worker.GetZoneExtra( *ev );
@ -10976,13 +11025,11 @@ void View::DrawZoneList( const Vector<short_ptr<ZoneEvent>>& zones )
ImGui::TextUnformatted( m_worker.GetString( extra.name ) ); ImGui::TextUnformatted( m_worker.GetString( extra.name ) );
} }
} }
ImGui::NextColumn();
if( m_zoneHover == ev ) ImGui::PopStyleColor(); if( m_zoneHover == ev ) ImGui::PopStyleColor();
ImGui::PopID(); ImGui::PopID();
} }
} }
ImGui::Columns( 1 ); ImGui::EndTable();
ImGui::Separator();
ImGui::TreePop(); ImGui::TreePop();
} }

View File

@ -488,7 +488,6 @@ private:
enum : uint64_t { Unselected = std::numeric_limits<uint64_t>::max() - 1 }; enum : uint64_t { Unselected = std::numeric_limits<uint64_t>::max() - 1 };
enum class GroupBy : int { Thread, UserText, ZoneName, Callstack, Parent, NoGrouping }; enum class GroupBy : int { Thread, UserText, ZoneName, Callstack, Parent, NoGrouping };
enum class SortBy : int { Order, Count, Time, Mtpc }; enum class SortBy : int { Order, Count, Time, Mtpc };
enum class TableSortBy : int { Starttime, Runtime, Name };
struct Group struct Group
{ {
@ -513,7 +512,6 @@ private:
bool runningTime = false; bool runningTime = false;
GroupBy groupBy = GroupBy::Thread; GroupBy groupBy = GroupBy::Thread;
SortBy sortBy = SortBy::Count; SortBy sortBy = SortBy::Count;
TableSortBy tableSortBy = TableSortBy::Starttime;
Region highlight; Region highlight;
int64_t hlOrig_t0, hlOrig_t1; int64_t hlOrig_t0, hlOrig_t1;
int64_t numBins = -1; int64_t numBins = -1;