I've seen precisely this problem on many, many versions of macOS, both release and beta. Usually the delay is caused by some Apple process. For me, diagnosing is not the problem, the problem is fixing it.
You didn't say how much memory your computer has. A few years ago, Apple introduced compression on virtual memory. This is especially important in SSD-based computers: it decreases wear on the SSD to just compress memory, rather than sending it out to mass storage. But more and more programs are using more and more memory. So most of the freezes I've seen are related to long-running processes, typically Apple's processes used for things like curating photographs or background indexing of the SSD, waking up, having lots of memory decompressed, making the program you are using have its memory compressed, and then the scheduler changing its mine and giving your program memory. One of the related problems is that the Mach process scheduler doesn't seem to be as memory and swapping aware as it should be.
Your question is about how to diagnose this, so here's what I do:
- First thing I do is set my system clock to count every second so I can always look up at the menu bar and see if the computer has crashed.
- Next, I set up a program that does a
ps aux
every second and stores the result in another file.
- I use the computer until it freezes.
- Then I look at the relevant
ps aux
to see which process was taking up the most memory or the most CPU.
If you are pretty sure you have identified the process, you can STOP it without killing it. See if this makes the problem go away.
Once you've identified the culprit, you have a problem. It's typically an Apple process, not your own, not a third-party driver, not anything that you have control over. Here are some of the things I've tried:
Create a new user on your computer and try using it without copying over all of your files. Does the problem go away? If so, it's either that your profile is corrupted or, more likely, a file in your profile is causing the problem. Now you can slowly copy things into the new profile until you have identified the problem.
Sometimes I've found individual files that causes the full-text indexing program to blow up the amount of memory it needs or to crash. I delete those files and the problem goes away.
Sometimes I just wipe the computer and restore my files. That works.
Good luck. This is annoying and it's almost certainly apple's fault.