Merge branch 'worktree-agent-a9a25296deadb0eaa'
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -33,6 +33,34 @@ const String _attributeShowcase =
|
||||
'\x1b]11;#000000\x07after strings\r\n'
|
||||
'abc\x1b[2D';
|
||||
|
||||
/// `?terminalUnicode=1`: widths, grapheme clusters, box drawing, blocks,
|
||||
/// Powerline and Nerd Font glyphs, printed after the build terminal's
|
||||
/// prompt. Each cluster takes the columns its width says (combining marks
|
||||
/// none, emoji and CJK two), so the first three lines' `|` fall in columns
|
||||
/// 6, 11 and 12.
|
||||
const String _unicodeShowcase =
|
||||
'printf unicode\r\n'
|
||||
'e\u0301 n\u0303 a\u0300\u0316 |\r\n'
|
||||
'\u4E2D\u6587 \u{1F600} \u{1F44D}\u{1F3FD} |\r\n'
|
||||
'\u{1F468}\u200D\u{1F469}\u200D\u{1F467} \u{1F1F5}\u{1F1F9} '
|
||||
'\u2764\uFE0F 1\uFE0F\u20E3 |\r\n'
|
||||
'\u250C\u2500\u252C\u2500\u2510 \u250F\u2501\u2533\u2501\u2513 '
|
||||
'\u2554\u2550\u2566\u2550\u2557 \u256D\u2500\u2500\u2500\u256E '
|
||||
'\u2588\u2589\u258A\u258B\u258C\u258D\u258E\u258F '
|
||||
'\u2581\u2582\u2583\u2584\u2585\u2586\u2587\u2588\r\n'
|
||||
'\u251C\u2500\u253C\u2500\u2524 \u2523\u2501\u254B\u2501\u252B '
|
||||
'\u2560\u2550\u256C\u2550\u2563 \u2502 \u2502 '
|
||||
'\u2591\u2591\u2592\u2592\u2593\u2593\u2588\u2588 '
|
||||
'\u2596\u2597\u2598\u2599\u259A\u259B\u259C\u259D\u259E\u259F\r\n'
|
||||
'\u2514\u2500\u2534\u2500\u2518 \u2517\u2501\u253B\u2501\u251B '
|
||||
'\u255A\u2550\u2569\u2550\u255D \u2570\u2500\u2500\u2500\u256F '
|
||||
'\u2504\u2504 \u2506 \u254C\u254C \u2571\u2572\u2573\r\n'
|
||||
'\x1b[30;44m \uE0A0 main \x1b[34;42m\uE0B0\x1b[30m ~/src \x1b[32;49m\uE0B0'
|
||||
'\x1b[0m \x1b[35m\uE0B6\x1b[30;45mok\x1b[35;49m\uE0B4\x1b[0m '
|
||||
'\x1b[33m\uE0B2\x1b[30;43m 12:00 \x1b[33;49m\uE0BC\x1b[0m '
|
||||
'\uE0B1 \uE0B3 |\r\n'
|
||||
'icons: \uF418 \uF09B \uF303 \uE615 \u23FB |\r\n';
|
||||
|
||||
void configureTerminalFixture(Map<String, String> params) {
|
||||
_enabled = params['terminals'] == '1';
|
||||
if (!_enabled) return;
|
||||
@@ -65,6 +93,9 @@ void configureTerminalFixture(Map<String, String> params) {
|
||||
if (params['terminalAttrs'] == '1') {
|
||||
_output['term_build'] = _output['term_build']! + _attributeShowcase;
|
||||
}
|
||||
if (params['terminalUnicode'] == '1') {
|
||||
_output['term_build'] = _output['term_build']! + _unicodeShowcase;
|
||||
}
|
||||
final mode = switch (params['terminal']) {
|
||||
'panel' => TerminalMode.panel,
|
||||
'float' => TerminalMode.float,
|
||||
|
||||
@@ -0,0 +1,215 @@
|
||||
// Terminal rendering bench: the app's emulator view (theme, text style and
|
||||
// the sliced output feed the terminals use) streaming generated output at a
|
||||
// fixed rate, with Flutter frame timings and rAF intervals recorded.
|
||||
//
|
||||
// Build (from app/):
|
||||
// flutter build web --profile --target tool/perf/terminal_stream_bench.dart \
|
||||
// --output build/terminal-bench
|
||||
// Run with tool/perf/terminal_stream_bench.mjs, or open the page with
|
||||
// `?workload=seq|yes|unicode|colors|screen|progress&mb=30&rate=30` (the window size sets the grid).
|
||||
// When the stream ends `window.__benchResult` holds a JSON summary:
|
||||
// frames, build/raster/total quantiles (ms), rAF interval quantiles (ms),
|
||||
// MB written, seconds and MB/s.
|
||||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
import 'dart:js_interop';
|
||||
import 'dart:ui';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/scheduler.dart';
|
||||
import 'package:pipelines_app/features/chat/shell/chat_shell_terminal_feed.dart';
|
||||
import 'package:pipelines_app/features/chat/shell/chat_shell_terminal_theme.dart';
|
||||
import 'package:xterm/xterm.dart';
|
||||
|
||||
@JS('__benchResult')
|
||||
external set _benchResult(JSString value);
|
||||
|
||||
void main() {
|
||||
final params = Uri.base.queryParameters;
|
||||
runApp(_Bench(params));
|
||||
}
|
||||
|
||||
class _Bench extends StatefulWidget {
|
||||
const _Bench(this.params);
|
||||
|
||||
final Map<String, String> params;
|
||||
|
||||
@override
|
||||
State<_Bench> createState() => _BenchState();
|
||||
}
|
||||
|
||||
class _BenchState extends State<_Bench> {
|
||||
late final Terminal _terminal = Terminal(maxLines: 10000);
|
||||
late final ChatShellTerminalFeed _feed = ChatShellTerminalFeed(
|
||||
(text, _) => _terminal.write(text),
|
||||
);
|
||||
final List<FrameTiming> _timings = [];
|
||||
final List<double> _intervals = [];
|
||||
Duration? _lastFrame;
|
||||
Timer? _producer;
|
||||
final Stopwatch _clock = Stopwatch();
|
||||
int _written = 0;
|
||||
int _counter = 0;
|
||||
bool _done = false;
|
||||
|
||||
String get _workload => widget.params['workload'] ?? 'seq';
|
||||
double get _megabytes => double.tryParse(widget.params['mb'] ?? '') ?? 30;
|
||||
double get _rate => double.tryParse(widget.params['rate'] ?? '') ?? 30;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
SchedulerBinding.instance.addTimingsCallback(_onTimings);
|
||||
SchedulerBinding.instance.addPersistentFrameCallback(_onFrame);
|
||||
// Let the first frames settle before streaming.
|
||||
Timer(const Duration(milliseconds: 1500), _start);
|
||||
}
|
||||
|
||||
void _onTimings(List<FrameTiming> timings) {
|
||||
if (_clock.isRunning) _timings.addAll(timings);
|
||||
}
|
||||
|
||||
void _onFrame(Duration stamp) {
|
||||
if (_clock.isRunning && _lastFrame != null) {
|
||||
_intervals.add((stamp - _lastFrame!).inMicroseconds / 1000);
|
||||
}
|
||||
_lastFrame = stamp;
|
||||
}
|
||||
|
||||
void _start() {
|
||||
_clock.start();
|
||||
const tick = Duration(milliseconds: 4);
|
||||
final perTick = (_rate * 1e6 * tick.inMicroseconds / 1e6).round();
|
||||
_producer = Timer.periodic(tick, (_) {
|
||||
if (_written >= _megabytes * 1e6) {
|
||||
_producer?.cancel();
|
||||
_feed.then(_finish);
|
||||
return;
|
||||
}
|
||||
final chunk = _chunk(perTick);
|
||||
_written += chunk.length;
|
||||
_feed.add(chunk, _written);
|
||||
});
|
||||
}
|
||||
|
||||
String _chunk(int size) {
|
||||
final out = StringBuffer();
|
||||
while (out.length < size) {
|
||||
_counter++;
|
||||
switch (_workload) {
|
||||
case 'yes':
|
||||
out.write('y\r\n');
|
||||
case 'unicode':
|
||||
out.write(
|
||||
'$_counter e\u0301 \u00F1 \u4E2D\u6587 \u{1F600} \u{1F44D}\u{1F3FD} \u{1F1F5}\u{1F1F9} \u2502 \u256D\u2500\u256E \u2593\u2592\u2591 \u{E0B0} done\r\n',
|
||||
);
|
||||
case 'colors':
|
||||
final c = 31 + _counter % 7;
|
||||
out.write(
|
||||
'\x1b[${c}m$_counter\x1b[0m \x1b[1mbold\x1b[0m '
|
||||
'plain text line with some words\r\n',
|
||||
);
|
||||
case 'screen':
|
||||
// A full-screen program redrawing every row (top, an editor).
|
||||
out.write('\x1b[H');
|
||||
for (var row = 0; row < 48; row++) {
|
||||
final c = 31 + (row + _counter) % 7;
|
||||
out.write(
|
||||
'\x1b[${c}m${(_counter + row).toString().padLeft(8)}'
|
||||
'\x1b[0m \x1b[7m cpu ${row % 100}% \x1b[0m '
|
||||
'${'process name and arguments ' * 4}\x1b[K\r\n',
|
||||
);
|
||||
}
|
||||
case 'progress':
|
||||
// A screen of text, then one status line rewritten in place (a
|
||||
// progress bar, a build counter): one row changes per frame.
|
||||
if (_counter == 1) {
|
||||
for (var row = 0; row < 47; row++) {
|
||||
out.write(
|
||||
'\x1b[3${row % 7 + 1}mline $row\x1b[0m '
|
||||
'${'static output that does not change ' * 3}\r\n',
|
||||
);
|
||||
}
|
||||
}
|
||||
final done = _counter % 50;
|
||||
out.write(
|
||||
'\r\x1b[1m[${'#' * done}${'.' * (50 - done)}]\x1b[0m '
|
||||
'$_counter files',
|
||||
);
|
||||
default:
|
||||
out.write('$_counter\r\n');
|
||||
}
|
||||
}
|
||||
return out.toString();
|
||||
}
|
||||
|
||||
void _finish() {
|
||||
if (_done) return;
|
||||
_done = true;
|
||||
// A last frame flushes the engine's batched timings.
|
||||
SchedulerBinding.instance.scheduleFrame();
|
||||
Timer(const Duration(milliseconds: 600), () {
|
||||
_clock.stop();
|
||||
final seconds = _clock.elapsedMicroseconds / 1e6;
|
||||
List<double> ms(Duration Function(FrameTiming t) pick) => [
|
||||
for (final t in _timings) pick(t).inMicroseconds / 1000,
|
||||
];
|
||||
final result = {
|
||||
'workload': _workload,
|
||||
'frames': _timings.length,
|
||||
'build': _quantiles(ms((t) => t.buildDuration)),
|
||||
'raster': _quantiles(ms((t) => t.rasterDuration)),
|
||||
'total': _quantiles(ms((t) => t.totalSpan)),
|
||||
'interval': _quantiles(_intervals),
|
||||
'mb': _written / 1e6,
|
||||
'seconds': seconds,
|
||||
'mbPerSecond': _written / 1e6 / seconds,
|
||||
};
|
||||
_benchResult = jsonEncode(result).toJS;
|
||||
// ignore: avoid_print
|
||||
print('BENCH_RESULT ${jsonEncode(result)}');
|
||||
});
|
||||
}
|
||||
|
||||
static Map<String, double> _quantiles(List<double> values) {
|
||||
if (values.isEmpty) return const {};
|
||||
final sorted = [...values]..sort();
|
||||
double at(double q) =>
|
||||
sorted[(q * (sorted.length - 1)).round().clamp(0, sorted.length - 1)];
|
||||
double round(double v) => (v * 100).roundToDouble() / 100;
|
||||
return {
|
||||
'p50': round(at(0.5)),
|
||||
'p90': round(at(0.9)),
|
||||
'p99': round(at(0.99)),
|
||||
'max': round(sorted.last),
|
||||
'mean': round(sorted.reduce((a, b) => a + b) / sorted.length),
|
||||
};
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_producer?.cancel();
|
||||
_feed.dispose();
|
||||
SchedulerBinding.instance.removeTimingsCallback(_onTimings);
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return MaterialApp(
|
||||
debugShowCheckedModeBanner: false,
|
||||
theme: ThemeData(brightness: Brightness.dark),
|
||||
home: Builder(
|
||||
builder: (context) => Scaffold(
|
||||
body: TerminalView(
|
||||
_terminal,
|
||||
theme: chatShellTerminalTheme(context),
|
||||
textStyle: chatShellTerminalStyle(context),
|
||||
padding: const EdgeInsets.all(8),
|
||||
readOnly: true,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
#!/usr/bin/env node
|
||||
// Streams generated output through the terminal bench build
|
||||
// (tool/perf/terminal_stream_bench.dart) in headless Chrome and prints one
|
||||
// JSON line per workload: Flutter frame build/raster quantiles, rAF
|
||||
// intervals measured in the page, and the throughput reached.
|
||||
//
|
||||
// node tool/perf/terminal_stream_bench.mjs --build build/terminal-bench \
|
||||
// [--workloads seq,yes,unicode,colors,screen,progress] [--mb 30] [--rate 30] [--size 1280x800]
|
||||
import { parseArgs } from 'node:util';
|
||||
import { setTimeout as delay } from 'node:timers/promises';
|
||||
import { openBrowser } from '../capture/browser.mjs';
|
||||
import { serveBuild } from '../capture/serve.mjs';
|
||||
|
||||
const { values: options } = parseArgs({
|
||||
options: {
|
||||
build: { type: 'string' },
|
||||
workloads: { type: 'string', default: 'seq,yes,unicode,colors,screen,progress' },
|
||||
mb: { type: 'string', default: '30' },
|
||||
rate: { type: 'string', default: '30' },
|
||||
size: { type: 'string', default: '1280x800' },
|
||||
timeout: { type: 'string', default: '120000' },
|
||||
params: { type: 'string', default: '' },
|
||||
},
|
||||
});
|
||||
if (!options.build) throw new Error('--build required');
|
||||
const [width, height] = options.size.split('x').map(Number);
|
||||
|
||||
const quantiles = (values) => {
|
||||
const sorted = [...values].sort((a, b) => a - b);
|
||||
const at = (q) => sorted[Math.round(q * (sorted.length - 1))] ?? 0;
|
||||
const r = (v) => Math.round(v * 100) / 100;
|
||||
return { p50: r(at(0.5)), p90: r(at(0.9)), p99: r(at(0.99)), max: r(sorted.at(-1) ?? 0) };
|
||||
};
|
||||
|
||||
const server = await serveBuild(options.build);
|
||||
const browser = await openBrowser();
|
||||
const evaluate = async (expression) => {
|
||||
const r = await browser.send('Runtime.evaluate', { expression, returnByValue: true });
|
||||
return r.result.value;
|
||||
};
|
||||
try {
|
||||
await browser.send('Page.enable');
|
||||
await browser.send('Runtime.enable');
|
||||
for (const workload of options.workloads.split(',')) {
|
||||
const url = new URL('/', server.origin);
|
||||
url.searchParams.set('workload', workload);
|
||||
url.searchParams.set('mb', options.mb);
|
||||
url.searchParams.set('rate', options.rate);
|
||||
for (const [k, v] of new URLSearchParams(options.params)) url.searchParams.set(k, v);
|
||||
await browser.send('Emulation.setDeviceMetricsOverride', { width, height, deviceScaleFactor: 1, mobile: false });
|
||||
await browser.send('Page.navigate', { url: url.href });
|
||||
await delay(300);
|
||||
await evaluate(`(() => {
|
||||
window.__raf = [];
|
||||
let last = performance.now();
|
||||
const tick = (t) => { window.__raf.push(t - last); last = t; if (!window.__benchResult) requestAnimationFrame(tick); };
|
||||
requestAnimationFrame(tick);
|
||||
return true;
|
||||
})()`);
|
||||
const deadline = Date.now() + Number(options.timeout);
|
||||
let result = null;
|
||||
while (!result && Date.now() < deadline) {
|
||||
await delay(500);
|
||||
result = await evaluate('window.__benchResult ?? null');
|
||||
}
|
||||
if (!result) throw new Error(`${workload}: no result before the timeout`);
|
||||
const raf = await evaluate('window.__raf');
|
||||
// Skip the start-up frames before streaming starts.
|
||||
console.log(JSON.stringify({ ...JSON.parse(result), pageRaf: quantiles(raf.slice(50)) }));
|
||||
}
|
||||
} finally {
|
||||
await browser.close?.();
|
||||
await server.close?.();
|
||||
}
|
||||
@@ -888,7 +888,9 @@ class _FixtureSink implements WebSocketSink {
|
||||
/// `?hits=N`, `?chats=N` and `?graph=1` add bench data
|
||||
/// (tool/perf/perf_fixture.dart);
|
||||
/// `?terminals=1` lists two machine terminals, and `?terminal=panel` or
|
||||
/// `?terminal=float` opens them at launch (tool/perf/terminal_fixture.dart);
|
||||
/// `?terminal=float` opens them at launch, with `?terminalAttrs=1` and
|
||||
/// `?terminalUnicode=1` adding emulator showcases
|
||||
/// (tool/perf/terminal_fixture.dart);
|
||||
/// `?windows=N` opens N floating probe windows whose content opens every
|
||||
/// kind of popup and a pushed page (tool/capture/window_probe.dart);
|
||||
/// `?speech=fake` reads replies aloud with a scripted engine, one word per
|
||||
|
||||
Reference in New Issue
Block a user