How do you get debugging symbols working in linux perf tool inside Docker containers?

后端 未结 2 1323
别那么骄傲
别那么骄傲 2021-02-08 22:58

I am using Docker containers based on the \"ubuntu\" tag and cannot get linux perf tool to display debugging symbols.

Here is what I\'m doing to demonstrate the problem.

2条回答
  •  挽巷
    挽巷 (楼主)
    2021-02-08 23:31

    Running the container with -v /:/host flag and running perf report in the container with --symfs /host flag fixes it:

     96.59%  a.out  a.out              [.] function
      2.93%  a.out  [kernel.kallsyms]  [k] 0xffffffff8105144a
      0.13%  a.out  [nvidia]           [k] 0x00000000002eda57
      0.11%  a.out  libc-2.19.so       [.] vfprintf
      0.11%  a.out  libc-2.19.so       [.] 0x0000000000049980
      0.09%  a.out  a.out              [.] main
      0.02%  a.out  libc-2.19.so       [.] _IO_file_write
      0.02%  a.out  libc-2.19.so       [.] write
    

    Part of the reason why it doesn't work as is? The output from perf script sort of sheds some light on this:

    ...
               a.out    24 3374818.880960: cycles:  ffffffff81141140 __perf_event__output_id_sample ([kernel.kallsyms])
               a.out    24 3374818.881012: cycles:  ffffffff817319fd _raw_spin_lock_irqsave ([kernel.kallsyms])
               a.out    24 3374818.882217: cycles:  ffffffff8109aba3 ttwu_do_activate.constprop.75 ([kernel.kallsyms])
               a.out    24 3374818.884071: cycles:            40053d [unknown] (/var/lib/docker/aufs/diff/9bd2d4389cf7ad185405245b1f5c7d24d461bd565757880bfb4f970d3f4f7915/a.out)
               a.out    24 3374818.885329: cycles:            400544 [unknown] (/var/lib/docker/aufs/diff/9bd2d4389cf7ad185405245b1f5c7d24d461bd565757880bfb4f970d3f4f7915/a.out)
    ...
    

    Note the /var/lib/docker/aufs path. That's from the host so it won't exist in the container and you need to help perf report to locate it. This likely happens because the mmap events are tracked by perf outside of any cgroup and perf does not attempt to remap the paths.

    Another option is to run perf host-side, like sudo perf record -a docker run -ti . But the collection has to be system-wide here (the -a flag) as containers are spawned by docker daemon process which is not in the process hierarchy of the docker client tool we run here.

提交回复
热议问题