Nacre/tools/engine-test/run.sh

76 lines
3.6 KiB
Shell
Executable file

#!/usr/bin/env bash
# Engine comparison run: one browser, visible on the user's monitor, throwaway profile, sampled every second.
#
# Usage: tools/engine-test/run.sh chromium|webkit [outdir]
# chromium the old Python Nacre on Qt WebEngine (~/.local/bin/nacre), driven by qtwebengine_driver.py
# webkit webkit_shell.py (WebKitGTK 6.0) in driver mode
# outdir (default docs/engine/runs/<engine>) gets samples.csv, check-<site>.json, <site>.png, browser.log, home/.
#
# The run focuses an empty workspace on ENGINE_MONITOR (default DP-1), samples ENGINE_BASELINE seconds (default 15)
# with no browser, starts the browser, maximizes its column (the same window size for all three), then goes through
# sites.txt (settle per site), idles ENGINE_IDLE seconds (default 60) with every tab open and quits.
# ENGINE_ARGS adds arguments to webkit_shell.py (its tuning flags).
# Ad blocking is off and tab freezing/unloading is off in both Nacres, so all three load the same pages and keep
# every tab live. Proxies are unset; the real runtime dir is kept for the Wayland and audio sockets only.
set -u
here=$(cd "$(dirname "$0")" && pwd)
root=$(cd "$here/../.." && pwd)
engine=${1:?usage: run.sh chromium|webkit [outdir]}
out=${2:-$root/docs/engine/runs/$engine}
monitor=${ENGINE_MONITOR:-DP-1}
idle=${ENGINE_IDLE:-60}
sites=${ENGINE_SITES:-$here/sites.txt}
if pgrep -a cargo; then echo "run: cargo is running, measurements would be skewed" >&2; exit 2; fi
rm -rf "$out"
mkdir -p "$out/home"
out=$(cd "$out" && pwd)
home=$out/home
: >"$out/mark"
: >"$out/pid"
python3 "$here/sample.py" --out "$out/samples.csv" --pid-file "$out/pid" --mark "$out/mark" --until-gone &
sampler=$!
echo baseline >"$out/mark"
niri msg action focus-monitor "$monitor"
# the last workspace of a niri monitor is always empty
niri msg action focus-workspace "$(niri msg -j workspaces | python3 -c "import json,sys
print(max(w['idx'] for w in json.load(sys.stdin) if w['output'] == '$monitor'))")"
sleep "${ENGINE_BASELINE:-15}"
echo launch >"$out/mark"
envs=(env -u http_proxy -u https_proxy -u all_proxy -u HTTP_PROXY -u HTTPS_PROXY -u ALL_PROXY -u NACRE_HOME
HOME="$home" XDG_CONFIG_HOME="$home/.config" XDG_DATA_HOME="$home/.local/share"
XDG_CACHE_HOME="$home/.cache" XDG_STATE_HOME="$home/.local/state")
case $engine in
chromium)
mkdir -p "$home/.config/nacre"
echo '{"welcome.done": true, "adblock.enabled": false, "tabs.freeze_min": 0, "tabs.discard_min": 0}' \
>"$home/.config/nacre/settings.json"
"${envs[@]}" ENGINE_OUT="$out" ENGINE_PLAN="$sites" ENGINE_IDLE="$idle" ENGINE_OUTPUT="$monitor" \
NACRE_SCRIPT="$here/qtwebengine_driver.py" "$HOME/.local/bin/nacre" >"$out/browser.log" 2>&1 &
;;
webkit)
"${envs[@]}" python3 "$here/webkit_shell.py" --plan "$sites" --out "$out" --idle "$idle" \
--output "$monitor" ${ENGINE_ARGS:-} >"$out/browser.log" 2>&1 &
;;
*) echo "run: unknown engine $engine" >&2; exit 2 ;;
esac
browser=$!
echo "$browser" >"$out/pid"
# same window size for all: a maximized column (wait up to 30 s for the window)
for _ in $(seq 60); do
w=$(niri msg -j focused-window | python3 -c "import json,sys; d=json.load(sys.stdin)
print(int(d['layout']['window_size'][0]) if d else 0)")
[ "$w" -gt 0 ] && break
sleep 0.5
done
[ "$w" -gt 0 ] && [ "$w" -lt 1500 ] && niri msg action maximize-column
sleep 1
niri msg -j focused-window | python3 -c "import json,sys; d=json.load(sys.stdin) or {}
print('window', d.get('app_id'), d.get('layout', {}).get('window_size'))" >>"$out/browser.log"
wait "$browser"
echo "exit $?" >>"$out/browser.log"
wait "$sampler"
niri msg action focus-workspace 1
echo "run: $engine done, results in $out"