Skip to content

Commit 19e012a

Browse files
committed
feat(tests): add systemd_analyze data as boot time metric
Currently we measure boottime by looking at the Firecracker logs and waiting for the guest to trigger a special boot device inside Firecracker. There is an alternative way of measuring boot time from a guest perspective by using systemd-analyze. Will help us to understand boot times better. Signed-off-by: Egor Lazarchuk <yegorlz@amazon.co.uk>
1 parent dafee92 commit 19e012a

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

tests/integration_tests/performance/test_boottime.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,37 @@ def find_events(log_data):
6969
return timestamps
7070

7171

72+
def get_systemd_analyze_times(microvm):
73+
"""
74+
Parse systemd-analyze output
75+
"""
76+
rc, stdout, stderr = microvm.ssh.run("systemd-analyze")
77+
assert rc == 0, stderr
78+
assert stderr == ""
79+
80+
boot_line = stdout.splitlines()[0]
81+
# The line will look like this:
82+
# Startup finished in 79ms (kernel) + 231ms (userspace) = 310ms
83+
# In the regex we capture the time and the unit for kernel, userspace and total values
84+
pattern = r"Startup finished in (\d*)(ms|s)\s+\(kernel\) \+ (\d*)(ms|s)\s+\(userspace\) = ([\d.]*)(ms|s)\s*"
85+
kernel, kernel_unit, userspace, userspace_unit, total, total_unit = re.findall(
86+
pattern, boot_line
87+
)[0]
88+
89+
def to_ms(v, unit):
90+
match unit:
91+
case "ms":
92+
return float(v)
93+
case "s":
94+
return float(v) * 1000
95+
96+
kernel = to_ms(kernel, kernel_unit)
97+
userspace = to_ms(userspace, userspace_unit)
98+
total = to_ms(total, total_unit)
99+
100+
return kernel, userspace, total
101+
102+
72103
@pytest.mark.parametrize(
73104
"vcpu_count,mem_size_mib",
74105
[(1, 128), (1, 1024), (2, 2048), (4, 4096)],
@@ -112,4 +143,10 @@ def test_boottime(
112143
boottime_us - build_time.microseconds,
113144
unit="Microseconds",
114145
)
146+
147+
kernel, userspace, total = get_systemd_analyze_times(vm)
148+
metrics.put_metric("systemd_kernel", kernel, unit="Milliseconds")
149+
metrics.put_metric("systemd_userspace", userspace, unit="Milliseconds")
150+
metrics.put_metric("systemd_total", total, unit="Milliseconds")
151+
115152
vm.kill()

0 commit comments

Comments
 (0)