From 5767d2f129458637aa0300fe04e7100d1b1947cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20=C3=85dahl?= Date: Fri, 28 Oct 2022 15:46:48 +0200 Subject: [PATCH] cogl/trace: Don't enable/disable in idle callback if thread matches This makes it possible to start profiling immediately on startup, during context/backend/display setup, as well as flush during tear down. Part-of: --- cogl/cogl/cogl-trace.c | 41 ++++++++++++++++++++++++++++------------- 1 file changed, 28 insertions(+), 13 deletions(-) diff --git a/cogl/cogl/cogl-trace.c b/cogl/cogl/cogl-trace.c index f2d0f789d..22aff2892 100644 --- a/cogl/cogl/cogl-trace.c +++ b/cogl/cogl/cogl-trace.c @@ -204,22 +204,30 @@ set_tracing_enabled_on_thread (GMainContext *main_context, const char *filename) { TraceData *data; - GSource *source; data = g_new0 (TraceData, 1); data->fd = fd; data->group = group ? strdup (group) : NULL; data->filename = filename ? strdup (filename) : NULL; - source = g_idle_source_new (); + if (main_context == g_main_context_get_thread_default ()) + { + enable_tracing_idle_callback (data); + trace_data_free (data); + } + else + { + GSource *source; + source = g_idle_source_new (); - g_source_set_callback (source, - enable_tracing_idle_callback, - data, - trace_data_free); + g_source_set_callback (source, + enable_tracing_idle_callback, + data, + trace_data_free); - g_source_attach (source, main_context); - g_source_unref (source); + g_source_attach (source, main_context); + g_source_unref (source); + } } void @@ -241,14 +249,21 @@ cogl_set_tracing_enabled_on_thread (GMainContext *main_context, void cogl_set_tracing_disabled_on_thread (GMainContext *main_context) { - GSource *source; + if (g_main_context_get_thread_default () == main_context) + { + disable_tracing_idle_callback (NULL); + } + else + { + GSource *source; - source = g_idle_source_new (); + source = g_idle_source_new (); - g_source_set_callback (source, disable_tracing_idle_callback, NULL, NULL); + g_source_set_callback (source, disable_tracing_idle_callback, NULL, NULL); - g_source_attach (source, main_context); - g_source_unref (source); + g_source_attach (source, main_context); + g_source_unref (source); + } } static void