diff --git a/src/core/meta-context-main.c b/src/core/meta-context-main.c index f673432f5..b40384f13 100644 --- a/src/core/meta-context-main.c +++ b/src/core/meta-context-main.c @@ -73,6 +73,7 @@ typedef struct _MetaContextMainOptions #ifdef HAVE_NATIVE_BACKEND GList *virtual_monitor_infos; #endif + char *trace_file; } MetaContextMainOptions; struct _MetaContextMain @@ -298,6 +299,10 @@ meta_context_main_configure (MetaContext *context, context_main->options.sm.client_id = g_strdup (desktop_autostart_id); } +#ifdef HAVE_PROFILER + meta_context_set_trace_file (context, context_main->options.trace_file); +#endif + g_unsetenv ("DESKTOP_AUTOSTART_ID"); return TRUE; @@ -662,6 +667,12 @@ meta_context_main_add_option_entries (MetaContextMain *context_main) N_("Run with X11 backend") }, #endif + { + "profile", 0, 0, G_OPTION_ARG_FILENAME, + &context_main->options.trace_file, + N_("Profile performance using trace instrumentation"), + "FILE" + }, { NULL } }; diff --git a/src/core/meta-context-private.h b/src/core/meta-context-private.h index ec69fd0ca..cb23e621b 100644 --- a/src/core/meta-context-private.h +++ b/src/core/meta-context-private.h @@ -86,6 +86,9 @@ gboolean meta_context_is_x11_sync (MetaContext *context); #ifdef HAVE_PROFILER MetaProfiler * meta_context_get_profiler (MetaContext *context); + +void meta_context_set_trace_file (MetaContext *context, + const char *trace_file); #endif #endif /* META_CONTEXT_PRIVATE_H */ diff --git a/src/core/meta-context.c b/src/core/meta-context.c index fa9cf052f..a85cb2cc6 100644 --- a/src/core/meta-context.c +++ b/src/core/meta-context.c @@ -98,6 +98,7 @@ typedef struct _MetaContextPrivate #endif #ifdef HAVE_PROFILER + char *trace_file; MetaProfiler *profiler; #endif @@ -292,6 +293,15 @@ meta_context_get_profiler (MetaContext *context) return priv->profiler; } + +void +meta_context_set_trace_file (MetaContext *context, + const char *trace_file) +{ + MetaContextPrivate *priv = meta_context_get_instance_private (context); + + priv->trace_file = g_strdup (trace_file); +} #endif static gboolean @@ -343,6 +353,10 @@ meta_context_configure (MetaContext *context, return FALSE; } +#ifdef HAVE_PROFILER + priv->profiler = meta_profiler_new (priv->trace_file); +#endif + compositor_type = meta_context_get_compositor_type (context); switch (compositor_type) { @@ -739,6 +753,7 @@ meta_context_finalize (GObject *object) #ifdef HAVE_PROFILER g_clear_object (&priv->profiler); + g_clear_pointer (&priv->trace_file, g_free); #endif g_clear_pointer (&priv->gnome_wm_keybindings, g_free); @@ -801,10 +816,6 @@ meta_context_init (MetaContext *context) MetaContextPrivate *priv = meta_context_get_instance_private (context); g_autoptr (GError) error = NULL; -#ifdef HAVE_PROFILER - priv->profiler = meta_profiler_new (); -#endif - priv->plugin_gtype = G_TYPE_NONE; priv->gnome_wm_keybindings = g_strdup ("Mutter"); diff --git a/src/core/meta-profiler.c b/src/core/meta-profiler.c index 9d098f4ae..453cbd4d4 100644 --- a/src/core/meta-profiler.c +++ b/src/core/meta-profiler.c @@ -265,8 +265,6 @@ meta_profiler_class_init (MetaProfilerClass *klass) static void meta_profiler_init (MetaProfiler *self) { - const char *env_trace_file; - g_mutex_init (&self->mutex); self->cancellable = g_cancellable_new (); @@ -274,9 +272,16 @@ meta_profiler_init (MetaProfiler *self) self->cancellable, on_bus_acquired_cb, self); +} - env_trace_file = g_getenv ("MUTTER_DEBUG_TRACE_FILE"); - if (env_trace_file && env_trace_file[0]) +MetaProfiler * +meta_profiler_new (const char *trace_file) +{ + MetaProfiler *profiler; + + profiler = g_object_new (META_TYPE_PROFILER, NULL); + + if (trace_file) { GMainContext *main_context = g_main_context_default (); const char *group_name; @@ -286,15 +291,11 @@ meta_profiler_init (MetaProfiler *self) cogl_set_tracing_enabled_on_thread (main_context, group_name, - env_trace_file); - self->persistent = TRUE; + trace_file); + profiler->persistent = TRUE; } -} -MetaProfiler * -meta_profiler_new (void) -{ - return g_object_new (META_TYPE_PROFILER, NULL); + return profiler; } void diff --git a/src/core/meta-profiler.h b/src/core/meta-profiler.h index 6c08dc4ad..2ff5edf66 100644 --- a/src/core/meta-profiler.h +++ b/src/core/meta-profiler.h @@ -34,7 +34,7 @@ G_DECLARE_FINAL_TYPE (MetaProfiler, PROFILER, MetaDBusSysprof3ProfilerSkeleton) -MetaProfiler * meta_profiler_new (void); +MetaProfiler * meta_profiler_new (const char *trace_file); void meta_profiler_register_thread (MetaProfiler *profiler, GMainContext *main_context,