Hey, Im curious, what would be the best way to run...
# general
a
Hey, Im curious, what would be the best way to run profilers like py-spy on a pants python target? So far I have issues like
Copy code
Permission Denied: Try running again with elevated permissions by going 'sudo env "PATH=$PATH" !!
or py-spy not being able to find the pid/python code at all..
b
This is a good question! It's something I hope to eventually make really easy! For now, I recommend packaging a pex binary with your code in it (likely using venv execution mode, and a packed layout). Run the binary once, then you can use py-spy to run the pex. I think that'll work (I did something like this before but don't remember the exact steps settings)
👍 1
a
having something like
./pants bench
would be awesome (maybe with the ability to chose different benchmark tools 🙂
b
I was thinking adding a flag to the
test
and run goals
a
I tried:
Copy code
py-spy top -- python dist/benchmarks.python.perf_bench/bench_predict.pex

after building the pex dir using this target:

pex_binary(
    name="bench_predict",
    dependencies=[":lib"],
    execution_mode="venv",
    layout="packed",
    entry_point="bench.py",
)
But I get:
Error Rate 49.43% (Bad address (os error 14))
and don't see the python function which should be benched (Which is just a CPU burner function currently)
w
you do need
sudo
on macOS, fwiw
sudo py-spy top -p $pid
generally does it.
a
I'm running it in a docker container with --cap-add=SYS_PTRACE so I think it should work there out of the box without sudo
👍 1