From f5f6989a6565280c64b269ec47b41a82eb2e75a0 Mon Sep 17 00:00:00 2001 From: Derek Foreman Date: Tue, 5 May 2026 14:54:37 -0500 Subject: [PATCH] trace: Put annotations in a separate file For now just the three we have, but we'll be adding a bunch of complex annotations, so having their own place will be cleaner. Signed-off-by: Derek Foreman --- libweston/meson.build | 2 + libweston/perfetto/annotations.c | 71 ++++++++++++++++++++++++++++++++ libweston/perfetto/annotations.h | 45 ++++++++++++++++++++ libweston/perfetto/u_perfetto.cc | 42 ------------------- libweston/perfetto/u_perfetto.h | 15 ------- libweston/weston-trace.h | 1 + 6 files changed, 119 insertions(+), 57 deletions(-) create mode 100644 libweston/perfetto/annotations.c create mode 100644 libweston/perfetto/annotations.h diff --git a/libweston/meson.build b/libweston/meson.build index b2a8cac8d..2bc719fb0 100644 --- a/libweston/meson.build +++ b/libweston/meson.build @@ -117,6 +117,8 @@ endif if get_option('perfetto') srcs_libweston += [ + 'perfetto/annotations.c', + 'perfetto/annotations.h', 'perfetto/u_perfetto.cc', 'perfetto/u_perfetto.h', 'timeline-perfetto.c' diff --git a/libweston/perfetto/annotations.c b/libweston/perfetto/annotations.c new file mode 100644 index 000000000..1f3e3f3c8 --- /dev/null +++ b/libweston/perfetto/annotations.c @@ -0,0 +1,71 @@ +/* + * Copyright (C) 2026 Amazon.com, Inc. or its affiliates + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial + * portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include + +#include "perfetto/annotations.h" +#include "weston-trace.h" + +WL_EXPORT void +perfetto_annotate_int(struct weston_debug_annotations *annots, + const char *key, + int value) +{ + struct weston_debug_annotation *annot = &annots->annots[annots->count]; + + annot->type = WESTON_DEBUG_ANNOTATION_INT_VAL; + annot->ivalue = value; + annot->key = key; + + annots->count++; +} + +WL_EXPORT void +perfetto_annotate_float(struct weston_debug_annotations *annots, + const char *key, + float value) +{ + struct weston_debug_annotation *annot = &annots->annots[annots->count]; + + annot->type = WESTON_DEBUG_ANNOTATION_FLOAT_VAL; + annot->fvalue = value; + annot->key = key; + + annots->count++; +} + +WL_EXPORT void +perfetto_annotate_string(struct weston_debug_annotations *annots, + const char *key, + const char *value) +{ + struct weston_debug_annotation *annot = &annots->annots[annots->count]; + + annot->type = WESTON_DEBUG_ANNOTATION_STR_VAL; + annot->svalue = value; + annot->key = key; + + annots->count++; +} diff --git a/libweston/perfetto/annotations.h b/libweston/perfetto/annotations.h new file mode 100644 index 000000000..5e7df581a --- /dev/null +++ b/libweston/perfetto/annotations.h @@ -0,0 +1,45 @@ +/* + * Copyright (C) 2026 Amazon.com, Inc. or its affiliates + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial + * portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#pragma once + +#include + +#include "perfetto/u_perfetto.h" + +void +perfetto_annotate_int(struct weston_debug_annotations *annots, + const char *key, + int value); + +void +perfetto_annotate_float(struct weston_debug_annotations *annots, + const char *key, + float value); + +void +perfetto_annotate_string(struct weston_debug_annotations *annots, + const char *key, + const char *value); diff --git a/libweston/perfetto/u_perfetto.cc b/libweston/perfetto/u_perfetto.cc index 281658f07..9492e9897 100644 --- a/libweston/perfetto/u_perfetto.cc +++ b/libweston/perfetto/u_perfetto.cc @@ -228,48 +228,6 @@ util_perfetto_trace_commit_annotate_func_flow(uint64_t id, const char *name, }); } -void -perfetto_annotate_int(struct weston_debug_annotations *annots, - const char *key, - int value) -{ - struct weston_debug_annotation *annot = &annots->annots[annots->count]; - - annot->type = WESTON_DEBUG_ANNOTATION_INT_VAL; - annot->ivalue = value; - annot->key = key; - - annots->count++; -} - -void -perfetto_annotate_float(struct weston_debug_annotations *annots, - const char *key, - float value) -{ - struct weston_debug_annotation *annot = &annots->annots[annots->count]; - - annot->type = WESTON_DEBUG_ANNOTATION_FLOAT_VAL; - annot->fvalue = value; - annot->key = key; - - annots->count++; -} - -void -perfetto_annotate_string(struct weston_debug_annotations *annots, - const char *key, - const char *value) -{ - struct weston_debug_annotation *annot = &annots->annots[annots->count]; - - annot->type = WESTON_DEBUG_ANNOTATION_STR_VAL; - annot->svalue = value; - annot->key = key; - - annots->count++; -} - class UtilPerfettoObserver : public perfetto::TrackEventSessionObserver { public: UtilPerfettoObserver() { perfetto::TrackEvent::AddSessionObserver(this); } diff --git a/libweston/perfetto/u_perfetto.h b/libweston/perfetto/u_perfetto.h index 6130e28ad..8341e3f91 100644 --- a/libweston/perfetto/u_perfetto.h +++ b/libweston/perfetto/u_perfetto.h @@ -97,21 +97,6 @@ uint64_t util_perfetto_next_id(void); uint64_t util_perfetto_new_track(const char *name); -void -perfetto_annotate_int(struct weston_debug_annotations *annots, - const char *key, - int value); - -void -perfetto_annotate_float(struct weston_debug_annotations *annots, - const char *key, - float value); - -void -perfetto_annotate_string(struct weston_debug_annotations *annots, - const char *key, - const char *value); - #else /* HAVE_PERFETTO */ static inline void diff --git a/libweston/weston-trace.h b/libweston/weston-trace.h index 50e8148db..a3b9b3b57 100644 --- a/libweston/weston-trace.h +++ b/libweston/weston-trace.h @@ -10,6 +10,7 @@ #ifndef WESTON_TRACE_H #define WESTON_TRACE_H +#include "perfetto/annotations.h" #include "perfetto/u_perfetto.h" #include