Blame SOURCES/perf-tool-wayland.patch

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