For others who might struggle with running py-spy on a VM this is how I’ve done it:
- Start the VM
- Once Hassio is ready, in the VM window, type “login”
- When prompted for the username type “root”, there is no password
- You should see a big Home Assistant logo
- Now type “login” again to get access to the host
- There will be no username or password, but the cursor should change to “# _”
Frome there this is how I installed py-spy:
docker exec -it homeassistant /bin/bash
echo 'manylinux1_compatible = True' > /usr/local/lib/python3.8/site-packages/_manylinux.py
pip install py-spy
Once the py-spy is installed your cursor should change to something like “bash-5.0# _”
Type top
to display all the processes that are currently running. At the top of the list will be the process that is using most of the resources. Take a note of its PPID, in my case 236 (python3 -m homeassistant --config /config
)
Press ctrl+c to exit the list and run this command to generate the flame graph:
py-spy record --pid <your_ppid_goes_here> --output /config/py-spy.svg --duration 120
The SVG file will be saved in the config folder.