2019-02-01 00:16:20 +00:00
|
|
|
/* eslint camelcase: ["error", { properties: "never", allow: ["^script_", "^clutter"] }] */
|
2023-07-11 12:57:41 +00:00
|
|
|
import Clutter from 'gi://Clutter';
|
|
|
|
import Gio from 'gi://Gio';
|
|
|
|
import Shell from 'gi://Shell';
|
2014-06-05 19:18:25 +00:00
|
|
|
const Main = imports.ui.main;
|
|
|
|
const Scripting = imports.ui.scripting;
|
|
|
|
|
2023-06-13 00:13:01 +00:00
|
|
|
export var METRICS = {
|
2020-03-29 21:51:13 +00:00
|
|
|
timeToDesktop: {
|
|
|
|
description: 'Time from starting graphical.target to desktop showing',
|
|
|
|
units: 'us',
|
|
|
|
},
|
|
|
|
|
|
|
|
overviewShowTime: {
|
|
|
|
description: 'Time to switch to overview view, first time',
|
|
|
|
units: 'us',
|
|
|
|
},
|
|
|
|
|
|
|
|
applicationsShowTime: {
|
|
|
|
description: 'Time to switch to applications view, first time',
|
|
|
|
units: 'us',
|
|
|
|
},
|
|
|
|
|
|
|
|
mainViewRedrawTime: {
|
|
|
|
description: 'Time to redraw the main view, full screen',
|
|
|
|
units: 'us',
|
|
|
|
},
|
|
|
|
|
|
|
|
overviewRedrawTime: {
|
|
|
|
description: 'Time to redraw the overview, full screen, 5 windows',
|
|
|
|
units: 'us',
|
|
|
|
},
|
|
|
|
|
|
|
|
applicationRedrawTime: {
|
|
|
|
description: 'Time to redraw frame with a maximized application update',
|
|
|
|
units: 'us',
|
|
|
|
},
|
|
|
|
|
|
|
|
geditStartTime: {
|
|
|
|
description: 'Time from gedit launch to window drawn',
|
|
|
|
units: 'us',
|
|
|
|
},
|
2019-01-29 01:18:52 +00:00
|
|
|
};
|
2014-06-05 19:18:25 +00:00
|
|
|
|
2023-07-13 19:29:13 +00:00
|
|
|
/**
|
|
|
|
* @param {number} milliseconds - time to wait
|
|
|
|
* @returns {callback}
|
|
|
|
*/
|
2014-06-05 19:18:25 +00:00
|
|
|
function waitAndDraw(milliseconds) {
|
|
|
|
let cb;
|
|
|
|
|
2023-07-13 19:29:13 +00:00
|
|
|
let timeline = new Clutter.Timeline({duration: milliseconds});
|
2014-06-05 19:18:25 +00:00
|
|
|
timeline.start();
|
|
|
|
|
2019-02-04 11:30:53 +00:00
|
|
|
timeline.connect('new-frame', (_timeline, _frame) => {
|
2017-10-31 00:38:18 +00:00
|
|
|
global.stage.queue_redraw();
|
|
|
|
});
|
|
|
|
|
|
|
|
timeline.connect('completed', () => {
|
|
|
|
timeline.stop();
|
|
|
|
if (cb)
|
|
|
|
cb();
|
|
|
|
});
|
|
|
|
|
2019-08-19 20:20:35 +00:00
|
|
|
return callback => (cb = callback);
|
2014-06-05 19:18:25 +00:00
|
|
|
}
|
|
|
|
|
2023-07-13 19:29:13 +00:00
|
|
|
/**
|
|
|
|
* @param {object} object - emitter object
|
|
|
|
* @param {string} signal - signal name
|
|
|
|
* @returns {callback}
|
|
|
|
*/
|
2014-06-05 19:18:25 +00:00
|
|
|
function waitSignal(object, signal) {
|
|
|
|
let cb;
|
|
|
|
|
2017-10-31 00:38:18 +00:00
|
|
|
let id = object.connect(signal, () => {
|
2014-06-05 19:18:25 +00:00
|
|
|
object.disconnect(id);
|
|
|
|
if (cb)
|
|
|
|
cb();
|
|
|
|
});
|
|
|
|
|
2019-08-19 20:20:35 +00:00
|
|
|
return callback => (cb = callback);
|
2014-06-05 19:18:25 +00:00
|
|
|
}
|
|
|
|
|
2023-07-13 19:29:13 +00:00
|
|
|
/**
|
|
|
|
* @returns {number}
|
|
|
|
*/
|
2014-06-05 19:18:25 +00:00
|
|
|
function extractBootTimestamp() {
|
2020-03-27 13:18:34 +00:00
|
|
|
const sp = Gio.Subprocess.new([
|
|
|
|
'journalctl', '-b',
|
|
|
|
'MESSAGE_ID=7d4958e842da4a758f6c1cdc7b36dcc5',
|
|
|
|
'UNIT=graphical.target',
|
|
|
|
'-o',
|
|
|
|
'json',
|
|
|
|
], Gio.SubprocessFlags.STDOUT_PIPE);
|
2014-06-05 19:18:25 +00:00
|
|
|
let result = null;
|
|
|
|
|
|
|
|
let datastream = Gio.DataInputStream.new(sp.get_stdout_pipe());
|
2019-02-04 12:14:09 +00:00
|
|
|
while (true) { // eslint-disable-line no-constant-condition
|
2019-01-31 14:08:00 +00:00
|
|
|
let [line, length_] = datastream.read_line_utf8(null);
|
2014-06-05 19:18:25 +00:00
|
|
|
if (line === null)
|
|
|
|
break;
|
|
|
|
|
2014-07-16 17:20:15 +00:00
|
|
|
let fields = JSON.parse(line);
|
|
|
|
result = Number(fields['__MONOTONIC_TIMESTAMP']);
|
2014-06-05 19:18:25 +00:00
|
|
|
}
|
|
|
|
datastream.close(null);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2023-07-13 19:29:13 +00:00
|
|
|
/** @returns {void} */
|
2023-06-13 00:13:01 +00:00
|
|
|
export async function run() {
|
2020-07-30 16:41:11 +00:00
|
|
|
/* eslint-disable no-await-in-loop */
|
2023-07-13 19:29:13 +00:00
|
|
|
Scripting.defineScriptEvent('desktopShown', 'Finished initial animation');
|
|
|
|
Scripting.defineScriptEvent('overviewShowStart', 'Starting to show the overview');
|
|
|
|
Scripting.defineScriptEvent('overviewShowDone', 'Overview finished showing');
|
|
|
|
Scripting.defineScriptEvent('applicationsShowStart', 'Starting to switch to applications view');
|
|
|
|
Scripting.defineScriptEvent('applicationsShowDone', 'Done switching to applications view');
|
|
|
|
Scripting.defineScriptEvent('mainViewDrawStart', 'Drawing main view');
|
|
|
|
Scripting.defineScriptEvent('mainViewDrawDone', 'Ending timing main view drawing');
|
|
|
|
Scripting.defineScriptEvent('overviewDrawStart', 'Drawing overview');
|
|
|
|
Scripting.defineScriptEvent('overviewDrawDone', 'Ending timing overview drawing');
|
|
|
|
Scripting.defineScriptEvent('redrawTestStart', 'Drawing application window');
|
|
|
|
Scripting.defineScriptEvent('redrawTestDone', 'Ending timing application window drawing');
|
|
|
|
Scripting.defineScriptEvent('collectTimings', 'Accumulate frame timings from redraw tests');
|
|
|
|
Scripting.defineScriptEvent('geditLaunch', 'gedit application launch');
|
|
|
|
Scripting.defineScriptEvent('geditFirstFrame', 'first frame of gedit window drawn');
|
2014-06-05 19:18:25 +00:00
|
|
|
|
2020-07-30 16:41:11 +00:00
|
|
|
await Scripting.waitLeisure();
|
2014-06-05 19:18:25 +00:00
|
|
|
Scripting.scriptEvent('desktopShown');
|
|
|
|
|
2019-04-04 13:45:01 +00:00
|
|
|
let interfaceSettings = new Gio.Settings({
|
2019-08-20 21:43:54 +00:00
|
|
|
schema_id: 'org.gnome.desktop.interface',
|
2019-04-04 13:45:01 +00:00
|
|
|
});
|
|
|
|
interfaceSettings.set_boolean('enable-animations', false);
|
2014-06-05 19:18:25 +00:00
|
|
|
|
|
|
|
Scripting.scriptEvent('overviewShowStart');
|
|
|
|
Main.overview.show();
|
2020-07-30 16:41:11 +00:00
|
|
|
await Scripting.waitLeisure();
|
2014-06-05 19:18:25 +00:00
|
|
|
Scripting.scriptEvent('overviewShowDone');
|
|
|
|
|
2020-07-30 16:41:11 +00:00
|
|
|
await Scripting.sleep(1000);
|
2014-06-05 19:18:25 +00:00
|
|
|
|
|
|
|
Scripting.scriptEvent('applicationsShowStart');
|
2019-06-29 13:14:37 +00:00
|
|
|
// eslint-disable-next-line require-atomic-updates
|
2019-08-31 01:51:02 +00:00
|
|
|
Main.overview.dash.showAppsButton.checked = true;
|
2014-06-05 19:18:25 +00:00
|
|
|
|
2020-07-30 16:41:11 +00:00
|
|
|
await Scripting.waitLeisure();
|
2014-06-05 19:18:25 +00:00
|
|
|
Scripting.scriptEvent('applicationsShowDone');
|
|
|
|
|
2020-07-30 16:41:11 +00:00
|
|
|
await Scripting.sleep(1000);
|
2014-06-05 19:18:25 +00:00
|
|
|
|
|
|
|
Main.overview.hide();
|
2020-07-30 16:41:11 +00:00
|
|
|
await Scripting.waitLeisure();
|
2014-06-05 19:18:25 +00:00
|
|
|
|
2019-08-20 00:31:52 +00:00
|
|
|
// --------------------- //
|
|
|
|
// Tests of redraw speed //
|
|
|
|
// --------------------- //
|
2014-06-05 19:18:25 +00:00
|
|
|
|
|
|
|
global.frame_timestamps = true;
|
|
|
|
global.frame_finish_timestamp = true;
|
|
|
|
|
|
|
|
for (let k = 0; k < 5; k++)
|
2023-07-13 19:29:13 +00:00
|
|
|
await Scripting.createTestWindow({maximized: true});
|
2020-07-30 16:41:11 +00:00
|
|
|
await Scripting.waitTestWindows();
|
2014-06-05 19:18:25 +00:00
|
|
|
|
2020-07-30 16:41:11 +00:00
|
|
|
await Scripting.sleep(1000);
|
2014-06-05 19:18:25 +00:00
|
|
|
|
|
|
|
Scripting.scriptEvent('mainViewDrawStart');
|
2020-07-30 16:41:11 +00:00
|
|
|
await waitAndDraw(1000);
|
2014-06-05 19:18:25 +00:00
|
|
|
Scripting.scriptEvent('mainViewDrawDone');
|
|
|
|
|
|
|
|
Main.overview.show();
|
|
|
|
Scripting.waitLeisure();
|
|
|
|
|
2020-07-30 16:41:11 +00:00
|
|
|
await Scripting.sleep(1500);
|
2014-06-05 19:18:25 +00:00
|
|
|
|
|
|
|
Scripting.scriptEvent('overviewDrawStart');
|
2020-07-30 16:41:11 +00:00
|
|
|
await waitAndDraw(1000);
|
2014-06-05 19:18:25 +00:00
|
|
|
Scripting.scriptEvent('overviewDrawDone');
|
|
|
|
|
2020-07-30 16:41:11 +00:00
|
|
|
await Scripting.destroyTestWindows();
|
2014-06-05 19:18:25 +00:00
|
|
|
Main.overview.hide();
|
|
|
|
|
2020-03-29 21:51:13 +00:00
|
|
|
await Scripting.createTestWindow({
|
|
|
|
maximized: true,
|
|
|
|
redraws: true,
|
|
|
|
});
|
2020-07-30 16:41:11 +00:00
|
|
|
await Scripting.waitTestWindows();
|
2014-06-05 19:18:25 +00:00
|
|
|
|
2020-07-30 16:41:11 +00:00
|
|
|
await Scripting.sleep(1000);
|
2014-06-05 19:18:25 +00:00
|
|
|
|
|
|
|
Scripting.scriptEvent('redrawTestStart');
|
2020-07-30 16:41:11 +00:00
|
|
|
await Scripting.sleep(1000);
|
2014-06-05 19:18:25 +00:00
|
|
|
Scripting.scriptEvent('redrawTestDone');
|
|
|
|
|
2020-07-30 16:41:11 +00:00
|
|
|
await Scripting.sleep(1000);
|
2014-06-05 19:18:25 +00:00
|
|
|
Scripting.scriptEvent('collectTimings');
|
|
|
|
|
2020-07-30 16:41:11 +00:00
|
|
|
await Scripting.destroyTestWindows();
|
2014-06-05 19:18:25 +00:00
|
|
|
|
|
|
|
global.frame_timestamps = false;
|
|
|
|
global.frame_finish_timestamp = false;
|
|
|
|
|
2020-07-30 16:41:11 +00:00
|
|
|
await Scripting.sleep(1000);
|
2014-06-05 19:18:25 +00:00
|
|
|
|
|
|
|
let appSys = Shell.AppSystem.get_default();
|
2014-07-25 08:39:10 +00:00
|
|
|
let app = appSys.lookup_app('org.gnome.gedit.desktop');
|
2014-06-05 19:18:25 +00:00
|
|
|
|
|
|
|
Scripting.scriptEvent('geditLaunch');
|
|
|
|
app.activate();
|
|
|
|
|
|
|
|
let windows = app.get_windows();
|
|
|
|
if (windows.length > 0)
|
|
|
|
throw new Error('gedit was already running');
|
|
|
|
|
2023-07-13 19:29:13 +00:00
|
|
|
while (windows.length === 0) {
|
2020-07-30 16:41:11 +00:00
|
|
|
await waitSignal(global.display, 'window-created');
|
2014-06-05 19:18:25 +00:00
|
|
|
windows = app.get_windows();
|
|
|
|
}
|
|
|
|
|
|
|
|
let actor = windows[0].get_compositor_private();
|
2020-07-30 16:41:11 +00:00
|
|
|
await waitSignal(actor, 'first-frame');
|
2014-06-05 19:18:25 +00:00
|
|
|
Scripting.scriptEvent('geditFirstFrame');
|
|
|
|
|
2020-07-30 16:41:11 +00:00
|
|
|
await Scripting.sleep(1000);
|
2014-06-05 19:18:25 +00:00
|
|
|
|
|
|
|
windows[0].delete(global.get_current_time());
|
|
|
|
|
2020-07-30 16:41:11 +00:00
|
|
|
await Scripting.sleep(1000);
|
2014-06-05 19:18:25 +00:00
|
|
|
|
2019-04-04 13:45:01 +00:00
|
|
|
interfaceSettings.set_boolean('enable-animations', true);
|
2020-07-30 16:41:11 +00:00
|
|
|
/* eslint-enable no-await-in-loop */
|
2014-06-05 19:18:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
let overviewShowStart;
|
|
|
|
let applicationsShowStart;
|
|
|
|
let stagePaintStart;
|
|
|
|
let redrawTiming;
|
|
|
|
let redrawTimes = {};
|
|
|
|
let geditLaunchTime;
|
|
|
|
|
2023-07-13 19:29:13 +00:00
|
|
|
/**
|
|
|
|
* @param {number} time - event timestamp
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
2023-06-13 00:13:01 +00:00
|
|
|
export function script_desktopShown(time) {
|
2014-06-05 19:18:25 +00:00
|
|
|
let bootTimestamp = extractBootTimestamp();
|
|
|
|
METRICS.timeToDesktop.value = time - bootTimestamp;
|
|
|
|
}
|
|
|
|
|
2023-07-13 19:29:13 +00:00
|
|
|
/**
|
|
|
|
* @param {number} time - event timestamp
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
2023-06-13 00:13:01 +00:00
|
|
|
export function script_overviewShowStart(time) {
|
2014-06-05 19:18:25 +00:00
|
|
|
overviewShowStart = time;
|
|
|
|
}
|
|
|
|
|
2023-07-13 19:29:13 +00:00
|
|
|
/**
|
|
|
|
* @param {number} time - event timestamp
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
2023-06-13 00:13:01 +00:00
|
|
|
export function script_overviewShowDone(time) {
|
2014-06-05 19:18:25 +00:00
|
|
|
METRICS.overviewShowTime.value = time - overviewShowStart;
|
|
|
|
}
|
|
|
|
|
2023-07-13 19:29:13 +00:00
|
|
|
/**
|
|
|
|
* @param {number} time - event timestamp
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
2023-06-13 00:13:01 +00:00
|
|
|
export function script_applicationsShowStart(time) {
|
2014-06-05 19:18:25 +00:00
|
|
|
applicationsShowStart = time;
|
|
|
|
}
|
|
|
|
|
2023-07-13 19:29:13 +00:00
|
|
|
/**
|
|
|
|
* @param {number} time - event timestamp
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
2023-06-13 00:13:01 +00:00
|
|
|
export function script_applicationsShowDone(time) {
|
2014-06-05 19:18:25 +00:00
|
|
|
METRICS.applicationsShowTime.value = time - applicationsShowStart;
|
|
|
|
}
|
|
|
|
|
2023-07-13 19:29:13 +00:00
|
|
|
/**
|
|
|
|
* @param {number} _time - event timestamp
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
2023-06-13 00:13:01 +00:00
|
|
|
export function script_mainViewDrawStart(_time) {
|
2014-06-05 19:18:25 +00:00
|
|
|
redrawTiming = 'mainView';
|
|
|
|
}
|
|
|
|
|
2023-07-13 19:29:13 +00:00
|
|
|
/**
|
|
|
|
* @param {number} _time - event timestamp
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
2023-06-13 00:13:01 +00:00
|
|
|
export function script_mainViewDrawDone(_time) {
|
2014-06-05 19:18:25 +00:00
|
|
|
redrawTiming = null;
|
|
|
|
}
|
|
|
|
|
2023-07-13 19:29:13 +00:00
|
|
|
/**
|
|
|
|
* @param {number} _time - event timestamp
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
2023-06-13 00:13:01 +00:00
|
|
|
export function script_overviewDrawStart(_time) {
|
2014-06-05 19:18:25 +00:00
|
|
|
redrawTiming = 'overview';
|
|
|
|
}
|
|
|
|
|
2023-07-13 19:29:13 +00:00
|
|
|
/**
|
|
|
|
* @param {number} _time - event timestamp
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
2023-06-13 00:13:01 +00:00
|
|
|
export function script_overviewDrawDone(_time) {
|
2014-06-05 19:18:25 +00:00
|
|
|
redrawTiming = null;
|
|
|
|
}
|
|
|
|
|
2023-07-13 19:29:13 +00:00
|
|
|
/**
|
|
|
|
* @param {number} _time - event timestamp
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
2023-06-13 00:13:01 +00:00
|
|
|
export function script_redrawTestStart(_time) {
|
2014-06-05 19:18:25 +00:00
|
|
|
redrawTiming = 'application';
|
|
|
|
}
|
|
|
|
|
2023-07-13 19:29:13 +00:00
|
|
|
/**
|
|
|
|
* @param {number} _time - event timestamp
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
2023-06-13 00:13:01 +00:00
|
|
|
export function script_redrawTestDone(_time) {
|
2014-06-05 19:18:25 +00:00
|
|
|
redrawTiming = null;
|
|
|
|
}
|
|
|
|
|
2023-07-13 19:29:13 +00:00
|
|
|
/**
|
|
|
|
* @param {number} _time - event timestamp
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
2023-06-13 00:13:01 +00:00
|
|
|
export function script_collectTimings(_time) {
|
2014-06-05 19:18:25 +00:00
|
|
|
for (let timing in redrawTimes) {
|
|
|
|
let times = redrawTimes[timing];
|
2017-10-31 00:38:18 +00:00
|
|
|
times.sort((a, b) => a - b);
|
2014-06-05 19:18:25 +00:00
|
|
|
|
|
|
|
let len = times.length;
|
|
|
|
let median;
|
|
|
|
|
2023-07-13 19:29:13 +00:00
|
|
|
if (len === 0)
|
2014-06-05 19:18:25 +00:00
|
|
|
median = -1;
|
2023-07-13 19:29:13 +00:00
|
|
|
else if (len % 2 === 1)
|
2019-01-29 01:27:05 +00:00
|
|
|
median = times[(len - 1) / 2];
|
2014-06-05 19:18:25 +00:00
|
|
|
else
|
|
|
|
median = Math.round((times[len / 2 - 1] + times[len / 2]) / 2);
|
|
|
|
|
2019-01-30 00:18:24 +00:00
|
|
|
METRICS[`${timing}RedrawTime`].value = median;
|
2014-06-05 19:18:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-13 19:29:13 +00:00
|
|
|
/**
|
|
|
|
* @param {number} time - event timestamp
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
2023-06-13 00:13:01 +00:00
|
|
|
export function script_geditLaunch(time) {
|
2014-06-05 19:18:25 +00:00
|
|
|
geditLaunchTime = time;
|
|
|
|
}
|
|
|
|
|
2023-07-13 19:29:13 +00:00
|
|
|
/**
|
|
|
|
* @param {number} time - event timestamp
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
2023-06-13 00:13:01 +00:00
|
|
|
export function script_geditFirstFrame(time) {
|
2014-06-05 19:18:25 +00:00
|
|
|
METRICS.geditStartTime.value = time - geditLaunchTime;
|
|
|
|
}
|
|
|
|
|
2023-07-13 19:29:13 +00:00
|
|
|
/**
|
|
|
|
* @param {number} time - event timestamp
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
2023-06-13 00:13:01 +00:00
|
|
|
export function clutter_stagePaintStart(time) {
|
2014-06-05 19:18:25 +00:00
|
|
|
stagePaintStart = time;
|
|
|
|
}
|
|
|
|
|
2023-07-13 19:29:13 +00:00
|
|
|
/**
|
|
|
|
* @param {number} time - event timestamp
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
2023-06-13 00:13:01 +00:00
|
|
|
export function clutter_paintCompletedTimestamp(time) {
|
2014-06-05 19:18:25 +00:00
|
|
|
if (redrawTiming != null && stagePaintStart != null) {
|
|
|
|
if (!(redrawTiming in redrawTimes))
|
|
|
|
redrawTimes[redrawTiming] = [];
|
|
|
|
redrawTimes[redrawTiming].push(time - stagePaintStart);
|
|
|
|
}
|
|
|
|
stagePaintStart = null;
|
|
|
|
}
|