News for hackers. Stuff that matters.
Re:A thorough introduction to bpftrace by suifbwish on Monday August 09, 2021 @02:30PM (#28120437)
What is the main advantage of this over native strace?
Re:A thorough introduction to bpftrace by yakubin on Monday August 09, 2021 @03:17PM (#28121106)
bpftrace has lower overhead, because, thanks to BPF, it can accumulate all the data needed in kernel and only send a summary to userspace to be displayed. strace on the other hand uses the ptrace(2) syscall to set a breakpoint on each syscall, including the ones that you do not trace (when you filter calls e.g.) and on each syscall data travels between kernel and strace.

It's possible that in the future strace will use BPF as well to lower its overhead.

bpftrace is also more versatile. You could use it to e.g. collect stack traces for all the syscalls a program makes. You can also attach actions to more things than just syscalls. You can e.g. use kprobes to inject code into kernel functions which aren't exported as syscalls.

Re:A thorough introduction to bpftrace by wmf on Monday August 09, 2021 @03:13PM (#28121047)
strace only traces system calls while bpftrace does much more. Just looking at the first example, vfs_read isn't a system call (read() may also operate on sockets or whatever) and strace doesn't calculate histograms AFAIK.
Re:A thorough introduction to bpftrace by tych0 on Monday August 09, 2021 @03:29PM (#28121259)
I use it a lot to figure out why things fail. For example, what if you get an -EPERM from mount()? Was it denied by seccomp, an LSM, because you don't own the user namespace that owns your mount namespace?

strace will tell you it failed, but bpftrace can help understand why.

Note that I said "help": bpftrace can tell you "this function failed with EPERM", but e.g. ovl_fill_super() can fill with EPERM for lots of different reasons. So it's a bit like printf debugging. And you're SOL if the error is generated within that function or from an inlined function :(

Re:A thorough introduction to bpftrace by 1vuio0pswjnm7 on Monday August 09, 2021 @05:53PM (#28122772)
bpftrace requires about 318 MB to install

strace requires less than 2 MB

Bigger is better :)

Re:A thorough introduction to bpftrace by Sevan777 on Monday August 09, 2021 @06:44PM (#28123226)
Standalone binary the project publishes is 45MB. https://github.com/iovisor/bpftrace/releases/download/v0.13....
Re:A thorough introduction to bpftrace by PennRobotics on Monday August 09, 2021 @06:46PM (#28123245)
I just tried two commands.

apt install bpftrace: needs 1,201 kB

apt remove strace: frees 1,792 kB

Re:A thorough introduction to bpftrace by 1vuio0pswjnm7 on Monday August 09, 2021 @07:49PM (#28123722)
Need to look at the bpftrace dependencies

For example, is clang already installed

Re:A thorough introduction to bpftrace by 1vuio0pswjnm7 on Monday August 09, 2021 @07:50PM (#28123734)
How large is strace standalone binary

45MB is still huge; its not even statically-linked

The largest programs I use, even when statically-linked against musl are all under 6MB

Re:A thorough introduction to bpftrace by 1vuio0pswjnm7 on Tuesday August 10, 2021 @06:10PM (#28135337)
And I can count on one hand the number of programs I use that are over 1MB