Skip to content

Commit

Permalink
Merge pull request #1794 from utam0k/bpftrace
Browse files Browse the repository at this point in the history
Add the bpftrace program file for debugging.
  • Loading branch information
utam0k authored Apr 13, 2023
2 parents fc68936 + 70e672f commit 1e894a0
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ lint:
cargo fmt --all -- --check
cargo clippy --all-targets --all-features -- -D warnings

.PHONY: hack/bpftrace
hack/bpftrace:
BPFTRACE_STRLEN=120 ./hack/debug.bt

.PHONY: clean
clean:
./scripts/clean.sh $(ROOT)
52 changes: 52 additions & 0 deletions hack/debug.bt
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/usr/bin/env bpftrace

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

tracepoint:syscalls:sys_enter_write
/comm == "4"|| comm == "youki*"/
{

$s = str(args->buf, args->count);
if ($s != "\n") {
printf("%-12ld %-10s %-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"/
{
@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 %-10s %-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"/
{
printf("%-12ld %-10s %-8d %-9s ", elapsed , comm, pid, "clone3");
}

END
{
clear(@filename);
printf("Tracing ended.\n");
}

0 comments on commit 1e894a0

Please sign in to comment.