mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2025-12-20 07:20:10 +01:00
util/perf: Add sysprof integration
Signed-off-by: Christian Gmeiner <cgmeiner@igalia.com> Acked-by: Emma Anholt <emma@anholt.net> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/34893>
This commit is contained in:
parent
8358d44223
commit
9da5eafa8e
6 changed files with 99 additions and 2 deletions
|
|
@ -2210,6 +2210,12 @@ if with_gpuvis
|
||||||
pre_args += '-DHAVE_GPUVIS'
|
pre_args += '-DHAVE_GPUVIS'
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
with_sysprof = get_option('sysprof')
|
||||||
|
if with_sysprof
|
||||||
|
dep_sysprof = dependency('sysprof-capture-4', version: '>= 3.38.0')
|
||||||
|
pre_args += '-DHAVE_SYSPROF'
|
||||||
|
endif
|
||||||
|
|
||||||
add_project_arguments(pre_args, language : ['c', 'cpp'])
|
add_project_arguments(pre_args, language : ['c', 'cpp'])
|
||||||
add_project_arguments(c_cpp_args, language : ['c', 'cpp'])
|
add_project_arguments(c_cpp_args, language : ['c', 'cpp'])
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -638,6 +638,13 @@ option(
|
||||||
description : 'Enable tracing markers for gpuvis. Default: false'
|
description : 'Enable tracing markers for gpuvis. Default: false'
|
||||||
)
|
)
|
||||||
|
|
||||||
|
option(
|
||||||
|
'sysprof',
|
||||||
|
type : 'boolean',
|
||||||
|
value : false,
|
||||||
|
description : 'Enable tracing markers for sysprof. Default: false'
|
||||||
|
)
|
||||||
|
|
||||||
option(
|
option(
|
||||||
'custom-shader-replacement',
|
'custom-shader-replacement',
|
||||||
type : 'string',
|
type : 'string',
|
||||||
|
|
|
||||||
|
|
@ -277,6 +277,14 @@ if with_gpuvis
|
||||||
)
|
)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
if with_sysprof
|
||||||
|
files_mesa_util += files(
|
||||||
|
'perf/u_sysprof.c',
|
||||||
|
'perf/u_sysprof.h',
|
||||||
|
)
|
||||||
|
deps_for_libmesa_util += dep_sysprof
|
||||||
|
endif
|
||||||
|
|
||||||
u_trace_py = files('perf/u_trace.py')
|
u_trace_py = files('perf/u_trace.py')
|
||||||
|
|
||||||
libmesa_util_simd = static_library(
|
libmesa_util_simd = static_library(
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@
|
||||||
|
|
||||||
#include "u_perfetto.h"
|
#include "u_perfetto.h"
|
||||||
#include "u_gpuvis.h"
|
#include "u_gpuvis.h"
|
||||||
|
#include "u_sysprof.h"
|
||||||
|
|
||||||
#include "util/detect_os.h"
|
#include "util/detect_os.h"
|
||||||
#include "util/macros.h"
|
#include "util/macros.h"
|
||||||
|
|
@ -93,6 +94,18 @@
|
||||||
|
|
||||||
#endif /* HAVE_GPUVIS */
|
#endif /* HAVE_GPUVIS */
|
||||||
|
|
||||||
|
#if defined(HAVE_SYSPROF)
|
||||||
|
|
||||||
|
#define _MESA_SYSPROF_TRACE_BEGIN(name) util_sysprof_begin(name)
|
||||||
|
#define _MESA_SYSPROF_TRACE_END(scope) util_sysprof_end(scope)
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
#define _MESA_SYSPROF_TRACE_BEGIN(name) NULL
|
||||||
|
#define _MESA_SYSPROF_TRACE_END(scope)
|
||||||
|
|
||||||
|
#endif /* HAVE_SYSPROF */
|
||||||
|
|
||||||
#if __has_attribute(cleanup) && __has_attribute(unused)
|
#if __has_attribute(cleanup) && __has_attribute(unused)
|
||||||
|
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
|
|
@ -126,6 +139,7 @@ static inline void *
|
||||||
_mesa_trace_scope_begin(const char *format, ...)
|
_mesa_trace_scope_begin(const char *format, ...)
|
||||||
{
|
{
|
||||||
char name[_MESA_TRACE_SCOPE_MAX_NAME_LENGTH];
|
char name[_MESA_TRACE_SCOPE_MAX_NAME_LENGTH];
|
||||||
|
void *scope = NULL;
|
||||||
va_list args;
|
va_list args;
|
||||||
|
|
||||||
va_start(args, format);
|
va_start(args, format);
|
||||||
|
|
@ -136,17 +150,21 @@ _mesa_trace_scope_begin(const char *format, ...)
|
||||||
|
|
||||||
_MESA_TRACE_BEGIN(name);
|
_MESA_TRACE_BEGIN(name);
|
||||||
_MESA_GPUVIS_TRACE_BEGIN(name);
|
_MESA_GPUVIS_TRACE_BEGIN(name);
|
||||||
return NULL;
|
scope = _MESA_SYSPROF_TRACE_BEGIN(name);
|
||||||
|
return scope;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void *
|
static inline void *
|
||||||
_mesa_trace_scope_flow_begin(const char *name, uint64_t *id)
|
_mesa_trace_scope_flow_begin(const char *name, uint64_t *id)
|
||||||
{
|
{
|
||||||
|
void *scope = NULL;
|
||||||
|
|
||||||
if (*id == 0)
|
if (*id == 0)
|
||||||
*id = util_perfetto_next_id();
|
*id = util_perfetto_next_id();
|
||||||
_MESA_TRACE_FLOW_BEGIN(name, *id);
|
_MESA_TRACE_FLOW_BEGIN(name, *id);
|
||||||
_MESA_GPUVIS_TRACE_BEGIN(name);
|
_MESA_GPUVIS_TRACE_BEGIN(name);
|
||||||
return NULL;
|
scope = _MESA_SYSPROF_TRACE_BEGIN(name);
|
||||||
|
return scope;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void
|
static inline void
|
||||||
|
|
@ -154,6 +172,7 @@ _mesa_trace_scope_end(UNUSED void **scope)
|
||||||
{
|
{
|
||||||
_MESA_GPUVIS_TRACE_END();
|
_MESA_GPUVIS_TRACE_END();
|
||||||
_MESA_TRACE_END();
|
_MESA_TRACE_END();
|
||||||
|
_MESA_SYSPROF_TRACE_END(scope);
|
||||||
}
|
}
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
|
||||||
40
src/util/perf/u_sysprof.c
Normal file
40
src/util/perf/u_sysprof.c
Normal file
|
|
@ -0,0 +1,40 @@
|
||||||
|
/*
|
||||||
|
* 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 **scope)
|
||||||
|
{
|
||||||
|
struct perf_sysprof_entry *trace = (struct perf_sysprof_entry *) *scope;
|
||||||
|
|
||||||
|
sysprof_collector_mark(trace->begin,
|
||||||
|
SYSPROF_CAPTURE_CURRENT_TIME - trace->begin, "Mesa",
|
||||||
|
trace->name, NULL);
|
||||||
|
free(trace);
|
||||||
|
}
|
||||||
17
src/util/perf/u_sysprof.h
Normal file
17
src/util/perf/u_sysprof.h
Normal file
|
|
@ -0,0 +1,17 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2025 Igalia S.L.
|
||||||
|
* SPDX-License-Identifier: MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void *util_sysprof_begin(const char *name);
|
||||||
|
void util_sysprof_end(void **scope);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
Loading…
Add table
Reference in a new issue