我想创建一个性能测试用例,以便从我的本机应用程序中测量UI和JS FPS。
如何调用性能监视器并以编程方式获取FPS?
(目前我们可以从摇动菜单中启用性能监视器[PCTPerMonitor]。)
答案 0 :(得分:0)
我们可以通过以下代码以编程方式启用性能监视器
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSDictionary *settings = [defaults objectForKey:@"RCTDevMenu"];
NSMutableDictionary *newSettings = [NSMutableDictionary dictionaryWithDictionary:settings];
newSettings[@"RCTPerfMonitorKey"] = @1;
[defaults setObject:newSettings forKey:@"RCTDevMenu"];
[defaults synchronize];
更新设置后,会触发通知' settingsDidChange'来自RCTDevMenu。
我们可以在启用性能监视器后获取FPS。它将在窗口中添加性能监视器(应该是最后一个对象)
UIView *performanceMonitorView = self.window.subviews.lastObject;
for (id view in performanceMonitorView.subviews) {
if ([view isKindOfClass:[RCTFPSGraph class]]){
RCTFPSGraph *fpsGraph = (RCTFPSGraph *)view;
NSLog(@"FPS Graph minFPS: %zd maxFPS: %zd fps: %zd", fpsGraph.minFPS, fpsGraph.maxFPS, fpsGraph.FPS);
}
}
然后我们可以遍历性能监视器子视图并保存RCTFPSGraph实例以获取FPS。