From 022cd156d4bb8e3a7bd48a490be3e97b51ec4c00 Mon Sep 17 00:00:00 2001 From: Chia-I Wu Date: Thu, 25 Aug 2022 14:10:20 -0700 Subject: [PATCH] util/perf: add cpu_trace.h Move MESA_TRACE_* to the new file. Acked-by: Rob Clark Reviewed-by: Antonio Caggiano Reviewed-by: Yiwei Zhang Part-of: --- src/egl/main/eglapi.c | 2 +- src/freedreno/drm/virtio/virtio_priv.h | 1 + src/util/log.h | 48 ---------------------- src/util/perf/cpu_trace.h | 57 ++++++++++++++++++++++++++ 4 files changed, 59 insertions(+), 49 deletions(-) create mode 100644 src/util/perf/cpu_trace.h diff --git a/src/egl/main/eglapi.c b/src/egl/main/eglapi.c index 95a5e76adf1..d308f08cdf6 100644 --- a/src/egl/main/eglapi.c +++ b/src/egl/main/eglapi.c @@ -95,8 +95,8 @@ #include #include "c11/threads.h" #include "util/debug.h" -#include "util/log.h" #include "util/macros.h" +#include "util/perf/cpu_trace.h" #include "egldefines.h" #include "eglglobals.h" diff --git a/src/freedreno/drm/virtio/virtio_priv.h b/src/freedreno/drm/virtio/virtio_priv.h index 83fb8c9d685..32ff89acdfb 100644 --- a/src/freedreno/drm/virtio/virtio_priv.h +++ b/src/freedreno/drm/virtio/virtio_priv.h @@ -28,6 +28,7 @@ #include "freedreno_priv.h" +#include "util/perf/cpu_trace.h" #include "util/u_atomic.h" #include "util/slab.h" #include "util/timespec.h" diff --git a/src/util/log.h b/src/util/log.h index 047d196d366..d9e965a2bf6 100644 --- a/src/util/log.h +++ b/src/util/log.h @@ -110,52 +110,4 @@ __mesa_log_use_args(UNUSED const char *format, ...) { } } #endif -/* NOTE: for now disable atrace for C++ to workaround a ndk bug with ordering - * between stdatomic.h and atomic.h. See: - * - * https://github.com/android/ndk/issues/1178 - */ -#if defined(ANDROID) && !defined(__cplusplus) - -#include - -#define MESA_TRACE_BEGIN(name) atrace_begin(ATRACE_TAG_GRAPHICS, name) -#define MESA_TRACE_END() atrace_end(ATRACE_TAG_GRAPHICS) - -#else - -/* XXX we would like to use perfetto, but it lacks a C header */ -#define MESA_TRACE_BEGIN(name) -#define MESA_TRACE_END() - -#endif /* ANDROID */ - -#if __has_attribute(cleanup) && __has_attribute(unused) - -#define MESA_TRACE_SCOPE(name) \ - int _mesa_trace_scope_##__LINE__ \ - __attribute__((cleanup(mesa_trace_scope_end), unused)) = \ - mesa_trace_scope_begin(name) - -static inline int -mesa_trace_scope_begin(const char *name) -{ - MESA_TRACE_BEGIN(name); - return 0; -} - -static inline void -mesa_trace_scope_end(int *scope) -{ - MESA_TRACE_END(); -} - -#else - -#define MESA_TRACE_SCOPE(name) - -#endif /* __has_attribute(cleanup) && __has_attribute(unused) */ - -#define MESA_TRACE_FUNC() MESA_TRACE_SCOPE(__func__) - #endif /* MESA_LOG_H */ diff --git a/src/util/perf/cpu_trace.h b/src/util/perf/cpu_trace.h new file mode 100644 index 00000000000..2cd510aa6e2 --- /dev/null +++ b/src/util/perf/cpu_trace.h @@ -0,0 +1,57 @@ +/* + * Copyright 2022 Google LLC + * SPDX-License-Identifier: MIT + */ + +#ifndef CPU_TRACE_H +#define CPU_TRACE_H + +/* NOTE: for now disable atrace for C++ to workaround a ndk bug with ordering + * between stdatomic.h and atomic.h. See: + * + * https://github.com/android/ndk/issues/1178 + */ +#if defined(ANDROID) && !defined(__cplusplus) + +#include + +#define MESA_TRACE_BEGIN(name) atrace_begin(ATRACE_TAG_GRAPHICS, name) +#define MESA_TRACE_END() atrace_end(ATRACE_TAG_GRAPHICS) + +#else + +/* XXX we would like to use perfetto, but it lacks a C header */ +#define MESA_TRACE_BEGIN(name) +#define MESA_TRACE_END() + +#endif /* ANDROID */ + +#if __has_attribute(cleanup) && __has_attribute(unused) + +#define MESA_TRACE_SCOPE(name) \ + int _mesa_trace_scope_##__LINE__ \ + __attribute__((cleanup(mesa_trace_scope_end), unused)) = \ + mesa_trace_scope_begin(name) + +static inline int +mesa_trace_scope_begin(const char *name) +{ + MESA_TRACE_BEGIN(name); + return 0; +} + +static inline void +mesa_trace_scope_end(int *scope) +{ + MESA_TRACE_END(); +} + +#else + +#define MESA_TRACE_SCOPE(name) + +#endif /* __has_attribute(cleanup) && __has_attribute(unused) */ + +#define MESA_TRACE_FUNC() MESA_TRACE_SCOPE(__func__) + +#endif /* CPU_TRACE_H */