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

Author: Emma Anholt <[email protected]>
Date:   Mon Feb  6 13:18:08 2023 -0800

u_trace: Add an interface for checking trace enablement outside a context.

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 | 14 +++++++++++++-
 src/util/perf/u_trace.h |  3 +++
 2 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/src/util/perf/u_trace.c b/src/util/perf/u_trace.c
index c57631e3d0f..fb2ac0ddadb 100644
--- a/src/util/perf/u_trace.c
+++ b/src/util/perf/u_trace.c
@@ -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)
 {
diff --git a/src/util/perf/u_trace.h b/src/util/perf/u_trace.h
index 7b2e9049025..5db696fc8bc 100644
--- a/src/util/perf/u_trace.h
+++ b/src/util/perf/u_trace.h
@@ -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

Reply via email to