diff --git a/include/libweston/libweston.h b/include/libweston/libweston.h index 80db69fa1..472d47856 100644 --- a/include/libweston/libweston.h +++ b/include/libweston/libweston.h @@ -45,6 +45,10 @@ extern "C" { #include #include +struct weston_trace_flow { + uint64_t id; +}; + struct weston_log_pacer { /** This must be set to zero before first use */ bool initialized; diff --git a/libweston/compositor.c b/libweston/compositor.c index 3b4f04bda..4762b4174 100644 --- a/libweston/compositor.c +++ b/libweston/compositor.c @@ -287,7 +287,7 @@ paint_node_update_rectangles(struct weston_paint_node *pnode) static void paint_node_update_early(struct weston_paint_node *pnode) { - WESTON_TRACE_FUNC_FLOW(&pnode->flow_id); + WESTON_TRACE_ANNOTATE_FUNC(("paint node flow", &pnode->flow)); struct weston_matrix *mat = &pnode->buffer_to_output_matrix; struct weston_output *output = pnode->output; struct weston_surface *surface = pnode->surface; @@ -411,7 +411,7 @@ paint_node_validate_ready(struct weston_paint_node *pnode) static void paint_node_update_late(struct weston_paint_node *pnode) { - WESTON_TRACE_FUNC_FLOW(&pnode->flow_id); + WESTON_TRACE_ANNOTATE_FUNC(("paint node flow", &pnode->flow)); struct weston_surface *surf = pnode->surface; struct weston_buffer *buffer = surf->buffer_ref.buffer; struct weston_view *view = pnode->view; @@ -3382,7 +3382,7 @@ weston_output_damage(struct weston_output *output) static void paint_node_add_damage(struct weston_paint_node *node) { - WESTON_TRACE_FUNC_FLOW(&node->flow_id); + WESTON_TRACE_ANNOTATE_FUNC(("paint node flow", &node->flow)); struct weston_view *view = node->view; pixman_region32_t damage; @@ -3411,7 +3411,7 @@ paint_node_add_damage(struct weston_paint_node *node) static void paint_node_flush_surface_damage(struct weston_paint_node *pnode) { - WESTON_TRACE_FUNC_FLOW(&pnode->flow_id); + WESTON_TRACE_ANNOTATE_FUNC(("paint node flow", &pnode->flow)); struct weston_output *output = pnode->output; struct weston_surface *surface = pnode->surface; struct weston_buffer *buffer = surface->buffer_ref.buffer; @@ -3909,7 +3909,7 @@ weston_output_repaint(struct weston_output *output) assert(pnode->output == output); /* Reset paint node perfetto flows at start of repaint */ - pnode->flow_id = 0; + pnode->flow.id = 0; } /* Find the highest protection desired for an output */ diff --git a/libweston/libweston-internal.h b/libweston/libweston-internal.h index b6897b0bf..bb7f08f02 100644 --- a/libweston/libweston-internal.h +++ b/libweston/libweston-internal.h @@ -678,7 +678,7 @@ enum try_view_on_plane_failure_reasons { * A generic data structure unique for surface-view-output combination. */ struct weston_paint_node { - uint64_t flow_id; /* Perfetto flow id */ + struct weston_trace_flow flow; /* Perfetto flow */ /* Immutable members: */ diff --git a/libweston/perfetto/annotations.c b/libweston/perfetto/annotations.c index a66a2eec9..ae6b21d44 100644 --- a/libweston/perfetto/annotations.c +++ b/libweston/perfetto/annotations.c @@ -267,3 +267,35 @@ perfetto_annotate_buffer(struct weston_debug_annotations *annots, do_annotate_buffer(annots, annots->count, key, key_size, buffer); } + +WL_EXPORT void +perfetto_annotate_flow_const(struct weston_debug_annotations *annots, + const char *key, + unsigned char key_size, + const struct weston_trace_flow *flow) +{ + struct weston_debug_annotation *annot = &annots->annots[annots->count]; + + weston_assert_u8_gt(NULL, WESTON_MAX_DEBUG_ANNOTS, annots->count); + weston_assert_u64_gt(NULL, flow->id, 0); + + annot->type = WESTON_DEBUG_ANNOTATION_FLOW; + annot->flow_value = flow->id; + annot->parent = annots->count; + annot->key = key; + annot->key_size = key_size; + + annots->count++; +} + +WL_EXPORT void +perfetto_annotate_flow(struct weston_debug_annotations *annots, + const char *key, + unsigned char key_size, + struct weston_trace_flow *flow) +{ + if (flow->id == 0) + flow->id = util_perfetto_next_id(); + + perfetto_annotate_flow_const(annots, key, key_size, flow); +} diff --git a/libweston/perfetto/annotations.h b/libweston/perfetto/annotations.h index cf0e88bc5..fe315ccec 100644 --- a/libweston/perfetto/annotations.h +++ b/libweston/perfetto/annotations.h @@ -26,6 +26,7 @@ #pragma once #include +#include #include "perfetto/u_perfetto.h" @@ -69,3 +70,15 @@ perfetto_annotate_solid_buffer_values(struct weston_debug_annotations *annots, const char *key, unsigned char key_size, const struct weston_solid_buffer_values *values); + +void +perfetto_annotate_flow(struct weston_debug_annotations *annots, + const char *key, + unsigned char key_size, + struct weston_trace_flow *flow); + +void +perfetto_annotate_flow_const(struct weston_debug_annotations *annots, + const char *key, + unsigned char key_size, + const struct weston_trace_flow *flow); diff --git a/libweston/perfetto/u_perfetto.cc b/libweston/perfetto/u_perfetto.cc index 09f6a4ab5..de6b7f554 100644 --- a/libweston/perfetto/u_perfetto.cc +++ b/libweston/perfetto/u_perfetto.cc @@ -253,6 +253,9 @@ util_perfetto_flush_debug_annotation(perfetto::EventContext *ctx, else ctx->AddDebugAnnotation(key, annot->svalue); break; + case WESTON_DEBUG_ANNOTATION_FLOW: + perfetto::Flow::ProcessScoped(annot->flow_value)(*ctx); + break; default: break; } diff --git a/libweston/perfetto/u_perfetto.h b/libweston/perfetto/u_perfetto.h index 8251f4174..8d9ca2b51 100644 --- a/libweston/perfetto/u_perfetto.h +++ b/libweston/perfetto/u_perfetto.h @@ -45,11 +45,13 @@ enum weston_debug_annotation_type { WESTON_DEBUG_ANNOTATION_DOUBLE_VAL, WESTON_DEBUG_ANNOTATION_STR_VAL, WESTON_DEBUG_ANNOTATION_CONTAINER, + WESTON_DEBUG_ANNOTATION_FLOW, }; struct weston_debug_annotation { const char *key; union { + uint64_t flow_value; int ivalue; float fvalue; double dvalue; diff --git a/libweston/renderer-gl/gl-renderer.c b/libweston/renderer-gl/gl-renderer.c index 87218021a..7c65d5073 100644 --- a/libweston/renderer-gl/gl-renderer.c +++ b/libweston/renderer-gl/gl-renderer.c @@ -443,7 +443,7 @@ gl_log_paint_node_bbox_and_region(struct gl_renderer *gr, struct weston_paint_no ("box_width", box_width), ("box_height", box_height)); - WESTON_TRACE_COMMIT_ANNOTATION(&pnode->flow_id); + WESTON_TRACE_COMMIT_ANNOTATION(&pnode->flow.id); if (!weston_log_scope_is_enabled(gr->paint_node_scope)) return; @@ -2373,7 +2373,7 @@ set_blend_state(struct gl_renderer *gr, struct weston_paint_node *pnode, bool st if (pnode) { WESTON_TRACE_ANNOTATE(("paint node", pnode->internal_name)); - WESTON_TRACE_COMMIT_ANNOTATION(&pnode->flow_id); + WESTON_TRACE_COMMIT_ANNOTATION(&pnode->flow.id); } else { WESTON_TRACE_COMMIT_ANNOTATION(NULL); } @@ -2544,8 +2544,7 @@ apply_color_effect(struct gl_renderer *gr, struct weston_paint_node *pnode, stru return; } - WESTON_TRACE_FUNC_FLOW(&pnode->flow_id); - WESTON_TRACE_BEGIN_ANNOTATION(); + WESTON_TRACE_ANNOTATE_FUNC(("paint node flow", &pnode->flow)); WESTON_TRACE_ANNOTATE(("paint node", pnode->internal_name)); weston_assert_f32_eq(compositor, a, 1.0f); @@ -2557,7 +2556,7 @@ apply_color_effect(struct gl_renderer *gr, struct weston_paint_node *pnode, stru *b = 1.0f - *b; gl_log_paint_node(gr, "\t\tcolor effect: inversion\n"); WESTON_TRACE_ANNOTATE(("color effect", "inversion")); - WESTON_TRACE_COMMIT_ANNOTATION(&pnode->flow_id); + WESTON_TRACE_COMMIT_ANNOTATION(&pnode->flow.id); return; case WESTON_OUTPUT_COLOR_EFFECT_TYPE_GRAYSCALE: *r = 0.2126f * (*r) + 0.7152f * (*g) + 0.0722f * (*b); @@ -2565,7 +2564,7 @@ apply_color_effect(struct gl_renderer *gr, struct weston_paint_node *pnode, stru *b = *r; gl_log_paint_node(gr, "\t\tcolor effect: grayscale\n"); WESTON_TRACE_ANNOTATE(("color effect", "greyscale")); - WESTON_TRACE_COMMIT_ANNOTATION(&pnode->flow_id); + WESTON_TRACE_COMMIT_ANNOTATION(&pnode->flow.id); return; case WESTON_OUTPUT_COLOR_EFFECT_TYPE_CVD_CORRECTION: /** @@ -2581,7 +2580,7 @@ apply_color_effect(struct gl_renderer *gr, struct weston_paint_node *pnode, stru weston_output_cvd_type_to_str(effect->u.cvd)); WESTON_TRACE_ANNOTATE(("color effect", weston_output_cvd_type_to_str(effect->u.cvd))); - WESTON_TRACE_COMMIT_ANNOTATION(&pnode->flow_id); + WESTON_TRACE_COMMIT_ANNOTATION(&pnode->flow.id); return; }; @@ -2629,7 +2628,7 @@ static void draw_paint_node(struct weston_paint_node *pnode, pixman_region32_t *damage /* in global coordinates */) { - WESTON_TRACE_FUNC_FLOW(&pnode->flow_id); + WESTON_TRACE_ANNOTATE_FUNC(("paint node flow", &pnode->flow)); struct gl_renderer *gr = get_renderer(pnode->surface->compositor); struct gl_surface_state *gs = get_surface_state(pnode->surface); /* repaint bounding region in global coordinates: */ @@ -2641,7 +2640,6 @@ draw_paint_node(struct weston_paint_node *pnode, struct gl_shader_config sconf; struct clipper_quad *quads = NULL; int nquads; - WESTON_TRACE_BEGIN_ANNOTATION(); pixman_region32_init(&repaint); pixman_region32_intersect(&repaint, &pnode->visible, damage); @@ -2732,7 +2730,7 @@ draw_paint_node(struct weston_paint_node *pnode, pixman_region32_fini(&surface_blend); pixman_region32_fini(&surface_opaque); - WESTON_TRACE_COMMIT_ANNOTATION(&pnode->flow_id); + WESTON_TRACE_COMMIT_ANNOTATION(&pnode->flow.id); out: pixman_region32_fini(&repaint); diff --git a/libweston/renderer-gl/gl-shaders.c b/libweston/renderer-gl/gl-shaders.c index f4b3fddc9..9af350c18 100644 --- a/libweston/renderer-gl/gl-shaders.c +++ b/libweston/renderer-gl/gl-shaders.c @@ -978,7 +978,7 @@ gl_shader_load_config(struct gl_renderer *gr, struct weston_paint_node *pnode, } if (pnode) { - WESTON_TRACE_COMMIT_ANNOTATION(&pnode->flow_id); + WESTON_TRACE_COMMIT_ANNOTATION(&pnode->flow.id); } else { WESTON_TRACE_COMMIT_ANNOTATION(NULL); } diff --git a/libweston/weston-trace.h b/libweston/weston-trace.h index 82f4e3aa9..2a34ca571 100644 --- a/libweston/weston-trace.h +++ b/libweston/weston-trace.h @@ -88,6 +88,8 @@ #define _WESTON_TRACE_ANNOTATE_ADD_GENERIC(k, v) \ static_assert(sizeof(k) < WESTON_TRACE_MAX_KEY_LENGTH); \ _Generic((v), \ + struct weston_trace_flow *: perfetto_annotate_flow, \ + const struct weston_trace_flow *: perfetto_annotate_flow_const, \ int: perfetto_annotate_int, \ bool: perfetto_annotate_bool, \ unsigned int: perfetto_annotate_int, \