u_trace: Add an interface for checking trace enablement outside a context.
authorEmma Anholt <emma@anholt.net>
Mon, 6 Feb 2023 21:18:08 +0000 (13:18 -0800)
committerMarge Bot <emma+marge@anholt.net>
Thu, 9 Feb 2023 03:27:34 +0000 (03:27 +0000)
For zink, we want to know if we should pass command stream markers down to
the underlying driver, but we don't have our own trace context we're
recording trace events with.  We definitely want those markers if the
underlying driver is going to be doing perfetto tracing, or is requesting
marker tracing.  So, create an interface for querying those flags before
they get copied down to an actual u_trace_context.

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

src/util/perf/u_trace.c
src/util/perf/u_trace.h

index c57631e..fb2ac0d 100644 (file)
@@ -394,12 +394,24 @@ u_trace_state_init_once(void)
    }
 }
 
-static void
+void
 u_trace_state_init(void)
 {
    util_call_once(&u_trace_state.once, u_trace_state_init_once);
 }
 
+bool
+u_trace_is_enabled(enum u_trace_type type)
+{
+   /* Active is only tracked in a given u_trace context, so if you're asking us
+    * if U_TRACE_TYPE_PERFETTO (_ENV | _ACTIVE) is enabled, then just check
+    * _ENV ("perfetto tracing is desired, but perfetto might not be running").
+    */
+   type &= ~U_TRACE_TYPE_PERFETTO_ACTIVE;
+
+   return (u_trace_state.enabled_traces & type) == type;
+}
+
 static void
 queue_init(struct u_trace_context *utctx)
 {
index 7b2e904..5db696f 100644 (file)
@@ -234,6 +234,9 @@ void u_trace_context_process(struct u_trace_context *utctx, bool eof);
 void u_trace_init(struct u_trace *ut, struct u_trace_context *utctx);
 void u_trace_fini(struct u_trace *ut);
 
+void u_trace_state_init(void);
+bool u_trace_is_enabled(enum u_trace_type type);
+
 bool u_trace_has_points(struct u_trace *ut);
 
 struct u_trace_iterator