From f21184c325fc78ecd64f27e3c3076972f7664238 Mon Sep 17 00:00:00 2001 From: Philipp Schuster Date: Thu, 9 Apr 2026 09:29:52 +0200 Subject: [PATCH] vm-migration: expose memory timing needed by migration metrics Expose the finalized per-iteration timing fields needed by higher-level migration metrics and factor the iteration-overhead calculation into a small helper. This keeps the existing MemoryMigrationContext behavior intact while making the timing data easier to consume from migration-level context in the following commits. On-behalf-of: SAP philipp.schuster@sap.com Signed-off-by: Philipp Schuster --- vm-migration/src/context.rs | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/vm-migration/src/context.rs b/vm-migration/src/context.rs index 69f9f3730..0bb9ea190 100644 --- a/vm-migration/src/context.rs +++ b/vm-migration/src/context.rs @@ -54,13 +54,13 @@ pub struct MemoryMigrationContext { /// This includes the transmission, all logging, and update of any metrics. /// /// This is only `None` for iteration 0. - iteration_duration: Option, + pub iteration_duration: Option, /// Begin of the current transfer. transfer_begin: Instant, /// Duration of the current transfer. /// /// This is only `None` for iteration 0. - transfer_duration: Option, + pub transfer_duration: Option, } impl MemoryMigrationContext { @@ -178,6 +178,22 @@ impl MemoryMigrationContext { bytes as f64 / duration.as_secs_f64() } } + + /// Calculates the overhead of an iteration. + /// + /// This is the additional time next to the transfer time and includes + /// fetching and parsing the dirty log, for example. + fn iteration_overhead(&self) -> Duration { + self.iteration_duration + .and_then(|iter| { + self.transfer_duration.map(|tr| { + // This is guaranteed by update_metrics_after_transfer() + assert!(iter >= tr); + iter - tr + }) + }) + .unwrap_or_default() + } } impl Default for MemoryMigrationContext { @@ -207,16 +223,7 @@ impl Display for MemoryMigrationContext { // Transfer duration and iteration overhead let transfer_s = self.transfer_duration.map_or(0.0, |d| d.as_secs_f64()); - let iteration_overhead_ms = self - .iteration_duration - .and_then(|iter| { - self.transfer_duration.map(|tr| { - // This is guaranteed by update_metrics_after_transfer() - assert!(iter >= tr); - (iter - tr).as_millis() - }) - }) - .unwrap_or(0); + let iteration_overhead_ms = self.iteration_overhead().as_millis(); let est_downtime_ms = self.estimated_downtime.map_or(0, |d| d.as_millis());