Skip to content

Commit 9668fa5

Browse files
author
Eric Eaton
committed
Merge GpuEvent and ZoneEvent
This patch changes GPU to use ZoneEvents, to reduce code duplication and allow consistent feature support between GPU and CPU. The CPU is given a context similar to how GPUs have a context. The following features now work with GPU events: Trace Comparison Zone Search Zone Histogram Flame Graph Fixes #1109
1 parent 981717f commit 9668fa5

32 files changed

Lines changed: 1265 additions & 1948 deletions

cmake/server.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ set(TRACY_SERVER_SOURCES
2222
TracyTextureCompression.cpp
2323
TracyThreadCompress.cpp
2424
TracyWorker.cpp
25+
TracyContext.cpp
2526
)
2627

2728
list(TRANSFORM TRACY_SERVER_SOURCES PREPEND "${TRACY_SERVER_DIR}/")

profiler/src/profiler/TracyTimelineItemGpu.cpp

Lines changed: 17 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ const char* TimelineItemGpu::HeaderLabel() const
3131
}
3232
else
3333
{
34-
sprintf( buf, "%s context %i", GpuContextNames[(int)m_gpu->type], m_idx );
34+
sprintf( buf, "%s context %i", ZoneContextNames[(int)m_gpu->type], m_idx );
3535
}
3636
return buf;
3737
}
@@ -40,13 +40,13 @@ void TimelineItemGpu::HeaderTooltip( const char* label ) const
4040
{
4141
const bool dynamicColors = m_view.GetViewData().dynamicColors;
4242
const bool isMultithreaded =
43-
( m_gpu->type == GpuContextType::Vulkan ) ||
44-
( m_gpu->type == GpuContextType::OpenCL ) ||
45-
( m_gpu->type == GpuContextType::Direct3D12 ) ||
46-
( m_gpu->type == GpuContextType::Metal );
43+
( m_gpu->type == ZoneContextType::Vulkan ) ||
44+
( m_gpu->type == ZoneContextType::OpenCL ) ||
45+
( m_gpu->type == ZoneContextType::Direct3D12 ) ||
46+
( m_gpu->type == ZoneContextType::Metal );
4747

4848
char buf[64];
49-
sprintf( buf, "%s context %i", GpuContextNames[(int)m_gpu->type], m_idx );
49+
sprintf( buf, "%s context %i", ZoneContextNames[(int)m_gpu->type], m_idx );
5050

5151
ImGui::BeginTooltip();
5252
if( m_gpu->name.Active() ) TextFocused( "Name:", m_worker.GetString( m_gpu->name ) );
@@ -66,18 +66,7 @@ void TimelineItemGpu::HeaderTooltip( const char* label ) const
6666
auto tid = it->first;
6767
if( tid == 0 )
6868
{
69-
if( !it->second.timeline.empty() )
70-
{
71-
if( it->second.timeline.is_magic() )
72-
{
73-
auto& tl = *(Vector<GpuEvent>*)&it->second.timeline;
74-
tid = m_worker.DecompressThread( tl.begin()->Thread() );
75-
}
76-
else
77-
{
78-
tid = m_worker.DecompressThread( (*it->second.timeline.begin())->Thread() );
79-
}
80-
}
69+
tid = it->second->id;
8170
}
8271
SmallColorBox( GetThreadColor( tid, 0, dynamicColors ) );
8372
ImGui::SameLine();
@@ -134,7 +123,7 @@ void TimelineItemGpu::HeaderExtraContents( const TimelineContext& ctx, int offse
134123
const auto ty = ImGui::GetTextLineHeight();
135124

136125
char buf[64];
137-
sprintf( buf, "%s context %i", GpuContextNames[(int)m_gpu->type], m_idx );
126+
sprintf( buf, "%s context %i", ZoneContextNames[(int)m_gpu->type], m_idx );
138127
draw->AddText( ctx.wpos + ImVec2( ty * 1.5f + labelWidth, offset ), HeaderColorInactive(), buf );
139128
}
140129
}
@@ -145,13 +134,13 @@ int64_t TimelineItemGpu::RangeBegin() const
145134
for( auto& td : m_gpu->threadData )
146135
{
147136
int64_t t0;
148-
if( td.second.timeline.is_magic() )
137+
if( td.second->timeline.is_magic() )
149138
{
150-
t0 = ((Vector<GpuEvent>*)&td.second.timeline)->front().GpuStart();
139+
t0 = ((Vector<ZoneEvent>*)&td.second->timeline)->front().Start();
151140
}
152141
else
153142
{
154-
t0 = td.second.timeline.front()->GpuStart();
143+
t0 = td.second->timeline.front()->Start();
155144
}
156145
if( t0 >= 0 )
157146
{
@@ -167,23 +156,23 @@ int64_t TimelineItemGpu::RangeEnd() const
167156
for( auto& td : m_gpu->threadData )
168157
{
169158
int64_t t0;
170-
if( td.second.timeline.is_magic() )
159+
if( td.second->timeline.is_magic() )
171160
{
172-
t0 = ((Vector<GpuEvent>*)&td.second.timeline)->front().GpuStart();
161+
t0 = ((Vector<ZoneEvent>*)&td.second->timeline)->front().Start();
173162
}
174163
else
175164
{
176-
t0 = td.second.timeline.front()->GpuStart();
165+
t0 = td.second->timeline.front()->Start();
177166
}
178167
if( t0 >= 0 )
179168
{
180-
if( td.second.timeline.is_magic() )
169+
if( td.second->timeline.is_magic() )
181170
{
182-
t = std::max( t, std::min( m_worker.GetLastTime(), m_worker.GetZoneEnd( ((Vector<GpuEvent>*)&td.second.timeline)->back() ) ) );
171+
t = std::max( t, std::min( m_worker.GetLastTime(), m_worker.GetZoneEnd( ((Vector<ZoneEvent>*)&td.second->timeline)->back() ) ) );
183172
}
184173
else
185174
{
186-
t = std::max( t, std::min( m_worker.GetLastTime(), m_worker.GetZoneEnd( *td.second.timeline.back() ) ) );
175+
t = std::max( t, std::min( m_worker.GetLastTime(), m_worker.GetZoneEnd( *td.second->timeline.back() ) ) );
187176
}
188177
}
189178
}

profiler/src/profiler/TracyTimelineItemGpu.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#define __TRACYTIMELINEITEMGPU_HPP__
33

44
#include "TracyEvent.hpp"
5+
#include "TracyContext.hpp"
56
#include "TracyTimelineItem.hpp"
67

78
namespace tracy

profiler/src/profiler/TracyTimelineItemThread.cpp

Lines changed: 43 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,10 @@ bool TimelineItemThread::IsEmpty() const
3434
{
3535
auto& crash = m_worker.GetCrashEvent();
3636
return crash.thread != m_thread->id &&
37-
m_thread->timeline.empty() &&
38-
m_thread->messages.empty() &&
39-
m_thread->ghostZones.empty();
37+
m_thread->timeline.empty() &&
38+
m_thread->messages.empty() &&
39+
( m_thread->ctx->type != ZoneContextType::CPU ||
40+
static_cast<const CPUThreadData*>( m_thread )->ghostZones.empty() );
4041
}
4142

4243
uint32_t TimelineItemThread::HeaderColor() const
@@ -220,14 +221,18 @@ void TimelineItemThread::HeaderTooltip( const char* label ) const
220221
{
221222
TextFocused( "Running state regions:", RealToString( ctx->v.size() ) );
222223
}
223-
if( !m_thread->samples.empty() )
224+
if( m_thread->ctx->type != ZoneContextType::CPU )
224225
{
225-
TextFocused( "Call stack samples:", RealToString( m_thread->samples.size() ) );
226-
if( m_thread->kernelSampleCnt != 0 )
226+
auto cpu_thread = static_cast<const CPUThreadData*>( m_thread );
227+
if( !cpu_thread->samples.empty() )
227228
{
228-
TextFocused( "Kernel samples:", RealToString( m_thread->kernelSampleCnt ) );
229-
ImGui::SameLine();
230-
ImGui::TextDisabled( "(%.2f%%)", 100.f * m_thread->kernelSampleCnt / m_thread->samples.size() );
229+
TextFocused( "Call stack samples:", RealToString( cpu_thread->samples.size() ) );
230+
if( cpu_thread->kernelSampleCnt != 0 )
231+
{
232+
TextFocused( "Kernel samples:", RealToString( cpu_thread->kernelSampleCnt ) );
233+
ImGui::SameLine();
234+
ImGui::TextDisabled( "(%.2f%%)", 100.f * cpu_thread->kernelSampleCnt / cpu_thread->samples.size() );
235+
}
231236
}
232237
}
233238
ImGui::EndTooltip();
@@ -238,21 +243,25 @@ void TimelineItemThread::HeaderExtraContents( const TimelineContext& ctx, int of
238243
m_view.DrawThreadMessagesList( ctx, m_msgDraw, offset, m_thread->id );
239244

240245
#ifndef TRACY_NO_STATISTICS
241-
const bool hasGhostZones = m_worker.AreGhostZonesReady() && !m_thread->ghostZones.empty();
242-
if( hasGhostZones && !m_thread->timeline.empty() )
246+
if( m_thread->ctx->type == ZoneContextType::CPU )
243247
{
244-
auto draw = ImGui::GetWindowDrawList();
245-
const auto ty = ImGui::GetTextLineHeight();
248+
auto cpu_thread = static_cast<const CPUThreadData*>( m_thread );
249+
const bool hasGhostZones = m_worker.AreGhostZonesReady() && !cpu_thread->ghostZones.empty();
250+
if( hasGhostZones && !m_thread->timeline.empty() )
251+
{
252+
auto draw = ImGui::GetWindowDrawList();
253+
const auto ty = ImGui::GetTextLineHeight();
246254

247-
const auto color = m_ghost ? 0xFFAA9999 : 0x88AA7777;
248-
draw->AddText( ctx.wpos + ImVec2( 1.5f * ty + labelWidth, offset ), color, ICON_FA_GHOST );
249-
float ghostSz = ImGui::CalcTextSize( ICON_FA_GHOST ).x;
255+
const auto color = m_ghost ? 0xFFAA9999 : 0x88AA7777;
256+
draw->AddText( ctx.wpos + ImVec2( 1.5f * ty + labelWidth, offset ), color, ICON_FA_GHOST );
257+
float ghostSz = ImGui::CalcTextSize( ICON_FA_GHOST ).x;
250258

251-
if( ctx.hover && ImGui::IsMouseHoveringRect( ctx.wpos + ImVec2( 1.5f * ty + labelWidth, offset ), ctx.wpos + ImVec2( 1.5f * ty + labelWidth + ghostSz, offset + ty ) ) )
252-
{
253-
if( IsMouseClicked( 0 ) )
259+
if( ctx.hover && ImGui::IsMouseHoveringRect( ctx.wpos + ImVec2( 1.5f * ty + labelWidth, offset ), ctx.wpos + ImVec2( 1.5f * ty + labelWidth + ghostSz, offset + ty ) ) )
254260
{
255-
m_ghost = !m_ghost;
261+
if( IsMouseClicked( 0 ) )
262+
{
263+
m_ghost = !m_ghost;
264+
}
256265
}
257266
}
258267
}
@@ -309,9 +318,10 @@ void TimelineItemThread::Preprocess( const TimelineContext& ctx, TaskDispatch& t
309318

310319
td.Queue( [this, &ctx, visible] {
311320
#ifndef TRACY_NO_STATISTICS
312-
if( m_worker.AreGhostZonesReady() && ( m_ghost || ( m_view.GetViewData().ghostZones && m_thread->timeline.empty() ) ) )
321+
if( m_thread->ctx->type == ZoneContextType::CPU && m_worker.AreGhostZonesReady() && ( m_ghost || ( m_view.GetViewData().ghostZones && m_thread->timeline.empty() ) ) )
313322
{
314-
m_depth = PreprocessGhostLevel( ctx, m_thread->ghostZones, 0, visible );
323+
auto cpu_thread = static_cast<const CPUThreadData*>( m_thread );
324+
m_depth = PreprocessGhostLevel( ctx, cpu_thread->ghostZones, 0, visible );
315325
}
316326
else
317327
#endif
@@ -336,12 +346,16 @@ void TimelineItemThread::Preprocess( const TimelineContext& ctx, TaskDispatch& t
336346
}
337347
}
338348

339-
m_hasSamples = false;
340-
if( vd.drawSamples && !m_thread->samples.empty() )
349+
if( m_thread->ctx->type == ZoneContextType::CPU )
341350
{
342-
td.Queue( [this, &ctx, visible, yPos] {
343-
PreprocessSamples( ctx, m_thread->samples, visible, yPos );
344-
} );
351+
auto cpu_thread = static_cast<const CPUThreadData*>( m_thread );
352+
m_hasSamples = false;
353+
if( vd.drawSamples && !cpu_thread->samples.empty() )
354+
{
355+
td.Queue( [this, &ctx, visible, yPos, cpu_thread] {
356+
PreprocessSamples( ctx, cpu_thread->samples, visible, yPos );
357+
} );
358+
}
345359
}
346360

347361
m_hasMessages = false;
@@ -525,7 +539,6 @@ void TimelineItemThread::PreprocessContextSwitches( const TimelineContext& ctx,
525539
if( !visible ) return;
526540

527541
const auto MinCtxNs = int64_t( round( GetScale() * MinCtxSize * nspx ) );
528-
const auto& sampleData = m_thread->samples;
529542

530543
bool first = true;
531544
while( it < citend )
@@ -535,8 +548,9 @@ void TimelineItemThread::PreprocessContextSwitches( const TimelineContext& ctx,
535548
{
536549
first = false;
537550
}
538-
else
551+
else if ( m_thread->ctx->type == ZoneContextType::CPU )
539552
{
553+
const Vector<SampleData>& sampleData = static_cast<const CPUThreadData*>( m_thread )->samples;
540554
uint32_t waitStack = 0;
541555
if( !sampleData.empty() )
542556
{

profiler/src/profiler/TracyTimelineItemThread.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#define __TRACYTIMELINEITEMTHREAD_HPP__
33

44
#include "TracyEvent.hpp"
5+
#include "TracyContext.hpp"
56
#include "TracyTimelineDraw.hpp"
67
#include "TracyTimelineItem.hpp"
78

profiler/src/profiler/TracyUtility.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
#include "imgui.h"
99
#include "../server/TracyEvent.hpp"
10+
#include "../server/TracyContext.hpp"
1011

1112
namespace tracy
1213
{

profiler/src/profiler/TracyView.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1140,7 +1140,6 @@ bool View::DrawImpl()
11401140
ImGui::End();
11411141

11421142
m_zoneHighlight = nullptr;
1143-
m_gpuHighlight = nullptr;
11441143

11451144
DrawInfoWindow();
11461145

0 commit comments

Comments
 (0)