Perf and python in container

Hello, I’m running the latest Fedora Rawhide and the latest python (python3-3.12.0~b3-2.fc39.x86_64) that ships with the new support for perf.

It works pretty well, for example using the provided example (augmented with an infinite loop):

def foo(n):
    result = 0
    for _ in range(n):
        result += 1
    return result

def bar(n):

def baz(n):

if __name__ == "__main__":
    while True:

we can run python3 -X perf ./ and perf top -g -p <pid> and we can see some of the python function names in the output which is very neat.

My goal is to be able to troubleshoot python applications running in containers, as such I would like to be able to run this:

podman run --name mypy   -v `pwd`/ \
  --entrypoint python --rm python:3.12.0b3-bookworm  \
  -X perf /srv/

and perform my perf top -g -p <pid> from the host, I don’t want to install anything extra in the container.

Well this does not seem to work, perf top will look for a /tmp/perf-<pid>.map file (that I tried to copy), and also for binaries on the host instead of the container. perf documents --prefix, --prefix-strip, --objdump options, but they seem all useless and objdump is in fact never called. My idea was to extract the container with podman export mypy | tar -x -f - and use the --prefix option but this just does not work, and python symbols are never displayed.

Has anyone played with perf and containers? Any idea how to make this work? Thanks!