Daily iOS
Performance and debugging

Building an in-app hang monitor

You want to add a feature to your in-house APM that captures a stack whenever the main thread stalls past a threshold. How would you detect jank from inside the app?

How would an interviewer hear this answer? You'll see whether they'd move on, dig in, or say no, and which sentences would trip you up. Your score doesn't change.
See the short answer

Attach a CFRunLoopObserver to the main RunLoop and have a watcher thread use a semaphore timeout to check whether the gap from BeforeSources to AfterWaiting exceeds a threshold (say 250ms), or have a watchdog thread ping the main thread periodically and time the response. In production, lean on MetricKit's MXHangDiagnostic first.

Share a question