context: Start persistent profiling via command line argument

Persistent profiling was started via an env var, but that's rather hard
to discover and remember without grepping; change to use a command line
argument.

The profiler is started early, even during (though late in)
configuration, but configuration should ideally be instant and pointless
to configure.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2998>
This commit is contained in:
Jonas Ådahl 2023-05-10 22:26:08 +02:00 committed by Marge Bot
parent e16d683721
commit 1ca76e9b9c
5 changed files with 42 additions and 16 deletions

View File

@ -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 }
};

View File

@ -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 */

View File

@ -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");

View File

@ -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

View File

@ -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,