mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-06-04 19:38:16 +02:00
Add a 'cond' argument to the _MESA_TRACE_SCOPE(), _MESA_TRACE_SCOPE_NAME() and _MESA_TRACE_SCOPE_FLOW() macros, fix up the MESA_TRACE_SCOPE(), MESA_TRACE_SCOPE_FLOW(), MESA_TRACE_FUNC() and MESA_TRACE_FUNC_FLOW() macros depending on it and add the new MESA_TRACE_SCOPE_IF(), MESA_TRACE_SCOPE_FLOW_IF(), MESA_TRACE_FUNC_IF() and MESA_TRACE_FUNC_FLOW_IF() conditional macros. The trace macros are now based on the conditional ones. Code gen stays the same for all the current traces though since compilers optimize out the condition to always taken. See the compiler explorer link. Conditional CPU scope traces are meant to allow builds with either Perfetto, Gpuvis or sysprof tracing enabled to filter traces at run-time. Link: https://godbolt.org/z/886PKWEqf Signed-off-by: Loïc Molinari <loic.molinari@collabora.com> Reviewed-by: Ashley Smith <ashley.smith@collabora.com> Reviewed-by: Boris Brezillon <boris.brezillon@collabora.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/39407>
40 lines
912 B
C
40 lines
912 B
C
/*
|
|
* Copyright 2025 Igalia S.L.
|
|
* SPDX-License-Identifier: MIT
|
|
*/
|
|
|
|
#include "u_sysprof.h"
|
|
|
|
#include <stdbool.h> /* needed for sysprof-collector.h */
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <sysprof-collector.h>
|
|
|
|
struct perf_sysprof_entry {
|
|
SysprofTimeStamp begin;
|
|
/* SysprofCaptureMark itself limits it to 40 characters */
|
|
char name[40];
|
|
};
|
|
|
|
void *
|
|
util_sysprof_begin(const char *name)
|
|
{
|
|
struct perf_sysprof_entry *trace =
|
|
malloc(sizeof(struct perf_sysprof_entry));
|
|
|
|
trace->begin = SYSPROF_CAPTURE_CURRENT_TIME;
|
|
snprintf(trace->name, sizeof(trace->name), "%s", name);
|
|
|
|
return trace;
|
|
}
|
|
|
|
void
|
|
util_sysprof_end(void *t)
|
|
{
|
|
struct perf_sysprof_entry *trace = (struct perf_sysprof_entry *) t;
|
|
|
|
sysprof_collector_mark(trace->begin,
|
|
SYSPROF_CAPTURE_CURRENT_TIME - trace->begin, "Mesa",
|
|
trace->name, NULL);
|
|
free(trace);
|
|
}
|