From 1efb93e145fdd2a7746f1af33e5c7bdabc79ea08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20=C3=85dahl?= Date: Thu, 13 Oct 2022 14:52:59 +0200 Subject: [PATCH] profiler: Allow enable tracing via env var This is helpful to e.g. trace e.g. launching. Part-of: --- src/core/meta-profiler.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/core/meta-profiler.c b/src/core/meta-profiler.c index f4484a2ae..86585ae89 100644 --- a/src/core/meta-profiler.c +++ b/src/core/meta-profiler.c @@ -36,6 +36,7 @@ struct _MetaProfiler GDBusConnection *connection; GCancellable *cancellable; + gboolean persistent; gboolean running; }; @@ -105,6 +106,15 @@ handle_stop (MetaDBusSysprof3Profiler *dbus_profiler, { MetaProfiler *profiler = META_PROFILER (dbus_profiler); + if (profiler->persistent) + { + g_dbus_method_invocation_return_error (invocation, + G_DBUS_ERROR, + G_DBUS_ERROR_FAILED, + "Can't stop persistent profiling"); + return TRUE; + } + if (!profiler->running) { g_dbus_method_invocation_return_error (invocation, @@ -188,12 +198,28 @@ meta_profiler_class_init (MetaProfilerClass *klass) static void meta_profiler_init (MetaProfiler *self) { + const char *env_trace_file; + self->cancellable = g_cancellable_new (); g_bus_get (G_BUS_TYPE_SESSION, self->cancellable, on_bus_acquired_cb, self); + + env_trace_file = g_getenv ("MUTTER_DEBUG_TRACE_FILE"); + if (env_trace_file && env_trace_file[0]) + { + GMainContext *main_context = g_main_context_default (); + const char *group_name; + + /* Translators: this string will appear in Sysprof */ + group_name = _("Compositor"); + + cogl_set_tracing_enabled_on_thread (main_context, + group_name, + env_trace_file); + } } MetaProfiler *