From 9ce3759bc56109fd7e6731f9d401c910e43d4950 Mon Sep 17 00:00:00 2001 From: Derek Foreman Date: Wed, 20 May 2026 09:57:41 -0500 Subject: [PATCH] trace: Ensure flow id is always set Ever since 160394b2c3db7457b1f246a3ae371c6b08c00b74 we can have perfetto flow ids in const structs. We need to preserve the perfetto flow even when tracing is disabled - a flow will start in a function that has non-const access to a struct, but other functions further along the flow may only have const access. Fix up "instant annotations" to preserve flows when not tracing, and to reset the annotation count on commit when not tracing. I suppose this also fixes a potential race where annotations aren't properly reset if tracing is started and stopped multiple times during the execution of a single function - but I can't imagine that being possible to hit. Signed-off-by: Derek Foreman --- libweston/weston-trace.h | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/libweston/weston-trace.h b/libweston/weston-trace.h index abb3cc511..8354e7cbb 100644 --- a/libweston/weston-trace.h +++ b/libweston/weston-trace.h @@ -106,9 +106,7 @@ #define _WESTON_TRACE_COMMIT_ANNOTATION(id, name) \ do { \ - if (unlikely(util_perfetto_is_tracing_enabled())) { \ - _weston_trace_scope_annotate_commit(id, name, &__pd_annots); \ - } \ + _weston_trace_scope_annotate_commit(id, name, &__pd_annots); \ } while (0) /* annotated funcs */ @@ -219,15 +217,18 @@ static inline void _weston_trace_scope_annotate_commit(uint64_t *id, const char *name, struct weston_debug_annotations *annots) { - if (id && *id == 0) { - *id = util_perfetto_next_id(); - util_perfetto_trace_commit_debug_annots(*id, name, annots); - goto reset_entries; + uint64_t flow_id = 0; + + if (id) { + if (*id == 0) + *id = util_perfetto_next_id(); + + flow_id = *id; } - util_perfetto_trace_commit_debug_annots(0, name, annots); + if (unlikely(util_perfetto_is_tracing_enabled())) + util_perfetto_trace_commit_debug_annots(flow_id, name, annots); -reset_entries: annots->count = 0; }