trace: Add flow as an annotation and use it for paint nodes

Annotations give us a more generic way to incorporate flows into our
perfetto traces.

This will eventually let us remove some _FLOW() variants of our trace
macros.

It also lets us have multiple flows through the same function/annotation.

Signed-off-by: Derek Foreman <derek.foreman@collabora.com>
This commit is contained in:
Derek Foreman 2026-05-20 16:46:58 -05:00
parent 3796267cfc
commit cc2a85cb59
10 changed files with 71 additions and 17 deletions

View file

@ -45,6 +45,10 @@ extern "C" {
#include <libweston/zalloc.h>
#include <libweston/colorimetry.h>
struct weston_trace_flow {
uint64_t id;
};
struct weston_log_pacer {
/** This must be set to zero before first use */
bool initialized;

View file

@ -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 */

View file

@ -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: */

View file

@ -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);
}

View file

@ -26,6 +26,7 @@
#pragma once
#include <libweston/libweston.h>
#include <libweston/libweston-internal.h>
#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);

View file

@ -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;
}

View file

@ -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;

View file

@ -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);

View file

@ -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);
}

View file

@ -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, \