mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
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 <philipp.schuster@cyberus-technology.de>
This commit is contained in:
committed by
Rob Bradford
parent
6a3024c13d
commit
f32506447f
@@ -563,6 +563,17 @@ pub fn start_vmm_thread(
|
||||
})
|
||||
}
|
||||
|
||||
/// Measures the time of the callback, in case it returns `Ok`.
|
||||
fn measure_ok<T, E, F>(f: F) -> result::Result<(T, Duration), E>
|
||||
where
|
||||
F: FnOnce() -> result::Result<T, E>,
|
||||
{
|
||||
let begin = Instant::now();
|
||||
let value = f()?;
|
||||
let duration = begin.elapsed();
|
||||
Ok((value, duration))
|
||||
}
|
||||
|
||||
#[derive(Clone, Deserialize, Serialize)]
|
||||
struct VmMigrationConfig {
|
||||
vm_config: Arc<Mutex<VmConfig>>,
|
||||
|
||||
Reference in New Issue
Block a user