diff --git a/src/xrt/auxiliary/util/u_pacing_app.c b/src/xrt/auxiliary/util/u_pacing_app.c index 0b15a4312..e6486df34 100644 --- a/src/xrt/auxiliary/util/u_pacing_app.c +++ b/src/xrt/auxiliary/util/u_pacing_app.c @@ -13,6 +13,7 @@ #include "util/u_misc.h" #include "util/u_debug.h" #include "util/u_pacing.h" +#include "util/u_metrics.h" #include "util/u_logging.h" #include "util/u_trace_marker.h" @@ -253,6 +254,33 @@ predict_display_time(const struct pacing_app *pa, uint64_t now_ns, uint64_t peri * */ +static void +do_metrics(struct pacing_app *pa, struct u_pa_frame *f, bool discarded) +{ + if (!u_metrics_is_active()) { + return; + } + + struct u_metrics_session_frame umsf = { + .session_id = pa->session_id, + .frame_id = f->frame_id, + .predicted_frame_time_ns = f->predicted_frame_time_ns, + .predicted_wake_up_time_ns = f->predicted_wake_up_time_ns, + .predicted_gpu_done_time_ns = f->predicted_gpu_done_time_ns, + .predicted_display_time_ns = f->predicted_display_time_ns, + .predicted_display_period_ns = f->predicted_display_period_ns, + .display_time_ns = f->display_time_ns, + .when_predicted_ns = f->when.predicted_ns, + .when_wait_woke_ns = f->when.wait_woke_ns, + .when_begin_ns = f->when.begin_ns, + .when_delivered_ns = f->when.delivered_ns, + .when_gpu_done_ns = f->when.gpu_done_ns, + .discarded = discarded, + }; + + u_metrics_write_session_frame(&umsf); +} + static void do_tracing(struct pacing_app *pa, struct u_pa_frame *f) { @@ -406,7 +434,11 @@ pa_mark_discarded(struct u_pacing_app *upa, int64_t frame_id, uint64_t when_ns) // Update all data. f->when.delivered_ns = when_ns; + // Write out metrics data. + do_metrics(pa, f, true); + // Reset the frame. + U_ZERO(f); // Zero for metrics f->state = U_PA_READY; f->frame_id = -1; } @@ -477,12 +509,13 @@ pa_mark_gpu_done(struct u_pacing_app *upa, int64_t frame_id, uint64_t when_ns) do_iir_filter(&pa->app.draw_time_ns, IIR_ALPHA_LT, IIR_ALPHA_GT, diff_draw_ns); do_iir_filter(&pa->app.wait_time_ns, IIR_ALPHA_LT, IIR_ALPHA_GT, diff_wait_ns); - // Write out tracing data. + // Write out metrics and tracing data. + do_metrics(pa, f, false); do_tracing(pa, f); #ifndef VALIDATE_LATCHED_AND_RETIRED // Reset the frame. - U_ZERO(f); + U_ZERO(f); // Zero for metrics f->state = U_PA_READY; f->frame_id = -1; #endif @@ -501,6 +534,15 @@ pa_latched(struct u_pacing_app *upa, int64_t frame_id, uint64_t when_ns, int64_t #else (void)pa; #endif + + struct u_metrics_used umu = { + .session_id = pa->session_id, + .session_frame_id = frame_id, + .system_frame_id = system_frame_id, + .when_ns = when_ns, + }; + + u_metrics_write_used(&umu); } static void @@ -515,7 +557,7 @@ pa_retired(struct u_pacing_app *upa, int64_t frame_id, uint64_t when_ns) assert(f->state == U_RT_GPU_DONE || f->state == U_RT_DELIVERED); // Reset the frame. - U_ZERO(f); + U_ZERO(f); // Zero for metrics f->state = U_PA_READY; f->frame_id = -1; #else diff --git a/src/xrt/auxiliary/util/u_pacing_compositor.c b/src/xrt/auxiliary/util/u_pacing_compositor.c index 32b4cd2b9..965194d88 100644 --- a/src/xrt/auxiliary/util/u_pacing_compositor.c +++ b/src/xrt/auxiliary/util/u_pacing_compositor.c @@ -13,6 +13,7 @@ #include "util/u_misc.h" #include "util/u_debug.h" #include "util/u_pacing.h" +#include "util/u_metrics.h" #include "util/u_logging.h" #include "util/u_trace_marker.h" @@ -399,6 +400,34 @@ adjust_comp_time(struct pacing_compositor *pc, struct frame *f) * */ +static void +do_metrics(struct pacing_compositor *pc, struct frame *f) +{ + if (!u_metrics_is_active()) { + return; + } + + struct u_metrics_system_present_info umpi = { + .frame_id = f->frame_id, + .expected_comp_time_ns = f->current_comp_time_ns, + .predicted_wake_up_time_ns = f->wake_up_time_ns, + .predicted_done_time_ns = f->expected_done_time_ns, + .predicted_display_time_ns = f->predicted_display_time_ns, + .when_predict_ns = f->when_predict_ns, + .when_woke_ns = f->when_woke_ns, + .when_began_ns = f->when_began_ns, + .when_submitted_ns = f->when_submitted_ns, + .when_infoed_ns = f->when_infoed_ns, + .desired_present_time_ns = f->desired_present_time_ns, + .present_slop_ns = PRESENT_SLOP_NS, + .present_margin_ns = f->present_margin_ns, + .actual_present_time_ns = f->actual_present_time_ns, + .earliest_present_time_ns = f->earliest_present_time_ns, + }; + + u_metrics_write_system_present_info(&umpi); +} + static void do_tracing(struct pacing_compositor *pc, struct frame *f) { @@ -657,7 +686,8 @@ pc_info(struct u_pacing_compositor *upc, f->present_margin_ns, // present_margin_ms); // - // Write out tracing data. + // Write out metrics and tracing data. + do_metrics(pc, f); do_tracing(pc, f); } @@ -665,7 +695,16 @@ static void pc_info_gpu( struct u_pacing_compositor *upc, int64_t frame_id, uint64_t gpu_start_ns, uint64_t gpu_end_ns, uint64_t when_ns) { - // No-op + if (u_metrics_is_active()) { + struct u_metrics_system_gpu_info umgi = { + .frame_id = frame_id, + .gpu_start_ns = gpu_start_ns, + .gpu_end_ns = gpu_end_ns, + .when_ns = when_ns, + }; + + u_metrics_write_system_gpu_info(&umgi); + } } static void diff --git a/src/xrt/auxiliary/util/u_pacing_compositor_fake.c b/src/xrt/auxiliary/util/u_pacing_compositor_fake.c index b1c5c0895..84233b84d 100644 --- a/src/xrt/auxiliary/util/u_pacing_compositor_fake.c +++ b/src/xrt/auxiliary/util/u_pacing_compositor_fake.c @@ -13,6 +13,7 @@ #include "util/u_misc.h" #include "util/u_debug.h" #include "util/u_pacing.h" +#include "util/u_metrics.h" #include "util/u_logging.h" #include "util/u_trace_marker.h" @@ -123,6 +124,21 @@ pc_predict(struct u_pacing_compositor *upc, *out_predicted_display_time_ns = predicted_display_time_ns; *out_predicted_display_period_ns = predicted_display_period_ns; *out_min_display_period_ns = min_display_period_ns; + + if (!u_metrics_is_active()) { + return; + } + + struct u_metrics_system_frame umsf = { + .frame_id = frame_id, + .predicted_display_time_ns = predicted_display_time_ns, + .predicted_display_period_ns = predicted_display_period_ns, + .desired_present_time_ns = desired_present_time_ns, + .wake_up_time_ns = wake_up_time_ns, + .present_slop_ns = present_slop_ns, + }; + + u_metrics_write_system_frame(&umsf); } static void @@ -156,6 +172,17 @@ static void pc_info_gpu( struct u_pacing_compositor *upc, int64_t frame_id, uint64_t gpu_start_ns, uint64_t gpu_end_ns, uint64_t when_ns) { + if (u_metrics_is_active()) { + struct u_metrics_system_gpu_info umgi = { + .frame_id = frame_id, + .gpu_start_ns = gpu_start_ns, + .gpu_end_ns = gpu_end_ns, + .when_ns = when_ns, + }; + + u_metrics_write_system_gpu_info(&umgi); + } + #ifdef U_TRACE_PERCETTO // Uses Percetto specific things. if (U_TRACE_CATEGORY_IS_ENABLED(timing)) { #define TE_BEG(TRACK, TIME, NAME) U_TRACE_EVENT_BEGIN_ON_TRACK_DATA(timing, TRACK, TIME, NAME, PERCETTO_I(frame_id))