iovisor / bcc

BCC - Tools for BPF-based Linux IO analysis, networking, monitoring, and more
Apache License 2.0
20.36k stars 3.86k forks source link

libbpf-tools: support to find symbols in different mount namespace #4854

Open ethercflow opened 9 months ago

ethercflow commented 9 months ago

Resolving symbols from different mnt namespaces is currently not supported, which is very unfriendly for debugging container environments. So add this ability as perf: https://github.com/torvalds/linux/commit/843ff37bb59edbe51d64e77ba1b3245a15a4dd9f.

The test result looks as below (run in root ns to debug non-root ns's task):

sudo ./offcputime -p  1137374
bpf_prog_9435ef55c0230b1b_sched_switch
    bpf_prog_9435ef55c0230b1b_sched_switch
    bpf_trace_run3
    __bpf_trace_sched_switch
    __schedule
    schedule
    futex_wait_queue_me
    futex_wait
    do_futex
    __x64_sys_futex
    do_syscall_64
    entry_SYSCALL_64_after_hwframe
    mlockall
    _ZN4absl12lts_2021110224synchronization_internal6Waiter4WaitENS1_13KernelTimeoutE
    AbslInternalPerThreadSemWait_lts_20211102
    _ZN4absl12lts_2021110224synchronization_internal12PerThreadSem4WaitENS1_13KernelTimeoutE
    _ZN4absl12lts_202111025Mutex17DecrementSynchSemEPS1_PNS0_13base_internal14PerThreadSynchENS0_24synchronization_internal13KernelTimeoutE
    _ZN4absl12lts_202111027CondVar10WaitCommonEPNS0_5MutexENS0_24synchronization_internal13KernelTimeoutE
    _ZN4absl12lts_202111027CondVar16WaitWithDeadlineEPNS0_5MutexENS0_4TimeE
    gpr_cv_wait
    _ZL10wait_untilN9grpc_core9TimestampE
    _ZL15timer_main_loopv
    _ZL12timer_threadPv
    _ZZN9grpc_core12_GLOBAL__N_120ThreadInternalsPosixC4EPKcPFvPvES4_PbRKNS_6Thread7OptionsEENKUlS4_E_clES4_
    _ZZN9grpc_core12_GLOBAL__N_120ThreadInternalsPosixC4EPKcPFvPvES4_PbRKNS_6Thread7OptionsEENUlS4_E_4_FUNES4_
    [unknown]
    -                grpc_global_tim (1137523)
        4689072
ethercflow commented 9 months ago

@chenhengqi @yonghong-song @davemarchevsky PTAL, thanks!

KentaTada commented 9 months ago

Recently, I have fixed the same issue in https://github.com/iovisor/bcc/pull/4785. So I'm interested in this PR. BTW, we need to notice that the license of https://github.com/torvalds/linux/commit/843ff37bb59edbe51d64e77ba1b3245a15a4dd9f is different from libbpf-tools/trace_helpers.c

ethercflow commented 9 months ago

Recently, I have fixed the same issue in #4785. So I'm interested in this PR. BTW, we need to notice that the license of torvalds/linux@843ff37 is different from libbpf-tools/trace_helpers.c

Thanks, will modify the license after review done.

yonghong-song commented 9 months ago

@ethercflow I looked at the code, mostly from high level work flow. It looks fine. But it would be great if you can provide a test/script or something to set up the environment and then to run sudo ./offcputime -p <pid> which exercises the new changes. It would be great!

ethercflow commented 9 months ago

@ethercflow I looked at the code, mostly from high level work flow. It looks fine. But it would be great if you can provide a test/script or something to set up the environment and then to run sudo ./offcputime -p <pid> which exercises the new changes. It would be great!

@yonghong-song Thank you for your suggestion, I'll follow up in the near future. :)