Skip to content

Commit 07e287f

Browse files
committed
feat: add a debug log for vm build time
Add a couple of events to the debug logs. With this information we can extract information of how long did those events take. Added as debug messages to make it clear to customers that these are unstable and may change format or disappear at any moment, at should not be depended upon. Signed-off-by: Pablo Barbáchano <[email protected]>
1 parent f3913e1 commit 07e287f

File tree

2 files changed

+35
-3
lines changed

2 files changed

+35
-3
lines changed

src/vmm/src/builder.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ use crate::devices::virtio::vsock::{Vsock, VsockUnixBackend};
5252
use crate::devices::BusDevice;
5353
#[cfg(target_arch = "aarch64")]
5454
use crate::logger;
55-
use crate::logger::error;
55+
use crate::logger::{debug, error};
5656
use crate::persist::{MicrovmState, MicrovmStateError};
5757
use crate::resources::VmResources;
5858
use crate::vmm_config::boot_source::BootConfig;
@@ -380,14 +380,16 @@ pub fn build_and_boot_microvm(
380380
event_manager: &mut EventManager,
381381
seccomp_filters: &BpfThreadMap,
382382
) -> Result<Arc<Mutex<Vmm>>, StartMicrovmError> {
383+
debug!("event_start: build microvm for boot");
383384
let vmm = build_microvm_for_boot(instance_info, vm_resources, event_manager, seccomp_filters)?;
384-
385+
debug!("event_end: build microvm for boot");
385386
// The vcpus start off in the `Paused` state, let them run.
387+
debug!("event_start: boot microvm");
386388
vmm.lock()
387389
.unwrap()
388390
.resume_vm()
389391
.map_err(StartMicrovmError::Internal)?;
390-
392+
debug!("event_end: boot microvm");
391393
Ok(vmm)
392394
}
393395

@@ -448,6 +450,7 @@ pub fn build_microvm_from_snapshot(
448450
})?;
449451

450452
// Build Vmm.
453+
debug!("event_start: build microvm from snapshot");
451454
let (mut vmm, mut vcpus) = create_vmm_and_vcpus(
452455
instance_info,
453456
event_manager,
@@ -545,6 +548,7 @@ pub fn build_microvm_from_snapshot(
545548
.get("vmm")
546549
.ok_or(BuildMicrovmFromSnapshotError::MissingVmmSeccompFilters)?,
547550
)?;
551+
debug!("event_end: build microvm from snapshot");
548552

549553
Ok(vmm)
550554
}

tests/integration_tests/performance/test_boottime.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# SPDX-License-Identifier: Apache-2.0
33
"""Tests that ensure the boot time to init process is within spec."""
44

5+
import datetime
56
import re
67
import time
78

@@ -153,6 +154,25 @@ def _configure_and_run_vm(microvm, network=False, initrd=False):
153154
microvm.start()
154155

155156

157+
def find_events(log_data):
158+
"""
159+
Parse events in the Firecracker logs
160+
161+
Events have this format:
162+
163+
TIMESTAMP [LOGLEVEL] event_(start|end): EVENT
164+
"""
165+
ts_fmt = "%Y-%m-%dT%H:%M:%S.%f"
166+
matches = re.findall(r"(.+) \[.+\] event_(start|end): (.*)", log_data)
167+
timestamps = {}
168+
for ts, when, what in matches:
169+
evt1 = timestamps.setdefault(what, {})
170+
evt1[when] = datetime.datetime.strptime(ts[:-3], ts_fmt)
171+
for _, val in timestamps.items():
172+
val["duration"] = val["end"] - val["start"]
173+
return timestamps
174+
175+
156176
@pytest.mark.parametrize(
157177
"vcpu_count,mem_size_mib",
158178
[(1, 128), (1, 1024), (2, 2048), (4, 4096)],
@@ -184,3 +204,11 @@ def test_boottime(
184204
vm.start()
185205
boottime_us = _get_microvm_boottime(vm)
186206
metrics.put_metric("boot_time", boottime_us, unit="Microseconds")
207+
timestamps = find_events(vm.log_data)
208+
build_time = timestamps["build microvm for boot"]["duration"]
209+
metrics.put_metric("build_time", build_time.microseconds, unit="Microseconds")
210+
metrics.put_metric(
211+
"guest_boot_time",
212+
boottime_us - build_time.microseconds,
213+
unit="Microseconds",
214+
)

0 commit comments

Comments
 (0)