util/perf: add u_trace_instrument
authorChia-I Wu <olvaffe@gmail.com>
Mon, 29 Aug 2022 23:38:30 +0000 (16:38 -0700)
committerMarge Bot <emma+marge@anholt.net>
Fri, 2 Sep 2022 19:46:50 +0000 (19:46 +0000)
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
src/util/perf/u_trace.c
src/util/perf/u_trace.h
src/util/perf/u_trace.py

index 419d7e9..ce03470 100644 (file)
@@ -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);
index 116ed9e..2bd80d9 100644 (file)
@@ -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;
    }
index b9bfb1d..fcee749 100644 (file)
@@ -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)
 {
index d9536fc..9b9fbce 100644 (file)
@@ -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