Module: Mesa
Branch: main
Commit: 18d7cb4abbd65b6eb1091d902245271dc49cd8ed
URL:    
http://cgit.freedesktop.org/mesa/mesa/commit/?id=18d7cb4abbd65b6eb1091d902245271dc49cd8ed

Author: Chia-I Wu <[email protected]>
Date:   Mon Aug 29 16:38:30 2022 -0700

util/perf: add u_trace_instrument

It is called from tracepoints.  When it returns false, instrumentation
is disabled.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/18309>

---

 src/gallium/auxiliary/util/u_trace_gallium.c |  2 +-
 src/util/perf/u_trace.c                      |  4 ++--
 src/util/perf/u_trace.h                      | 17 +++++++++++------
 src/util/perf/u_trace.py                     |  7 +------
 4 files changed, 15 insertions(+), 15 deletions(-)

diff --git a/src/gallium/auxiliary/util/u_trace_gallium.c 
b/src/gallium/auxiliary/util/u_trace_gallium.c
index 419d7e93ac6..ce034703a6f 100644
--- a/src/gallium/auxiliary/util/u_trace_gallium.c
+++ b/src/gallium/auxiliary/util/u_trace_gallium.c
@@ -76,7 +76,7 @@ u_trace_pipe_context_init(struct u_trace_context *utctx,
 inline void
 trace_framebuffer_state(struct u_trace *ut, void *cs, const struct 
pipe_framebuffer_state *pfb)
 {
-   if (likely(!(ut_trace_instrument || ut_perfetto_enabled)))
+   if (likely(!u_trace_instrument()))
       return;
 
    trace_framebuffer(ut, cs, pfb);
diff --git a/src/util/perf/u_trace.c b/src/util/perf/u_trace.c
index 116ed9edb7f..2bd80d98e95 100644
--- a/src/util/perf/u_trace.c
+++ b/src/util/perf/u_trace.c
@@ -38,7 +38,7 @@
 #define TIMESTAMP_BUF_SIZE 0x1000
 #define TRACES_PER_CHUNK   (TIMESTAMP_BUF_SIZE / sizeof(uint64_t))
 
-bool ut_trace_instrument;
+bool _u_trace_instrument;
 
 #ifdef HAVE_PERFETTO
 int ut_perfetto_enabled;
@@ -369,7 +369,7 @@ get_tracefile(void)
          tracefile = stdout;
       }
 
-      ut_trace_instrument = tracefile || debug_get_option_trace_instrument();
+      _u_trace_instrument = tracefile || debug_get_option_trace_instrument();
 
       firsttime = false;
    }
diff --git a/src/util/perf/u_trace.h b/src/util/perf/u_trace.h
index b9bfb1ded21..fcee7499891 100644
--- a/src/util/perf/u_trace.h
+++ b/src/util/perf/u_trace.h
@@ -270,12 +270,6 @@ void u_trace_disable_event_range(struct u_trace_iterator 
begin_it,
  */
 void u_trace_flush(struct u_trace *ut, void *flush_data, bool free_data);
 
-/**
- * Whether command buffers should be instrumented even if not collecting
- * traces.
- */
-extern bool ut_trace_instrument;
-
 #ifdef HAVE_PERFETTO
 extern int ut_perfetto_enabled;
 
@@ -285,6 +279,17 @@ void u_trace_perfetto_stop(void);
 #  define ut_perfetto_enabled 0
 #endif
 
+/**
+ * Return whether instrumentations should be enabled or not.  This is called
+ * from tracepoints.
+ */
+static inline bool
+u_trace_instrument(void)
+{
+   extern bool _u_trace_instrument;
+   return _u_trace_instrument || ut_perfetto_enabled;
+}
+
 static inline bool
 u_trace_context_actively_tracing(struct u_trace_context *utctx)
 {
diff --git a/src/util/perf/u_trace.py b/src/util/perf/u_trace.py
index d9536fccea5..9b9fbceff74 100644
--- a/src/util/perf/u_trace.py
+++ b/src/util/perf/u_trace.py
@@ -252,13 +252,8 @@ static inline void trace_${trace_name}(
    , ${arg.type} ${arg.var}
 %    endfor
 ) {
-%    if trace.tp_perfetto is not None:
-   if (!unlikely((ut_trace_instrument || ut_perfetto_enabled) &&
-                 ${trace.enabled_expr(trace_toggle_name)}))
-%    else:
-   if (!unlikely(ut_trace_instrument &&
+   if (!unlikely(u_trace_instrument() &&
                  ${trace.enabled_expr(trace_toggle_name)}))
-%    endif
       return;
    __trace_${trace_name}(
         ut

Reply via email to