1

I am running docker containers on CentOS 7. If run perf on the PID on the host node I get an error about symbols not being found. This seems to be because it looks for the path of the file relative to the container but on the host node's filesystem.

If I copy the required binary files to the expected path on the host node then perf works from the host node since it can find the same symbols that match the binary files in the container (though it's not possible to create equivalent paths on host to match all).

Is there a better/cleaner way to run perf against a process running in a container with a CentOS 7 host?

mR.aTA
  • 174
  • 2
  • 19
  • [How do you get debugging symbols working in linux perf tool inside Docker containers?](https://stackoverflow.com/questions/38927895/how-do-you-get-debugging-symbols-working-in-linux-perf-tool-inside-docker-contai) suggests bind-mounting the entire host filesystem into the container, then using a `perf report --symfs` option pointing at it. Does that approach work for you? – David Maze Mar 31 '22 at 11:20
  • @DavidMaze thanks for the pointer. Not quite, because I want to attach to running containers. It's not possible to bind-mount to a running container, unfortunately. – mR.aTA Apr 01 '22 at 01:42
  • You can absolutely bind-mount directories into a running container. E.g., if I have a running container, I can `docker inspect | jq '.[0].GraphDriver.Data.MergedDir'` to get the container root directory, and then do something like `mount -o bind /bin .../mnt` (where `...` is the `MergedDir`) to expose the host `/bin` directory on `/mnt` inside the container. – larsks Apr 01 '22 at 02:30
  • @larsks interesting. my use case is k8s pods with containerd and I don't have docker running on the node. what would be the equivalent approach for containerd? – mR.aTA Apr 01 '22 at 16:42
  • You should be able to do pretty much the same thing: using the corresponding `inspect` command (possibly `crictl inspect`, depending on how you have things set up), and then continue as above. If `crictl inspect` doesn't have the root fs path, you can also get it from `/proc//mounts`. – larsks Apr 01 '22 at 17:59
  • thanks, @larsks I could mount-bind it! though as mentioned in the linked question above, seems using --symfs option doesn't work. The problem is that when I look at the target path from host (i.e. `.../mnt`) I can see the mounted files/folders, but inside the container it's empty. – mR.aTA Apr 01 '22 at 22:01
  • Seems to work for me even with containerd based containers (I'm running k3s w/ containerd locally). This is kind of getting into the weeds, but if you want to update your question with details of your k8s environment I'm happy to take another stab at it. – larsks Apr 01 '22 at 22:13

0 Answers0