• 5개의 툴

    • XCode Orgainzer
    • MetricKit
    • Instrumentss
    • XCTest
    • App Store Connect API
  • Introduction

    • 어떤 걸 추적해야 할까?
      • Battery Usage
      • Launch time
      • Hang rate
      • Memory
      • Disk writes
      • Scrolling
      • Terminations
      • MXSignpost
  • Metrics ans resoultion

    • Battery Usage

      • 실기기에서는 배터리 사용량을 설정에서 볼 수 있다.
      • 배터리 소모량이 적어야 앱을 오래 쓸 수 있다.
      • CPU, 네트워킹, Location이 Top3고, GPU, Bluetooth, Audio가 그 다음이다.
      • 개발할 때는 debug navigatior에서 energy impact를 확인할 수 있다.
        • 그 아래에 관련한 추천 옵션을 통해서 바로 프로파일링도 가능
      • 재현이 되지 않거나, 컨텍스트가 많이 필요한 경우는 MetricKit을 적용할 수 있다.
      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에서 볼 수 있다. → 물론 명시적으로 동의한 경우에만 온다

      • regression 항목이 추가되었다.
    • Hang rate & Scrolling Hitch: 앱이 사용자 이벤트에 응답하지 않는 것

      • 이 정보도 App Store Connect API로 받을 수 있다.
      • Xcode Organizer로도 볼 수 있다.
      • Instrument로도 볼 수 있다.
      • UITest로도 돌려볼 수 있다.
      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에서 넘어온다.

        • 원래는 24시간마다였는데, 15부터는 발생 즉시 넘어온다.
      • 커스텀 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

      • 최대한 batch로 풀어야 한다.
      • 저장 테스트
      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))
      	}
      }
      
      • Organizer에서도 볼 수 있다.
        • iOS 13부터는 좀 더 힌트를 주고 있다.
      • 이것도 Appstore Connect API로 가져올 수 있다.
      • 커스텀 가능
      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

      • 첫실행이 길면 사용자가 응답 안하는 지 알고 꺼버릴 가능성이 높고, 이 시간은 백그라운드에서 돌아올때보다 크다
      • 역시 Organizer에서 볼 수 있다.
      • Time Profiler로도 확인할 수 있다.
      • XCTest로도 할 수 있고, MetricKit으로도 매일 날아온다.
    • Memory

      • Instrument로 확인 가능
        • Leak: 메모리 누수 확인
        • allocation: 메모리 라이프 사이클 확인
        • vm tracker: 앱이 사용하는 가상 메모리 공간 확인
      • 커스텀 트래킹
      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: 직접 해라