增加小壹长对话的无窗口帧耗时基准
This commit is contained in:
parent
f9924a8531
commit
0b7aacf285
@ -3876,12 +3876,16 @@ mod tests {
|
||||
}
|
||||
|
||||
fn dock_fixture() -> (PhotocraftApp, mpsc::Receiver<Request>) {
|
||||
dock_fixture_with_size(3600)
|
||||
}
|
||||
|
||||
fn dock_fixture_with_size(height: u32) -> (PhotocraftApp, mpsc::Receiver<Request>) {
|
||||
let (tx, requests) = mpsc::channel();
|
||||
let (_, rx) = mpsc::channel();
|
||||
let mut w = Workspace::new(tx, rx);
|
||||
while requests.try_recv().is_ok() {}
|
||||
let mut session = photocraft_engine::Session::new();
|
||||
session.execute("file.new", json!({"width":1440,"height":3600,"name":"小壹 · 本地界面验收"})).unwrap();
|
||||
session.execute("file.new", json!({"width":1440,"height":height,"name":"小壹 · 本地界面验收"})).unwrap();
|
||||
let services = crate::Services {
|
||||
import: Some(Box::new(|name, bytes, depth| {
|
||||
photocraft_io::import_with_options(name, bytes, depth).map(|r| (r.document, r.warnings)).map_err(|error| error.to_string())
|
||||
@ -4118,7 +4122,11 @@ mod tests {
|
||||
}
|
||||
|
||||
fn live_production_fixture() -> (PhotocraftApp, mpsc::Receiver<Request>) {
|
||||
let (mut app, requests) = dock_fixture();
|
||||
live_production_fixture_with_size(3600)
|
||||
}
|
||||
|
||||
fn live_production_fixture_with_size(height: u32) -> (PhotocraftApp, mpsc::Receiver<Request>) {
|
||||
let (mut app, requests) = dock_fixture_with_size(height);
|
||||
let w = app.jiansun.as_mut().unwrap();
|
||||
w.composer.clear();
|
||||
w.pi_run = Some("offline-production".into());
|
||||
@ -4177,6 +4185,98 @@ mod tests {
|
||||
[(1, WorkerStage::Generating), (2, WorkerStage::Generating), (27, WorkerStage::Reviewing)]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn long_conversation_frame_budget() {
|
||||
use std::time::Instant;
|
||||
|
||||
let (mut app, _requests) = live_production_fixture_with_size(34_838);
|
||||
for index in 0..299 {
|
||||
app.session.execute("layer.new.layer", json!({"name":format!("详情图层 {index}")})).unwrap();
|
||||
}
|
||||
app.session.execute("type.create", json!({"text":"原始标题","x":40,"y":40})).unwrap();
|
||||
let doc = app.session.active().unwrap();
|
||||
let layer = doc.selected_layers()[0].0;
|
||||
let w = app.jiansun.as_mut().unwrap();
|
||||
w.owner_doc = Some(doc.doc.id.0);
|
||||
w.observed_doc = w.owner_doc;
|
||||
let mut progress = w.workflow.production_progress().clone();
|
||||
progress["pictureCells"] = json!((0..16).map(|i| json!({"slotId":format!("pic-{i}"),"label":format!("图位 {i}"),"state":"verified"})).collect::<Vec<_>>());
|
||||
progress["copyCells"] = json!(vec![json!({"state":"filled"}); 33]);
|
||||
w.workflow.set_production_progress(&progress);
|
||||
let active_turn = std::mem::take(&mut w.messages);
|
||||
for index in 0..60 {
|
||||
w.messages.extend([
|
||||
json!({"role":"user","text":"保留椅子的木纹和结构,补一张自然光下的细节图。"}),
|
||||
json!({"role":"assistant","kind":"thinking","active":false}),
|
||||
json!({"role":"assistant","kind":"activity","text":"工具活动","event":{
|
||||
"version":1,"type":"tool","toolCallId":format!("read-{index}"),"toolName":"canvas_read","status":"completed","durationMs":320
|
||||
}}),
|
||||
json!({"role":"assistant","kind":"image","taskId":format!("candidate-{index}"),"width":1440,"height":1800}),
|
||||
json!({"role":"assistant","kind":"reply","text":"候选图已生成。保留当前画布,确认光线和细节后可以采纳这张图。"}),
|
||||
json!({"role":"assistant","kind":"copywriting-fields","optionsId":format!("copy-{index}"),"items":[
|
||||
{"layer":layer,"name":"主标题","field":{"fieldId":"S01-T01","label":"主标题","maxChars":16,"maxLines":1},
|
||||
"original":"原始标题","text":"自然木纹餐椅","applied":false}
|
||||
],"target":{}}),
|
||||
]);
|
||||
}
|
||||
w.messages.extend(active_turn);
|
||||
let mut harness = egui_kittest::Harness::builder()
|
||||
.with_size(vec2(1440.0, 900.0)).with_max_steps(4).build_eframe(move |cc| {
|
||||
PhotocraftApp::setup_context(&cc.egui_ctx, crate::theme::ThemeKind::ProMedium);
|
||||
crate::cjk_fonts::install_system_provider_for_tests(&cc.egui_ctx);
|
||||
let images = &mut app.jiansun.as_mut().unwrap().agent_images;
|
||||
for index in 0..60 {
|
||||
let id = format!("candidate-{index}");
|
||||
let image = egui::ColorImage::filled([96, 120], Color32::from_rgb(index * 3, 92, 52));
|
||||
images.insert(id.clone(), cc.egui_ctx.load_texture(id, image, egui::TextureOptions::LINEAR));
|
||||
}
|
||||
app
|
||||
});
|
||||
harness.run_steps(8);
|
||||
let app = harness.state_mut();
|
||||
let panel = &app.jiansun.as_ref().unwrap().panel_geometry;
|
||||
assert_eq!(panel["open"], true);
|
||||
assert!(panel["productionProgress"].is_array(), "{panel}");
|
||||
app.slow_frames.set_threshold_ms(0.0);
|
||||
|
||||
#[cfg(target_os = "windows")]
|
||||
let thread_cpu_ticks = || {
|
||||
let (_, _, kernel, user) = winsafe::HTHREAD::GetCurrentThread().GetThreadTimes().unwrap();
|
||||
u64::from(kernel) + u64::from(user)
|
||||
};
|
||||
#[cfg(target_os = "windows")]
|
||||
let cpu_start = (Instant::now(), thread_cpu_ticks());
|
||||
|
||||
let mut samples = Vec::with_capacity(600);
|
||||
let mut total = 0.0;
|
||||
let mut regions = [0.0; 6];
|
||||
for _ in 0..600 {
|
||||
let started = Instant::now();
|
||||
harness.step();
|
||||
samples.push(started.elapsed().as_secs_f64() * 1000.0);
|
||||
let frame = harness.state().slow_frames.frames().next_back().unwrap();
|
||||
let ui = &frame.ui_regions;
|
||||
total += frame.frame_ms;
|
||||
for (sum, time) in regions.iter_mut().zip([
|
||||
ui.conversation, ui.production_head, ui.composer, ui.dock_panels, ui.canvas_overlays, ui.menu_status,
|
||||
]) {
|
||||
*sum += time;
|
||||
}
|
||||
}
|
||||
#[cfg(target_os = "windows")]
|
||||
{
|
||||
let cpu_ms = (thread_cpu_ticks() - cpu_start.1) as f64 / 10_000.0;
|
||||
let cpu_share = cpu_ms / (cpu_start.0.elapsed().as_secs_f64() * 10.0);
|
||||
eprintln!("UI thread CPU: {cpu_ms:.1} ms ({cpu_share:.1}% of one core)");
|
||||
}
|
||||
samples.sort_unstable_by(f64::total_cmp);
|
||||
let (p50, p95, p99, max) = (samples[299], samples[569], samples[593], samples[599]);
|
||||
let shares = regions.map(|time| time * 100.0 / total);
|
||||
eprintln!("600 frames: p50 {p50:.2}, p95 {p95:.2}, p99 {p99:.2}, max {max:.2} ms");
|
||||
eprintln!("Percent of frame build (conversation, head, composer, dock, overlays, menu/status): {shares:.1?}");
|
||||
assert!(p95 <= 150.0, "long conversation p95 {p95:.2} ms");
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore = "GPU screenshots from the production dock with offline fixtures"]
|
||||
fn agent_panel_batch2_gpu_evidence() {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user