How to investigate system freeze?

Occasionally my desktop freezes while I’m using it, and I have to shut down with the power button. I think it might be related to the window manager, but I can’t say for sure.

What commands/logs would be useful to investigate this issue?
I am on Ubuntu Budgie 22.04.