diff options
author | Georges Basile Stavracas Neto <georges.stavracas@gmail.com> | 2020-09-02 17:28:07 -0300 |
---|---|---|
committer | Georges Basile Stavracas Neto <georges.stavracas@gmail.com> | 2022-08-20 01:07:10 -0300 |
commit | 5bd8d805afbeb012a92df68ceabef2f260ccc7e7 (patch) | |
tree | 6c4e5fe9e3af7757b013de86e0df036c1c2e889c | |
parent | 2866af72c4c7eda8565990fff40bc83dd014a273 (diff) | |
download | mutter-gbsneto/profiling-for-real.tar.gz |
profiler: Add support for plugin capturesgbsneto/profiling-for-real
A new plugin-specific SysprofCaptureWriter is created when profiling
starts, and then is concatenated with Cogl's capture writer when
profiling stops.
-rw-r--r-- | src/backends/meta-profiler.c | 71 |
1 files changed, 70 insertions, 1 deletions
diff --git a/src/backends/meta-profiler.c b/src/backends/meta-profiler.c index 7a18b85ce..5d1f634d9 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; |