Blame SOURCES/perf-tool-wayland.patch

5731ec
From 119ec213b8f9a9e55ca340dbde10b0d19becab41 Mon Sep 17 00:00:00 2001
441107
From: =?UTF-8?q?Florian=20M=C3=BCllner?= <fmuellner@gnome.org>
441107
Date: Thu, 5 Dec 2019 14:12:47 +0100
5731ec
Subject: [PATCH 1/4] perf-helper: Add content for custom drawing
441107
441107
Drawing windows got a lot more involved with the advent of client-side
441107
decorations. Instead of accounting for visible and invisible borders,
441107
titlebar and shadows when necessary, just add an empty child for the
441107
custom drawing.
441107
441107
https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/887
441107
---
441107
 src/shell-perf-helper.c | 12 ++++++++----
441107
 1 file changed, 8 insertions(+), 4 deletions(-)
441107
441107
diff --git a/src/shell-perf-helper.c b/src/shell-perf-helper.c
5731ec
index e5eab208b..55bdbef02 100644
441107
--- a/src/shell-perf-helper.c
441107
+++ b/src/shell-perf-helper.c
5731ec
@@ -120,9 +120,9 @@ on_window_map_event (GtkWidget   *window,
441107
 }
441107
 
441107
 static gboolean
441107
-on_window_draw (GtkWidget  *window,
441107
-		cairo_t    *cr,
441107
-                WindowInfo *info)
441107
+on_child_draw (GtkWidget  *window,
441107
+               cairo_t    *cr,
441107
+               WindowInfo *info)
441107
 {
441107
   cairo_rectangle_int_t allocation;
441107
   double x_offset, y_offset;
5731ec
@@ -204,6 +204,7 @@ create_window (int      width,
441107
                gboolean redraws)
441107
 {
441107
   WindowInfo *info;
441107
+  GtkWidget *child;
441107
 
441107
   info = g_new0 (WindowInfo, 1);
441107
   info->width = width;
5731ec
@@ -219,10 +220,13 @@ create_window (int      width,
441107
   info->pending = TRUE;
441107
   info->start_time = -1;
441107
 
441107
+  child = g_object_new (GTK_TYPE_BOX, "visible", TRUE, "app-paintable", TRUE, NULL);
441107
+  gtk_container_add (GTK_CONTAINER (info->window), child);
441107
+
441107
   gtk_widget_set_size_request (info->window, width, height);
441107
   gtk_widget_set_app_paintable (info->window, TRUE);
441107
   g_signal_connect (info->window, "map-event", G_CALLBACK (on_window_map_event), info);
441107
-  g_signal_connect (info->window, "draw", G_CALLBACK (on_window_draw), info);
441107
+  g_signal_connect (child, "draw", G_CALLBACK (on_child_draw), info);
441107
   gtk_widget_show (info->window);
441107
 
441107
   if (info->redraws)
441107
-- 
5731ec
2.26.2
441107
441107
5731ec
From bb4c2acaef4d8fdea50915030c221e1190f704a4 Mon Sep 17 00:00:00 2001
441107
From: =?UTF-8?q?Florian=20M=C3=BCllner?= <fmuellner@gnome.org>
441107
Date: Thu, 5 Dec 2019 13:29:38 +0100
5731ec
Subject: [PATCH 2/4] perf-helper: Remove unused atoms
441107
441107
Those aren't used for anything, but make the helper dependent on X11.
441107
441107
https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/887
441107
---
441107
 src/shell-perf-helper.c | 18 ------------------
441107
 1 file changed, 18 deletions(-)
441107
441107
diff --git a/src/shell-perf-helper.c b/src/shell-perf-helper.c
5731ec
index 55bdbef02..d3280de96 100644
441107
--- a/src/shell-perf-helper.c
441107
+++ b/src/shell-perf-helper.c
441107
@@ -12,7 +12,6 @@
441107
 #include <math.h>
441107
 
441107
 #include <gtk/gtk.h>
441107
-#include <gdk/gdkx.h>
441107
 
441107
 #define BUS_NAME "org.gnome.Shell.PerfHelper"
441107
 
441107
@@ -60,12 +59,6 @@ static GOptionEntry opt_entries[] =
441107
     { NULL }
441107
   };
441107
 
441107
-static Display *xdisplay;
441107
-static Window xroot;
441107
-static Atom atom_wm_state;
441107
-static Atom atom__net_wm_name;
441107
-static Atom atom_utf8_string;
441107
-
441107
 static guint timeout_id;
441107
 static GList *our_windows;
441107
 static GList *wait_windows_invocations;
5731ec
@@ -351,8 +344,6 @@ on_name_lost  (GDBusConnection *connection,
441107
 int
441107
 main (int argc, char **argv)
441107
 {
441107
-  GdkDisplay *display;
441107
-  GdkScreen *screen;
441107
   GOptionContext *context;
441107
   GError *error = NULL;
441107
 
5731ec
@@ -368,15 +359,6 @@ main (int argc, char **argv)
441107
       return 1;
441107
     }
441107
 
441107
-  display = gdk_display_get_default ();
441107
-  screen = gdk_screen_get_default ();
441107
-
441107
-  xdisplay = gdk_x11_display_get_xdisplay (display);
441107
-  xroot = gdk_x11_window_get_xid (gdk_screen_get_root_window (screen));
441107
-  atom_wm_state = gdk_x11_get_xatom_by_name_for_display (display, "WM_STATE");
441107
-  atom__net_wm_name = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_NAME");
441107
-  atom_utf8_string = gdk_x11_get_xatom_by_name_for_display (display, "UTF8_STRING");
441107
-
441107
   g_bus_own_name (G_BUS_TYPE_SESSION,
441107
                   BUS_NAME,
441107
                   G_BUS_NAME_OWNER_FLAGS_ALLOW_REPLACEMENT |
441107
-- 
5731ec
2.26.2
5731ec
5731ec
5731ec
From d8b4d72b89340dab46bdcb92ee54bde18dbb9ba9 Mon Sep 17 00:00:00 2001
5731ec
From: Olivier Fourdan <ofourdan@redhat.com>
5731ec
Date: Fri, 24 Jan 2020 10:59:31 +0100
5731ec
Subject: [PATCH 3/4] perf-tool: Spawn perf-tool-helper from gnome-shell
5731ec
5731ec
On Wayland, the display server is the Wayland compositor, i.e.
5731ec
`gnome-shell` itself.
5731ec
5731ec
As a result, we cannot spawn `gnome-shell-perf-helper` before
5731ec
`gnome-shell` is started, as `gnome-shell-perf-helper` needs to connect
5731ec
to the display server.
5731ec
5731ec
So, instead of spawning `gnome-shell-perf-helper` from the perf tool,
5731ec
start it from `gnome-shell` itself.
5731ec
5731ec
https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/941
5731ec
---
5731ec
 js/ui/scripting.js           | 51 ++++++++++++++++++++++------------
5731ec
 src/gnome-shell-perf-tool.in | 53 ------------------------------------
5731ec
 2 files changed, 34 insertions(+), 70 deletions(-)
5731ec
5731ec
diff --git a/js/ui/scripting.js b/js/ui/scripting.js
5731ec
index d227b9ef4..eef8f3887 100644
5731ec
--- a/js/ui/scripting.js
5731ec
+++ b/js/ui/scripting.js
5731ec
@@ -3,8 +3,10 @@
5731ec
 const { Gio, GLib, Meta, Shell } = imports.gi;
5731ec
 const Mainloop = imports.mainloop;
5731ec
 
5731ec
+const Config = imports.misc.config;
5731ec
 const Main = imports.ui.main;
5731ec
 const Params = imports.misc.params;
5731ec
+const Util = imports.misc.util;
5731ec
 
5731ec
 const { loadInterfaceXML } = imports.misc.fileUtils;
5731ec
 
5731ec
@@ -73,6 +75,12 @@ function _getPerfHelper() {
5731ec
     return _perfHelper;
5731ec
 }
5731ec
 
5731ec
+function _spawnPerfHelper() {
5731ec
+    let path = Config.LIBEXECDIR;
5731ec
+    let command = `${path}/gnome-shell-perf-helper`;
5731ec
+    Util.trySpawnCommandLine(command);
5731ec
+}
5731ec
+
5731ec
 function _callRemote(obj, method, ...args) {
5731ec
     return new Promise((resolve, reject) => {
5731ec
         args.push((result, excp) => {
5731ec
@@ -270,6 +278,25 @@ function _collect(scriptModule, outputFile) {
5731ec
     }
5731ec
 }
5731ec
 
5731ec
+async function _runPerfScript(scriptModule, outputFile) {
5731ec
+    for (let step of scriptModule.run()) {
5731ec
+        try {
5731ec
+            await step; // eslint-disable-line no-await-in-loop
5731ec
+        } catch (err) {
5731ec
+            log(`Script failed: ${err}\n${err.stack}`);
5731ec
+            Meta.exit(Meta.ExitCode.ERROR);
5731ec
+        }
5731ec
+    }
5731ec
+
5731ec
+    try {
5731ec
+        _collect(scriptModule, outputFile);
5731ec
+    } catch (err) {
5731ec
+        log(`Script failed: ${err}\n${err.stack}`);
5731ec
+        Meta.exit(Meta.ExitCode.ERROR);
5731ec
+    }
5731ec
+    Meta.exit(Meta.ExitCode.SUCCESS);
5731ec
+}
5731ec
+
5731ec
 /**
5731ec
  * runPerfScript
5731ec
  * @scriptModule: module object with run and finish functions
5731ec
@@ -310,23 +337,13 @@ function _collect(scriptModule, outputFile) {
5731ec
  * After running the script and collecting statistics from the
5731ec
  * event log, GNOME Shell will exit.
5731ec
  **/
5731ec
-async function runPerfScript(scriptModule, outputFile) {
5731ec
+function runPerfScript(scriptModule, outputFile) {
5731ec
     Shell.PerfLog.get_default().set_enabled(true);
5731ec
+    _spawnPerfHelper();
5731ec
 
5731ec
-    for (let step of scriptModule.run()) {
5731ec
-        try {
5731ec
-            await step;
5731ec
-        } catch (err) {
5731ec
-            log(`Script failed: ${err}\n${err.stack}`);
5731ec
-            Meta.exit(Meta.ExitCode.ERROR);
5731ec
-        }
5731ec
-    }
5731ec
-
5731ec
-    try {
5731ec
-        _collect(scriptModule, outputFile);
5731ec
-    } catch (err) {
5731ec
-        log(`Script failed: ${err}\n${err.stack}`);
5731ec
-        Meta.exit(Meta.ExitCode.ERROR);
5731ec
-    }
5731ec
-    Meta.exit(Meta.ExitCode.SUCCESS);
5731ec
+    Gio.bus_watch_name(Gio.BusType.SESSION,
5731ec
+        'org.gnome.Shell.PerfHelper',
5731ec
+        Gio.BusNameWatcherFlags.NONE,
5731ec
+        () => _runPerfScript(scriptModule, outputFile),
5731ec
+        null);
5731ec
 }
5731ec
diff --git a/src/gnome-shell-perf-tool.in b/src/gnome-shell-perf-tool.in
5731ec
index f4b48f730..050c66b30 100755
5731ec
--- a/src/gnome-shell-perf-tool.in
5731ec
+++ b/src/gnome-shell-perf-tool.in
5731ec
@@ -24,52 +24,6 @@ def show_version(option, opt_str, value, parser):
5731ec
     print("GNOME Shell Performance Test @VERSION@")
5731ec
     sys.exit()
5731ec
 
5731ec
-def wait_for_dbus_name(wait_name):
5731ec
-    loop = GLib.MainLoop()
5731ec
-
5731ec
-    def on_name_appeared(connection, name, new_owner, *args):
5731ec
-        if not (name == wait_name and new_owner != ''):
5731ec
-            return
5731ec
-        loop.quit()
5731ec
-        return
5731ec
-
5731ec
-    watch_id = Gio.bus_watch_name(Gio.BusType.SESSION,
5731ec
-                                  wait_name,
5731ec
-                                  Gio.BusNameWatcherFlags.NONE,
5731ec
-                                  on_name_appeared,
5731ec
-                                  None)
5731ec
-
5731ec
-    def on_timeout():
5731ec
-        print("\nFailed to start %s: timed out" % (wait_name,))
5731ec
-        sys.exit(1)
5731ec
-    GLib.timeout_add_seconds(7, on_timeout)
5731ec
-
5731ec
-    loop.run()
5731ec
-    Gio.bus_unwatch_name(watch_id)
5731ec
-
5731ec
-PERF_HELPER_NAME = "org.gnome.Shell.PerfHelper"
5731ec
-PERF_HELPER_IFACE = "org.gnome.Shell.PerfHelper"
5731ec
-PERF_HELPER_PATH = "/org/gnome/Shell/PerfHelper"
5731ec
-
5731ec
-def start_perf_helper():
5731ec
-    self_dir = os.path.dirname(os.path.abspath(sys.argv[0]))
5731ec
-    perf_helper_path = "@libexecdir@/gnome-shell-perf-helper"
5731ec
-
5731ec
-    subprocess.Popen([perf_helper_path])
5731ec
-    wait_for_dbus_name (PERF_HELPER_NAME)
5731ec
-
5731ec
-def stop_perf_helper():
5731ec
-    bus = Gio.bus_get_sync(Gio.BusType.SESSION, None)
5731ec
-
5731ec
-    proxy = Gio.DBusProxy.new_sync(bus,
5731ec
-                                   Gio.DBusProxyFlags.NONE,
5731ec
-                                   None,
5731ec
-                                   PERF_HELPER_NAME,
5731ec
-                                   PERF_HELPER_PATH,
5731ec
-                                   PERF_HELPER_IFACE,
5731ec
-                                   None)
5731ec
-    proxy.Exit()
5731ec
-
5731ec
 def start_shell(perf_output=None):
5731ec
     # Set up environment
5731ec
     env = dict(os.environ)
5731ec
@@ -204,8 +158,6 @@ def run_performance_test():
5731ec
     logs = []
5731ec
     metric_summaries = {}
5731ec
 
5731ec
-    start_perf_helper()
5731ec
-
5731ec
     for i in range(0, iters):
5731ec
         # We create an empty temporary file that the shell will overwrite
5731ec
         # with the contents.
5731ec
@@ -217,14 +169,12 @@ def run_performance_test():
5731ec
         try:
5731ec
             normal_exit = run_shell(perf_output=output_file)
5731ec
         except:
5731ec
-            stop_perf_helper()
5731ec
             raise
5731ec
         finally:
5731ec
             if not normal_exit:
5731ec
                 os.remove(output_file)
5731ec
 
5731ec
         if not normal_exit:
5731ec
-            stop_perf_helper()
5731ec
             return False
5731ec
 
5731ec
         try:
5731ec
@@ -232,7 +182,6 @@ def run_performance_test():
5731ec
             output = json.load(f)
5731ec
             f.close()
5731ec
         except:
5731ec
-            stop_perf_helper()
5731ec
             raise
5731ec
         finally:
5731ec
             os.remove(output_file)
5731ec
@@ -260,8 +209,6 @@ def run_performance_test():
5731ec
 
5731ec
         logs.append(output['log'])
5731ec
 
5731ec
-    stop_perf_helper()
5731ec
-
5731ec
     if options.perf_output or options.perf_upload:
5731ec
         # Write a complete report, formatted as JSON. The Javascript/C code that
5731ec
         # generates the individual reports we are summarizing here is very careful
5731ec
-- 
5731ec
2.26.2
5731ec
5731ec
5731ec
From 8090db0f29dc72e602be341d43b3113373404b21 Mon Sep 17 00:00:00 2001
5731ec
From: Olivier Fourdan <ofourdan@redhat.com>
5731ec
Date: Tue, 21 Jan 2020 11:05:58 +0100
5731ec
Subject: [PATCH 4/4] perf-tool: Allow to run as a Wayland compositor
5731ec
5731ec
`gnome-shell-perf-tool` is initially designed to run on X11, using the
5731ec
`--replace` option which does not work when gnome-shell is a Wayland
5731ec
compositor.
5731ec
5731ec
A solution would be to run `gnome-shell-perf-tool` in place of just
5731ec
`gnome-shell` to run the entire perf session under Wayland, but the
5731ec
script `gnome-shell-perf-tool` does not spawn `gnome-shell` as a Wayladn
5731ec
compositor, so that fails as well.
5731ec
5731ec
Add a `--wayland` option to `gnome-shell-perf-tool` so that it can
5731ec
optionally spawn gnome-shell as a Wayland compositor so the whole perf
5731ec
tool can be starred from a console with:
5731ec
5731ec
```
5731ec
  $ dbus-run-session -- gnome-shell-perf-tool --wayland
5731ec
```
5731ec
5731ec
Alternatively, for testing purposes, it can also be started nested with:
5731ec
5731ec
```
5731ec
  $ dbus-run-session -- gnome-shell-perf-tool --nested
5731ec
```
5731ec
5731ec
Closes: https://gitlab.gnome.org/GNOME/gnome-shell/issues/2139
5731ec
https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/941
5731ec
---
5731ec
 src/gnome-shell-perf-tool.in | 11 +++++++++++
5731ec
 1 file changed, 11 insertions(+)
5731ec
5731ec
diff --git a/src/gnome-shell-perf-tool.in b/src/gnome-shell-perf-tool.in
5731ec
index 050c66b30..04072c4cd 100755
5731ec
--- a/src/gnome-shell-perf-tool.in
5731ec
+++ b/src/gnome-shell-perf-tool.in
5731ec
@@ -45,6 +45,13 @@ def start_shell(perf_output=None):
5731ec
     if options.replace:
5731ec
         args.append('--replace')
5731ec
 
5731ec
+    if options.wayland or options.nested:
5731ec
+        args.append('--wayland')
5731ec
+        if options.nested:
5731ec
+            args.append('--nested')
5731ec
+        else:
5731ec
+            args.append('--display-server')
5731ec
+
5731ec
     return subprocess.Popen(args, env=env)
5731ec
 
5731ec
 def run_shell(perf_output=None):
5731ec
@@ -284,6 +291,10 @@ parser.add_option("", "--version", action="callback", callback=show_version,
5731ec
 
5731ec
 parser.add_option("-r", "--replace", action="store_true",
5731ec
                   help="Replace the running window manager")
5731ec
+parser.add_option("-w", "--wayland", action="store_true",
5731ec
+                  help="Run as a Wayland compositor")
5731ec
+parser.add_option("-n", "--nested", action="store_true",
5731ec
+                  help="Run as a Wayland nested compositor")
5731ec
 
5731ec
 options, args = parser.parse_args()
5731ec
 
5731ec
-- 
5731ec
2.26.2
441107