Skip to content

Commit 6c61184

Browse files
committed
tests: add a trace-cmd helper
For now it's a very simple one, but we can use it as a base to provide more complicated ones in the future. Signed-off-by: Pablo Barbáchano <[email protected]>
1 parent 38a7951 commit 6c61184

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

tests/framework/microvm_helpers.py

+23
Original file line numberDiff line numberDiff line change
@@ -222,3 +222,26 @@ def run_in_netns(cmd):
222222

223223
# add a route on the host for the clone address
224224
run(f"ip route add {ingress_ipv4} via {veth_guest_ip}")
225+
226+
def trace_cmd_guest(self, fns, cmd, port=4321):
227+
"""Run trace-cmd on the guest, but transfer the data directly to the host."""
228+
docker_apt_install("trace-cmd")
229+
print("host> trace-cmd listen")
230+
_proc = subprocess.Popen(
231+
[
232+
"ip",
233+
"netns",
234+
"exec",
235+
self.vm.netns.id,
236+
"trace-cmd",
237+
"listen",
238+
"-p",
239+
str(port),
240+
]
241+
)
242+
print("guest> trace-cmd record")
243+
host_ip = self.vm.iface["eth0"]["iface"].host_ip
244+
_guest_ps = self.vm.ssh.run(
245+
f"trace-cmd record -N {host_ip}:{port} -p function {" ".join(fns)} {cmd}"
246+
)
247+
return list(Path(".").glob("trace.*.dat"))

tools/sandbox.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ def parse_byte_size(param):
6868
else:
6969
bins = get_firecracker_binaries()
7070

71-
print("This step may take a while to compile Firecracker ...")
7271
cpu_template = None
7372
if args.cpu_template_path is not None:
7473
cpu_template = json.loads(args.cpu_template_path.read_text())
@@ -96,3 +95,6 @@ def parse_byte_size(param):
9695
uvm2.add_net_iface()
9796
uvm2.basic_config(vcpu_count=args.vcpus, mem_size_mib=args.guest_mem_size // 2**20)
9897
uvm2.start()
98+
# trace-cmd needs this (DNS resolution?)
99+
uvm2.help.enable_ip_forwarding()
100+
files = uvm2.help.trace_cmd_guest(["-l", "read_msr"], cmd="sleep 5")

0 commit comments

Comments
 (0)