From 800e4154000ccc29009a01a4f25c82158b716b7f Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Mon, 22 Jun 2026 17:26:33 +0200 Subject: [PATCH] Calculate section rows content. --- profiler/src/profiler/TracyView.hpp | 1 + .../src/profiler/TracyView_FrameTimeline.cpp | 72 +++++++++++++++++++ profiler/src/profiler/TracyView_Timeline.cpp | 1 + 3 files changed, 74 insertions(+) diff --git a/profiler/src/profiler/TracyView.hpp b/profiler/src/profiler/TracyView.hpp index 188ecc53..f152f3c0 100644 --- a/profiler/src/profiler/TracyView.hpp +++ b/profiler/src/profiler/TracyView.hpp @@ -289,6 +289,7 @@ private: void DrawFrames(); void DrawTimelineFramesHeader(); void DrawTimelineFrames( const FrameData& frames ); + void DrawTimelineSections(); void DrawTimeline(); void DrawSampleList( const TimelineContext& ctx, const std::vector& drawList, const Vector& vec, int offset, uint64_t tid ); void DrawZoneList( const TimelineContext& ctx, const std::vector& drawList, int offset, uint64_t tid, int maxDepth, double margin ); diff --git a/profiler/src/profiler/TracyView_FrameTimeline.cpp b/profiler/src/profiler/TracyView_FrameTimeline.cpp index 6ee9fd2a..4d626c1a 100644 --- a/profiler/src/profiler/TracyView_FrameTimeline.cpp +++ b/profiler/src/profiler/TracyView_FrameTimeline.cpp @@ -7,6 +7,8 @@ #include "TracyTexture.hpp" #include "TracyView.hpp" +#include "tracy_pdqsort.h" + namespace tracy { @@ -319,4 +321,74 @@ void View::DrawTimelineFrames( const FrameData& frames ) } } +struct SectionEntry +{ + uint32_t idx; + int64_t len; + int64_t start; + int64_t end; +}; + +struct SectionRow +{ + std::vector items; + std::vector> available; +}; + +void View::DrawTimelineSections() +{ + auto& data = m_worker.GetSections(); + if( data.empty() ) return; + + uint32_t idx = 0; + std::vector visible; + visible.reserve( data.size() ); + for( auto& v : data ) + { + const auto start = v.start.Val(); + const auto end = v.end.IsNonNegative() ? v.end.Val() : m_worker.GetLastTime(); + if( start < m_vd.zvEnd && end > m_vd.zvStart ) visible.emplace_back( SectionEntry { + .idx = idx, + .len = end - start, + .start = std::max( start, m_vd.zvStart ), + .end = std::min( end, m_vd.zvEnd ) + } ); + idx++; + } + if( visible.empty() ) return; + + pdqsort( visible.begin(), visible.end(), []( const SectionEntry& a, const SectionEntry& b ) { return a.len > b.len; } ); + + std::vector rows; + for( auto& e : visible ) + { + bool found = false; + for( auto& row : rows ) + { + for( size_t i=0; i= e.end ) + { + row.available.erase( row.available.begin() + i ); + if( gap.second > e.end ) row.available.insert( row.available.begin() + i, { e.end, gap.second } ); + if( gap.first < e.start ) row.available.insert( row.available.begin() + i, { gap.first, e.start } ); + row.items.push_back( e.idx ); + found = true; + break; + } + } + if( found ) break; + } + if( !found ) + { + rows.emplace_back(); + auto& row = rows.back(); + if( m_vd.zvStart < e.start ) row.available.emplace_back( m_vd.zvStart, e.start ); + if( m_vd.zvEnd > e.end ) row.available.emplace_back( e.end, m_vd.zvEnd ); + row.items.push_back( e.idx ); + } + } +} + } diff --git a/profiler/src/profiler/TracyView_Timeline.cpp b/profiler/src/profiler/TracyView_Timeline.cpp index 83b31bcc..19bce0e2 100644 --- a/profiler/src/profiler/TracyView_Timeline.cpp +++ b/profiler/src/profiler/TracyView_Timeline.cpp @@ -348,6 +348,7 @@ void View::DrawTimeline() } } } + DrawTimelineSections(); const auto yMin = ImGui::GetCursorScreenPos().y; const auto yMax = linepos.y + lineh;