From 1aeb1d9a2d8cf1de7dd195a98a5cc0bd2324d645 Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Sat, 2 Jul 2022 13:58:37 +0200 Subject: [PATCH] More find zones extraction. --- server/TracyView.cpp | 175 ---------------------------------- server/TracyView_FindZone.cpp | 175 ++++++++++++++++++++++++++++++++++ 2 files changed, 175 insertions(+), 175 deletions(-) diff --git a/server/TracyView.cpp b/server/TracyView.cpp index a4a05dd0..135238ef 100644 --- a/server/TracyView.cpp +++ b/server/TracyView.cpp @@ -6800,181 +6800,6 @@ void View::DrawHistogramMinMaxLabel( ImDrawList* draw, int64_t tmin, int64_t tma draw->AddText( wpos + ImVec2( round( (w-1-rsz) * 0.5 ), ty15 ), 0x66FFFFFF, range ); } -void View::DrawZoneList( int id, const Vector>& zones ) -{ - const auto zsz = zones.size(); - char buf[32]; - sprintf( buf, "%i##zonelist", id ); - if( !ImGui::BeginTable( buf, 3, ImGuiTableFlags_NoSavedSettings | ImGuiTableFlags_Resizable | ImGuiTableFlags_Hideable | ImGuiTableFlags_BordersInnerV | ImGuiTableFlags_Sortable | ImGuiTableFlags_ScrollY, ImVec2( 0, ImGui::GetTextLineHeightWithSpacing() * std::min( zsz + 1, 15 ) ) ) ) return; - ImGui::TableSetupScrollFreeze( 0, 1 ); - ImGui::TableSetupColumn( "Time from start" ); - ImGui::TableSetupColumn( "Execution time", ImGuiTableColumnFlags_PreferSortDescending ); - ImGui::TableSetupColumn( "Name", ImGuiTableColumnFlags_NoSort ); - ImGui::TableHeadersRow(); - - const Vector>* zonesToIterate = &zones; - Vector> sortedZones; - - const auto& sortspec = *ImGui::TableGetSortSpecs()->Specs; - if( sortspec.ColumnIndex != 0 || sortspec.SortDirection != ImGuiSortDirection_Ascending ) - { - zonesToIterate = &sortedZones; - sortedZones.reserve_and_use( zones.size() ); - memcpy( sortedZones.data(), zones.data(), zones.size() * sizeof( decltype( *zones.begin() ) ) ); - - switch( sortspec.ColumnIndex ) - { - case 0: - assert( sortspec.SortDirection != ImGuiSortDirection_Descending ); - std::reverse( sortedZones.begin(), sortedZones.end() ); - break; - case 1: - if( m_findZone.selfTime ) - { - if( sortspec.SortDirection == ImGuiSortDirection_Descending ) - { - 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 - { - 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 ) - { - if( sortspec.SortDirection == ImGuiSortDirection_Descending ) - { - 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 - { - 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 ) { - 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; - case 2: - if( sortspec.SortDirection == ImGuiSortDirection_Descending ) - { - 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; - } ); - } - 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; - default: - assert( false ); - break; - } - } - - ImGuiListClipper clipper; - clipper.Begin( zonesToIterate->size() ); - while( clipper.Step() ) - { - for( auto i=clipper.DisplayStart; iStart(); - if( m_findZone.selfTime ) timespan -= GetZoneChildTimeFast( *ev ); - } - - ImGui::PushID( ev ); - if( m_zoneHover == ev ) ImGui::PushStyleColor( ImGuiCol_Text, ImVec4( 0, 1, 0, 1 ) ); - if( ImGui::Selectable( TimeToStringExact( ev->Start() ), m_zoneInfoWindow == ev, ImGuiSelectableFlags_SpanAllColumns ) ) - { - ShowZoneInfo( *ev ); - } - if( ImGui::IsItemHovered() ) - { - m_zoneHighlight = ev; - if( IsMouseClicked( 2 ) ) - { - ZoomToZone( *ev ); - } - ZoneTooltip( *ev ); - m_zoneHover2 = ev; - } - - ImGui::TableNextColumn(); - ImGui::TextUnformatted( TimeToString( timespan ) ); - ImGui::TableNextColumn(); - if( m_worker.HasZoneExtra( *ev ) ) - { - const auto& extra = m_worker.GetZoneExtra( *ev ); - if( extra.name.Active() ) - { - ImGui::TextUnformatted( m_worker.GetString( extra.name ) ); - } - } - if( m_zoneHover == ev ) ImGui::PopStyleColor(); - ImGui::PopID(); - } - } - ImGui::EndTable(); - ImGui::TreePop(); -} - void View::DrawSamplesStatistics(Vector& data, int64_t timeRange, AccumulationMode accumulationMode) { static unordered_flat_map inlineMap; diff --git a/server/TracyView_FindZone.cpp b/server/TracyView_FindZone.cpp index f952627d..775634a1 100644 --- a/server/TracyView_FindZone.cpp +++ b/server/TracyView_FindZone.cpp @@ -68,6 +68,181 @@ uint64_t View::GetSelectionTarget( const Worker::ZoneThreadData& ev, FindZone::G } } +void View::DrawZoneList( int id, const Vector>& zones ) +{ + const auto zsz = zones.size(); + char buf[32]; + sprintf( buf, "%i##zonelist", id ); + if( !ImGui::BeginTable( buf, 3, ImGuiTableFlags_NoSavedSettings | ImGuiTableFlags_Resizable | ImGuiTableFlags_Hideable | ImGuiTableFlags_BordersInnerV | ImGuiTableFlags_Sortable | ImGuiTableFlags_ScrollY, ImVec2( 0, ImGui::GetTextLineHeightWithSpacing() * std::min( zsz + 1, 15 ) ) ) ) return; + ImGui::TableSetupScrollFreeze( 0, 1 ); + ImGui::TableSetupColumn( "Time from start" ); + ImGui::TableSetupColumn( "Execution time", ImGuiTableColumnFlags_PreferSortDescending ); + ImGui::TableSetupColumn( "Name", ImGuiTableColumnFlags_NoSort ); + ImGui::TableHeadersRow(); + + const Vector>* zonesToIterate = &zones; + Vector> sortedZones; + + const auto& sortspec = *ImGui::TableGetSortSpecs()->Specs; + if( sortspec.ColumnIndex != 0 || sortspec.SortDirection != ImGuiSortDirection_Ascending ) + { + zonesToIterate = &sortedZones; + sortedZones.reserve_and_use( zones.size() ); + memcpy( sortedZones.data(), zones.data(), zones.size() * sizeof( decltype( *zones.begin() ) ) ); + + switch( sortspec.ColumnIndex ) + { + case 0: + assert( sortspec.SortDirection != ImGuiSortDirection_Descending ); + std::reverse( sortedZones.begin(), sortedZones.end() ); + break; + case 1: + if( m_findZone.selfTime ) + { + if( sortspec.SortDirection == ImGuiSortDirection_Descending ) + { + 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 + { + 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 ) + { + if( sortspec.SortDirection == ImGuiSortDirection_Descending ) + { + 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 + { + 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 ) { + 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; + case 2: + if( sortspec.SortDirection == ImGuiSortDirection_Descending ) + { + 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; + } ); + } + 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; + default: + assert( false ); + break; + } + } + + ImGuiListClipper clipper; + clipper.Begin( zonesToIterate->size() ); + while( clipper.Step() ) + { + for( auto i=clipper.DisplayStart; iStart(); + if( m_findZone.selfTime ) timespan -= GetZoneChildTimeFast( *ev ); + } + + ImGui::PushID( ev ); + if( m_zoneHover == ev ) ImGui::PushStyleColor( ImGuiCol_Text, ImVec4( 0, 1, 0, 1 ) ); + if( ImGui::Selectable( TimeToStringExact( ev->Start() ), m_zoneInfoWindow == ev, ImGuiSelectableFlags_SpanAllColumns ) ) + { + ShowZoneInfo( *ev ); + } + if( ImGui::IsItemHovered() ) + { + m_zoneHighlight = ev; + if( IsMouseClicked( 2 ) ) + { + ZoomToZone( *ev ); + } + ZoneTooltip( *ev ); + m_zoneHover2 = ev; + } + + ImGui::TableNextColumn(); + ImGui::TextUnformatted( TimeToString( timespan ) ); + ImGui::TableNextColumn(); + if( m_worker.HasZoneExtra( *ev ) ) + { + const auto& extra = m_worker.GetZoneExtra( *ev ); + if( extra.name.Active() ) + { + ImGui::TextUnformatted( m_worker.GetString( extra.name ) ); + } + } + if( m_zoneHover == ev ) ImGui::PopStyleColor(); + ImGui::PopID(); + } + } + ImGui::EndTable(); + ImGui::TreePop(); +} + void View::DrawFindZone() { if( m_shortcut == ShortcutAction::OpenFind ) ImGui::SetNextWindowFocus();