iOS:Xcode Instruments的使用

2.码表 同时被 2 个专栏收录
174 篇文章 0 订阅
419 篇文章 0 订阅

1.使用实例

1.1 Points of Inerest(标记代码执行的点和执行时间)

import MetricKit

class ViewController: UIViewController {
    
    static let startupActivities:StaticString = "viewDidLoad"
    let poiLog = OSLog(subsystem: "com.example.CocoaPictures", category: .pointsOfInterest)
    
    override func viewDidLoad() {
        super.viewDidLoad()
        os_signpost(.begin, log: self.poiLog, name: ViewController.startupActivities)
        for i in 0...100 {
            print(i)
        }
        os_signpost(.end, log: self.poiLog, name: ViewController.startupActivities)

在这里插入图片描述
代码出处:
Apple Developer: Reducing Your App’s Launch Time

1.1.1 oc版,+load方法

override class func load()在swift中不被允许

在这里插入图片描述

instruments测试截图:+load方法的执行在启动的Initializing - Static Runtime Initialization阶段

在这里插入图片描述

代码:用swift代码通过桥接文件来实现

import UIKit
import MetricKit

class XXYMetric: NSObject {
    
   static var startupActivities:StaticString = "didFinishLaunching"
   static var poiLog = OSLog(subsystem: "com.example.CocoaPictures", category: .pointsOfInterest)
    
    @objc class func start(str: String) {
        poiLog = OSLog(subsystem: str, category: .pointsOfInterest)
        os_signpost(.begin, log: poiLog, name: startupActivities)
        
    }
    
    @objc class func end(str: String) {
        poiLog = OSLog(subsystem: str, category: .pointsOfInterest)
        os_signpost(.end, log: poiLog, name: startupActivities)
    }

}
#import "XXYPerson.h"
#import "XCTEST_oc-Swift.h"

@implementation XXYPerson

+ (void)load {
    [XXYMetric startWithStr:@"load"];
    for (int i = 0; i < 1000; i++) {
        NSLog(@"%d",i);
    }
    [XXYMetric endWithStr:@"load"];
    
}

@end

2.苹果官网资料

WWDC视频:
WWDC2019:Developing a Great Profiling Experience
WWDC2019:Modeling in Custom Instruments

WWDC2019: Getting Started with Instruments

在这里插入图片描述

苹果官方文档:
Apple Developer: Instruments Help

参考博客:
Xcode Instruments的使用
iOS -调试工具Instruments使用总结

  • 0
    点赞
  • 0
    评论
  • 0
    收藏
  • 一键三连
    一键三连
  • 扫一扫,分享海报

相关推荐
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值