util/perf: add cpu_trace.h
authorChia-I Wu <olvaffe@gmail.com>
Thu, 25 Aug 2022 21:10:20 +0000 (14:10 -0700)
committerMarge Bot <emma+marge@anholt.net>
Fri, 26 Aug 2022 21:47:44 +0000 (21:47 +0000)
Move MESA_TRACE_* to the new file.

Acked-by: Rob Clark <robdclark@chromium.org>
Reviewed-by: Antonio Caggiano <antonio.caggiano@collabora.com>
Reviewed-by: Yiwei Zhang <zzyiwei@chromium.org>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/18260>

src/egl/main/eglapi.c
src/freedreno/drm/virtio/virtio_priv.h
src/util/log.h
src/util/perf/cpu_trace.h [new file with mode: 0644]

index 95a5e76..d308f08 100644 (file)
@@ -95,8 +95,8 @@
 #include <string.h>
 #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"
index 83fb8c9..32ff89a 100644 (file)
@@ -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"
index 047d196..d9e965a 100644 (file)
@@ -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 <cutils/trace.h>
-
-#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 (file)
index 0000000..2cd510a
--- /dev/null
@@ -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 <cutils/trace.h>
+
+#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 */