Hi everyone,
(I am running on an M2 MacBook Pro 14 inch with 96 GB of memory)
I've been profiling with Instruments to find out why program suddenly goes from full CPU usage (all of my threads active and all cores working) to about 33% CPU usage. An Instruments system trace is showing me a massive performance cliff where I suddenly get taken off the performance cores and only run on efficiency cores. The performance cores are then occupied by "kernel.release.t6020". What is this thing?
I have kernel callstacks enabled but I only get the instruction pointer and have no symbols for any of those callstacks. I'm accustomed to Windows development where kernel symbols are available so you can see deeply into the kernel to know why you're spending time there (for example, semaphore wait or thread scheduling). Is there a way for me to get a similar level of information or kernel symbols so I can see what the kernel is doing?
Around the time I observe the performance cliff, I also noticed in the narrative view some of the preemptions are done "because thread was balanced off CPU i (P Core) to optimize the system's CPU performance". What does this mean? Have I begun to hit some sort of thermal limit?
Here are some example screenshots of what I am seeing in Instruments:
After a bit more searching and investigating, the root cause of my performance problem was caused by App Nap. I only realized this by happenstance while looking through my Instruments capture where my main thread was running "mach_msg2_trap" and the callstack involved "rbs_acquire_appnap_assertion".
Realizing this, I went to use https://developer.apple.com/documentation/foundation/nsprocessinfo/1415995-beginactivitywithoptions with https://developer.apple.com/documentation/foundation/nsactivityoptions/nsactivityuserinitiatedallowingidlesystemsleep and now everything works perfectly.
It would be great if Instruments would more obviously surface App Nap as a state change in the process so it's easier to understand what's going on.