On Tue, Sep 5, 2017 at 10:01 AM, Sasha Goldshtein <[email protected]> wrote:
> On Tue, Sep 5, 2017 at 7:40 PM Y Song via iovisor-dev
> <[email protected]> wrote:
>>
>> On Tue, Sep 5, 2017 at 7:43 AM, Nair, Reena via iovisor-dev
>> <[email protected]> wrote:
>> > Hi,
>> >
>> >
>> > I was trying to retrieve stack traces from tracepoint probe by modifying
>> > offcputime.py
>> >
>> >
>> > 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
>> >     if ((THREAD_FILTER) && (STATE_FILTER)) {
>> >         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.
>
>
> It works for me in the 'trace' tool, e.g.:

Now I remember. The tracepoint get_stackid should still work.
In kernel, we store the pt_regs in the first 8-byte unused args space and use it
to walk through the stacks.

>
> # /usr/share/bcc/tools/trace -K t:sched:sched_process_fork
> PID    TID    COMM         FUNC
> 1632   1632   sshd         sched_process_fork
>         _do_fork+0x1e9 [kernel]
>         SyS_clone+0x19 [kernel]
>         do_syscall_64+0x5e [kernel]
>         return_from_SYSCALL_64+0x0 [kernel]
>
> The tool uses stacks.get_stack_id(args, ...) exactly like the code above.
> Indeed it looks like the patch linked below is responsible for enabling it
> -- unless I'm missing something.
>>
>>
>> >
>> > However, no stack traces, kernel/ user, were returned. Is it not
>> > possible to
>> > get stack traces from tracepoint probes?
>> >
>> > I came across this link:
>> > https://patchwork.kernel.org/patch/8747201/
>> >
>> > Do we have any functions to access the pt_regs from tracepoint probes? I
>> > am
>> > running the probes in kernel version 4.8.
>> >
>> > Thanks,
>> > Reena.
>> >
>> >
>> >
>> >
>> > _______________________________________________
>> > iovisor-dev mailing list
>> > [email protected]
>> > https://lists.iovisor.org/mailman/listinfo/iovisor-dev
>> >
>> _______________________________________________
>> iovisor-dev mailing list
>> [email protected]
>> https://lists.iovisor.org/mailman/listinfo/iovisor-dev
_______________________________________________
iovisor-dev mailing list
[email protected]
https://lists.iovisor.org/mailman/listinfo/iovisor-dev

Reply via email to