trace: Add multiple annotations with a single macro

Use recursive macro magic to make a single ANNOTATE macro that processes
a list of annotations.

Signed-off-by: Derek Foreman <derek.foreman@collabora.com>
This commit is contained in:
Derek Foreman 2026-05-05 12:33:33 -05:00
parent 31ee8848e2
commit 6748ed6b57
4 changed files with 80 additions and 45 deletions

View file

@ -436,12 +436,12 @@ gl_log_paint_node_bbox_and_region(struct gl_renderer *gr, struct weston_paint_no
WESTON_TRACE_BEGIN_ANNOTATION();
WESTON_TRACE_ANNOTATE_ADD("paint node", pnode->internal_name);
WESTON_TRACE_ANNOTATE_ADD("type", str);
WESTON_TRACE_ANNOTATE_ADD("x", box_x);
WESTON_TRACE_ANNOTATE_ADD("y", box_y);
WESTON_TRACE_ANNOTATE_ADD("box_width", box_width);
WESTON_TRACE_ANNOTATE_ADD("box_height", box_height);
WESTON_TRACE_ANNOTATE(("paint node", pnode->internal_name),
("type", str),
("x", box_x),
("y", box_y),
("box_width", box_width),
("box_height", box_height));
WESTON_TRACE_COMMIT_ANNOTATION(&pnode->flow_id);
@ -2364,15 +2364,15 @@ set_blend_state(struct gl_renderer *gr, struct weston_paint_node *pnode, bool st
if (state) {
glEnable(GL_BLEND);
gl_log_paint_node(gr, "\t\tblending enabled\n");
WESTON_TRACE_ANNOTATE_ADD("blending", "enabled");
WESTON_TRACE_ANNOTATE(("blending", "enabled"));
} else {
glDisable(GL_BLEND);
gl_log_paint_node(gr, "\t\tblending disabled\n");
WESTON_TRACE_ANNOTATE_ADD("blending", "disabled");
WESTON_TRACE_ANNOTATE(("blending", "disabled"));
}
if (pnode) {
WESTON_TRACE_ANNOTATE_ADD("paint node", pnode->internal_name);
WESTON_TRACE_ANNOTATE(("paint node", pnode->internal_name));
WESTON_TRACE_COMMIT_ANNOTATION(&pnode->flow_id);
} else {
WESTON_TRACE_COMMIT_ANNOTATION(NULL);
@ -2546,7 +2546,7 @@ apply_color_effect(struct gl_renderer *gr, struct weston_paint_node *pnode, stru
WESTON_TRACE_FUNC_FLOW(&pnode->flow_id);
WESTON_TRACE_BEGIN_ANNOTATION();
WESTON_TRACE_ANNOTATE_ADD("paint node", pnode->internal_name);
WESTON_TRACE_ANNOTATE(("paint node", pnode->internal_name));
weston_assert_f32_eq(compositor, a, 1.0f);
@ -2556,7 +2556,7 @@ apply_color_effect(struct gl_renderer *gr, struct weston_paint_node *pnode, stru
*g = 1.0f - *g;
*b = 1.0f - *b;
gl_log_paint_node(gr, "\t\tcolor effect: inversion\n");
WESTON_TRACE_ANNOTATE_ADD("color effect", "inversion");
WESTON_TRACE_ANNOTATE(("color effect", "inversion"));
WESTON_TRACE_COMMIT_ANNOTATION(&pnode->flow_id);
return;
case WESTON_OUTPUT_COLOR_EFFECT_TYPE_GRAYSCALE:
@ -2564,7 +2564,7 @@ apply_color_effect(struct gl_renderer *gr, struct weston_paint_node *pnode, stru
*g = *r;
*b = *r;
gl_log_paint_node(gr, "\t\tcolor effect: grayscale\n");
WESTON_TRACE_ANNOTATE_ADD("color effect", "greyscale");
WESTON_TRACE_ANNOTATE(("color effect", "greyscale"));
WESTON_TRACE_COMMIT_ANNOTATION(&pnode->flow_id);
return;
case WESTON_OUTPUT_COLOR_EFFECT_TYPE_CVD_CORRECTION:
@ -2579,8 +2579,8 @@ apply_color_effect(struct gl_renderer *gr, struct weston_paint_node *pnode, stru
weston_log_scope_printf(gr->paint_node_scope,
"\t\tcolor effect: cvd - %s\n",
weston_output_cvd_type_to_str(effect->u.cvd));
WESTON_TRACE_ANNOTATE_ADD("color effect",
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);
return;
};
@ -2646,22 +2646,22 @@ draw_paint_node(struct weston_paint_node *pnode,
pixman_region32_init(&repaint);
pixman_region32_intersect(&repaint, &pnode->visible, damage);
WESTON_TRACE_ANNOTATE_ADD("paint node", pnode->internal_name);
WESTON_TRACE_ANNOTATE_ADD("label", pnode->surface->label);
WESTON_TRACE_ANNOTATE_ADD("surface id", pnode->surface->s_id);
WESTON_TRACE_ANNOTATE(("paint node", pnode->internal_name),
("label", pnode->surface->label),
("surface id", pnode->surface->s_id));
gl_log_paint_node_start(gr, pnode);
if (!pixman_region32_not_empty(&repaint)) {
gl_log_paint_node(gr, "\t\tskipped repaint: repaint region empty\n");
WESTON_TRACE_ANNOTATE_ADD("skipped repaint", "repaint region empty");
WESTON_TRACE_ANNOTATE(("skipped repaint", "repaint region empty"));
goto out;
}
if (pnode->is_fully_transparent) {
gl_log_paint_node(gr, "\t\tskipped repaint: paint node transparent\n");
gs->used_in_output_repaint = true; /* sort of */
WESTON_TRACE_ANNOTATE_ADD("skipped repaint", "paint node transparent");
WESTON_TRACE_ANNOTATE(("skipped repaint", "paint node transparent"));
goto out;
}
@ -2669,7 +2669,7 @@ draw_paint_node(struct weston_paint_node *pnode,
pnode->valid_transform && (pnode->surf_xform_valid &&
!pnode->surf_xform.transform)) {
gl_log_paint_node(gr, "\t\toptimize: using glClear\n");
WESTON_TRACE_ANNOTATE_ADD("optimization", "using glClear");
WESTON_TRACE_ANNOTATE(("optimization", "using glClear"));
clear_region(gr, pnode, &repaint);
gs->used_in_output_repaint = true;
goto out;
@ -2677,13 +2677,13 @@ draw_paint_node(struct weston_paint_node *pnode,
if (ensure_surface_buffer_is_ready(gr, gs, pnode) < 0) {
gl_log_paint_node(gr, "\t\tskipped repaint: buffer not ready\n");
WESTON_TRACE_ANNOTATE_ADD("skipped repaint", "buffer not ready");
WESTON_TRACE_ANNOTATE(("skipped repaint", "buffer not ready"));
goto out;
}
if (!gl_shader_config_init_for_paint_node(&sconf, pnode)) {
gl_log_paint_node(gr, "\t\tskipped repaint: shader config failure\n");
WESTON_TRACE_ANNOTATE_ADD("skipped repaint", "shader config failure");
WESTON_TRACE_ANNOTATE(("skipped repaint", "shader config failure"));
goto out;
}

View file

@ -856,7 +856,7 @@ gl_shader_load_config(struct gl_renderer *gr, struct weston_paint_node *pnode,
WESTON_TRACE_BEGIN_ANNOTATION();
if (pnode) {
WESTON_TRACE_ANNOTATE_ADD("paint node", pnode->internal_name);
WESTON_TRACE_ANNOTATE(("paint node", pnode->internal_name));
}
glUniformMatrix4fv(shader->proj_uniform,
@ -871,10 +871,10 @@ gl_shader_load_config(struct gl_renderer *gr, struct weston_paint_node *pnode,
"\t\tcolor: r: %.2f, g: %.2f, b: %.2f, a: %.2f\n",
sconf->unicolor[0], sconf->unicolor[1],
sconf->unicolor[2], sconf->unicolor[3]);
WESTON_TRACE_ANNOTATE_ADD("color r", sconf->unicolor[0]);
WESTON_TRACE_ANNOTATE_ADD("color g", sconf->unicolor[1]);
WESTON_TRACE_ANNOTATE_ADD("color b", sconf->unicolor[2]);
WESTON_TRACE_ANNOTATE_ADD("color a", sconf->unicolor[3]);
WESTON_TRACE_ANNOTATE(("color r", sconf->unicolor[0]),
("color g", sconf->unicolor[1]),
("color b", sconf->unicolor[2]),
("color a", sconf->unicolor[3]));
glUniform4fv(shader->color_uniform, 1, sconf->unicolor);
}
if (shader->tint_uniform != -1) {
@ -882,15 +882,15 @@ gl_shader_load_config(struct gl_renderer *gr, struct weston_paint_node *pnode,
"\t\ttint: r: %.2f, g: %.2f, b: %.2f, a: %.2f\n",
sconf->tint[0], sconf->tint[1],
sconf->tint[2], sconf->tint[3]);
WESTON_TRACE_ANNOTATE_ADD("tint r", sconf->tint[0]);
WESTON_TRACE_ANNOTATE_ADD("tint g", sconf->tint[1]);
WESTON_TRACE_ANNOTATE_ADD("tint b", sconf->tint[2]);
WESTON_TRACE_ANNOTATE_ADD("tint a", sconf->tint[3]);
WESTON_TRACE_ANNOTATE(("tint r", sconf->tint[0]),
("tint g", sconf->tint[1]),
("tint b", sconf->tint[2]),
("tint a", sconf->tint[3]));
glUniform4fv(shader->tint_uniform, 1, sconf->tint);
}
weston_log_scope_printf(gr->paint_node_scope, "\t\talpha: %.2f\n", sconf->view_alpha);
WESTON_TRACE_ANNOTATE_ADD("alpha", sconf->view_alpha);
WESTON_TRACE_ANNOTATE(("alpha", sconf->view_alpha));
glUniform1f(shader->view_alpha_uniform, sconf->view_alpha);
assert(sconf->input_num <= SHADER_INPUT_TEX_MAX);
@ -935,11 +935,11 @@ gl_shader_load_config(struct gl_renderer *gr, struct weston_paint_node *pnode,
break;
case SHADER_COLOR_EFFECT_INVERSION:
weston_log_scope_printf(gr->paint_node_scope, "\t\tcolor effect: inversion\n");
WESTON_TRACE_ANNOTATE_ADD("color effect", "inversion");
WESTON_TRACE_ANNOTATE(("color effect", "inversion"));
break;
case SHADER_COLOR_EFFECT_GRAYSCALE:
weston_log_scope_printf(gr->paint_node_scope, "\t\tcolor effect: grayscale\n");
WESTON_TRACE_ANNOTATE_ADD("color effect", "greyscale");
WESTON_TRACE_ANNOTATE(("color effect", "greyscale"));
break;
case SHADER_COLOR_EFFECT_CVD_CORRECTION:
weston_assert_int_ne(gr->compositor, shader->cvd_correction_uniform, -1);
@ -948,8 +948,8 @@ gl_shader_load_config(struct gl_renderer *gr, struct weston_paint_node *pnode,
glUniformMatrix3fv(shader->cvd_correction_uniform,
1, GL_FALSE,
sconf->color_effect.cvd.correction.colmaj);
WESTON_TRACE_ANNOTATE_ADD("color effect",
weston_output_cvd_type_to_str(sconf->color_effect.cvd));
WESTON_TRACE_ANNOTATE(("color effect",
weston_output_cvd_type_to_str(sconf->color_effect.cvd)));
break;
}

View file

@ -206,11 +206,11 @@ weston_surface_attach(struct weston_surface *surface,
WESTON_TRACE_BEGIN_ANNOTATION();
if (buffer) {
WESTON_TRACE_ANNOTATE_ADD("surface", surface->internal_name);
WESTON_TRACE_ANNOTATE_ADD("format", buffer->pixel_format->drm_format_name);
WESTON_TRACE_ANNOTATE_ADD("modifier", buffer->format_modifier_name);
WESTON_TRACE_ANNOTATE_ADD("width", buffer->width);
WESTON_TRACE_ANNOTATE_ADD("height", buffer->height);
WESTON_TRACE_ANNOTATE(("surface", surface->internal_name),
("format", buffer->pixel_format->drm_format_name),
("modifier", buffer->format_modifier_name),
("width", buffer->width),
("height", buffer->height));
}
WESTON_TRACE_ANNOTATE_FUNC_FLOW(&surface->flow_id);

View file

@ -117,6 +117,35 @@
} \
} while (0)
#define _WESTON_TRACE_ANNOTATE(...) \
do { \
_WESTON_TRACE_EXPAND(_WESTON_TRACE_ITER_HELPER( \
_WESTON_TRACE_ANNOTATE_PAIR, __VA_ARGS__)) \
} while (0)
/* Helpers macros for recursive variadic expansion, never to
* be used outside of this header.
*/
#define _WESTON_TRACE_EXPAND(arg) \
_WESTON_TRACE_EXPAND1(_WESTON_TRACE_EXPAND1( \
_WESTON_TRACE_EXPAND1(_WESTON_TRACE_EXPAND1(arg))))
#define _WESTON_TRACE_EXPAND1(arg) \
_WESTON_TRACE_EXPAND2(_WESTON_TRACE_EXPAND2( \
_WESTON_TRACE_EXPAND2(_WESTON_TRACE_EXPAND2(arg))))
#define _WESTON_TRACE_EXPAND2(arg) arg
#define _WESTON_TRACE_ITER_HELPER(operation, pair, ...) \
operation(pair) \
__VA_OPT__(_WESTON_TRACE_ITER_AGAIN \
_WESTON_TRACE_FORCE_RECURSE (operation, __VA_ARGS__))
#define _WESTON_TRACE_ITER_AGAIN() _WESTON_TRACE_ITER_HELPER
#define _WESTON_TRACE_FORCE_RECURSE ()
#define _WESTON_TRACE_ANNOTATE_PAIR(pair) _WESTON_TRACE_ANNOTATE_ADD_GENERIC pair
/* end of helper section */
#if __has_attribute(cleanup) && __has_attribute(unused)
#define _WESTON_TRACE_SCOPE_VAR_CONCAT(name, suffix) name##suffix
@ -229,9 +258,9 @@ _weston_trace_scope_end(int *scope)
#define _WESTON_TRACE_BEGIN_ANNOTATION()
#define _WESTON_TRACE_COMMIT_ANNOTATION(id, name)
#define _WESTON_TRACE_ANNOTATE_ADD(k, v)
#define _WESTON_TRACE_ANNOTATE_FUNC()
#define _WESTON_TRACE_ANNOTATE_FUNC_FLOW(id, name)
#define _WESTON_TRACE_ANNOTATE(...)
#endif /* HAVE_PERFETTO */
@ -248,9 +277,6 @@ _weston_trace_scope_end(int *scope)
#define WESTON_TRACE_BEGIN_ANNOTATION() \
_WESTON_TRACE_BEGIN_ANNOTATION()
#define WESTON_TRACE_ANNOTATE_ADD(k, v) \
_WESTON_TRACE_ANNOTATE_ADD(k, v)
#define WESTON_TRACE_COMMIT_ANNOTATION(id) \
_WESTON_TRACE_COMMIT_ANNOTATION(id, __func__)
@ -260,4 +286,13 @@ _weston_trace_scope_end(int *scope)
#define WESTON_TRACE_ANNOTATE_FUNC_FLOW(id) \
_WESTON_TRACE_ANNOTATE_FUNC_FLOW(id, __func__)
/* Adds a series of annotations of the form '("key string", value)' separated
* by commas.
*
* Brackets are necessary, and the value can be any type understood by the
* _Generic block in _WESTON_TRACE_ANNOTATE_ADD
*/
#define WESTON_TRACE_ANNOTATE(...) \
_WESTON_TRACE_ANNOTATE(__VA_ARGS__)
#endif /* WESTON_TRACE_H */