Skip to content

Commit

Permalink
add bfp tracing
Browse files Browse the repository at this point in the history
Signed-off-by: Jorge Prendes <[email protected]>
  • Loading branch information
jprendes committed Oct 6, 2023
1 parent 56d334e commit cf70920
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 8 deletions.
6 changes: 4 additions & 2 deletions .github/workflows/action-test-k3s.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ jobs:
path: dist
- name: run
timeout-minutes: 5
run: make test/k3s-${{ inputs.runtime }}
run: |
sudo BPFTRACE_STRLEN=120 ./scripts/debug.bt > bpf_debug.txt 2>&1 &
make test/k3s-${{ inputs.runtime }}
# only runs when the previous step fails
- name: inspect failed pods
if: failure()
Expand All @@ -47,7 +49,7 @@ jobs:
if: failure()
run: |
sudo journalctl -u k3s-runwasi > k3s.log
sudo tar czf k3s-logs-${{ inputs.runtime }}-${{ inputs.os }}.tar.gz -C . k3s.log -C /var/log/pods . -C /var/lib/rancher/k3s/agent/containerd/ containerd.log
sudo tar czf k3s-logs-${{ inputs.runtime }}-${{ inputs.os }}.tar.gz -C . k3s.log bpf_debug.txt -C /var/log/pods . -C /var/lib/rancher/k3s/agent/containerd/ containerd.log
sudo chown ${USER}:${USER} k3s-logs-${{ inputs.runtime }}-${{ inputs.os }}.tar.gz
- name: upload logs
if: failure()
Expand Down
6 changes: 4 additions & 2 deletions .github/workflows/action-test-kind.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ jobs:
path: dist
- name: run
timeout-minutes: 5
run: make test/k8s-${{ inputs.runtime }}
run: |
sudo BPFTRACE_STRLEN=120 ./scripts/debug.bt > bpf_debug.txt 2>&1 &
make test/k8s-${{ inputs.runtime }}
# only runs when the previous step fails
- name: inspect failed pods
if: failure()
Expand All @@ -47,7 +49,7 @@ jobs:
if: failure()
run: |
bin/kind export logs ./kind-logs --name containerd-wasm
tar czf kind-logs-${{ inputs.runtime }}-${{ inputs.os }}.tar.gz -C ./kind-logs .
tar czf kind-logs-${{ inputs.runtime }}-${{ inputs.os }}.tar.gz -C . bpf_debug.txt -C ./kind-logs .
- name: upload logs
if: failure()
uses: actions/upload-artifact@master
Expand Down
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ containerd-shim-wasm-test-modules = { path = "crates/containerd-shim-wasm-test-m
crossbeam = { version = "0.8.2", default-features = false }
env_logger = "0.10"
libc = "0.2.148"
libcontainer = { git = "https://github.com/jprendes/youki.git", rev = "1497c1bdc42ed98950f21aa4fcd2d0b31913a4fe", default-features = false }
libcontainer = { git = "https://github.com/jprendes/youki.git", rev = "c753bf9846209b81183ca7b3fce3274f134b7e36", default-features = false }
log = "0.4"
nix = "0.27"
oci-spec = { version = "0.6.1", features = ["runtime"] }
Expand Down
87 changes: 87 additions & 0 deletions scripts/debug.bt
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
#!/usr/bin/env bpftrace

// from https://github.com/containers/youki/blob/main/hack/debug.bt

BEGIN
{
printf("Tracing Youki syscalls... Hit Ctrl-C to end.\n");
printf("%-12s %15s %-8s %-9s %s\n", "TIME", "COMMAND", "PID", "EVENT", "CONTENT");
}

tracepoint:syscalls:sys_enter_write
/comm == "4"|| comm == "youki" || comm == "youki:[1:INTER]" || comm == "youki:[2:INIT]"/
{

$s = str(args->buf, args->count);
if ($s != "\n") {
printf("%-12ld %15s %-8d %-9s ", elapsed , comm, pid, "write");
printf("fd=%d, %s\n", args->fd, $s);
}
}

tracepoint:syscalls:sys_enter_open,
tracepoint:syscalls:sys_enter_openat
/comm == "4"|| comm == "youki" || comm == "youki:[1:INTER]" || comm == "youki:[2:INIT]"/
{
@filename[tid] = args->filename;
}


tracepoint:syscalls:sys_exit_open,
tracepoint:syscalls:sys_exit_openat
/@filename[tid]/
{
$ret = args->ret;
$fd = $ret >= 0 ? $ret : -1;
$errno = $ret >= 0 ? 0 : - $ret;

printf("%-12ld %15s %-8d %-9s ", elapsed , comm, pid, "open");
printf("errno=%d, fd=%d, file=%s\n", $errno, $fd, str(@filename[tid]));
delete(@filename[tid]);
}

tracepoint:syscalls:sys_enter_clone3
/comm == "4"|| comm == "youki" || comm == "youki:[1:INTER]" || comm == "youki:[2:INIT]"/
{
printf("%-12ld %15s %-8d %-9s\n", elapsed , comm, pid, "clone3");
}

tracepoint:syscalls:sys_enter_setns
/comm == "4"|| comm == "youki" || comm == "youki:[1:INTER]" || comm == "youki:[2:INIT]"/
{
printf("%-12ld %15s %-8d %-9s ", elapsed , comm, pid, "setns");
printf("fd=%d, flag=%d\n", args->fd, args->flags);
}

tracepoint:syscalls:sys_enter_capset
/comm == "4"|| comm == "youki" || comm == "youki:[1:INTER]" || comm == "youki:[2:INIT]"/
{
printf("%-12ld %15s %-8d %-9s\n", elapsed , comm, pid, "capset");
}

tracepoint:syscalls:sys_enter_pivot_root
/comm == "4"|| comm == "youki" || comm == "youki:[1:INTER]" || comm == "youki:[2:INIT]"/
{
printf("%-12ld %15s %-8d %-9s ", elapsed , comm, pid, "pivt_root");
printf("new_root=%s, put_old=%s\n", str(args->new_root), str(args->put_old));
}

tracepoint:syscalls:sys_enter_mount
/comm == "4"|| comm == "youki" || comm == "youki:[1:INTER]" || comm == "youki:[2:INIT]"/
{
printf("%-12ld %15s %-8d %-9s ", elapsed , comm, pid, "mount");
printf("dev_name=%s, dir_name=%s\n", str(args->dev_name), str(args->dir_name));
}

tracepoint:syscalls:sys_enter_setresuid
/comm == "4"|| comm == "youki" || comm == "youki:[1:INTER]" || comm == "youki:[2:INIT]"/
{
printf("%-12ld %15s %-8d %-9s ", elapsed , comm, pid, "setresuid");
printf("ruid=%d, euid=%d, suid=%d\n", args->ruid, args->euid, args->suid);
}

END
{
clear(@filename);
printf("Tracing ended.\n");
}
2 changes: 1 addition & 1 deletion scripts/setup-linux.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash
sudo apt -y update
sudo apt install -y pkg-config libsystemd-dev libdbus-glib-1-dev build-essential libelf-dev libseccomp-dev libclang-dev
sudo apt install -y pkg-config bpftrace-dbgsym libsystemd-dev libdbus-glib-1-dev build-essential libelf-dev libseccomp-dev libclang-dev

if [ ! -z "$CI" ] && ! mount | grep cgroup; then
echo "cgroup is not mounted" 1>&2
Expand Down

0 comments on commit cf70920

Please sign in to comment.