How can I programmatically determine the CPU usage or how busy / busy is the system in iPhone-OS?
My app does some pretty nice but heavy core animations while scrolling. Sometimes it crashes due to poor performance. So I need to find out if there is enough animation capability, and if not, I'll just leave it. It would be best if I could ask the system how busy it is.
UPDATE: I mean Core Animation in particular.
a source to share
By animation, you mean frames that play one after another (like an animated GIF) or a CoreAnimation (OpenGL) effect that moves polygons with rendered textures around?
If this is the former, I would really consider some way to optimize the animation or eliminate it in all cases.
If this is the latter, I would do a deeper dig into the source of the problem. Core Animation will drop frames under normal conditions to avoid getting into situations like this in the first place.
In any case, you may want to consider loading texture assets a little earlier. I had some problems in my apps with animation methods that take a UIImage parameter when I created the UIImage in a function call. Asset preloading a little earlier in my code took good care of the problem.
As an example:
BAD
[[UIImage imageNamed:@"checkmark.png"] drawAtPoint:p];
BETTER
//declared at top of class
static UIImage *checkmark = nil;
in init:
checkmark = [UIImage imageNamed:@"checkmark.png"];
in drawRect:
[checkmark drawAtPoint:p];
You will need to adapt this method to your specific situation. In my case, the checkbox is used a lot and it's pretty small, I don't mind keeping the memory permanently.
I wonder if it is possible to fix your crashes by making sure the assets are ready for use by the application.
a source to share
I wouldn't do that . If your application crashes, it becomes heavy. You can run your application with some tools to find out where your bottlenecks are.
So, without trying to sound too harsh, the best way is to rewrite some parts so that you run the app on the iPhone all the time .. p>
a source to share