ios查看帧率的软件_有几种方法可以通过编程方式计算iOS应用的FPS(每秒帧数)?...

Since we are talking about programmatically, Instruments are not under my consideration.

Some reference listed in advance:

According to the doc,

The duration property provides the amount of time between frames. You

can use this value in your application to calculate the frame rate of

the display...

So in my demo project, I add a displayLink to mainRunLoop for UITrackingRunLoopMode:

self.displayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(screenDidUpdated)];

[self.displayLink addToRunLoop:[NSRunLoop mainRunLoop] forMode:UITrackingRunLoopMode];

and use duration to calculate FPS. But out of my expectation, the duration is always 0.016667 (~ FPS 60) not matter the tableView scrolls smoothly or not.

How I make the tableView lag is to add one line in - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath:

NSData *data = [NSData dataWithContentsOfURL:url];

Then I turned to displayLink.timestamp, and it worked.

2. Observing drawRect:?

My second idea is to observe drawRect:, I thought when the tableView scrolls, its drawRect: would be called frame by frame, then I could calculate the FPS according to the time diff between drawRect: callings.

But it failed, cause the drawRect: was called only once (while cells for many times). This way is similar to Using CADisplayLink, but maybe I chose the wrong position/method(like drawRect:) to observe, any recommended method for me to observe?

Questions:

How the Instruments measure the FPS accurately?

Is the doc said using duration to calculate FPS wrong?

What's the right/best method to observe to calculate the FPS?

Thanks!

解决方案

As the documentation for CADisplayLink states, duration is basically just 1 / maximumFramesPerSecond. You need to check the discrepancy between targetTimestamp and timestamp to detect dropped frames:

The duration property provides the amount of time between frames at the maximumFramesPerSecond. To calculate the actual frame duration, use targetTimestamp - timestamp.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值