From 1cd5ccb3c1f6832c5b84c66669180a52d20a892a Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Fri, 4 Oct 2019 21:34:00 +0200 Subject: [PATCH] Display zone time distribution. --- server/TracyView.cpp | 83 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) diff --git a/server/TracyView.cpp b/server/TracyView.cpp index 736d5d73..61b06626 100644 --- a/server/TracyView.cpp +++ b/server/TracyView.cpp @@ -5243,6 +5243,40 @@ void DrawZoneTrace( T zone, const std::vector& trace, const Worker& worker, B ImGui::TreePop(); } +struct ZoneTimeData +{ + int64_t time; + uint64_t count; +}; + +void CalcZoneTimeData( flat_hash_map>& data, flat_hash_map>::iterator zit, const ZoneEvent& zone, Worker& worker ) +{ + assert( zone.Child() >= 0 ); + const auto& children = worker.GetZoneChildren( zone.Child() ); + + for( auto& child : children ) + { + const auto t = worker.GetZoneEnd( *child ) - child->Start(); + zit->second.time -= t; + } + for( auto& child : children ) + { + const auto srcloc = child->SrcLoc(); + const auto t = worker.GetZoneEnd( *child ) - child->Start(); + auto it = data.find( srcloc ); + if( it == data.end() ) + { + it = data.emplace( srcloc, ZoneTimeData { t, 1 } ).first; + } + else + { + it->second.time += t; + it->second.count++; + } + if( child->Child() >= 0 ) CalcZoneTimeData( data, it, *child, worker ); + } +} + void View::DrawZoneInfoWindow() { auto& ev = *m_zoneInfoWindow; @@ -6041,6 +6075,55 @@ void View::DrawZoneInfoWindow() } } + if( ev.Child() >= 0 ) + { + const auto& children = m_worker.GetZoneChildren( ev.Child() ); + bool expand = ImGui::TreeNode( "Time distribution" ); + if( expand ) + { + flat_hash_map> data; + auto it = data.emplace( ev.SrcLoc(), ZoneTimeData{ ztime, 1 } ).first; + CalcZoneTimeData( data, it, ev, m_worker ); + std::vector>::const_iterator> vec; + vec.reserve( data.size() ); + for( auto it = data.cbegin(); it != data.cend(); ++it ) vec.emplace_back( it ); + pdqsort_branchless( vec.begin(), vec.end(), []( const auto& lhs, const auto& rhs ) { return lhs->second.time > rhs->second.time; } ); + static bool widthSet = false; + ImGui::Columns( 3 ); + if( !widthSet ) + { + widthSet = true; + const auto w = ImGui::GetWindowWidth(); + ImGui::SetColumnWidth( 0, w * 0.57f ); + ImGui::SetColumnWidth( 1, w * 0.25f ); + ImGui::SetColumnWidth( 2, w * 0.18f ); + } + ImGui::TextUnformatted( "Zone" ); + ImGui::NextColumn(); + ImGui::TextUnformatted( "Time" ); + ImGui::NextColumn(); + ImGui::TextUnformatted( "MTPC" ); + ImGui::NextColumn(); + ImGui::Separator(); + const auto fztime = 100.f / ztime; + for( auto& v : vec ) + { + ImGui::TextUnformatted( m_worker.GetZoneName( m_worker.GetSourceLocation( v->first ) ) ); + ImGui::SameLine(); + ImGui::TextDisabled( "(\xc3\x97%s)", RealToString( v->second.count, true ) ); + ImGui::NextColumn(); + ImGui::TextUnformatted( TimeToString( v->second.time ) ); + ImGui::SameLine(); + ImGui::TextDisabled( "(%.2f%%)", v->second.time * fztime ); + ImGui::NextColumn(); + ImGui::TextUnformatted( TimeToString( v->second.time / v->second.count ) ); + ImGui::NextColumn(); + } + ImGui::EndColumns(); + ImGui::TreePop(); + } + } + ImGui::EndChild(); ImGui::End();