Bench: edits timed at the drawn tile; per-cycle document counts; posted chords
release / macos (arm64, macos-15) (push) Canceled after 0s
release / macos (x86_64, macos-15-intel) (push) Canceled after 0s

This commit is contained in:
ZacharyZhang-NY committed 2026-10-08 22:22:29 -04:00
1 parent 946e5cf835
commit 98d7e75fca
7 files changed
+93 -30

No files matched your search

Binary file not shown.
+21 -13
View File
@@ -29,7 +29,7 @@ def sh(*args, **kw):
def tools(folder):
for tool in ["ax-values", "ax-press", "click"]:
for tool in ["ax-values", "ax-press", "click", "chord"]:
sh("swiftc", "-O", "-o", os.path.join(folder, tool), os.path.join(ROOT, "tests", "scripts", tool + ".swift"))
@@ -98,9 +98,6 @@ class App:
def memory_mb(self):
return self.family()[1] / 1024
def files(self):
return sum(self.handles().values())
def handles(self):
"""Open handles of the app and its children, as type and name."""
ours, _ = self.family()
@@ -207,6 +204,9 @@ def perf02(work, runs):
lines = app.lines()
finally:
app.stop()
failed = [line for line in lines if re.search(PAINT_FAILED, line)]
if failed:
raise RuntimeError(f"ely-doc: a tile failed to draw while typing: {failed[0]}")
ticks = [int(m.group(1)) for line in lines if (m := re.search(tick, line))]
if len(ticks) != runs:
raise RuntimeError(f"ely-doc: {runs} keys gave {len(ticks)} timings")
@@ -269,8 +269,8 @@ def perf08(work, cycles=40):
"""New and close a document; memory, handles and live documents."""
app = App("ely-doc", os.path.join(work, "home-cycles"))
def open_docs():
return documents_open(app.lines())
def open_docs(since=0):
return documents_open(app.lines()[since:])
try:
app.wait("opened Untitled")
@@ -280,19 +280,24 @@ def perf08(work, cycles=40):
baseline = (app.memory_mb(), sum(before.values()), open_docs())
seen, extra = [], None
for n in range(cycles):
keys('keystroke "n" using command down')
cursor = len(app.lines())
sh(os.path.join(work, "chord"), str(app.process.pid), "45")
for _ in range(40):
if "title=Use template" in app.ax():
break
time.sleep(0.25)
sh(os.path.join(work, "ax-press"), str(app.process.pid), "Use template", "AXButton")
app.wait(f"opened Untitled {n + 2} ", timeout=30)
# This cycle's own report, not an earlier one.
if open_docs(cursor) != baseline[2] + 1:
raise RuntimeError(f"ely-doc: cycle {n + 1} opened, yet {open_docs(cursor)} documents")
cursor = len(app.lines())
time.sleep(1)
# A keystroke can miss a window still taking focus.
for _ in range(3):
app.front()
raise_main(app)
keys('keystroke "w" using command down')
sh(os.path.join(work, "chord"), str(app.process.pid), "13")
try:
app.wait(f"office: closed Untitled {n + 2}$", timeout=5)
break
@@ -304,17 +309,20 @@ def perf08(work, cycles=40):
else:
said = [line for line in app.lines() if re.search("clos|dialog|opened|focus", line)]
raise RuntimeError(f"ely-doc: Untitled {n + 2} never closed: {said[-8:]}")
# The kernel lets go in the background.
# The kernel lets go later; a fresh report must come.
for _ in range(100):
if open_docs() == baseline[2]:
break
try:
if open_docs(cursor) == baseline[2]:
break
except RuntimeError:
pass
time.sleep(0.05)
else:
raise RuntimeError(f"ely-doc: {open_docs()} documents after closing, not {baseline[2]}")
raise RuntimeError(f"ely-doc: cycle {n + 1} closed, yet no report of {baseline[2]} documents")
time.sleep(0.5)
now = app.handles()
extra = handles_kept(before, now, extra, n + 1)
seen.append((app.memory_mb(), sum(now.values()), open_docs()))
seen.append((app.memory_mb(), sum(now.values()), open_docs(cursor)))
finally:
app.stop()
return baseline, seen
+6
View File
@@ -35,6 +35,12 @@ class Verdicts(unittest.TestCase):
with self.assertRaisesRegex(RuntimeError, "no document count"):
bench.documents_open(["office: closed Untitled 2"])
def test_a_cycle_needs_its_own_count(self):
log = ["lok-worker: 1 documents open", "ely-doc: opened Untitled 2 as tab 1", "office: closed Untitled 2"]
cursor = 1
with self.assertRaisesRegex(RuntimeError, "no document count"):
bench.documents_open(log[cursor:])
if __name__ == "__main__":
unittest.main()
+14
View File
@@ -0,0 +1,14 @@
// Posts Command plus a key to one process, flag included.
import CoreGraphics
import Foundation
// chord <pid> <virtual key code>
let pid = pid_t(CommandLine.arguments[1])!
let code = CGKeyCode(CommandLine.arguments[2])!
let source = CGEventSource(stateID: .privateState)
for down in [true, false] {
let event = CGEvent(keyboardEventSource: source, virtualKey: code, keyDown: down)!
event.flags = .maskCommand
event.postToPid(pid)
usleep(30_000)
}