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..7cee650a3 --- /dev/null +++ b/libweston/perfetto/annotations.c @@ -0,0 +1,68 @@ +/* + * 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 int +perfetto_annotate_int(struct weston_debug_annotation *annots, + unsigned int count, + const char *key, + int value) +{ + annots[count].type = WESTON_DEBUG_ANNOTATION_INT_VAL; + annots[count].ivalue = value; + annots[count].key = key; + + return 1; +} + +WL_EXPORT int +perfetto_annotate_float(struct weston_debug_annotation *annots, + unsigned int count, + const char *key, + float value) +{ + annots[count].type = WESTON_DEBUG_ANNOTATION_FLOAT_VAL; + annots[count].fvalue = value; + annots[count].key = key; + + return 1; +} + +WL_EXPORT int +perfetto_annotate_string(struct weston_debug_annotation *annots, + unsigned int count, + const char *key, + const char *value) +{ + annots[count].type = WESTON_DEBUG_ANNOTATION_STR_VAL; + annots[count].svalue = value; + annots[count].key = key; + + return 1; +} diff --git a/libweston/perfetto/annotations.h b/libweston/perfetto/annotations.h new file mode 100644 index 000000000..17a90db4b --- /dev/null +++ b/libweston/perfetto/annotations.h @@ -0,0 +1,48 @@ +/* + * 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" + +int +perfetto_annotate_int(struct weston_debug_annotation *annots, + unsigned int count, + const char *key, + int value); + +int +perfetto_annotate_float(struct weston_debug_annotation *annots, + unsigned int count, + const char *key, + float value); + +int +perfetto_annotate_string(struct weston_debug_annotation *annots, + unsigned int count, + const char *key, + const char *value); diff --git a/libweston/perfetto/u_perfetto.cc b/libweston/perfetto/u_perfetto.cc index 40800c2d2..6a472dcc4 100644 --- a/libweston/perfetto/u_perfetto.cc +++ b/libweston/perfetto/u_perfetto.cc @@ -227,45 +227,6 @@ util_perfetto_trace_commit_annotate_func_flow(uint64_t id, const char *name, }); } -int -perfetto_annotate_int(struct weston_debug_annotation *annots, - unsigned int count, - const char *key, - int value) -{ - annots[count].type = WESTON_DEBUG_ANNOTATION_INT_VAL; - annots[count].ivalue = value; - annots[count].key = key; - - return 1; -} - -int -perfetto_annotate_float(struct weston_debug_annotation *annots, - unsigned int count, - const char *key, - float value) -{ - annots[count].type = WESTON_DEBUG_ANNOTATION_FLOAT_VAL; - annots[count].fvalue = value; - annots[count].key = key; - - return 1; -} - -int -perfetto_annotate_string(struct weston_debug_annotation *annots, - unsigned int count, - const char *key, - const char *value) -{ - annots[count].type = WESTON_DEBUG_ANNOTATION_STR_VAL; - annots[count].svalue = value; - annots[count].key = key; - - return 1; -} - 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 00570f615..4c84b7250 100644 --- a/libweston/perfetto/u_perfetto.h +++ b/libweston/perfetto/u_perfetto.h @@ -92,24 +92,6 @@ uint64_t util_perfetto_next_id(void); uint64_t util_perfetto_new_track(const char *name); -int -perfetto_annotate_int(struct weston_debug_annotation *annots, - unsigned int count, - const char *key, - int value); - -int -perfetto_annotate_float(struct weston_debug_annotation *annots, - unsigned int count, - const char *key, - float value); - -int -perfetto_annotate_string(struct weston_debug_annotation *annots, - unsigned int count, - 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 9d4b55979..b8b4f582a 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