SPB Git

Repository Public

perf.sh 2.8 KB 42 lines shellscript

1#!/usr/bin/env bash2# Measures launch time and memory of a built SP Browser with 1, 10 and 30 tabs.3# Usage: scripts/perf.sh [path/to/SPBrowser.app]     (default: the Debug build; pass dist/SPBrowser.app for Release)4# Method (reproducible, see docs/TEST_REPORT.md):5#  - each run uses a fresh, empty data folder inside the app's sandbox container;6#  - launch time = process creation → first window on screen, reported by the app itself (-SPBPerfLog);7#  - memory = physical footprint (`footprint`-equivalent via `ps` RSS) of the app process plus every8#    WebKit helper process that appeared after launch, sampled 20 s after launch;9#  - pages are real Wikipedia articles, so numbers depend on network and content of the day.10set -uo pipefail11cd "$(dirname "$0")/.."12APP="${1:-build/DerivedData/Build/Products/Debug/SPBrowser.app}"13APP="$(cd "$(dirname "$APP")" && pwd)/$(basename "$APP")"14BUNDLE="$(/usr/libexec/PlistBuddy -c "Print :CFBundleIdentifier" "$APP/Contents/Info.plist" 2>/dev/null || echo ai.spboucher.spbrowser)"15CONTAINER="$HOME/Library/Containers/$BUNDLE/Data/Library/Application Support"16PAGES=(Montreal Quebec Canada WebKit Swift_programming_language MacOS Safari HTML CSS JavaScript17       Internet World_Wide_Web HTTP Transport_Layer_Security Apple_Inc. Unicode Typography Graphite Cyan Violet18       Orbit Portal Navigation Compass Lighthouse Atlas Cartography Astronomy Telescope Mathematics)19webkit_pids() { pgrep -f "com.apple.WebKit" | sort; }20rss_mb() { local total=0; for pid in "$@"; do kb=$(ps -o rss= -p "$pid" 2>/dev/null | tr -d ' '); total=$((total + ${kb:-0})); done; echo $((total / 1024)); }2122echo "app: $APP"23echo "machine: $(sysctl -n machdep.cpu.brand_string), $(($(sysctl -n hw.memsize) / 1073741824)) GB, macOS $(sw_vers -productVersion)"24printf "%-6s %-22s %-14s %-18s %-10s %-8s\n" tabs launch_to_window_ms app_rss_mb webkit_rss_mb total_mb app_cpu_%25for COUNT in 1 10 30; do26  # Only the instance this script starts is measured and stopped (by PID): a running SP Browser of the user is left alone.27  DIR="SPB-Perf-$COUNT-$$"28  URLS=""29  for ((i = 1; i < COUNT; i++)); do URLS+="https://en.wikipedia.org/wiki/${PAGES[$((i - 1))]},"; done30  BEFORE="$(webkit_pids)"31  "$APP/Contents/MacOS/SPBrowser" -SPBDataDir "~/Library/Application Support/$DIR" -SPBPerfLog 1 -SPBOpenURLs "${URLS%,}" -ApplePersistenceIgnoreState YES >/dev/null 2>&1 &32  PID=$!33  sleep 2034  NEW="$(comm -13 <(echo "$BEFORE") <(webkit_pids))"35  LAUNCH="$(sed -n 's/.*: \([0-9]*\)}/\1/p' "$CONTAINER/$DIR/perf-launch.json" 2>/dev/null)"36  APPMB="$(rss_mb $PID)"; WKMB="$(rss_mb $NEW)"37  CPU="$(ps -o %cpu= -p "$PID" | tr -d ' ')"38  printf "%-6s %-22s %-14s %-18s %-10s %-8s\n" "$COUNT" "${LAUNCH:-n/a}" "$APPMB" "$WKMB ($(echo "$NEW" | grep -c .) procs)" "$((APPMB + WKMB))" "${CPU:-n/a}"39  kill "$PID" 2>/dev/null; wait "$PID" 2>/dev/null; sleep 140  rm -rf "$CONTAINER/$DIR"41done42
Files main
Menu

Theme