[gnome-shell/gbsneto/profiling-for-real: 142/142] plugin: Implement profiling vfuncs




commit 9548b72e9ba8e6eead75adf2437458754f611e0f
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Wed Sep 2 17:35:23 2020 -0300

    plugin: Implement profiling vfuncs
    
    Use the new GJS API to pass an external capture writer, and
    start/stop whenever the compositor asks us to do so.
    
    https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1430

 src/gnome-shell-plugin.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++
 src/shell-global.c       |  3 +++
 2 files changed, 50 insertions(+)
---
diff --git a/src/gnome-shell-plugin.c b/src/gnome-shell-plugin.c
index 41641948b2..b8af62b6c9 100644
--- a/src/gnome-shell-plugin.c
+++ b/src/gnome-shell-plugin.c
@@ -353,6 +353,48 @@ gnome_shell_plugin_locate_pointer (MetaPlugin *plugin)
   _shell_global_locate_pointer (shell_plugin->global);
 }
 
+#ifdef COGL_HAS_TRACING
+static void
+gnome_shell_plugin_start_profiler (MetaPlugin           *plugin,
+                                   SysprofCaptureWriter *writer)
+{
+  ShellGlobal *global;
+  GjsProfiler *profiler;
+  GjsContext *context;
+
+  global = shell_global_get ();
+  g_return_if_fail (global);
+
+  context = _shell_global_get_gjs_context (global);
+  g_return_if_fail (context);
+
+  profiler = gjs_context_get_profiler (context);
+  g_return_if_fail (profiler);
+
+  gjs_profiler_set_capture_writer (profiler, writer);
+  gjs_profiler_start (profiler);
+}
+
+static void
+gnome_shell_plugin_stop_profiler (MetaPlugin *plugin)
+{
+  ShellGlobal *global;
+  GjsProfiler *profiler;
+  GjsContext *context;
+
+  global = shell_global_get ();
+  g_return_if_fail (global);
+
+  context = _shell_global_get_gjs_context (global);
+  g_return_if_fail (context);
+
+  profiler = gjs_context_get_profiler (context);
+  g_return_if_fail (profiler);
+
+  gjs_profiler_stop (profiler);
+}
+#endif
+
 static void
 gnome_shell_plugin_class_init (GnomeShellPluginClass *klass)
 {
@@ -387,6 +429,11 @@ gnome_shell_plugin_class_init (GnomeShellPluginClass *klass)
   plugin_class->create_inhibit_shortcuts_dialog = gnome_shell_plugin_create_inhibit_shortcuts_dialog;
 
   plugin_class->locate_pointer = gnome_shell_plugin_locate_pointer;
+
+#ifdef COGL_HAS_TRACING
+  plugin_class->start_profiler = gnome_shell_plugin_start_profiler;
+  plugin_class->stop_profiler = gnome_shell_plugin_stop_profiler;
+#endif
 }
 
 static void
diff --git a/src/shell-global.c b/src/shell-global.c
index d115a6c333..b52e2071b5 100644
--- a/src/shell-global.c
+++ b/src/shell-global.c
@@ -420,6 +420,9 @@ shell_global_init (ShellGlobal *global)
 
   global->js_context = g_object_new (GJS_TYPE_CONTEXT,
                                      "search-path", search_path,
+#ifdef COGL_HAS_TRACING
+                                     "profiler-enabled", TRUE,
+#endif
                                      NULL);
 
   g_strfreev (search_path);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]