From 74411087d84f8608bd81857bf4692ffc69b58f73 Mon Sep 17 00:00:00 2001 From: nashzhou Date: Wed, 14 Oct 2026 14:24:25 +0800 Subject: [PATCH] feat(metrics): time pause stop and mem_config stages With the pause inner stages instrumented, the outer stage="pause" total (2-3s at high concurrency) was still dominated by unattributed time: vm_pause, mem_convert, persist stayed flat and restack_rootfs grew to only ~0.4s. The two remaining uninstrumented segments that can carry seconds at concurrency are the post-persist sandbox teardown and the memory image config rebuild (which compacts runtime-owned lowers when the stack exceeds its budget). - stop: the success-path sandbox.stop() in pause_sandbox_impl -- Firecracker process exit (vCPU teardown, guest RAM release), device release RPCs, stop hook, and network cleanup. - mem_config: build_mem_snapshot_image_config in snapshot_to_dir -- inherited lower localization plus occasional layer compaction. No behavior change; instrumentation only. Applies on top of 0003. --- src/orchestrator/service.rs | 4 +++- src/sandbox/firecracker/sandbox.rs | 18 +++++++++++------- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/orchestrator/service.rs b/src/orchestrator/service.rs index f02ea86..d2a7f85 100644 --- a/src/orchestrator/service.rs +++ b/src/orchestrator/service.rs @@ -1613,7 +1613,9 @@ where // Stop the sandbox to free up resources. let stop_result = { let mut sandbox = handle.lock().await; - sandbox.stop().await + SandboxStageTimer::new("pause") + .time("stop", sandbox.stop()) + .await }; if let Err(err) = stop_result { warn!(error = ?err, "failed to stop sandbox after pausing"); diff --git a/src/sandbox/firecracker/sandbox.rs b/src/sandbox/firecracker/sandbox.rs index f832a1d..27712fd 100644 --- a/src/sandbox/firecracker/sandbox.rs +++ b/src/sandbox/firecracker/sandbox.rs @@ -1210,13 +1210,17 @@ impl FirecrackerSandbox { } LaunchMode::Fresh(_) => None, }; - let mem_image_config = build_mem_snapshot_image_config( - resume_mem_image_config_path, - &mem_layer_path, - snapshot_dir, - memory_output, - ) - .await?; + let mem_image_config = stages + .time( + "mem_config", + build_mem_snapshot_image_config( + resume_mem_image_config_path, + &mem_layer_path, + snapshot_dir, + memory_output, + ), + ) + .await?; let mem_image_config_path = snapshot_dir.join("mem_image.json"); tokio::fs::write( &mem_image_config_path, -- 2.43.0