From f32506447fae80edf8987a2ef3264a29de33b998 Mon Sep 17 00:00:00 2001 From: Philipp Schuster Date: Thu, 9 Apr 2026 09:32:14 +0200 Subject: [PATCH] vmm: add helper to measure successful operation duration Add a small helper that returns both the successful result of an operation and the time it took to complete. Subsequent migration instrumentation uses this to keep timing code compact and consistent. On-behalf-of: SAP philipp.schuster@sap.com Signed-off-by: Philipp Schuster --- vmm/src/lib.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/vmm/src/lib.rs b/vmm/src/lib.rs index 92bf4c6b7..c64abac20 100644 --- a/vmm/src/lib.rs +++ b/vmm/src/lib.rs @@ -563,6 +563,17 @@ pub fn start_vmm_thread( }) } +/// Measures the time of the callback, in case it returns `Ok`. +fn measure_ok(f: F) -> result::Result<(T, Duration), E> +where + F: FnOnce() -> result::Result, +{ + let begin = Instant::now(); + let value = f()?; + let duration = begin.elapsed(); + Ok((value, duration)) +} + #[derive(Clone, Deserialize, Serialize)] struct VmMigrationConfig { vm_config: Arc>,