5개의 툴
Introduction
Metrics ans resoultion
Battery Usage
final class AppMetrics: MXMetrixManagerSubscriber {
init() {
let shared = MXMetricManager.shared
shared.add(self)
}
deinit {
let shared = MXMetricManager.shared
shared.remove(self)
}
// 일간 지표를 받을 수 있다.
func didReceive(_ payloads: [MXMetricPayload]) {
// Process Metrics
}
// 진단 정보를 받을 수 있다.
func didReceive(_ payloads: [MXDiagnosticPayload]) {
// Process Metrics
}
}
간단한 정보는 이런거 안해도 Xcode Organizer에서 볼 수 있다. → 물론 명시적으로 동의한 경우에만 온다
Hang rate & Scrolling Hitch: 앱이 사용자 이벤트에 응답하지 않는 것
func testScrollingAnimationPerformance() throws {
app.launch()
app.staticTexts["Meal Planner"].tap()
let foodCollection = app.collectionViews.firstMatch
let mearsureOptions = XCTMeasureOptions()
// 여러 번 돌리기 때문에, 이 옵션을 주고 수동으로 멈춘 뒤 원래대로 돌려놓는다.
measureOptions.invocationOptions = [.manuallyStop]
measure(metrics: [XCTOSSignpostMetric.scrollDecelerationMetric],
options: measureOptions) {
foodCollecion.swipeUp(velocity: .fast)
stopMeasuring()
foodCollecion.swipeDown(velocity: .fast)
}
}
iOS 14에서는 이 정보가 diagnostic으로 MetricKit에서 넘어온다.
커스텀 API도 측정할 수 있다.
func startAnimating() {
mxSignPostAnimationIntervalBegin(
log: MXMetricManager.makeLogHandle(category: "animation_telemetry"),
name: "custom_animation")
)
}
func animationDidComplete() {
mxSignPost(OSSignPostType.end,
log: MXMetricManager.makeLogHandle(category: "animation_telemetry"),
name: "custom_animation")
}
Disk writes
func testSaveMeal() {
let app = XCUIApplcation()
let options = XCTMeasureOptions()
options.invocationOptions = [.manuallyStart]
measure(metrics: [XCTStorageMetric(applicatin: app)],
options: options) {
app.launch()
startMeasuring()
let firstCell = app.cells.firstMatch
firstCell.buttons["Save meal"].firstMatch.tap()
let savedButton = firstCell.buttons["Saved"].firstMatch
XCTAssertTrue(savedButton.waitForExistence(timeout: 2))
}
}
func syncAllContentsToDb() {
mxSignpost(OSSignpostType.begin,
log: MXMetricManager.makeLogHandle(category: "diskWrite_telemetry"),
name: "custom_diskWrites")
mxSignPost(OSSignpostType.end,
log: MXMetricManager.makeLogHandle(category: "diskWrite_telemetry"),
name: "custom_diskWrites")
}
Launch time & Terminations
Memory
func saveAppAssets() {
mxSignpost(OSSignpostType.begin,
log: MXMetricManager.makeLogHandle(category: "memory_telemetry"),
name: "custom_memory")
// save app metadata
mxSignpost(OSSignpostType.end,
log: MXMetricManager.makeLogHandle(category: "memory_telemetry"),
name: "custom_memory")
}
Next Steps: 직접 해라