When using the application, the background problem when using the Weird CPU

I am experiencing a very strange CPU error with my streaming audio application.

When the application is in the foreground and playing music, the overall CPU usage of the device is only about 15%. However, as soon as the application is placed in the background, the CPU utilization reaches 100% and remains there.

About 40% of this process comes from the application process itself, while about another 60% comes from the SpringBoard process, which apparently handles all Core Animation calls (although I do not use Core Animation, I assume that it also handles other activities. associated with the user interface). In addition, according to the "CPU Activity" tool, most of the additional CPU usage from the application process itself falls into the "graphics" category, although I see an increase in both "sound processing" and (oddly enough) the "foreground" app activity " .

How can I find out what causes this problem? The tools tell me at a high level what is happening, but not why this is happening.

+4
source share
2 answers

It is very strange. However, without any code, it is really hard to say anything about anything. Purely based on assumptions, I would say that you are updating the user interface without knowing it in the background. Perhaps an animated call on -(void)applicationDidEnterBackground ? Give us some more work! I'm really curious about it now :)

+1
source

The mystery is solved!

Of course, I missed the obvious, thanks to Dylan G for pointing me in the right direction. I checked the loop to check the remaining background time. I didnโ€™t sleep at all in the flow of the cycle, so apparently the full speed just worked, sucking in all the processor power.

I'm not sure why it looked like it was related to graphics and related to the SpringBoard process, but as soon as I added sleep(1) at the end of the loop, CPU usage no longer increased when the application was placed in the background. The strange thing is that I donโ€™t call any interface or graphical related methods in this loop, it just calls [[UIApplication sharedApplication] backgroundTimeRemaining] and accesses some integer and bool properties.

There is still a fast CPU surge during the second or second period after it is placed in the background, as well as SpringBoard spikes, but only for a second, then the processor load drops to the same level as when the application was launched.

0
source

All Articles