Skip to content

Commit e08e0b6

Browse files
committed
adding "flatten view" to sequence points
1 parent 03868b0 commit e08e0b6

8 files changed

Lines changed: 150 additions & 8 deletions

File tree

profiler/src/profiler/TracyTimelineItemThread.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ uint32_t TimelineItemThread::HeaderColor() const
4444
auto& crash = m_worker.GetCrashEvent();
4545
if( crash.thread == m_thread->id ) return 0xFF2222FF;
4646
if( m_thread->isFiber ) return 0xFF88FF88;
47+
if( m_thread->isFlatView ) return 0xFFFFCC88; // light blue (ABGR)
4748
return 0xFFFFFFFF;
4849
}
4950

@@ -52,6 +53,7 @@ uint32_t TimelineItemThread::HeaderColorInactive() const
5253
auto& crash = m_worker.GetCrashEvent();
5354
if( crash.thread == m_thread->id ) return 0xFF111188;
5455
if( m_thread->isFiber ) return 0xFF448844;
56+
if( m_thread->isFlatView ) return 0xFF886644; // darker light blue
5557
return 0xFF888888;
5658
}
5759

@@ -235,6 +237,8 @@ void TimelineItemThread::HeaderTooltip( const char* label ) const
235237

236238
void TimelineItemThread::HeaderExtraContents( const TimelineContext& ctx, int offset, float labelWidth )
237239
{
240+
if( m_thread->isFlatView ) return;
241+
238242
m_view.DrawThreadMessagesList( ctx, m_msgDraw, offset, m_thread->id );
239243

240244
const bool hasGhostZones = m_worker.AreGhostZonesReady() && !m_thread->ghostZones.empty();
@@ -275,6 +279,16 @@ void TimelineItemThread::DrawOverlay( const ImVec2& ul, const ImVec2& dr )
275279

276280
void TimelineItemThread::DrawExtraPopupItems()
277281
{
282+
if( m_thread->isFlatView )
283+
{
284+
if( ImGui::MenuItem( ICON_FA_TRASH_CAN " Destroy flatten view" ) )
285+
{
286+
m_view.QueueDestroyFlattenViewByTid( m_thread->id );
287+
ImGui::CloseCurrentPopup();
288+
}
289+
return;
290+
}
291+
278292
if( m_view.GetSelectThread() == m_thread->id )
279293
{
280294
if( ImGui::MenuItem( ICON_FA_TIMELINE " Unselect in CPU timeline" ) )
@@ -493,7 +507,7 @@ int TimelineItemThread::PreprocessZoneLevel( const TimelineContext& ctx, const V
493507
if( hasChildren ) childrenInherited = DarkenColorSlightly( color );
494508
}
495509
}
496-
if( hasChildren )
510+
if( hasChildren && !m_thread->isFlatView )
497511
{
498512
const auto d = PreprocessZoneLevel( ctx, m_worker.GetZoneChildren( ev.Child() ), depth + 1, visible, childrenInherited );
499513
if( d > maxdepth ) maxdepth = d;

profiler/src/profiler/TracyView.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1234,9 +1234,17 @@ bool View::DrawImpl()
12341234
{
12351235
AddAnnotation( s, e );
12361236
}
1237+
if( m_seqFlattenPopupSeqId != 0 )
1238+
{
1239+
if( ImGui::Selectable( ICON_FA_DIAGRAM_PROJECT " Flatten sequence timeline" ) )
1240+
{
1241+
MakeFlattenView( m_seqFlattenPopupSeqId );
1242+
}
1243+
}
12371244
ImGui::EndPopup();
12381245
}
12391246
m_setRangePopupOpen = ImGui::IsPopupOpen( "SetZoneRange" );
1247+
if( !m_setRangePopupOpen ) m_seqFlattenPopupSeqId = 0;
12401248

12411249
if( m_zoomAnim.active )
12421250
{

profiler/src/profiler/TracyView.hpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ class View
171171
}
172172

173173
void HighlightThread( uint64_t thread );
174+
void QueueDestroyFlattenViewByTid( uint64_t tid );
174175
void SelectThread( uint64_t thread );
175176
uint64_t GetSelectThread() const { return m_selectedThread; }
176177
void ZoomToRange( int64_t start, int64_t end, bool pause = true );
@@ -279,8 +280,10 @@ class View
279280
void DrawTimelineFrames( const FrameData& frames );
280281
void DrawTimeline();
281282
void DrawSampleList( const TimelineContext& ctx, const std::vector<SamplesDraw>& drawList, const Vector<SampleData>& vec, int offset, uint64_t tid );
282-
void DrawZoneList( const TimelineContext& ctx, const std::vector<TimelineDraw>& drawList, int offset, uint64_t tid, int maxDepth, double margin );
283+
void DrawZoneList( const TimelineContext& ctx, const std::vector<TimelineDraw>& drawList, int offset, uint64_t tid, int maxDepth, double margin, bool isFlatView );
283284
void DrawSeqArrows( double pxns, const ImVec2& wpos );
285+
void MakeFlattenView( uint64_t seqId );
286+
void DestroyFlattenView( uint64_t seqId );
284287
void DrawThreadCropper( const int depth, const uint64_t tid, const float xPos, const float yPos, const float ostep, const float cropperWidth, const bool hasCtxSwitches );
285288
void DrawContextSwitchList( const TimelineContext& ctx, const std::vector<ContextSwitchDraw>& drawList, const Vector<ContextSwitchData>& ctxSwitch, int offset, int endOffset, bool isFiber );
286289
int DispatchGpuZoneLevel( const Vector<short_ptr<GpuEvent>>& vec, bool hover, double pxns, int64_t nspx, const ImVec2& wpos, int offset, int depth, uint64_t thread, float yMin, float yMax, int64_t begin, int drift );
@@ -534,6 +537,16 @@ class View
534537
};
535538
std::vector<SeqArrowDraw> m_seqArrowDraw;
536539
unordered_flat_map<const ZoneEvent*, float> m_seqZoneYPos;
540+
541+
struct FlattenView
542+
{
543+
std::unique_ptr<ThreadData> td;
544+
uint64_t seqId;
545+
};
546+
std::vector<FlattenView> m_flattenViews;
547+
std::vector<uint64_t> m_flattenViewDestroyQueue;
548+
uint32_t m_nextFlattenTid = 1;
549+
uint64_t m_seqFlattenPopupSeqId = 0;
537550
int m_frameHover = -1;
538551
bool m_messagesScrollBottom;
539552

profiler/src/profiler/TracyView_Timeline.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,12 @@ void View::DrawTimeline()
261261
m_zoneHover2.Decay( nullptr );
262262
m_seqArrowDraw.clear();
263263
m_seqZoneYPos.clear();
264+
265+
for( auto seqId : m_flattenViewDestroyQueue )
266+
{
267+
DestroyFlattenView( seqId );
268+
}
269+
m_flattenViewDestroyQueue.clear();
264270
m_findZone.range.StartFrame();
265271
m_statRange.StartFrame();
266272
m_flameRange.StartFrame();
@@ -398,6 +404,10 @@ void View::DrawTimeline()
398404
}
399405
m_threadReinsert.clear();
400406
}
407+
for( const auto& fv : m_flattenViews )
408+
{
409+
m_tc.AddItem<TimelineItemThread>( fv.td.get() );
410+
}
401411
for( const auto& v : m_threadOrder )
402412
{
403413
m_tc.AddItem<TimelineItemThread>( v );

profiler/src/profiler/TracyView_ZoneTimeline.cpp

Lines changed: 88 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ void View::DrawThread( const TimelineContext& ctx, const ThreadData& thread, con
7676
if( !draw.empty() && yPos <= yMax && yPos + ostep * croppedDepth >= yMin )
7777
{
7878
// Only apply margin when croppingActive to avoid text moving around when mouse is getting close to the cropper widget
79-
DrawZoneList( ctx, draw, offset, thread.id, croppedDepth, croppingActive ? cropperAdditionalMargin + GetScale() /* Ensure text has a bit of space for text */ : 0.f );
79+
DrawZoneList( ctx, draw, offset, thread.id, croppedDepth, croppingActive ? cropperAdditionalMargin + GetScale() /* Ensure text has a bit of space for text */ : 0.f, thread.isFlatView != 0 );
8080
}
8181
offset += ostep * croppedDepth;
8282

@@ -227,7 +227,7 @@ void View::DrawThreadOverlays( const ThreadData& thread, const ImVec2& ul, const
227227
}
228228

229229

230-
void View::DrawZoneList( const TimelineContext& ctx, const std::vector<TimelineDraw>& drawList, int _offset, uint64_t tid, int maxDepth, double margin )
230+
void View::DrawZoneList( const TimelineContext& ctx, const std::vector<TimelineDraw>& drawList, int _offset, uint64_t tid, int maxDepth, double margin, bool isFlatView )
231231
{
232232
auto draw = ImGui::GetWindowDrawList();
233233
const auto w = ctx.w;
@@ -353,12 +353,23 @@ void View::DrawZoneList( const TimelineContext& ctx, const std::vector<TimelineD
353353

354354
const auto& seqRefMap = m_worker.GetZoneSeqRef();
355355
const auto seqIt = seqRefMap.find( &ev );
356-
if( seqIt != seqRefMap.end() )
356+
if( !isFlatView && seqIt != seqRefMap.end() )
357357
{
358358
m_seqZoneYPos[&ev] = wpos.y + offset + ty * 0.5f;
359359
}
360360

361-
const auto zoneColor = GetZoneColorData( ev, tid, v.depth, v.inheritedColor );
361+
// Preserve original-thread coloring when rendered on a flat view.
362+
uint64_t colorTid = tid;
363+
if( isFlatView && seqIt != seqRefMap.end() )
364+
{
365+
const auto& seqMap = m_worker.GetSequences();
366+
auto sit = seqMap.find( seqIt->second.seqId );
367+
if( sit != seqMap.end() && seqIt->second.continuationIdx < sit->second->continuations.size() )
368+
{
369+
colorTid = sit->second->continuations[seqIt->second.continuationIdx].tid;
370+
}
371+
}
372+
const auto zoneColor = GetZoneColorData( ev, colorTid, v.depth, v.inheritedColor );
362373
const char* zoneName = m_worker.GetZoneName( ev );
363374

364375
auto tsz = ImGui::CalcTextSize( zoneName );
@@ -392,7 +403,11 @@ void View::DrawZoneList( const TimelineContext& ctx, const std::vector<TimelineD
392403
if( hover && ImGui::IsMouseHoveringRect( wpos + ImVec2( px0, offset ), wpos + ImVec2( px1, offset + tsz.y + 1 ) ) )
393404
{
394405
ZoneTooltip( ev );
395-
if( IsMouseClickReleased( 1 ) ) m_setRangePopup = RangeSlim { ev.Start(), m_worker.GetZoneEnd( ev ), true };
406+
if( IsMouseClickReleased( 1 ) )
407+
{
408+
m_setRangePopup = RangeSlim { ev.Start(), m_worker.GetZoneEnd( ev ), true };
409+
m_seqFlattenPopupSeqId = ( !isFlatView && seqIt != seqRefMap.end() ) ? seqIt->second.seqId : 0;
410+
}
396411

397412
if( !m_zoomAnim.active && IsMouseClicked( 2 ) )
398413
{
@@ -414,7 +429,7 @@ void View::DrawZoneList( const TimelineContext& ctx, const std::vector<TimelineD
414429
m_zoneSrcLocHighlight = ev.SrcLoc();
415430
m_zoneHover = &ev;
416431

417-
if( seqIt != seqRefMap.end() )
432+
if( !isFlatView && seqIt != seqRefMap.end() )
418433
{
419434
const auto& seqMap = m_worker.GetSequences();
420435
const auto sit = seqMap.find( seqIt->second.seqId );
@@ -435,6 +450,7 @@ void View::DrawZoneList( const TimelineContext& ctx, const std::vector<TimelineD
435450
conts[idx+1].resumeTime, (const ZoneEvent*)conts[idx+1].zone } );
436451
}
437452
}
453+
438454
}
439455
}
440456
break;
@@ -698,6 +714,72 @@ void View::DrawThreadCropper( const int depth, const uint64_t tid, const float x
698714
}
699715
}
700716

717+
void View::MakeFlattenView( uint64_t seqId )
718+
{
719+
for( const auto& fv : m_flattenViews )
720+
{
721+
if( fv.seqId == seqId ) return; // idempotent
722+
}
723+
const auto& seqMap = m_worker.GetSequences();
724+
auto sit = seqMap.find( seqId );
725+
if( sit == seqMap.end() || sit->second->continuations.empty() ) return;
726+
const auto& conts = sit->second->continuations;
727+
728+
const uint64_t synthTid = ( uint64_t(2) << 32 ) | m_nextFlattenTid++;
729+
730+
auto td = std::make_unique<ThreadData>();
731+
td->id = synthTid;
732+
td->count = 0;
733+
td->nextZoneId = 0;
734+
td->kernelSampleCnt = 0;
735+
td->isFiber = 0;
736+
td->isFlatView = 1;
737+
td->fiber = nullptr;
738+
td->stackCount = nullptr;
739+
td->groupHint = 0;
740+
#ifndef TRACY_NO_STATISTICS
741+
td->ghostIdx = 0;
742+
#endif
743+
744+
for( const auto& c : conts )
745+
{
746+
td->timeline.push_back( c.zone );
747+
}
748+
749+
char name[128];
750+
const auto* firstZone = (const ZoneEvent*)conts[0].zone;
751+
const char* zName = m_worker.GetZoneName( *firstZone );
752+
std::snprintf( name, sizeof( name ), "flat: %s", zName ? zName : "?" );
753+
m_worker.RegisterFlattenThreadName( synthTid, name, strlen( name ) );
754+
755+
m_flattenViews.push_back( FlattenView{ std::move( td ), seqId } );
756+
}
757+
758+
void View::DestroyFlattenView( uint64_t seqId )
759+
{
760+
for( auto it = m_flattenViews.begin(); it != m_flattenViews.end(); ++it )
761+
{
762+
if( it->seqId == seqId )
763+
{
764+
m_worker.UnregisterFlattenThreadName( it->td->id );
765+
m_flattenViews.erase( it );
766+
return;
767+
}
768+
}
769+
}
770+
771+
void View::QueueDestroyFlattenViewByTid( uint64_t tid )
772+
{
773+
for( const auto& fv : m_flattenViews )
774+
{
775+
if( fv.td->id == tid )
776+
{
777+
m_flattenViewDestroyQueue.push_back( fv.seqId );
778+
return;
779+
}
780+
}
781+
}
782+
701783
void View::DrawSeqArrows( double pxns, const ImVec2& wpos )
702784
{
703785
if( m_seqArrowDraw.empty() ) return;

server/TracyEvent.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -706,6 +706,7 @@ struct ThreadData
706706
Vector<SampleData> ctxSwitchSamples;
707707
uint64_t kernelSampleCnt;
708708
uint8_t isFiber;
709+
uint8_t isFlatView = 0;
709710
ThreadData* fiber;
710711
uint8_t* stackCount;
711712
int32_t groupHint;

server/TracyWorker.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3695,6 +3695,18 @@ void Worker::CheckFiberName( uint64_t id, uint64_t tid )
36953695
if( m_sock.IsValid() ) Query( ServerQueryFiberName, id );
36963696
}
36973697

3698+
void Worker::RegisterFlattenThreadName( uint64_t tid, const char* name, size_t sz )
3699+
{
3700+
if( m_data.threadNames.find( tid ) != m_data.threadNames.end() ) return;
3701+
const auto sl = StoreString( name, sz );
3702+
m_data.threadNames.emplace( tid, sl.ptr );
3703+
}
3704+
3705+
void Worker::UnregisterFlattenThreadName( uint64_t tid )
3706+
{
3707+
m_data.threadNames.erase( tid );
3708+
}
3709+
36983710
void Worker::CheckExternalName( uint64_t id )
36993711
{
37003712
if( m_data.externalNames.find( id ) != m_data.externalNames.end() ) return;

server/TracyWorker.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -614,6 +614,8 @@ class Worker
614614
const char* GetString( const StringRef& ref ) const;
615615
const char* GetString( const StringIdx& idx ) const;
616616
const char* GetThreadName( uint64_t id ) const;
617+
void RegisterFlattenThreadName( uint64_t tid, const char* name, size_t sz );
618+
void UnregisterFlattenThreadName( uint64_t tid );
617619
bool IsThreadLocal( uint64_t id ) { return IsThreadLocal( id, m_data.threadDataLast ); }
618620
bool IsThreadLocal( uint64_t id, ThreadCache& cache );
619621
bool IsThreadFiber( uint64_t id );

0 commit comments

Comments
 (0)