Merge branch 'worktree-agent-ae3af4174afca7f4d'

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-12-03 12:59:07 +00:00
26 changed files with 722 additions and 60 deletions
@@ -4,6 +4,7 @@ import 'package:flutter/services.dart';
import 'package:flutter/widgets.dart';
import 'package:pipelines_app/application/server_endpoint.dart';
import '../perf/frame_log_native.dart';
import 'fixture_steps.dart';
import 'narrow_view.dart';
@@ -31,8 +32,10 @@ Map<String, String> fixtureParams() {
return raw.isEmpty ? const {} : Uri.splitQueryString(raw);
}
/// The DevTools probes are browser-only.
void installHostProbes(Map<String, String> params) {}
/// The DevTools probes are browser-only; `perf=1` prints frame timings to
/// stdout (tool/perf/frame_log_native.dart).
void installHostProbes(Map<String, String> params) =>
installNativeFrameLog(params);
/// The route goes through [fixtureRouteProvider] instead.
void openFixtureRoute(String route) {}
+24 -1
View File
@@ -9,7 +9,10 @@ import 'package:flutter/services.dart';
/// [script] is `;`-separated steps run after the first frame, 700 ms apart:
/// `wait:<ms>`, `tap:<label>` (a Text, Tooltip, Semantics label or field
/// hint; `tap:<label>#<n>` picks the n-th match), `tapxy:<x>,<y>`,
/// `drag:<x>,<y>,<dx>,<dy>`, `type:<text>` (into the focused field; `\n`
/// `drag:<x>,<y>,<dx>,<dy>`, `wheel:<x>,<y>,<dy>,<count>` (mouse-wheel
/// notches 16 ms apart, as the web interaction bench sends), `mark:<name>`
/// (prints `FIXTURE_MARK <name>`, so a bench can tell its phases apart),
/// `type:<text>` (into the focused field; `\n`
/// is a newline), `orient:landscape|portrait` and `labels` (prints the
/// visible labels with their centres to the device log).
void runFixtureSteps(String script) {
@@ -54,6 +57,12 @@ Future<void> _run(String verb, String value) async {
case 'drag':
final p = value.split(',').map(double.parse).toList();
await _drag(Offset(p[0], p[1]), Offset(p[2], p[3]));
case 'mark':
// ignore: avoid_print
print('FIXTURE_MARK $value');
case 'wheel':
final p = value.split(',').map(double.parse).toList();
await _wheel(Offset(p[0], p[1]), p[2], p[3].toInt());
case 'type':
_type(value.replaceAll(r'\n', '\n'));
case 'orient':
@@ -141,6 +150,20 @@ Future<void> _drag(Offset from, Offset by) async {
);
}
Future<void> _wheel(Offset at, double dy, int count) async {
final binding = GestureBinding.instance;
for (var i = 0; i < count; i++) {
binding.handlePointerEvent(
PointerScrollEvent(
kind: PointerDeviceKind.mouse,
position: at,
scrollDelta: Offset(0, dy),
),
);
await Future<void>.delayed(const Duration(milliseconds: 16));
}
}
void _type(String text) {
EditableTextState? focused;
void visit(Element element) {
+28
View File
@@ -0,0 +1,28 @@
// Frame report for native fixture builds (the Linux desktop bench,
// tool/perf/linux_desktop_bench.py), the native twin of frame_log.dart.
//
// With `perf=1` in FIXTURE_QUERY it prints every frame's Flutter timings as
// `PERF_FRAME <build us> <raster us> <total us>`, and the first rasterised
// frame as `PERF_FIRST_FRAME_EPOCH <ms since the Unix epoch>`, which the
// bench subtracts from its own launch time. Without the flag nothing is
// installed.
import 'package:flutter/widgets.dart';
void installNativeFrameLog(Map<String, String> params) {
if (params['perf'] != '1') return;
final binding = WidgetsFlutterBinding.ensureInitialized();
binding.addTimingsCallback((timings) {
for (final timing in timings) {
// ignore: avoid_print
print(
'PERF_FRAME ${timing.buildDuration.inMicroseconds} '
'${timing.rasterDuration.inMicroseconds} '
'${timing.totalSpan.inMicroseconds}',
);
}
});
binding.waitUntilFirstFrameRasterized.then((_) {
// ignore: avoid_print
print('PERF_FIRST_FRAME_EPOCH ${DateTime.now().millisecondsSinceEpoch}');
});
}
+102
View File
@@ -0,0 +1,102 @@
#!/usr/bin/env python3
"""Startup and chat-scroll bench for the Linux desktop build of the full-app
fixture, the native counterpart of interaction_bench.mjs's `startup` and
`desktop: scroll a rich chat` scenarios.
Build the fixture as a Linux bundle (release, or profile for engine switches):
docker run ... pipelines-app-build linux --target tool/search_selection_probe_entry.dart
then:
python3 tool/perf/linux_desktop_bench.py --bundle <bundle dir> [--repeat 5]
[--switch enable-impeller=true] # profile builds only
Each run starts the bundle on a private Xvfb display (never the desktop
session) with an isolated HOME and its own D-Bus session, with FIXTURE_QUERY
`perf=1` (tool/perf/frame_log_native.dart). Startup is launch to the first
rasterised frame; the scroll is 30 mouse-wheel notches of -240 px over the
open rich chat. Xvfb has no GPU: Mesa's llvmpipe rasterises on the CPU, as
headless Chrome without --gpu does, so compare builds and engines with each
other rather than predicting a desktop with a GPU.
"""
import argparse
import json
import os
from pathlib import Path
import shutil
import statistics
import subprocess
import tempfile
import time
QUERY = ("route=/chat/perf-chat-0&chats=2&header=1&rich=1&perf=1"
"&do=wait:500;tap:Later;wait:800;mark:scroll;wheel:860,400,-240,30;wait:1500;mark:end")
def run_once(bundle, display, switches, timeout, extra_env=()):
root = Path(tempfile.mkdtemp(prefix="linux-bench-"))
runtime = root / "run"
runtime.mkdir(mode=0o700)
env = {"HOME": str(root / "home"), "XDG_RUNTIME_DIR": str(runtime), "DISPLAY": f":{display}",
"GDK_BACKEND": "x11", "PATH": "/usr/bin:/bin", "FIXTURE_QUERY": QUERY,
**dict(e.split("=", 1) for e in extra_env)}
if switches:
env["FLUTTER_ENGINE_SWITCHES"] = str(len(switches))
for index, switch in enumerate(switches, 1):
env[f"FLUTTER_ENGINE_SWITCH_{index}"] = switch
xvfb = subprocess.Popen(["Xvfb", f":{display}", "-screen", "0", "1280x800x24", "-nolisten", "tcp"],
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
lines = []
try:
time.sleep(1)
launched = time.time() * 1000
app = subprocess.Popen(["dbus-run-session", "--", str(Path(bundle) / "pipelines-app")], env=env,
stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True,
start_new_session=True)
deadline = time.time() + timeout
try:
for line in app.stdout:
lines.append(line.strip())
if line.startswith("FIXTURE_MARK end") or time.time() > deadline:
break
finally:
os.killpg(app.pid, 15)
app.wait(timeout=10)
finally:
xvfb.terminate()
xvfb.wait(timeout=10)
shutil.rmtree(root, ignore_errors=True)
first = next((int(l.split()[1]) for l in lines if l.startswith("PERF_FIRST_FRAME_EPOCH ")), None)
phase, scroll = None, []
for line in lines:
if line.startswith("FIXTURE_MARK "):
phase = line.split()[1]
elif line.startswith("PERF_FRAME ") and phase == "scroll":
build, raster, total = (int(v) for v in line.split()[1:4])
scroll.append((build, raster, total))
if first is None or not scroll:
raise RuntimeError("the run reported no first frame or no scroll frames:\n" + "\n".join(lines[-20:]))
return {"startupMs": first - launched, "frames": len(scroll),
"buildSumMs": sum(f[0] for f in scroll) / 1000, "buildMaxMs": max(f[0] for f in scroll) / 1000,
"rasterSumMs": sum(f[1] for f in scroll) / 1000, "rasterMaxMs": max(f[1] for f in scroll) / 1000,
"rasterMedianMs": statistics.median(f[1] for f in scroll) / 1000,
"worstFrameMs": max(f[2] for f in scroll) / 1000}
def main():
parser = argparse.ArgumentParser(description=__doc__.splitlines()[0])
parser.add_argument("--bundle", required=True)
parser.add_argument("--repeat", type=int, default=5)
parser.add_argument("--display", type=int, default=97)
parser.add_argument("--switch", action="append", default=[], help="engine switch (profile builds)")
parser.add_argument("--timeout", type=float, default=60)
parser.add_argument("--env", action="append", default=[], help="extra VAR=value for the app")
args = parser.parse_args()
runs = [run_once(args.bundle, args.display, args.switch, args.timeout, args.env) for _ in range(args.repeat)]
median = {key: round(statistics.median(r[key] for r in runs), 1) for key in runs[0]}
print(json.dumps({"bundle": args.bundle, "switches": args.switch, "runs": len(runs), "median": median}, indent=2))
if __name__ == "__main__":
main()