如何以编程方式确定系统在iPhone-OS中的CPU使用率或系统的繁忙/占用? [英] How can I programmatically determine CPU usage rate or how busy / occupied the system is in iPhone-OS?

查看:156
本文介绍了如何以编程方式确定系统在iPhone-OS中的CPU使用率或系统的繁忙/占用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序在滚动期间做了一些漂亮但重的核心动画。有时它由于性能不佳而崩溃。所以我需要一些方法来找出是否有足够的能力来制作动画,如果没有,我只是把他们离开。最好的方法是如果我能问系统有多忙。



UPDATE:我的意思是Core Animation。

解决方案

通过动画,你的意思是相继播放的帧(如动画GIF)或一些移动具有映射纹理的多边形的CoreAnimation(OpenGL)效果?



如果是前者,我会考虑在所有情况下优化动画或消除动画的方法。



如果是后者,我会深入挖掘问题的根源。核心动画在正常情况下会丢帧,以防止进入这种情况首先。



在任何一种情况下,您都可以考虑加载纹理资源。我在我的应用程序中遇到了一些麻烦,当我在函数调用中创建UIImage 时,动画方法需要一个UIImage参数。



例如:

BAD

  [[UIImage imageNamed:@checkmark.png] drawAtPoint:p]; 

更好

  //声明在类的顶部
static UIImage * checkmark = nil;

 

checkmark = [UIImage imageNamed:@checkmark.png];在drawRect中:

  [checkmark drawAtPoint:p]; 

您需要根据您的特定情况调整此技术。在我的情况下,复选标记经常使用,它很小,我不介意永久性的记忆。



我不知道你的崩溃是否可以修复确保资产已准备好由应用程序使用。


My app is doing some pretty but heavy weight core animations during scrolling. Sometimes it crashes due to bad performance. So I need some way to find out if there is enough capability to make the animations, and if not, I just leave them away. Best way would be if I could ask the system how busy it is.

UPDATE: I mean especially Core Animation.

解决方案

By animation, do you mean frames that play after one another (like an animated GIF) or some CoreAnimation (OpenGL) effect that is moving polygons with mapped textures around?

If it's the former, I'd really consider some way of optimizing the animation or eliminating it in all cases.

If it's the latter, I'd do some deeper digging into the source of the problem. Core Animation under normal circumstances will drop frames in order to keep from getting into situations like this in the first place.

In either case case you might consider loading the texture assets a little earlier. I have had some trouble in my apps with animation methods that take a UIImage parameter when I created the UIImage in the function call. Preloading the asset a little earlier in my code took care of the problem nicely.

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 would need to adapt this technique to your particular situation. In my case, checkmark is used often, and it quite small, I don't mind dedicating the memory to it permanently.

I wonder if your crashes could be fixed by making sure the assets were ready to be used by the application.

这篇关于如何以编程方式确定系统在iPhone-OS中的CPU使用率或系统的繁忙/占用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆