Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9cced063d7 |
No files matched your search
@@ -0,0 +1,105 @@
|
||||
# windows-flakes-hunt.yml - hunt scaffolding, never merged. Runs only on a push to a `hunt/windows-flakes**` branch.
|
||||
# Which thread of our process holds the GIL while the keys slip: py-spy --gil --threads on the typing run, and the plain round trip, ours against stock.
|
||||
name: windows flakes hunt
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: ['hunt/windows-flakes**']
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
concurrency:
|
||||
group: windows-flakes-hunt-${{ github.ref }}
|
||||
cancel-in-progress: true
|
||||
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ github.token }}
|
||||
|
||||
jobs:
|
||||
hunt:
|
||||
name: flakes hunt ${{ matrix.os }}
|
||||
runs-on: ${{ matrix.os }}
|
||||
timeout-minutes: 60
|
||||
strategy:
|
||||
max-parallel: 1
|
||||
fail-fast: false
|
||||
matrix:
|
||||
os: [ubuntu-24.04, windows-2022]
|
||||
defaults:
|
||||
run:
|
||||
shell: bash
|
||||
steps:
|
||||
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
|
||||
- uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5
|
||||
with: { python-version: '3.11' }
|
||||
- name: Install
|
||||
run: |
|
||||
set -e
|
||||
python -m pip install --quiet --upgrade pip
|
||||
python -m pip install --quiet ".[dev]" py-spy==0.4.1
|
||||
python -m pip install --quiet "playwright==$(cat scripts/playwright_pin.txt)"
|
||||
echo "FF=$(cd "$RUNNER_TEMP" && python -m invisible_playwright fetch | tail -1)" >> "$GITHUB_ENV"
|
||||
python scripts/ci_lab_geoip.py build
|
||||
if [ "$RUNNER_OS" = "Linux" ]; then python -m playwright install --with-deps firefox; else python -m playwright install firefox; fi
|
||||
- name: Round trip, and the typing run under py-spy
|
||||
env:
|
||||
PYTHONUNBUFFERED: "1"
|
||||
run: |
|
||||
set +e
|
||||
mkdir -p evidence
|
||||
SPY="py-spy" # a child of py-spy: ptrace scope 1 lets it read its own descendants, no sudo
|
||||
for engine in ours stock; do python -u scripts/hunt_rtt.py $engine "$FF" >> evidence/rtt_alone.log 2>&1; done
|
||||
$SPY record --gil --threads --subprocesses -r 250 -f raw -o evidence/spy_alone.txt -- python -u scripts/hunt_typing.py ours "$FF" > evidence/typing_alone.log 2>&1
|
||||
$SPY record --threads --subprocesses -r 250 -f raw -o evidence/spy_alone_all.txt -- python -u scripts/hunt_typing.py ours "$FF" > evidence/typing_alone_all.log 2>&1
|
||||
for c in 1 2 3; do python -u scripts/hunt_typing.py ours "$FF" > "evidence/typing_load_$c.log" 2>&1 & done
|
||||
$SPY record --gil --threads --subprocesses -r 250 -f raw -o evidence/spy_loaded.txt -- python -u scripts/hunt_typing.py ours "$FF" > evidence/typing_loaded.log 2>&1
|
||||
wait
|
||||
{
|
||||
echo "## threads alive in the middle of the typing ($RUNNER_OS, alone)"
|
||||
echo '```'
|
||||
grep -ah "^HUNT-THREADS" evidence/typing_alone_all.log | head -1 | cut -c1-3000
|
||||
echo '```'
|
||||
echo "## round trip ($RUNNER_OS)"
|
||||
echo '```'
|
||||
grep -ah "^HUNT-RTT" evidence/rtt_alone.log
|
||||
echo '```'
|
||||
for f in spy_alone spy_alone_all spy_loaded; do
|
||||
echo "## $f: samples per thread, and the top leaf functions per thread"
|
||||
echo '```'
|
||||
python - "evidence/$f.txt" <<'PY'
|
||||
import collections, sys
|
||||
threads = collections.Counter(); leaves = collections.defaultdict(collections.Counter)
|
||||
for line in open(sys.argv[1], encoding="utf-8", errors="replace"):
|
||||
line = line.rstrip()
|
||||
if not line:
|
||||
continue
|
||||
stack, _, n = line.rpartition(" ")
|
||||
n = int(n)
|
||||
frames = stack.split(";")
|
||||
th = frames[0]
|
||||
threads[th] += n
|
||||
leaf = [f for f in frames[1:] if "threading.py" not in f][-3:]
|
||||
leaves[th][" < ".join(reversed(leaf))[:230]] += n
|
||||
for th, n in threads.most_common(8):
|
||||
print(n, th)
|
||||
for leaf, m in leaves[th].most_common(6):
|
||||
print(" ", m, leaf)
|
||||
PY
|
||||
echo '```'
|
||||
done
|
||||
} | tee -a "$GITHUB_STEP_SUMMARY"
|
||||
- name: Close every Firefox left
|
||||
if: always()
|
||||
shell: pwsh
|
||||
run: |
|
||||
Get-Process firefox -ErrorAction SilentlyContinue | Stop-Process -Force -ErrorAction SilentlyContinue
|
||||
"left: " + @(Get-Process firefox -ErrorAction SilentlyContinue).Count
|
||||
- name: Upload the evidence
|
||||
if: always()
|
||||
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4
|
||||
with:
|
||||
name: flakes-prof-${{ matrix.os }}-${{ github.run_id }}
|
||||
path: evidence
|
||||
if-no-files-found: warn
|
||||
retention-days: 14
|
||||
@@ -0,0 +1,29 @@
|
||||
"""HUNT SCAFFOLDING, NEVER MERGED: the plain round trip, 200 x page.evaluate("1"), ours against stock. Usage: hunt_rtt.py ours|stock [binary]"""
|
||||
import json
|
||||
import sys
|
||||
import time
|
||||
|
||||
ENGINE = sys.argv[1]
|
||||
|
||||
|
||||
def run(page):
|
||||
page.goto("data:text/html,<p>x</p>")
|
||||
t = []
|
||||
for _ in range(200):
|
||||
t0 = time.perf_counter()
|
||||
page.evaluate("1")
|
||||
t.append((time.perf_counter() - t0) * 1000)
|
||||
t.sort()
|
||||
print("HUNT-RTT " + json.dumps({"engine": ENGINE, "p50": round(t[100], 2), "p95": round(t[190], 2), "max": round(t[-1], 2)}), flush=True)
|
||||
|
||||
|
||||
if ENGINE == "stock":
|
||||
from playwright.sync_api import sync_playwright
|
||||
with sync_playwright() as p:
|
||||
b = p.firefox.launch(headless=True)
|
||||
run(b.new_page())
|
||||
b.close()
|
||||
else:
|
||||
from invisible_playwright import InvisiblePlaywright
|
||||
with InvisiblePlaywright(seed=2, binary_path=sys.argv[2], headless=True) as browser:
|
||||
run(browser.new_page())
|
||||
@@ -0,0 +1,109 @@
|
||||
"""HUNT SCAFFOLDING, NEVER MERGED: one typed address, three times per key: planned, sent (before the keydown command), seen by the page.
|
||||
|
||||
Usage: python scripts/hunt_typing.py ours|stock [binary]. Both type the same plan (persona of seed 2, typing nonce 1, the plan the core's
|
||||
keyboard draws for a session's first field): ours through press_sequentially (the core keyboard), stock as down / sleep(dwell) / up /
|
||||
sleep(gap) through stock Playwright's keyboard. One JSON line per run with the three series in wall-clock milliseconds.
|
||||
"""
|
||||
import http.server
|
||||
import json
|
||||
import sys
|
||||
import threading
|
||||
import time
|
||||
|
||||
from invisible_core.juggler._behaviour import TypingPersona, plan_typing
|
||||
|
||||
ENGINE = sys.argv[1]
|
||||
TEXT = "someone@example.com"
|
||||
PLAN = plan_typing(TEXT, TypingPersona.from_seed(2), nonce=1)
|
||||
SENT = []
|
||||
PAGE = (b"<!doctype html><html><body><input id=f><script>window.__k=[];document.addEventListener('keydown',"
|
||||
b"e=>__k.push([e.key, performance.timeOrigin + performance.now()]),true);</script></body></html>")
|
||||
|
||||
|
||||
class H(http.server.BaseHTTPRequestHandler):
|
||||
def do_GET(self):
|
||||
self.send_response(200)
|
||||
self.send_header("Content-Type", "text/html")
|
||||
self.send_header("Content-Length", str(len(PAGE)))
|
||||
self.end_headers()
|
||||
self.wfile.write(PAGE)
|
||||
|
||||
def log_message(self, *a):
|
||||
pass
|
||||
|
||||
|
||||
srv = http.server.ThreadingHTTPServer(("127.0.0.1", 0), H)
|
||||
srv.daemon_threads = True
|
||||
threading.Thread(target=srv.serve_forever, daemon=True).start()
|
||||
url = "http://127.0.0.1:%d/" % srv.server_address[1]
|
||||
|
||||
|
||||
def report(page, t_start):
|
||||
keys = page.evaluate("__k")
|
||||
planned, t = [], 0.0
|
||||
for dwell, gap in PLAN:
|
||||
planned.append(round(t))
|
||||
t += dwell + gap
|
||||
print("HUNT-TYPING " + json.dumps({
|
||||
"engine": ENGINE, "planned_ms": planned,
|
||||
"sent_ms": [round(x * 1000 - SENT[0] * 1000) for x in SENT if True],
|
||||
"page_ms": [round(v - keys[0][1]) for k, v in keys if k != "Shift"],
|
||||
"page_keys": [k for k, v in keys], "send_offset_ms": round((SENT[0] - t_start) * 1000) if SENT else None,
|
||||
}), flush=True)
|
||||
|
||||
|
||||
def _dump_threads():
|
||||
time.sleep(2.0) # in the middle of the typing
|
||||
rows = []
|
||||
for t in threading.enumerate():
|
||||
target = getattr(t, "_target", None)
|
||||
rows.append({"name": t.name, "daemon": t.daemon,
|
||||
"target": getattr(target, "__qualname__", repr(target))[:100] if target else type(t).__qualname__})
|
||||
print("HUNT-THREADS " + json.dumps(rows), flush=True)
|
||||
|
||||
|
||||
if ENGINE == "stock":
|
||||
from playwright.sync_api import sync_playwright
|
||||
with sync_playwright() as p:
|
||||
b = p.firefox.launch(headless=True)
|
||||
page = b.new_page()
|
||||
for _ in range(5):
|
||||
SENT.clear()
|
||||
page.goto(url)
|
||||
page.click("#f")
|
||||
t_start = time.time()
|
||||
for (dwell, gap), ch in zip(PLAN, TEXT):
|
||||
SENT.append(time.time())
|
||||
if ch == "@":
|
||||
page.keyboard.down("Shift")
|
||||
page.keyboard.down(ch)
|
||||
time.sleep(dwell / 1000)
|
||||
page.keyboard.up(ch)
|
||||
if ch == "@":
|
||||
page.keyboard.up("Shift")
|
||||
time.sleep(gap / 1000)
|
||||
report(page, t_start)
|
||||
b.close()
|
||||
else:
|
||||
from invisible_core.juggler import keyboard as kb
|
||||
real_down = kb.Keyboard.down
|
||||
|
||||
def down(self, key, *a, **k):
|
||||
if key != "Shift":
|
||||
SENT.append(time.time())
|
||||
return real_down(self, key, *a, **k)
|
||||
|
||||
kb.Keyboard.down = down
|
||||
from invisible_playwright import InvisiblePlaywright
|
||||
for _ in range(5):
|
||||
# a fresh browser per run: the plan is the one of the session's first field (typing nonce 1)
|
||||
with InvisiblePlaywright(seed=2, binary_path=sys.argv[2], headless=True) as browser:
|
||||
SENT.clear()
|
||||
page = browser.new_page()
|
||||
page.goto(url)
|
||||
t_start = time.time()
|
||||
dumper = threading.Thread(target=_dump_threads, daemon=True)
|
||||
dumper.start()
|
||||
page.locator("#f").press_sequentially(TEXT)
|
||||
report(page, t_start)
|
||||
srv.shutdown()
|
||||
Reference in new issue
Block a user