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 <derek.foreman@collabora.com>
This commit is contained in:
Derek Foreman 2026-05-05 14:54:37 -05:00
parent c56f2bc709
commit eacb27b4cf
6 changed files with 119 additions and 57 deletions

View file

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

View file

@ -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 <libweston/libweston.h>
#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;
}

View file

@ -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 <libweston/libweston.h>
#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);

View file

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

View file

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

View file

@ -10,6 +10,7 @@
#ifndef WESTON_TRACE_H
#define WESTON_TRACE_H
#include "perfetto/annotations.h"
#include "perfetto/u_perfetto.h"
#include <string.h>