originally landed at How to install Py spy on a HA OS instance, please instruct - #44 by Mariusthvdb but this might be valuable to post as a standalone community guide. thanks to the relentless support by @bdraco, I can post the solution to original request for
instructions to install py-spy on HAOS (you need to run it on the host):
2 ways to install and run the required files:
1 The easiest way to run docker commands required for the py-spy is to install the ssh & web terminal add-on and disable protection mode then you can ( get into the host and) access the docker cli and follow the rest of the steps described below.
Important: this is the ssh add-on in the community add-ons repo, not the ssh add-on in the official add-ons repo. You cannot access the docker cli from the ssh add-on in the official add-ons repo.
2 On the other hand, you wonât be able to c&p commands (and results) from those terminal windows.
thats the main reason I run ssh in external terminal: to be able to c&p results
For that use the Debugging the Home Assistant Operating System | Home Assistant Developer Docs
method to create authorized keys and copy that to your instance via
ha os import
on an attached usb
So you can shell into the Host, which is required for these readings.
ssh [email protected] -p 22222
After having settled the above, you can now continue with the actual setup process of the py-spy files:
docker exec -it homeassistant /bin/bash
next, download and install the correct image for py-spy for your hardware:
For the RPI4:
wget https://github.com/benfred/py-spy/releases/download/v0.3.14/py_spy-0.3.14-py2.py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
unzip py_spy-0.3.14-py2.py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
For the intel based use:
wget https://github.com/benfred/py-spy/releases/download/v0.3.14/py_spy-0.3.14-py2.py3-none-manylinux_2_5_x86_64.manylinux1_x86_64.whl
instead.
There should be a py-spy
binary once you call unzip in one of the directories it creates
run top
(to get pid for homeassistant) (used below as --pid 60
)
go to the created dir in your /config folder using
cd py_spy-0.3.14.data
cd scripts
Run the next commands for the actual py-spy readings to be analyzed by devâs:
(in below commands, replace â60â with the actual pid you got above using top
)
./py-spy top --pid 60
./py-spy record --duration 120 --rate 100 -o homeassistant_$(date +"%Y_%m_%d_%H_%M").svg --pid 60
./py-spy record --duration 300 --rate 200 -o homeassistant_$(date +"%Y_%m_%d_%H_%M").svg --pid 60
./py-spy dump --pid 60
Thanks Nick!
alternative commands
as pointed out by @armin-gh in this post, we can also directly issue the command including the correct PID automagically, by using:
py-spy dump --pid $(pgrep -u homeassistant hass )
this is even easier, as it doesnât not require the extra steps of running top first, noting the pid, en stopping top again.
just replace the actual number (so 60 in my examples above) by $(pgrep -u homeassistant hass )