My mac's UI is randomly freezing for 5-10 seconds throughout the day. How can I figure out what's going wrong? I have a 2017 27&quot; iMac running macOS 10.14.6. Throughout the day the entire screen will freeze for a period of 5-10 seconds. This happens sporadically and there's no consistent way to trigger it, but toggling Exposé and opening tabs in Safari seem to be the two biggest triggers.
While the screen is frozen, I can still move the cursor around, but I can't interact with anything on screen. All clicks and keystrokes will be delayed until the screen unfreezes, and then they'll all haphazardly fire at once. I'll still be able to hear audio from any application that's running, including music, videos, voice calls, or video calls.
I tried reinstalling macOS 10.14.6 to fix the issue, but sadly that didn't help. I read somewhere that one of the security updates released by Apple for 10.14.6 could introduce this issue, but I don't have any security updates installed currently and the issue is still there, so that's not it. I also have a 2019 MacBook Pro with 10.14.6 and much of the same software loaded on to it as my iMac, and it's not experiencing this issue.
Is there anything I can do to debug this, or some other solution I can try?
I have discovered how to determine the cause of the freezes. The trick is to take a sample of the system WindowServer process while it is frozen.
Of course, since I can't interact with the system while it's frozen, I used a separate computer to ssh into my mac, switch that session to the root account with sudo -s, and then execute the following command the moment the system freezes: sample WindowServer 5
That creates a sample that shows what the window server was stuck doing while it was frozen, and it consistently showed it locked in the following functions:
4613 Thread_1658: Main Thread   DispatchQueue_&lt;multiple&gt;
+ 4613 start  (in libdyld.dylib) + 1  [0x7fff71e563d5]
+   4613 ???  (in WindowServer)  load address 0x107900000 + 0x150d  [0x10790150d]
+     4613 SLXServer  (in SkyLight) + 1349  [0x7fff6b2b7af1]
+       4613 server_loop  (in SkyLight) + 602  [0x7fff6b2b7d52]
+         2238 CGXRunOneServicesPass  (in SkyLight) + 731  [0x7fff6b2b6df9]
+         ! 2236 mach_msg  (in libsystem_kernel.dylib) + 60  [0x7fff71f8b76c]
+         ! : 2236 mach_msg_trap  (in libsystem_kernel.dylib) + 10  [0x7fff71f8b22a]
+         ! 2 mach_msg  (in libsystem_kernel.dylib) + 60,68  [0x7fff71f8b76c,0x7fff71f8b774]
+         2087 CGXRunOneServicesPass  (in SkyLight) + 1761  [0x7fff6b2b71ff]
+         ! 2086 post_port_data  (in SkyLight) + 237  [0x7fff6b2b7551]
+         ! : 1986 rendezvousHandler(unsigned int, mach_msg_header_t*, void*)  (in SkyLight) + 29  [0x7fff6b138bd1]
+         ! : | 1984 CGXHandleMessage  (in SkyLight) + 101  [0x7fff6b2738bc]
+         ! : | + 1984 invocation function for block in rendezvousHandler(unsigned int, mach_msg_header_t*, void*)  (in SkyLight) + 125  [0x7fff6b138c5f]
+         ! : | +   1979 _XGetEventShmem  (in SkyLight) + 310  [0x7fff6b0837bd]
+         ! : | +   ! 1979 WSEventSourceCreateGraphShmemForAuditToken  (in SkyLight) + 82  [0x7fff6b1bccb5]
+         ! : | +   !   1978 WSAuditTokenCanMonitorEvents  (in SkyLight) + 171  [0x7fff6b2bab0d]
+         ! : | +   !   : 1978 WSAuditTokenIsPostEventTCCApprovedCachingFailure  (in SkyLight) + 320  [0x7fff6b2ba977]
+         ! : | +   !   :   1978 TCCAccessCheckAuditToken  (in TCC) + 269  [0x7fff6c788a9e]
+         ! : | +   !   :     1978 TCCAccessRequest  (in TCC) + 345  [0x7fff6c783e5d]
+         ! : | +   !   :       1978 _os_activity_initiate_impl  (in libsystem_trace.dylib) + 53  [0x7fff7206889c]
+         ! : | +   !   :         1978 _dispatch_lane_barrier_sync_invoke_and_complete  (in libdispatch.dylib) + 60  [0x7fff71e15129]
+         ! : | +   !   :           1978 _dispatch_client_callout  (in libdispatch.dylib) + 8  [0x7fff71e0963d]
+         ! : | +   !   :             1978 __TCCAccessRequest_block_invoke.68  (in TCC) + 862  [0x7fff6c784549]
+         ! : | +   !   :               1978 tccd_send_message  (in TCC) + 656  [0x7fff6c784c25]
+         ! : | +   !   :                 1978 xpc_connection_send_message_with_reply_sync  (in libxpc.dylib) + 178  [0x7fff72088647]
+         ! : | +   !   :                   1978 dispatch_mach_send_with_result_and_wait_for_reply  (in libdispatch.dylib) + 50  [0x7fff71e1d882]
+         ! : | +   !   :                     1978 _dispatch_mach_send_and_wait_for_reply  (in libdispatch.dylib) + 609  [0x7fff71e1d3e7]
+         ! : | +   !   :                       1978 mach_msg  (in libsystem_kernel.dylib) + 60  [0x7fff71f8b76c]
+         ! : | +   !   :                         1978 mach_msg_trap  (in libsystem_kernel.dylib) + 10  [0x7fff71f8b22a]

This is taken from a sample that caught two seconds of a freeze.
This pretty clearly shows that TCC is the culprit. Now that I know that, the next question is figuring out how to fix the freezes.