https://developer.apple.com/videos/play/wwdc2021/10181/
툴이 되게 많음

자 이렇게 따라가 봅시다
Battery usage
- 배터리 관리를 잘해줘야 앱도 오래 머물 수 있음
- CPU, Networking, Location, GPU, Audio, Bluetooth 신경 써야함
스프레이 버튼 > Energy Impact 들어가서 Energy Impact 확인할 수 있음
MetricKit
원격 측정 프레임워크. 릴리즈된 앱을 측정하는데 도움이 될 수 있음
class AppMetrics: MXMetricManagerSubscriber {
init() {
let shared = MXMetricManager.shared
shared.add(self)
}
deinit {
let shared = MXMetricManager.shared
shared.remove(self)
}
// Receive daily metrics
func didReceive(_ payloads: [MXMetricPayload]) {
// Process metrics
}
// Receive diagnostics
func didReceive(_ payloads: [MXDiagnosticPayload]) {
// Process metrics
}
}
앱 사용 퍼포먼스 -> 애플 서버에 전달됨 -> Xcode Organizer에서 볼 수 있음
Organizer 켜면 Battery Usage 확인할 수 있음. 최근 16개 버전 볼 수 있음
Regression Pane
어떤 부분이 이슈를 만들어내는지 보려면, Report 아래에 있는 Energy Organizer를 보면 됨
배터리 성능 측정에 대해 더 알아보기
- Improving battery life and performance, WWDC19 (https://developer.apple.com/videos/play/wwdc2019/417/)
- Analyze HTTP traffic in instruments, WWDC21 (https://developer.apple.com/videos/play/wwdc2021/10212/)
Hang rate and scrolling
- Hang은 앱이 250밀리초 이상 사용자 입력 또는 작업에 응답하지 않는 경우
여기서 빨간 막대는 스크롤 경험이 안좋을 수록 표시됨 (렉 걸리는 그 느낌...)
Instruments로 어느 부분이 Hang을 일으키는지 분석할 수 있음
스크롤 경험을 XCTest로 측정할 수 있음
func testScrollingAnimationPerformance() throws {
app.launch()
app.staticTexts["Meal Planner"].tap()
let foodCollection = app.collectionViews.firstMatch
let measureOptions = XCTMeasureOptions()
measureOptions.invocationOptions = [.manuallyStop] // 이렇게 지정하면 블록 중간에 stopMeasuring 지정할 수 있음
measure(metrics: [XCTOSSignpostMetric.scrollDecelerationMetric], // 스크롤 측정
options: measureOptions) {
foodCollection.swipeUp(velocity: .fast) // start
stopMeasuring()
foodCollection.swipeDown(velocity: .fast) // reset
}
}
MetricKit을 구성하면 iOS 14에서는 24시간 간격으로 원격 이슈 파악 가능하고
iOS 15에서는 즉시 이슈 파악 가능함...!!!!
func startAnimating() {
// Mark the beginning of animations
mxSignpostAnimationIntervalBegin(
log: MXMetricManager.makeLogHandle(category: "animation_telemetry"),
name: "custom_animation”)
}
func animationDidComplete() {
// Mark the end of the animation to receive the collected hitch rate telemetry
mxSignpost(OSSignpostType.end,
log: MXMetricManager.makeLogHandle(category: "animation_telemetry"),
name: "custom_animation")
}
더 알아보기
Understand and eliminate hangs from your app, WWDC21 - https://developer.apple.com/videos/play/wwdc2021/10258/
Disk Writes
Instruments 통해서 Disk I/O 확인할 수 있음
Disk Usage를 XCTest로 측정할 수 있음
baseline를 설정해서 그것보다 퍼포먼스가 안나오면 테스트 실패되게 만들 수 있음
// Example performance XCTest
func testSaveMeal() {
let app = XCUIApplication()
let options = XCTMeasureOptions()
options.invocationOptions = [.manuallyStart]
measure(metrics: [XCTStorageMetric(application: 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))
}
}
이미 출시된 버전은 Organizer를 통해 확인 가능
Report 섹션 아래의 Disk Writes
앱이 24시간 내에 1GB 이상 디스크 쓰기를 하면 Report
Xcode13 에서는 어떻게 고쳐야할지 Insights 를 제공함.
Disk Write 이슈 더 알아보기:
Diagnose power and performance regressions in your app, WWDC21 - https://developer.apple.com/videos/play/wwdc2021/10087/
Launch time and termination
- 실행 시간: 실행 시간이 길면 유저는 짜증남...
- 종료 관리: 앱이 종료되게 되면 앱을 다시 사용할 떄도 실행하는 시간이 또 걸림
Organizer > Launch time
Organizer > Termination
Instruments > App Launch
앞서 본 것 처럼 XCTest를 활용할 수도 있음
MetricKit이 앱에 구현되어 있으면 daily metric payload로 매일 받아볼 수 있음
왜 앱이 종료되는지 자세히 확인하고 싶다면?
Why is my app getting killed?, WWDC 20 - https://developer.apple.com/videos/play/wwdc2020/10078/
Memory
Organizer > Memory
Instruments > Leaks, Allocations, VM Tracker
MetricKit
// Collect memory telemetry
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")
}
더 알아보기:
Detect and diagnose memory issues https://github.com/cozzin/cozzin.github.io/issues/36
https://developer.apple.com/videos/play/wwdc2021/10180/
Next step
'iOS' 카테고리의 다른 글
iPad Slide-over 키보드 높이 계산 이슈 해결 (0) | 2021.06.15 |
---|---|
Main Thread 무한 루프 문제해결 과정 (0) | 2021.06.14 |
커스텀 UIInputView height에 SafeArea 반영하기 (0) | 2021.04.28 |
Swift 객체 외부에서 객체가 해제되는 것 감지하기 (0) | 2021.04.20 |
@testable import로 연결한 모듈에서 Undefined symbol이 발생하는 이슈 대응 (0) | 2021.04.17 |