Skip to content

Commit

Permalink
debug: Configurable trace panel depth
Browse files Browse the repository at this point in the history
  • Loading branch information
BastianBlokland committed Jul 3, 2024
1 parent ba455ea commit 7514006
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions libs/debug/src/trace.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ static const String g_messageNoStoreSink = string_static("No store trace-sink f

#define debug_trace_max_name_length 15
#define debug_trace_max_threads 8
#define debug_trace_max_depth 4
#define debug_trace_default_depth 4

typedef struct {
ThreadId tid;
Expand All @@ -44,6 +44,7 @@ ecs_comp_define(DebugTracePanelComp) {
UiScrollview scrollview;
bool freeze, refresh;
bool hoverAny, panAny;
u32 eventDepth;
TimeSteady timeHead;
TimeDuration timeWindow;
DebugTraceTrigger trigger;
Expand Down Expand Up @@ -254,6 +255,8 @@ trace_options_draw(UiCanvasComp* c, DebugTracePanelComp* panel, const TraceSink*
UiTable table = ui_table(.spacing = ui_vector(10, 5), .rowHeight = 20);
ui_table_add_column(&table, UiTableColumn_Fixed, 160);
ui_table_add_column(&table, UiTableColumn_Fixed, 75);
ui_table_add_column(&table, UiTableColumn_Fixed, 60);
ui_table_add_column(&table, UiTableColumn_Fixed, 75);
ui_table_add_column(&table, UiTableColumn_Fixed, 40);
ui_table_add_column(&table, UiTableColumn_Fixed, 100);
ui_table_add_column(&table, UiTableColumn_Fixed, 100);
Expand All @@ -270,6 +273,14 @@ trace_options_draw(UiCanvasComp* c, DebugTracePanelComp* panel, const TraceSink*
ui_label(c, timeLabel);
}

ui_table_next_column(c, &table);
ui_label(c, string_lit("Depth:"));
ui_table_next_column(c, &table);
f64 depthVal = panel->eventDepth;
if (ui_numbox(c, &depthVal, .min = 1, .max = 8, .step = 1)) {
panel->eventDepth = (u32)depthVal;
}

ui_table_next_column(c, &table);
ui_label(c, string_lit("Freeze:"));
ui_table_next_column(c, &table);
Expand Down Expand Up @@ -378,12 +389,12 @@ static void trace_data_events_draw(
const f64 timeLeft = (f64)(panel->timeHead - panel->timeWindow);
const f64 timeRight = (f64)panel->timeHead;

const f32 eventHeight = 1.0f / debug_trace_max_depth;
const f32 eventHeight = 1.0f / panel->eventDepth;
dynarray_for_t(&data->events, TraceStoreEvent, evt) {
const f64 fracLeft = math_unlerp(timeLeft, timeRight, (f64)evt->timeStart);
const f64 fracRight = math_unlerp(timeLeft, timeRight, (f64)(evt->timeStart + evt->timeDur));

if (fracRight <= 0.0 || fracLeft >= 1.0 || evt->stackDepth >= debug_trace_max_depth) {
if (fracRight <= 0.0 || fracLeft >= 1.0 || evt->stackDepth >= panel->eventDepth) {
ui_canvas_id_skip(c, 4); // 4: +1 for bar, +1 for label, +2 for tooltip.
continue; // Event outside of the visible region.
}
Expand Down Expand Up @@ -463,7 +474,7 @@ trace_panel_draw(UiCanvasComp* c, DebugTracePanelComp* panel, const TraceSink* s
ui_layout_container_push(c, UiClip_None);

static const UiVector g_tablePadding = {10, 5};
UiTable table = ui_table(.spacing = g_tablePadding, .rowHeight = 20 * debug_trace_max_depth);
UiTable table = ui_table(.spacing = g_tablePadding, .rowHeight = 20 * panel->eventDepth);
ui_table_add_column(&table, UiTableColumn_Fixed, 125);
ui_table_add_column(&table, UiTableColumn_Flexible, 0);

Expand Down Expand Up @@ -600,7 +611,7 @@ ecs_module_init(debug_trace_module) {

EcsEntityId
debug_trace_panel_open(EcsWorld* world, const EcsEntityId window, const DebugPanelType type) {
const u32 panelHeight = math_min(100 + 20 * debug_trace_max_depth * g_jobsWorkerCount, 675);
const u32 panelHeight = math_min(100 + 20 * debug_trace_default_depth * g_jobsWorkerCount, 675);

const EcsEntityId panelEntity = debug_panel_create(world, window, type);
DebugTracePanelComp* tracePanel = ecs_world_add_t(
Expand All @@ -609,6 +620,7 @@ debug_trace_panel_open(EcsWorld* world, const EcsEntityId window, const DebugPan
DebugTracePanelComp,
.panel = ui_panel(.size = ui_vector(800, panelHeight)),
.scrollview = ui_scrollview(),
.eventDepth = debug_trace_default_depth,
.timeHead = time_steady_clock(),
.timeWindow = time_milliseconds(100),
.trigger.eventId = sentinel_u8,
Expand Down

0 comments on commit 7514006

Please sign in to comment.