mirror of
https://github.com/brl/mutter.git
synced 2025-06-14 01:09:30 +00:00
Move MetaProfiler from the backend to core
It's not really a backend thing, and we'll want to profile e.g. loading the backend too, so create it very early and destroy it very late and let MetaContextMain own it. Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2678>
This commit is contained in:
@ -74,10 +74,6 @@
|
||||
#include "meta/meta-enum-types.h"
|
||||
#include "meta/util.h"
|
||||
|
||||
#ifdef HAVE_PROFILER
|
||||
#include "backends/meta-profiler.h"
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_REMOTE_DESKTOP
|
||||
#include "backends/meta-dbus-session-watcher.h"
|
||||
#include "backends/meta-remote-access-controller-private.h"
|
||||
@ -158,10 +154,6 @@ struct _MetaBackendPrivate
|
||||
MetaRemoteDesktop *remote_desktop;
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_PROFILER
|
||||
MetaProfiler *profiler;
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_LIBWACOM
|
||||
WacomDeviceDatabase *wacom_db;
|
||||
#endif
|
||||
@ -262,10 +254,6 @@ meta_backend_dispose (GObject *object)
|
||||
|
||||
g_clear_object (&priv->settings);
|
||||
|
||||
#ifdef HAVE_PROFILER
|
||||
g_clear_object (&priv->profiler);
|
||||
#endif
|
||||
|
||||
g_clear_pointer (&priv->default_seat, clutter_seat_destroy);
|
||||
g_clear_pointer (&priv->stage, clutter_actor_destroy);
|
||||
g_clear_pointer (&priv->idle_manager, meta_idle_manager_free);
|
||||
@ -1220,10 +1208,6 @@ meta_backend_initable_init (GInitable *initable,
|
||||
system_bus_gotten_cb,
|
||||
backend);
|
||||
|
||||
#ifdef HAVE_PROFILER
|
||||
priv->profiler = meta_profiler_new ();
|
||||
#endif
|
||||
|
||||
if (!init_clutter (backend, error))
|
||||
return FALSE;
|
||||
|
||||
|
@ -1,203 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2019 Endless, Inc
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
||||
* 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "src/backends/meta-profiler.h"
|
||||
|
||||
#include <glib-unix.h>
|
||||
#include <glib/gi18n.h>
|
||||
#include <gio/gunixfdlist.h>
|
||||
|
||||
#include "cogl/cogl.h"
|
||||
|
||||
#define META_SYSPROF_PROFILER_DBUS_PATH "/org/gnome/Sysprof3/Profiler"
|
||||
|
||||
struct _MetaProfiler
|
||||
{
|
||||
MetaDBusSysprof3ProfilerSkeleton parent_instance;
|
||||
|
||||
GDBusConnection *connection;
|
||||
GCancellable *cancellable;
|
||||
|
||||
gboolean running;
|
||||
};
|
||||
|
||||
static void
|
||||
meta_sysprof_capturer_init_iface (MetaDBusSysprof3ProfilerIface *iface);
|
||||
|
||||
G_DEFINE_TYPE_WITH_CODE (MetaProfiler,
|
||||
meta_profiler,
|
||||
META_DBUS_TYPE_SYSPROF3_PROFILER_SKELETON,
|
||||
G_IMPLEMENT_INTERFACE (META_DBUS_TYPE_SYSPROF3_PROFILER,
|
||||
meta_sysprof_capturer_init_iface))
|
||||
|
||||
static gboolean
|
||||
handle_start (MetaDBusSysprof3Profiler *dbus_profiler,
|
||||
GDBusMethodInvocation *invocation,
|
||||
GUnixFDList *fd_list,
|
||||
GVariant *options,
|
||||
GVariant *fd_variant)
|
||||
{
|
||||
MetaProfiler *profiler = META_PROFILER (dbus_profiler);
|
||||
GMainContext *main_context = g_main_context_default ();
|
||||
const char *group_name;
|
||||
int position;
|
||||
int fd = -1;
|
||||
|
||||
if (profiler->running)
|
||||
{
|
||||
g_dbus_method_invocation_return_error (invocation,
|
||||
G_DBUS_ERROR,
|
||||
G_DBUS_ERROR_FAILED,
|
||||
"Profiler already running");
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
g_variant_get (fd_variant, "h", &position);
|
||||
|
||||
if (fd_list)
|
||||
fd = g_unix_fd_list_get (fd_list, position, NULL);
|
||||
|
||||
/* Translators: this string will appear in Sysprof */
|
||||
group_name = _("Compositor");
|
||||
|
||||
if (fd != -1)
|
||||
{
|
||||
cogl_set_tracing_enabled_on_thread_with_fd (main_context,
|
||||
group_name,
|
||||
fd);
|
||||
}
|
||||
else
|
||||
{
|
||||
cogl_set_tracing_enabled_on_thread (main_context,
|
||||
group_name,
|
||||
"mutter-profile.syscap");
|
||||
}
|
||||
|
||||
profiler->running = TRUE;
|
||||
|
||||
g_debug ("Profiler running");
|
||||
|
||||
meta_dbus_sysprof3_profiler_complete_start (dbus_profiler, invocation, NULL);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
handle_stop (MetaDBusSysprof3Profiler *dbus_profiler,
|
||||
GDBusMethodInvocation *invocation)
|
||||
{
|
||||
MetaProfiler *profiler = META_PROFILER (dbus_profiler);
|
||||
|
||||
if (!profiler->running)
|
||||
{
|
||||
g_dbus_method_invocation_return_error (invocation,
|
||||
G_DBUS_ERROR,
|
||||
G_DBUS_ERROR_FAILED,
|
||||
"Profiler not running");
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
cogl_set_tracing_disabled_on_thread (g_main_context_default ());
|
||||
profiler->running = FALSE;
|
||||
|
||||
g_debug ("Stopping profiler");
|
||||
|
||||
meta_dbus_sysprof3_profiler_complete_stop (dbus_profiler, invocation);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
meta_sysprof_capturer_init_iface (MetaDBusSysprof3ProfilerIface *iface)
|
||||
{
|
||||
iface->handle_start = handle_start;
|
||||
iface->handle_stop = handle_stop;
|
||||
}
|
||||
|
||||
static void
|
||||
on_bus_acquired_cb (GObject *source,
|
||||
GAsyncResult *result,
|
||||
gpointer user_data)
|
||||
{
|
||||
g_autoptr (GDBusConnection) connection = NULL;
|
||||
GDBusInterfaceSkeleton *interface_skeleton;
|
||||
g_autoptr (GError) error = NULL;
|
||||
MetaProfiler *profiler;
|
||||
|
||||
connection = g_bus_get_finish (result, &error);
|
||||
|
||||
if (error)
|
||||
{
|
||||
if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
|
||||
g_warning ("Failed to get session bus: %s", error->message);
|
||||
return;
|
||||
}
|
||||
|
||||
profiler = META_PROFILER (user_data);
|
||||
interface_skeleton = G_DBUS_INTERFACE_SKELETON (profiler);
|
||||
|
||||
if (!g_dbus_interface_skeleton_export (interface_skeleton,
|
||||
connection,
|
||||
META_SYSPROF_PROFILER_DBUS_PATH,
|
||||
&error))
|
||||
{
|
||||
g_warning ("Failed to export profiler object: %s", error->message);
|
||||
return;
|
||||
}
|
||||
|
||||
profiler->connection = g_steal_pointer (&connection);
|
||||
}
|
||||
|
||||
static void
|
||||
meta_profiler_finalize (GObject *object)
|
||||
{
|
||||
MetaProfiler *self = (MetaProfiler *)object;
|
||||
|
||||
g_cancellable_cancel (self->cancellable);
|
||||
|
||||
g_clear_object (&self->cancellable);
|
||||
g_clear_object (&self->connection);
|
||||
|
||||
G_OBJECT_CLASS (meta_profiler_parent_class)->finalize (object);
|
||||
}
|
||||
|
||||
static void
|
||||
meta_profiler_class_init (MetaProfilerClass *klass)
|
||||
{
|
||||
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
||||
|
||||
object_class->finalize = meta_profiler_finalize;
|
||||
}
|
||||
|
||||
static void
|
||||
meta_profiler_init (MetaProfiler *self)
|
||||
{
|
||||
self->cancellable = g_cancellable_new ();
|
||||
|
||||
g_bus_get (G_BUS_TYPE_SESSION,
|
||||
self->cancellable,
|
||||
on_bus_acquired_cb,
|
||||
self);
|
||||
}
|
||||
|
||||
MetaProfiler *
|
||||
meta_profiler_new (void)
|
||||
{
|
||||
return g_object_new (META_TYPE_PROFILER, NULL);
|
||||
}
|
@ -1,41 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2019 Endless, Inc
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
||||
* 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#ifndef META_PROFILER_H
|
||||
#define META_PROFILER_H
|
||||
|
||||
#include <glib-object.h>
|
||||
|
||||
#include "meta-dbus-sysprof3-profiler.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define META_TYPE_PROFILER (meta_profiler_get_type())
|
||||
|
||||
G_DECLARE_FINAL_TYPE (MetaProfiler,
|
||||
meta_profiler,
|
||||
META,
|
||||
PROFILER,
|
||||
MetaDBusSysprof3ProfilerSkeleton)
|
||||
|
||||
MetaProfiler * meta_profiler_new (void);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* META_PROFILER_H */
|
Reference in New Issue
Block a user