perf-tool: Spawn perf-tool-helper from gnome-shell

On Wayland, the display server is the Wayland compositor, i.e.
`gnome-shell` itself.

As a result, we cannot spawn `gnome-shell-perf-helper` before
`gnome-shell` is started, as `gnome-shell-perf-helper` needs to connect
to the display server.

So, instead of spawning `gnome-shell-perf-helper` from the perf tool,
start it from `gnome-shell` itself.

https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/941
This commit is contained in:
Olivier Fourdan
2020-01-24 10:59:31 +01:00
committed by Florian Müllner
parent a750d04bdb
commit ee7e62c9c8
2 changed files with 34 additions and 70 deletions

View File

@ -5,8 +5,10 @@
const { Gio, GLib, Meta, Shell } = imports.gi;
const Config = imports.misc.config;
const Main = imports.ui.main;
const Params = imports.misc.params;
const Util = imports.misc.util;
const { loadInterfaceXML } = imports.misc.fileUtils;
@ -77,6 +79,12 @@ function _getPerfHelper() {
return _perfHelper;
}
function _spawnPerfHelper() {
let path = Config.LIBEXECDIR;
let command = `${path}/gnome-shell-perf-helper`;
Util.trySpawnCommandLine(command);
}
function _callRemote(obj, method, ...args) {
return new Promise((resolve, reject) => {
args.push((result, excp) => {
@ -276,6 +284,25 @@ function _collect(scriptModule, outputFile) {
}
}
async function _runPerfScript(scriptModule, outputFile) {
for (let step of scriptModule.run()) {
try {
await step; // eslint-disable-line no-await-in-loop
} catch (err) {
log(`Script failed: ${err}\n${err.stack}`);
Meta.exit(Meta.ExitCode.ERROR);
}
}
try {
_collect(scriptModule, outputFile);
} catch (err) {
log(`Script failed: ${err}\n${err.stack}`);
Meta.exit(Meta.ExitCode.ERROR);
}
Meta.exit(Meta.ExitCode.SUCCESS);
}
/**
* runPerfScript
* @param {Object} scriptModule: module object with run and finish
@ -317,23 +344,13 @@ function _collect(scriptModule, outputFile) {
* After running the script and collecting statistics from the
* event log, GNOME Shell will exit.
**/
async function runPerfScript(scriptModule, outputFile) {
function runPerfScript(scriptModule, outputFile) {
Shell.PerfLog.get_default().set_enabled(true);
_spawnPerfHelper();
for (let step of scriptModule.run()) {
try {
await step; // eslint-disable-line no-await-in-loop
} catch (err) {
log(`Script failed: ${err}\n${err.stack}`);
Meta.exit(Meta.ExitCode.ERROR);
}
}
try {
_collect(scriptModule, outputFile);
} catch (err) {
log(`Script failed: ${err}\n${err.stack}`);
Meta.exit(Meta.ExitCode.ERROR);
}
Meta.exit(Meta.ExitCode.SUCCESS);
Gio.bus_watch_name(Gio.BusType.SESSION,
'org.gnome.Shell.PerfHelper',
Gio.BusNameWatcherFlags.NONE,
() => _runPerfScript(scriptModule, outputFile),
null);
}