Swift项目配置编译时间的命令行实用工具 - xcprofiler

2016-12-21      102      Ruby
项目简介 前往项目首页

xcprofiler

Swift项目配置编译时间的命令行实用工具。

安装

gem install xcprofiler

使用方法

  1. 在Xcode项目中的 Other Swift Flags的版本flag中添加  -Xfrontend -debug-time-function-bodies .

  2. 创建你的项目

  3. 执行xcprofiler
$ xcprofiler [PRODUCT_NAME or ACTIVITY_LOG_PATH] [options]

xcprofiler在DerivedData目录中搜索最新的版本日志。

你可以指定 .xcactivity日志.

$ xcprofiler MyApp
$ xcprofiler ~/Library/Developer/Xcode/DerivedData/MyApp-xxxxxxxxxxx/Logs/Build/0761C73D-3B6C-449A-BE89-6D11DAB748FE.xcactivitylog

示例如下:

+----------------------+------+---------------------------------------------------------------------------------------------------------------------------------------------------------------+----------+
| File                 | Line | Method name                                                                                                                                                   | Time(ms) |
+----------------------+------+---------------------------------------------------------------------------------------------------------------------------------------------------------------+----------+
| ResultProtocol.swift | 132  | public func ==<T : ResultProtocol where T.Value : Equatable, T.Error : Equatable>(left: T, right: T) -> Bool                                                  | 14.2     |
| Result.swift         | 66   | get {}                                                                                                                                                        | 13.1     |
| Result.swift         | 78   | public static func error(_ message: String? = default, function: String = #function, file: String = #file, line: Int = #line) -> NSError                      | 6.3      |
| Result.swift         | 69   | get {}                                                                                                                                                        | 2.2      |
| Result.swift         | 132  | public func `try`<T>(_ function: String = #function, file: String = #file, line: Int = #line, try: (NSErrorPointer) -> T?) -> Result<T, NSError>              | 1.7      |
| Result.swift         | 95   | get {}                                                                                                                                                        | 1.4      |
| Result.swift         | 21   | public init(_ value: T?, failWith: @autoclosure () -> Error)                                                                                                  | 0.9      |
| Result.swift         | 142  | public func `try`(_ function: String = #function, file: String = #file, line: Int = #line, try: (NSErrorPointer) -> Bool) -> Result<(), NSError>              | 0.9      |
| ResultProtocol.swift | 172  | @available(*, unavailable, renamed: "recover(with:)") public func recoverWith(_ result: @autoclosure () -> Self) -> Self                                      | 0.7      |
| Result.swift         | 72   | get {}                                                                                                                                                        | 0.6      |
| Result.swift         | 75   | get {}                                                                                                                                                        | 0.6      |
| ResultProtocol.swift | 72   | public func recover(_ value: @autoclosure () -> Value) -> Value                                                                                               | 0.5      |
| ResultProtocol.swift | 111  | public func &&&<L : ResultProtocol, R : ResultProtocol where L.Error == R.Error>(left: L, right: @autoclosure () -> R) -> Result<(L.Value, R.Value), L.Error> | 0.5      |
| ResultProtocol.swift | 144  | public func !=<T : ResultProtocol where T.Value : Equatable, T.Error : Equatable>(left: T, right: T) -> Bool                                                  | 0.5      |
| ResultProtocol.swift | 92   | public func tryMap<U>(_ transform: (Value) throws -> U) -> Result<U, Error>                                                                                   | 0.4      |
| Result.swift         | 175  | @available(*, unavailable, renamed: "success") public static func Success(_: T) -> Result<T, Error>                                                           | 0.3      |
| ResultProtocol.swift | 55   | public func mapError<Error2>(_ transform: (Error) -> Error2) -> Result<Value, Error2>                                                                         | 0.3      |
| ResultProtocol.swift | 77   | public func recover(with result: @autoclosure () -> Self) -> Self                                                                                             | 0.3      |
| ResultProtocol.swift | 93   | (closure)                                                                                                                                                     | 0.3      |
| Result.swift         | 31   | public init(attempt f: () throws -> T)                                                                                                                        | 0.2      |
+----------------------+------+---------------------------------------------------------------------------------------------------------------------------------------------------------------+----------+

Available Options

option shorthand description
--limit -l 显示的限制
--show-invalids 显示无效定位结果
--order -o 排序规则(default,time,file)

使用默认 reporter

你可以使用reporter来输出轨迹日历。

require 'xcprofiler'

profiler = Xcprofiler::Profiler.by_product_name('MyApp')
profiler.reporters = [
  Xcprofiler::StandardOutputReporter.new(limit: 20, order: :time)],
  Xcprofiler::JSONReporter.new({output_path: 'result.json'})
]
profiler.report!