[mutter/gbsneto/profiling-for-real: 2303/2303] profiler: Add support for plugin captures
- From: Georges Basile Stavracas Neto <gbsneto src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [mutter/gbsneto/profiling-for-real: 2303/2303] profiler: Add support for plugin captures
- Date: Sat, 20 Aug 2022 04:25:39 +0000 (UTC)
commit 5bd8d805afbeb012a92df68ceabef2f260ccc7e7
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date: Wed Sep 2 17:28:07 2020 -0300
profiler: Add support for plugin captures
A new plugin-specific SysprofCaptureWriter is created when profiling
starts, and then is concatenated with Cogl's capture writer when
profiling stops.
src/backends/meta-profiler.c | 71 +++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 70 insertions(+), 1 deletion(-)
---
diff --git a/src/backends/meta-profiler.c b/src/backends/meta-profiler.c
index 7a18b85ce1..5d1f634d96 100644
--- a/src/backends/meta-profiler.c
+++ b/src/backends/meta-profiler.c
@@ -20,19 +20,26 @@
#include "config.h"
#include "src/backends/meta-profiler.h"
+#include "src/compositor/compositor-private.h"
+#include "src/core/display-private.h"
#include <glib-unix.h>
-#include <glib/gi18n.h>
+#include <glib/gstdio.h>
#include <gio/gunixfdlist.h>
#include "cogl/cogl.h"
+#include <sysprof-capture.h>
+
#define META_SYSPROF_PROFILER_DBUS_PATH "/org/gnome/Sysprof3/Profiler"
struct _MetaProfiler
{
MetaDBusSysprof3ProfilerSkeleton parent_instance;
+ SysprofCaptureWriter *plugin_capture;
+ char *plugin_capture_filename;
+
GDBusConnection *connection;
GCancellable *cancellable;
@@ -48,6 +55,64 @@ G_DEFINE_TYPE_WITH_CODE (MetaProfiler,
G_IMPLEMENT_INTERFACE (META_DBUS_TYPE_SYSPROF3_PROFILER,
meta_sysprof_capturer_init_iface))
+static MetaPluginManager *
+get_plugin_manager (void)
+{
+ MetaCompositor *compositor;
+
+ compositor = meta_display_get_compositor (meta_get_display ());
+ return meta_compositor_get_plugin_manager (compositor);
+}
+
+static void
+setup_plugin_capture_writer (MetaProfiler *profiler)
+{
+ g_autofree char *tmpname = NULL;
+ int fd;
+
+ fd = g_file_open_tmp (".mutter-sysprof-plugin-XXXXXX", &tmpname, NULL);
+
+ if (fd == -1)
+ return;
+
+ profiler->plugin_capture = sysprof_capture_writer_new_from_fd (fd, 4096 * 4);
+ profiler->plugin_capture_filename = g_steal_pointer (&tmpname);
+
+ meta_plugin_manager_start_profiler (get_plugin_manager (),
+ profiler->plugin_capture);
+}
+
+static void
+teardown_plugin_capture_writer (MetaProfiler *profiler)
+{
+ SysprofCaptureReader *plugin_capture_reader = NULL;
+ SysprofCaptureWriter *cogl_capture;
+
+ if (!profiler->plugin_capture)
+ return;
+
+ meta_plugin_manager_stop_profiler (get_plugin_manager ());
+
+ cogl_capture = cogl_acquire_capture_writer ();
+
+ if (!cogl_capture)
+ goto out;
+
+ sysprof_capture_writer_flush (profiler->plugin_capture);
+
+ plugin_capture_reader =
+ sysprof_capture_writer_create_reader (profiler->plugin_capture);
+ sysprof_capture_writer_cat (cogl_capture, plugin_capture_reader);
+
+out:
+ g_unlink (profiler->plugin_capture_filename);
+
+ g_clear_pointer (&plugin_capture_reader, sysprof_capture_reader_unref);
+ g_clear_pointer (&profiler->plugin_capture_filename, g_free);
+
+ cogl_release_capture_writer ();
+}
+
static gboolean
handle_start (MetaDBusSysprof3Profiler *dbus_profiler,
GDBusMethodInvocation *invocation,
@@ -95,6 +160,8 @@ handle_start (MetaDBusSysprof3Profiler *dbus_profiler,
g_debug ("Profiler running");
+ setup_plugin_capture_writer (profiler);
+
meta_dbus_sysprof3_profiler_complete_start (dbus_profiler, invocation, NULL);
return TRUE;
}
@@ -114,6 +181,8 @@ handle_stop (MetaDBusSysprof3Profiler *dbus_profiler,
return TRUE;
}
+ teardown_plugin_capture_writer (profiler);
+
cogl_set_tracing_disabled_on_thread (g_main_context_default ());
profiler->running = FALSE;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]