Re: [PATCH v2] tracing/uprobe: Add missing PID filter for uretprobe
From: Tianyi Liu <hidden>
Date: 2024-08-26 14:53:03
Also in:
bpf
Hi Oleg,
For the moment, please forget about ret-probes. Could you compile this program
#define _GNU_SOURCE
#include <unistd.h>
#include <sched.h>
#include <signal.h>
int func(int i)
{
return i;
}
int test(void *arg)
{
int i;
for (i = 0;; ++i) {
sleep(1);
func(i);
}
return 0;
}
int main(void)
{
static char stack[65536];
clone(test, stack + sizeof(stack)/2, CLONE_VM|SIGCHLD, NULL);
test(NULL);
return 0;
}
and then do something like
$ ./test &
$ bpftrace -p $! -e 'uprobe:./test:func { printf("%d\n", pid); }'
I hope that the syntax of the 2nd command is correct...
I _think_ that it will print 2 pids too.
But "perf-record -p" works as expected.
Yes, the output from bpftrace and perf matches what you described:
$ ./tester &
[1] 158592
$ perf probe -x tester --add func
Added new event:
probe_tester:func (on func in /root/test/tester)
$ bpftrace -p 158592 -e 'uprobe:./tester:func { printf("time=%llu pid=%d\n", elapsed / 1000000000, pid); }'
Attaching 1 probe...
time=0 pid=158592
time=0 pid=158594
time=1 pid=158592
time=1 pid=158594
time=2 pid=158592
time=2 pid=158594
time=3 pid=158592
time=3 pid=158594
$ perf record -e probe_tester:func -p 158592 -o 158592
[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.022 MB 158592 (19 samples) ]
$ perf script -i 158592
tester 158592 [006] 246475.295762: probe_tester:func: (55a6def14149)
tester 158592 [006] 246476.295828: probe_tester:func: (55a6def14149)
tester 158592 [006] 246477.295892: probe_tester:func: (55a6def14149)
tester 158592 [006] 246478.295958: probe_tester:func: (55a6def14149)
tester 158592 [006] 246479.296024: probe_tester:func: (55a6def14149)
tester 158592 [010] 246480.296202: probe_tester:func: (55a6def14149)
tester 158592 [010] 246481.296360: probe_tester:func: (55a6def14149)
[...]
Thanks,