Random restarts, a fan that never rests, a USB port acting dead: before blaming software, it is worth letting the Mac check itself.
On Apple silicon:
1. Shut down the Mac
2. Press and hold the power button until you see Options
3. Release it
4. Press and hold Command-D until the Mac restarts
On an Intel Mac you turn it on and hold D right away, or Option-D if that does nothing.
First unplug what you don’t need. Apple suggests leaving only keyboard, mouse, display, Ethernet and power, which also tells you whether a dock or drive was the troublemaker. Install pending macOS updates beforehand if you can. On macOS Tahoe 26 and later you pick which test to run, such as display, keyboard or trackpad; older versions just run.
At the end you get a result, sometimes with a reference code. I’d photograph that code, since support will ask for it and nobody remembers it.
A clean result is reassuring but not proof. Faults that only appear under heat or after hours of use can slip through a short test. And it doesn’t repair anything, it only points. Back up first if the machine is behaving badly.
Further reading: Use Apple Diagnostics to test your Mac
Going deeper: Guide: keep your Mac apps in a Brewfile, so a new MacBook is one command away