perf(editor): native Windows preview and UI-first timeline navigation (#11)
Gitea CI / Check code and tests (push) Successful in 8m7s
Gitea CI / Build Windows x64 app (push) Successful in 5m48s
Gitea CI / Build Android APK (push) Successful in 5m59s
Gitea CI / Audit and package Windows x64 (push) Successful in 1m17s
Gitea CI / Assemble and validate CI artifacts (push) Successful in 1m22s
Gitea CI / Gitea CI passed (push) Successful in 2s
Gitea CI / Check code and tests (push) Successful in 8m7s
Gitea CI / Build Windows x64 app (push) Successful in 5m48s
Gitea CI / Build Android APK (push) Successful in 5m59s
Gitea CI / Audit and package Windows x64 (push) Successful in 1m17s
Gitea CI / Assemble and validate CI artifacts (push) Successful in 1m22s
Gitea CI / Gitea CI passed (push) Successful in 2s
This commit was merged in pull request #11.
This commit is contained in:
1 parent
0ecf920669
commit
b4cb12cbe3
36 files changed
+3292
-148
No files matched your search
@@ -0,0 +1,71 @@
|
||||
# 完整编辑器拖拽实测
|
||||
|
||||
没有 `CUTDEX_FULL_APP_VIEWPORT_BENCH` 时入口立即返回。启用后使用正常持久化项目和时间线,通过真实播放头手势进入生产预览链路;不会加载素材夹具或替换页面。请先在正常编辑器打开待测素材所在的时间线并暂停播放。
|
||||
|
||||
代码职责:`config.dart` 校验配置,`workload.dart` 生成目标轨迹,`drag.dart` 投递实际手势并验证播放头,`diagnostics.dart` 校准 QPC/采样,`records.dart` 写出证据,`capture.dart` 管理可选捕获进程,`runner.dart` 编排和验证停止。
|
||||
|
||||
以下变量统一加 `CUTDEX_FULL_APP_VIEWPORT_` 前缀:
|
||||
|
||||
| 后缀 | 默认/含义 |
|
||||
|---|---|
|
||||
| `BENCH` | 必填输出目录;每次使用新目录 |
|
||||
| `START_GATE` | 可选门文件路径;正常项目加载后创建文件,最多等待120秒 |
|
||||
| `EXPECTED_FRAMES` | 可选预期时间线长度,容差2帧;未指定时从实际时间线读取 |
|
||||
| `TIMELINE_FPS` | 30;目标坐标的时间基准,不是源视频帧率 |
|
||||
| `ROUNDS` | 5 |
|
||||
| `PAIRED` | 0;设为1比较全片5%–95%往返和局部往返 |
|
||||
| `INPUT_HZ` / `INPUT_COUNT` | 60 / 360;配对模式每场景6秒,输入数量必须是至少6的偶数 |
|
||||
| `LOCAL_START_FRAME` | 实际时间线长度的28%;可指定复现旧测试位置 |
|
||||
| `LOCAL_SPAN_FRAMES` / `LOCAL_PIXELS_PER_FRAME` | 20 / 4 |
|
||||
| `EDGE_MARGIN_FRAMES` | 900;旧五场景模式首尾边距,也用于检查时间线足够长;短素材需缩小 |
|
||||
| `SAMPLE_INTERVAL_MS` | 16 |
|
||||
| `NATIVE_ONLY` | 1;采样原生提交,不捕获桌面 |
|
||||
| `CAPTURE_HELPER` | `NATIVE_ONLY=0` 时必填捕获工具绝对路径 |
|
||||
| `SILENT` | 0;保持生产 audible policy,设为1仅用于明确要求的静音对照 |
|
||||
|
||||
MIDE旧测试配置:`PAIRED=1`、`ROUNDS=3`、`EXPECTED_FRAMES=214073.82`、`LOCAL_START_FRAME=60137`、`NATIVE_ONLY=1`,其余保持默认。
|
||||
|
||||
输出保留 `inputs.csv`、`phases.csv`、`native-samples.jsonl`、`meta.json` 和 `progress.json` 的既有字段,`meta.json.configuration` 增加实际配置。停止仅等待已有请求完成,不发出额外定位;最终时钟必须命中最后目标,之后观察冻结窗口。通过状态在采样与文件流完成后写出,异常写入 `error.txt`。
|
||||
|
||||
输入/阶段CSV里的帧数使用配置的时间基准。兼容元数据中名字含 `At30Hz` 的字段仍换算为30Hz。原生提交数不能当作DWM屏幕扫描帧数;正式分析还须校验GPU、输出尺寸、冻结期间源帧计数和最终提交相对松手的时刻。
|
||||
|
||||
## 时间线切换实测
|
||||
|
||||
`main.dart` 提供独立、默认关闭的完整应用切换测试,实现在
|
||||
`../timeline_switch_bench.dart`。启动正常 Profile 程序前,将
|
||||
`CUTDEX_TIMELINE_SWITCH_BENCH` 设置为新的输出目录。测试保持生产 provider
|
||||
和编辑页面,通过 `GestureBinding` 点击真实时间线标签,输出
|
||||
`results.json` 和 `done.json`。
|
||||
|
||||
初始时间线必须不同于 `CUTDEX_TIMELINE_SWITCH_TARGET`;不设置时选择项目中
|
||||
第一个非当前时间线,因此项目至少需要两条时间线。测试等待初始预览控制器
|
||||
完成初始化。可选的 `CUTDEX_TIMELINE_SWITCH_GATE` 文件允许先检查正常工作区,
|
||||
创建该文件后才开始测量。`CUTDEX_TIMELINE_SWITCH_RAPID=1` 改为连续点击五次,
|
||||
每次计划间隔 16 ms,并在最后一次点击后观察五秒,验证最新选择不被旧请求覆盖;
|
||||
输出为 `rapid.json`。
|
||||
|
||||
UI 耗时记录到目标工作区的 post-frame 回调,数据耗时记录到 `Projects` 发布
|
||||
准备好的文档。原生首帧采用异步 20 ms 诊断轮询,因此记录的是首次观察耗时;
|
||||
缓存时间线的原生计数表示复用已有帧。首次打开对照必须使用新进程和未缓存的
|
||||
目标会话。启动出错或正常切换测试缺少原生帧均判失败;`startup.json` 记录
|
||||
初始状态。快速切换模式验证状态一致性,未单独计时原生首帧。普通启动应清除
|
||||
上述测试环境变量。
|
||||
|
||||
## 触摸板缩放回放与驱动事件
|
||||
|
||||
`../timeline_gesture_bench.dart` 提供默认关闭的完整应用手势回放。启动正常
|
||||
Profile 程序前设置 `CUTDEX_TIMELINE_GESTURE_BENCH` 为新输出目录,测试等待
|
||||
六秒后向当前时间线发送原生 pan/zoom 协议及 Ctrl+滚轮输入。播放头应在
|
||||
viewport 内,键盘修饰键应松开。输入走正常命中测试和手势识别路径,输出
|
||||
`results.json`、`done.json`;异常输出 `error.txt`。回放结束恢复原相机,
|
||||
不定位播放头、不修改时间线文档。回放不等同于物理触摸板操作。
|
||||
|
||||
可独立设置 `CUTDEX_TIMELINE_GESTURE_TRACE` 为 JSONL 文件路径,记录实际
|
||||
`PointerPanZoom` 与 `PointerScroll` 事件以及 Ctrl/Meta 状态。`source` 区分
|
||||
`protocol-replay` 与 `driver`,回放使用 device 7200。记录默认关闭,启用时
|
||||
每秒刷新文件,可用于确认驱动是发送合并的 pan/scale,还是兼容滚轮输入。
|
||||
普通启动应清除这两个环境变量。
|
||||
|
||||
独立测试入口 `tool/windows/native_preview_bench.dart` 要求显式设置
|
||||
`CUTDEX_BENCH_SOURCE`、`CUTDEX_BENCH_DURATION_FRAMES`(30 Hz 时基下的正整数
|
||||
时长)和 `CUTDEX_BENCH_CAPTURE_HELPER`;素材及桌面捕获工具保留在仓库外。
|
||||
@@ -0,0 +1,62 @@
|
||||
import 'dart:async';
|
||||
import 'dart:io';
|
||||
|
||||
import 'config.dart';
|
||||
|
||||
/// Optional desktop capture process; its path is supplied explicitly.
|
||||
class BenchCapture {
|
||||
BenchCapture._(this.output, this.process);
|
||||
final Directory output;
|
||||
final Process process;
|
||||
|
||||
static Future<BenchCapture?> start(
|
||||
ViewportBenchConfig config,
|
||||
Directory output,
|
||||
) async {
|
||||
if (config.nativeOnly) return null;
|
||||
final helper = config.captureHelper!;
|
||||
final probe = await Process.run(helper, ['$pid']);
|
||||
if (probe.exitCode != 0) {
|
||||
throw StateError('Capture probe failed: ${probe.stderr}');
|
||||
}
|
||||
final line = probe.stdout
|
||||
.toString()
|
||||
.split('\n')
|
||||
.singleWhere((s) => s.startsWith('CutdexD3D11Preview 1 '));
|
||||
final rect = line.trim().split(' ').skip(2).map(int.parse).toList();
|
||||
final process = await Process.start(helper, [
|
||||
output.path,
|
||||
'$pid',
|
||||
'${rect[0] + 8}',
|
||||
'${rect[1] + 8}',
|
||||
'${rect[2] - 8}',
|
||||
'${rect[3] - 8}',
|
||||
]);
|
||||
unawaited(process.stdout.drain<void>());
|
||||
unawaited(process.stderr.drain<void>());
|
||||
final capture = BenchCapture._(output, process);
|
||||
for (
|
||||
var i = 0;
|
||||
!await File('${output.path}/capture-ready').exists() && i < 500;
|
||||
i++
|
||||
) {
|
||||
await Future<void>.delayed(const Duration(milliseconds: 10));
|
||||
}
|
||||
if (!await File('${output.path}/capture-ready').exists()) {
|
||||
await capture.stop();
|
||||
throw StateError('Capture not ready');
|
||||
}
|
||||
return capture;
|
||||
}
|
||||
|
||||
Future<void> stop() async {
|
||||
await File('${output.path}/capture-stop').writeAsString('stop');
|
||||
try {
|
||||
final code = await process.exitCode.timeout(const Duration(seconds: 10));
|
||||
if (code != 0) throw StateError('Capture exit $code');
|
||||
} on TimeoutException {
|
||||
process.kill();
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
/// Explicit inputs for the opt-in full-editor benchmark.
|
||||
class ViewportBenchConfig {
|
||||
ViewportBenchConfig.fromEnvironment(Map<String, String> environment)
|
||||
: outputPath = environment['CUTDEX_FULL_APP_VIEWPORT_BENCH']!,
|
||||
startGate = environment['CUTDEX_FULL_APP_VIEWPORT_START_GATE'],
|
||||
expectedFrames = _number(environment, 'EXPECTED_FRAMES'),
|
||||
rounds = _integer(environment, 'ROUNDS', 5),
|
||||
paired = _flag(environment, 'PAIRED', false),
|
||||
silent = _flag(environment, 'SILENT', false),
|
||||
nativeOnly = _flag(environment, 'NATIVE_ONLY', true),
|
||||
captureHelper = environment['CUTDEX_FULL_APP_VIEWPORT_CAPTURE_HELPER'],
|
||||
timelineFps = _integer(environment, 'TIMELINE_FPS', 30),
|
||||
inputHz = _integer(environment, 'INPUT_HZ', 60),
|
||||
inputCount = _integer(environment, 'INPUT_COUNT', 360),
|
||||
localStartFrame = _optionalInteger(environment, 'LOCAL_START_FRAME'),
|
||||
localSpanFrames = _integer(environment, 'LOCAL_SPAN_FRAMES', 20),
|
||||
localPixelsPerFrame = _number(environment, 'LOCAL_PIXELS_PER_FRAME') ?? 4,
|
||||
edgeMarginFrames = _integer(environment, 'EDGE_MARGIN_FRAMES', 900),
|
||||
sampleIntervalMs = _integer(environment, 'SAMPLE_INTERVAL_MS', 16) {
|
||||
if (outputPath.isEmpty ||
|
||||
rounds < 1 ||
|
||||
timelineFps < 1 ||
|
||||
inputHz < 1 ||
|
||||
inputCount < 6 ||
|
||||
inputCount.isOdd ||
|
||||
localSpanFrames < 1 ||
|
||||
localPixelsPerFrame <= 0 ||
|
||||
edgeMarginFrames < 1 ||
|
||||
sampleIntervalMs < 1 ||
|
||||
(expectedFrames != null && expectedFrames! <= 0)) {
|
||||
throw ArgumentError('Invalid viewport benchmark configuration');
|
||||
}
|
||||
if (!nativeOnly && (captureHelper == null || captureHelper!.isEmpty)) {
|
||||
throw ArgumentError('CAPTURE_HELPER is required when NATIVE_ONLY=0');
|
||||
}
|
||||
}
|
||||
|
||||
final String outputPath;
|
||||
final String? startGate;
|
||||
final double? expectedFrames;
|
||||
final int rounds, timelineFps, inputHz, inputCount, localSpanFrames;
|
||||
final int edgeMarginFrames, sampleIntervalMs;
|
||||
final int? localStartFrame;
|
||||
final double localPixelsPerFrame;
|
||||
final bool paired, silent, nativeOnly;
|
||||
final String? captureHelper;
|
||||
|
||||
Map<String, Object?> toJson() => {
|
||||
'expectedFrames': expectedFrames,
|
||||
'rounds': rounds,
|
||||
'paired': paired,
|
||||
'timelineFps': timelineFps,
|
||||
'inputHz': inputHz,
|
||||
'inputCount': inputCount,
|
||||
'localStartFrame': localStartFrame,
|
||||
'localSpanFrames': localSpanFrames,
|
||||
'localPixelsPerFrame': localPixelsPerFrame,
|
||||
'edgeMarginFrames': edgeMarginFrames,
|
||||
'sampleIntervalMs': sampleIntervalMs,
|
||||
'nativeOnly': nativeOnly,
|
||||
'captureHelper': captureHelper,
|
||||
'silent': silent,
|
||||
};
|
||||
|
||||
static int _integer(Map<String, String> env, String key, int fallback) =>
|
||||
_optionalInteger(env, key) ?? fallback;
|
||||
static int? _optionalInteger(Map<String, String> env, String key) {
|
||||
final value = env['CUTDEX_FULL_APP_VIEWPORT_$key'];
|
||||
return value == null ? null : int.parse(value);
|
||||
}
|
||||
|
||||
static double? _number(Map<String, String> env, String key) {
|
||||
final value = env['CUTDEX_FULL_APP_VIEWPORT_$key'];
|
||||
if (value == null) return null;
|
||||
final number = double.parse(value);
|
||||
if (!number.isFinite) throw ArgumentError('Non-finite $key');
|
||||
return number;
|
||||
}
|
||||
|
||||
static bool _flag(Map<String, String> env, String key, bool fallback) {
|
||||
final value = env['CUTDEX_FULL_APP_VIEWPORT_$key'];
|
||||
return switch (value) {
|
||||
null => fallback,
|
||||
'1' => true,
|
||||
'0' => false,
|
||||
_ => throw ArgumentError('$key must be 0 or 1'),
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
/// Native QPC clock calibration and bounded asynchronous diagnostics sampling.
|
||||
class BenchDiagnostics {
|
||||
BenchDiagnostics(this.sessionId, this.clock);
|
||||
final String sessionId;
|
||||
final Stopwatch clock;
|
||||
static const _channel = MethodChannel('cutdex_runtime');
|
||||
double uncertaintyMs = double.infinity, _offset = 0;
|
||||
Timer? _timer;
|
||||
Future<void>? _pending;
|
||||
Object? _sampleError;
|
||||
|
||||
double now() => _offset + clock.elapsedMicroseconds / 1000;
|
||||
Future<Map<String, dynamic>> read() async =>
|
||||
(await _channel.invokeMapMethod<String, dynamic>('previewDiagnostics', {
|
||||
'sessionId': sessionId,
|
||||
}))!;
|
||||
|
||||
Future<void> calibrate() async {
|
||||
for (var i = 0; i < 20; i++) {
|
||||
final begin = clock.elapsedMicroseconds / 1000;
|
||||
final diagnostic = await read();
|
||||
final end = clock.elapsedMicroseconds / 1000;
|
||||
if (end - begin < uncertaintyMs) {
|
||||
uncertaintyMs = end - begin;
|
||||
_offset = (diagnostic['qpcMs'] as num).toDouble() - (begin + end) / 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> until(double due) async {
|
||||
while (now() < due) {
|
||||
await Future<void>.delayed(
|
||||
Duration(microseconds: ((due - now()) * 1000).ceil().clamp(1, 1000000)),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
void startSamples(IOSink sink, int intervalMs) {
|
||||
_timer = Timer.periodic(Duration(milliseconds: intervalMs), (_) {
|
||||
if (_pending != null || _sampleError != null) return;
|
||||
_pending = _sample(sink).whenComplete(() => _pending = null);
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> _sample(IOSink sink) async {
|
||||
try {
|
||||
sink.writeln(jsonEncode(await read()));
|
||||
} catch (error) {
|
||||
_sampleError = error;
|
||||
}
|
||||
}
|
||||
|
||||
void check() {
|
||||
if (_sampleError != null) {
|
||||
throw StateError('Native sampler failed: $_sampleError');
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> stopSamples() async {
|
||||
_timer?.cancel();
|
||||
await _pending;
|
||||
check();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,138 @@
|
||||
import 'package:cutdex_sdk/timeline/model.dart';
|
||||
import 'package:cutdex_sdk/timeline/layout.dart';
|
||||
import 'package:cutdex_sdk/timeline_ui.dart';
|
||||
import 'package:flutter/gestures.dart';
|
||||
import 'package:flutter/rendering.dart';
|
||||
|
||||
/// Real playhead gesture input, quantized to physical pixels like desktop input.
|
||||
class BenchPlayheadDrag {
|
||||
BenchPlayheadDrag({
|
||||
required this.view,
|
||||
required this.ruler,
|
||||
required this.viewport,
|
||||
required this.scale,
|
||||
required this.clock,
|
||||
required this.pointer,
|
||||
required this.warmFrame,
|
||||
required this.fps,
|
||||
}) : camera = view.camera;
|
||||
final TimelineViewController view;
|
||||
final RenderBox ruler;
|
||||
final TimelineViewportRect viewport;
|
||||
final TimelineCamera camera;
|
||||
final double scale;
|
||||
final Stopwatch clock;
|
||||
final int pointer, warmFrame, fps;
|
||||
Offset _position = Offset.zero, _origin = Offset.zero;
|
||||
bool _active = false;
|
||||
|
||||
int tick(int frame) =>
|
||||
TimelineClock.standard.toTicks(RationalTime(frame, fps));
|
||||
double get _pixelsPerFrame => camera.pixelsPerTick * tick(1);
|
||||
int _delta(int frame) =>
|
||||
((frame - warmFrame) * _pixelsPerFrame * scale).round();
|
||||
int target(int frame) =>
|
||||
(warmFrame + _delta(frame) / (_pixelsPerFrame * scale)).round();
|
||||
|
||||
Future<void> begin() async {
|
||||
final point = ruler.localToGlobal(
|
||||
Offset(
|
||||
camera.screenXForTick(tick(warmFrame), viewport),
|
||||
ruler.size.height / 2,
|
||||
),
|
||||
);
|
||||
_position = Offset(
|
||||
(point.dx * scale).round() / scale,
|
||||
(point.dy * scale).round() / scale,
|
||||
);
|
||||
GestureBinding.instance.handlePointerEvent(
|
||||
PointerAddedEvent(
|
||||
pointer: pointer,
|
||||
device: 42,
|
||||
kind: PointerDeviceKind.mouse,
|
||||
position: _position,
|
||||
),
|
||||
);
|
||||
GestureBinding.instance.handlePointerEvent(
|
||||
PointerDownEvent(
|
||||
pointer: pointer,
|
||||
device: 42,
|
||||
kind: PointerDeviceKind.mouse,
|
||||
buttons: kPrimaryButton,
|
||||
position: _position,
|
||||
timeStamp: clock.elapsed,
|
||||
),
|
||||
);
|
||||
_active = true;
|
||||
_move(_position + const Offset(40, 0));
|
||||
await Future<void>.delayed(const Duration(milliseconds: 20));
|
||||
if (!view.isScrubbing || view.playheadTick != tick(warmFrame)) {
|
||||
throw StateError('Playhead drag warmup failed');
|
||||
}
|
||||
_origin = _position;
|
||||
}
|
||||
|
||||
void moveTo(int frame) {
|
||||
_move(_origin + Offset(_delta(frame) / scale, 0));
|
||||
if (!view.isScrubbing || view.playheadTick != tick(target(frame))) {
|
||||
throw StateError('Real playhead mismatch at input frame $frame');
|
||||
}
|
||||
}
|
||||
|
||||
void _move(Offset next) {
|
||||
GestureBinding.instance.handlePointerEvent(
|
||||
PointerMoveEvent(
|
||||
pointer: pointer,
|
||||
device: 42,
|
||||
kind: PointerDeviceKind.mouse,
|
||||
buttons: kPrimaryButton,
|
||||
position: next,
|
||||
delta: next - _position,
|
||||
timeStamp: clock.elapsed,
|
||||
),
|
||||
);
|
||||
_position = next;
|
||||
}
|
||||
|
||||
void end() {
|
||||
GestureBinding.instance.handlePointerEvent(
|
||||
PointerUpEvent(
|
||||
pointer: pointer,
|
||||
device: 42,
|
||||
kind: PointerDeviceKind.mouse,
|
||||
position: _position,
|
||||
timeStamp: clock.elapsed,
|
||||
),
|
||||
);
|
||||
_remove();
|
||||
if (view.isScrubbing || !identical(camera, view.camera)) {
|
||||
throw StateError('Release/camera failure');
|
||||
}
|
||||
}
|
||||
|
||||
void cancel() {
|
||||
if (!_active) return;
|
||||
GestureBinding.instance.handlePointerEvent(
|
||||
PointerCancelEvent(
|
||||
pointer: pointer,
|
||||
device: 42,
|
||||
kind: PointerDeviceKind.mouse,
|
||||
position: _position,
|
||||
timeStamp: clock.elapsed,
|
||||
),
|
||||
);
|
||||
_remove();
|
||||
}
|
||||
|
||||
void _remove() {
|
||||
GestureBinding.instance.handlePointerEvent(
|
||||
PointerRemovedEvent(
|
||||
pointer: pointer,
|
||||
device: 42,
|
||||
kind: PointerDeviceKind.mouse,
|
||||
position: _position,
|
||||
),
|
||||
);
|
||||
_active = false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
|
||||
/// Owns benchmark output streams and metadata, preserving the existing CSV schema.
|
||||
class BenchRecords {
|
||||
BenchRecords(this.output)
|
||||
: inputs = File('${output.path}/inputs.csv').openWrite(),
|
||||
phases = File('${output.path}/phases.csv').openWrite(),
|
||||
samples = File('${output.path}/native-samples.jsonl').openWrite() {
|
||||
inputs.writeln(
|
||||
'round,scenario,index,target,qpc_ms,scheduled_ms,request_ms',
|
||||
);
|
||||
phases.writeln(
|
||||
'round,scenario,start_ms,end_ms,release_begin_ms,final_frame,final_clock_frame,freeze_begin_ms,freeze_end_ms',
|
||||
);
|
||||
}
|
||||
final Directory output;
|
||||
final IOSink inputs, phases, samples;
|
||||
Future<void>? _closing;
|
||||
final stages = <Map<String, Object?>>[], checks = <Map<String, Object?>>[];
|
||||
|
||||
void input(
|
||||
int round,
|
||||
int scenario,
|
||||
int index,
|
||||
int target,
|
||||
double begin,
|
||||
double due,
|
||||
double returned,
|
||||
) => inputs.writeln(
|
||||
'$round,$scenario,$index,$target,$begin,$due,${returned - begin}',
|
||||
);
|
||||
void phase(
|
||||
int round,
|
||||
int scenario,
|
||||
double start,
|
||||
double end,
|
||||
double release,
|
||||
int finalFrame,
|
||||
double actual,
|
||||
double frozenBegin,
|
||||
double frozenEnd,
|
||||
) => phases.writeln(
|
||||
'$round,$scenario,$start,$end,$release,$finalFrame,$actual,$frozenBegin,$frozenEnd',
|
||||
);
|
||||
Future<void> progress(int round) =>
|
||||
File('${output.path}/progress.json')
|
||||
.writeAsString(jsonEncode({'completedRounds': round}));
|
||||
Future<void> complete(Map<String, Object?> metadata) =>
|
||||
File('${output.path}/meta.json').writeAsString(
|
||||
jsonEncode({
|
||||
...metadata,
|
||||
'nativeDiagnostics': stages,
|
||||
'checks': checks,
|
||||
}),
|
||||
);
|
||||
Future<void> close() => _closing ??= _close();
|
||||
|
||||
Future<void> _close() async {
|
||||
await samples.close();
|
||||
await inputs.close();
|
||||
await phases.close();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,259 @@
|
||||
import 'dart:async';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:cutdex/features/preview/preview_panel.dart';
|
||||
import 'package:cutdex_sdk/editor.dart';
|
||||
import 'package:cutdex_sdk/runtime.dart';
|
||||
import 'package:cutdex_sdk/timeline/model.dart';
|
||||
import 'package:cutdex_sdk/timeline/layout.dart';
|
||||
import 'package:cutdex_sdk/timeline_ui.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
|
||||
import 'capture.dart';
|
||||
import 'config.dart';
|
||||
import 'diagnostics.dart';
|
||||
import 'drag.dart';
|
||||
import 'records.dart';
|
||||
import 'workload.dart';
|
||||
|
||||
Future<void> _sleep(int ms) => Future<void>.delayed(Duration(milliseconds: ms));
|
||||
|
||||
/// Orchestrates existing editor state, real input, exact-stop validation and output.
|
||||
Future<void> runFullAppViewportBench(ViewportBenchConfig config) async {
|
||||
final output = Directory(config.outputPath);
|
||||
final clock = Stopwatch()..start();
|
||||
BenchCapture? capture;
|
||||
BenchDiagnostics? diagnostics;
|
||||
BenchRecords? records;
|
||||
BenchPlayheadDrag? activeDrag;
|
||||
await output.create(recursive: true);
|
||||
try {
|
||||
await _sleep(6000);
|
||||
if (config.startGate case final gatePath?) {
|
||||
final gate = File(gatePath);
|
||||
for (var i = 0; !await gate.exists() && i < 240; i++) {
|
||||
await _sleep(500);
|
||||
}
|
||||
if (!await gate.exists()) {
|
||||
throw StateError('Benchmark start gate timed out');
|
||||
}
|
||||
}
|
||||
Element? previewElement;
|
||||
TimelineViewport? timeline;
|
||||
RenderBox? ruler;
|
||||
void visit(Element element) {
|
||||
if (element.widget is EditorPreviewPanel) previewElement = element;
|
||||
if (element.widget is TimelineViewport) {
|
||||
timeline = element.widget as TimelineViewport;
|
||||
}
|
||||
if (element.widget is TimelineRuler) {
|
||||
ruler = element.findRenderObject() as RenderBox?;
|
||||
}
|
||||
element.visitChildElements(visit);
|
||||
}
|
||||
|
||||
WidgetsBinding.instance.rootElement!.visitChildElements(visit);
|
||||
if (previewElement == null || timeline == null || ruler == null) {
|
||||
throw StateError('Full normal editor is not open');
|
||||
}
|
||||
final panel = previewElement!.widget as EditorPreviewPanel;
|
||||
final container = ProviderScope.containerOf(previewElement!);
|
||||
final preview = container
|
||||
.read(editorPreviewProvider(panel.projectId, panel.timelineId))
|
||||
.asData
|
||||
?.value;
|
||||
if (preview?.session == null || preview!.error != null) {
|
||||
throw StateError('Normal preview unavailable');
|
||||
}
|
||||
final sequence = preview.activeSequence()!;
|
||||
final view = timeline!.controller;
|
||||
final endTime = TimelineClock.standard.fromTicks(view.contentEndTick);
|
||||
final endFrame =
|
||||
endTime.numerator * config.timelineFps / endTime.denominator;
|
||||
final workloads = ViewportBenchWorkload.forTimeline(config, endFrame);
|
||||
view.fitTimeline();
|
||||
await _sleep(500);
|
||||
final viewport = TimelineViewportRect(
|
||||
width: ruler!.size.width,
|
||||
height: ruler!.size.height,
|
||||
);
|
||||
final scale = View.of(previewElement!).devicePixelRatio;
|
||||
final clipStart = view.camera.screenXForTick(0, viewport);
|
||||
final clipEnd = view.camera.screenXForTick(view.contentEndTick, viewport);
|
||||
if (clipStart < 0 || clipEnd > viewport.width) {
|
||||
throw StateError('Clip outside viewport');
|
||||
}
|
||||
final native = diagnostics = BenchDiagnostics(preview.session!.id, clock);
|
||||
await native.calibrate();
|
||||
capture = await BenchCapture.start(config, output);
|
||||
final record = records = BenchRecords(output);
|
||||
native.startSamples(record.samples, config.sampleIntervalMs);
|
||||
int tick(int frame) =>
|
||||
TimelineClock.standard.toTicks(RationalTime(frame, config.timelineFps));
|
||||
|
||||
for (var round = 1; round <= config.rounds; round++) {
|
||||
for (final workload in workloads) {
|
||||
final scenario = workload.scenario;
|
||||
if (config.paired) {
|
||||
if (workload.local) {
|
||||
view.setCamera(
|
||||
TimelineCamera(
|
||||
baseTick: tick(workload.cameraBaseFrame),
|
||||
pixelsPerTick: config.localPixelsPerFrame / tick(1),
|
||||
verticalOffset: view.camera.verticalOffset,
|
||||
),
|
||||
);
|
||||
} else {
|
||||
view.fitTimeline();
|
||||
}
|
||||
await _sleep(100);
|
||||
}
|
||||
final warm = workload.warmFrame;
|
||||
final drag = activeDrag = BenchPlayheadDrag(
|
||||
view: view,
|
||||
ruler: ruler!,
|
||||
viewport: viewport,
|
||||
scale: scale,
|
||||
clock: clock,
|
||||
pointer: 100 + round * 10 + scenario,
|
||||
warmFrame: warm,
|
||||
fps: config.timelineFps,
|
||||
);
|
||||
await preview.controlPreview(
|
||||
sequence,
|
||||
PreviewAction.seek,
|
||||
at: CommandTime(warm, config.timelineFps),
|
||||
);
|
||||
await _sleep(80);
|
||||
if (config.silent) {
|
||||
await preview.session!.beginSkimming(mode: SkimmingMode.silent);
|
||||
}
|
||||
await drag.begin();
|
||||
drag.moveTo(workload.idealFrame(0));
|
||||
await _sleep(350);
|
||||
final before = await native.read();
|
||||
final start = native.now();
|
||||
for (var i = 0; i < workload.count; i++) {
|
||||
final due = start + 1000 * i / workload.hz;
|
||||
await native.until(due);
|
||||
final begin = native.now();
|
||||
final ideal = workload.idealFrame(i);
|
||||
drag.moveTo(ideal);
|
||||
record.input(
|
||||
round,
|
||||
scenario,
|
||||
i,
|
||||
drag.target(ideal),
|
||||
begin,
|
||||
due,
|
||||
native.now(),
|
||||
);
|
||||
}
|
||||
await native.until(start + workload.durationMs);
|
||||
final end = native.now();
|
||||
final release = native.now();
|
||||
drag.end();
|
||||
activeDrag = null;
|
||||
await preview.waitForPendingPreview();
|
||||
final settled = await preview.session!.refresh();
|
||||
final settledAt = native.now();
|
||||
await _sleep(350);
|
||||
final frozenBegin = native.now();
|
||||
await _sleep(350);
|
||||
final snapshot = await preview.session!.refresh();
|
||||
final after = await native.read();
|
||||
record.stages.add({
|
||||
'round': round,
|
||||
'scenario': scenario,
|
||||
'before': before,
|
||||
'after': after,
|
||||
'settledAtMs': settledAt,
|
||||
'settledClock':
|
||||
'${settled.position.numerator}/${settled.position.denominator}',
|
||||
});
|
||||
final actual =
|
||||
snapshot.position.numerator *
|
||||
config.timelineFps /
|
||||
snapshot.position.denominator;
|
||||
final finalTarget = drag.target(
|
||||
workload.idealFrame(workload.count - 1),
|
||||
);
|
||||
if ((actual - finalTarget).abs() > .01 || preview.error != null) {
|
||||
throw StateError('Final precision failure $actual');
|
||||
}
|
||||
native.check();
|
||||
record.checks.add({
|
||||
'round': round,
|
||||
'scenario': scenario,
|
||||
'finalClockFrame': actual,
|
||||
'target': finalTarget,
|
||||
'state': snapshot.state.name,
|
||||
});
|
||||
record.phase(
|
||||
round,
|
||||
scenario,
|
||||
start,
|
||||
end,
|
||||
release,
|
||||
finalTarget,
|
||||
actual,
|
||||
frozenBegin,
|
||||
native.now(),
|
||||
);
|
||||
}
|
||||
await record.progress(round);
|
||||
}
|
||||
await capture?.stop();
|
||||
capture = null;
|
||||
await native.stopSamples();
|
||||
await record.close();
|
||||
await record.complete({
|
||||
'status': 'passed',
|
||||
'entrypoint': 'lib/main.dart',
|
||||
'fullApp': true,
|
||||
'startGateUsed': config.startGate != null,
|
||||
'configuration': config.toJson(),
|
||||
'projectId': panel.projectId,
|
||||
'timelineId': panel.timelineId,
|
||||
'sequenceId': sequence.value,
|
||||
'timelineEndFramesAt30Hz': endFrame * 30 / config.timelineFps,
|
||||
'firstSampleFrameAt30Hz':
|
||||
config.edgeMarginFrames * 30 / config.timelineFps,
|
||||
'lastSampleFrameAt30Hz':
|
||||
(endFrame.round() - config.edgeMarginFrames - 1) *
|
||||
30 /
|
||||
config.timelineFps,
|
||||
'clipStartX': clipStart,
|
||||
'clipEndX': clipEnd,
|
||||
'viewportWidth': viewport.width,
|
||||
'devicePixelRatio': scale,
|
||||
'qpcCalibrationRoundTripMs': native.uncertaintyMs,
|
||||
'inputRoute': 'GestureBinding -> real normal TimelineViewport playhead handle -> production preview/runtime/native presenter',
|
||||
'physicalPixelInput': true,
|
||||
'rounds': config.rounds,
|
||||
'pairedWideLocal': config.paired,
|
||||
'nativeOnly': config.nativeOnly,
|
||||
'silentOverride': config.silent,
|
||||
'skimmingPolicy': preview.policy.skimmingMode.name,
|
||||
'canvas': {
|
||||
'width': preview.canvas.width,
|
||||
'height': preview.canvas.height,
|
||||
},
|
||||
'timelineSettings': preview.timeline.settings,
|
||||
});
|
||||
// Leave the normal editor paused with the complete clip visible.
|
||||
view.fitTimeline();
|
||||
} finally {
|
||||
activeDrag?.cancel();
|
||||
try {
|
||||
await capture?.stop();
|
||||
} finally {
|
||||
try {
|
||||
await diagnostics?.stopSamples();
|
||||
} finally {
|
||||
await records?.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
import 'config.dart';
|
||||
|
||||
/// A deterministic input sequence; independent of Flutter, decoding and sampling.
|
||||
class ViewportBenchWorkload {
|
||||
const ViewportBenchWorkload({
|
||||
required this.scenario,
|
||||
required this.hz,
|
||||
required this.count,
|
||||
required this.firstFrame,
|
||||
required this.lastFrame,
|
||||
required this.steps,
|
||||
required this.paired,
|
||||
required this.localSpanFrames,
|
||||
required this.timelineEndFrame,
|
||||
});
|
||||
|
||||
final int scenario, hz, count, firstFrame, lastFrame, steps, localSpanFrames;
|
||||
final bool paired;
|
||||
final double timelineEndFrame;
|
||||
bool get local => paired && scenario == 1;
|
||||
double get durationMs => 1000 * count / hz;
|
||||
int get warmFrame => idealFrame(0) - 1;
|
||||
int get cameraBaseFrame => firstFrame - 17;
|
||||
|
||||
int idealFrame(int i) {
|
||||
if (local) {
|
||||
final phase = i % (2 * localSpanFrames);
|
||||
return firstFrame +
|
||||
(phase <= localSpanFrames ? phase : 2 * localSpanFrames - phase);
|
||||
}
|
||||
if (paired) {
|
||||
final half = count ~/ 2;
|
||||
final phase = i % count;
|
||||
final index = phase < half ? phase : count - 1 - phase;
|
||||
return (timelineEndFrame * (.05 + .9 * index / (half - 1))).round();
|
||||
}
|
||||
final period = 2 * (steps - 1);
|
||||
final phase = i % period;
|
||||
final index = switch (scenario) {
|
||||
0 => i,
|
||||
1 => steps - 1 - i,
|
||||
_ => phase < steps ? phase : period - phase,
|
||||
};
|
||||
return (firstFrame * (steps - 1) +
|
||||
(lastFrame - firstFrame) * index +
|
||||
(steps - 1) ~/ 2) ~/
|
||||
(steps - 1);
|
||||
}
|
||||
|
||||
static List<ViewportBenchWorkload> forTimeline(
|
||||
ViewportBenchConfig config,
|
||||
double endFrame,
|
||||
) {
|
||||
if (!endFrame.isFinite ||
|
||||
endFrame < 2 * config.edgeMarginFrames + 2 ||
|
||||
(config.expectedFrames != null &&
|
||||
(endFrame - config.expectedFrames!).abs() > 2)) {
|
||||
throw StateError('Unexpected normal timeline length: $endFrame');
|
||||
}
|
||||
final localStart = config.localStartFrame ?? (endFrame * .28).round();
|
||||
if (config.paired &&
|
||||
(localStart < 18 || localStart + config.localSpanFrames >= endFrame)) {
|
||||
throw StateError('Local benchmark range falls outside the timeline');
|
||||
}
|
||||
final steps = config.inputCount ~/ 3;
|
||||
return List.generate(config.paired ? 2 : 5, (scenario) {
|
||||
final hz = config.paired
|
||||
? config.inputHz
|
||||
: config.inputHz * [1, 2, 1, 2, 4][scenario];
|
||||
final count = config.paired
|
||||
? config.inputCount
|
||||
: [
|
||||
steps,
|
||||
steps,
|
||||
config.inputCount,
|
||||
config.inputCount * 2,
|
||||
config.inputCount * 4,
|
||||
][scenario];
|
||||
return ViewportBenchWorkload(
|
||||
scenario: scenario,
|
||||
hz: hz,
|
||||
count: count,
|
||||
firstFrame: config.paired
|
||||
? (scenario == 0 ? (endFrame * .05).round() : localStart)
|
||||
: config.edgeMarginFrames,
|
||||
lastFrame: config.paired
|
||||
? (endFrame * .95).round()
|
||||
: endFrame.round() - config.edgeMarginFrames - 1,
|
||||
steps: steps,
|
||||
paired: config.paired,
|
||||
localSpanFrames: config.localSpanFrames,
|
||||
timelineEndFrame: endFrame,
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user