Re: Getting stack traces from tracepoint probes

Yonghong Song

On Tue, Sep 5, 2017 at 7:43 AM, Nair, Reena via iovisor-dev
<iovisor-dev@...> wrote:

I was trying to retrieve stack traces from tracepoint probe by modifying

The original code is in blue and the changed code is in yellow.

//int oncpu(struct pt_regs *ctx, struct task_struct *prev) {
TRACEPOINT_PROBE(sched, sched_switch){

//u32 pid = prev->pid;
//u32 tgid = prev->tgid;

u32 pid = args->prev_pid, tgid;
u64 ts, *tsp;
// record previous thread sleep time
ts = bpf_ktime_get_ns();
start.update(&pid, &ts);
// get the current thread's start time
//pid = bpf_get_current_pid_tgid();

pid = args->next_pid;
tgid = bpf_get_current_pid_tgid() >> 32;


I also replaced 'ctx' with 'args'

kernel_stack_get = "stack_traces.get_stackid(args, BPF_F_REUSE_STACKID)"
user_stack_get = \
"stack_traces.get_stackid(args, BPF_F_REUSE_STACKID | BPF_F_USER_STACK)"
This won't work. get_stackid needs pt_regs so that it can walk through
the frame to
get stacks. Here for tracepoint, "args" is the tracepoint structure.

However, no stack traces, kernel/ user, were returned. Is it not possible to
get stack traces from tracepoint probes?

I came across this link:

Do we have any functions to access the pt_regs from tracepoint probes? I am
running the probes in kernel version 4.8.


iovisor-dev mailing list

Join { to automatically receive all group messages.