What's the best way to analyse resource usage? Scripts, automations etc

Hi all. I’ve found that my setup has become a bit laggy, delays in automations firing and things like that.

The inbuilt system monitor also reports a different (lower) cpu usage than the top command on my pi. Is there any way to get a better breakdown on what the homeassistant process is doing? (log ceased to be responsive long ago).

Are there any types of things in particular that are resource intensive?

I have sometimes observed that it’ll be using something stupid like 50% cpu then I’ll restart hass and it’ll be back to 5% for a while at least.

Thanks