시작하기 전에
먼저 Android 프로젝트에 Firebase를 추가합니다.
1단계: 앱에 Performance Monitoring SDK 추가
Performance Monitoring SDK를 추가하면 Firebase에서 앱의 화면 렌더링과 앱의 수명 주기(예: 앱 시작 시간)에 관련된 데이터를 자동으로 수집하기 시작합니다. Firebase가 네트워크 요청을 모니터링하도록 사용 설정하려면 Performance Monitoring Gradle 플러그인도 추가해야 합니다(다음 단계).
Firebase Android BoM을 사용하여 모듈(앱 수준) Gradle 파일(일반적으로
app/build.gradle
)에서 Performance Monitoring Android 라이브러리의 종속 항목을 선언합니다.자바
dependencies { // Import the BoM for the Firebase platform implementation platform('com.google.firebase:firebase-bom:26.5.0') // Declare the dependency for the Performance Monitoring library // When using the BoM, you don't specify versions in Firebase library dependencies implementation 'com.google.firebase:firebase-perf' }
Firebase Android BoM을 사용하면 앱에서 항상 호환되는 Firebase Android 라이브러리 버전을 사용합니다.
(대안) BoM을 사용하지 않고 Firebase 라이브러리 종속 항목을 선언합니다.
Firebase BoM을 사용하지 않도록 선택한 경우에는 종속 항목 줄에 각 Firebase 라이브러리 버전을 지정해야 합니다.
앱에서 여러 Firebase 라이브러리를 사용하는 경우 모든 버전이 호환되도록 BoM을 사용하여 라이브러리 버전을 관리하는 것이 좋습니다.
dependencies { // Declare the dependency for the Performance Monitoring library // When NOT using the BoM, you must specify versions in Firebase library dependencies implementation 'com.google.firebase:firebase-perf:19.1.1' }
Kotlin+KTX
dependencies { // Import the BoM for the Firebase platform implementation platform('com.google.firebase:firebase-bom:26.5.0') // Declare the dependency for the Performance Monitoring library // When using the BoM, you don't specify versions in Firebase library dependencies implementation 'com.google.firebase:firebase-perf-ktx' }
Firebase Android BoM을 사용하면 앱에서 항상 호환되는 Firebase Android 라이브러리 버전을 사용합니다.
(대안) BoM을 사용하지 않고 Firebase 라이브러리 종속 항목을 선언합니다.
Firebase BoM을 사용하지 않도록 선택한 경우에는 종속 항목 줄에 각 Firebase 라이브러리 버전을 지정해야 합니다.
앱에서 여러 Firebase 라이브러리를 사용하는 경우 모든 버전이 호환되도록 BoM을 사용하여 라이브러리 버전을 관리하는 것이 좋습니다.
dependencies { // Declare the dependency for the Performance Monitoring library // When NOT using the BoM, you must specify versions in Firebase library dependencies implementation 'com.google.firebase:firebase-perf-ktx:19.1.1' }
앱을 다시 컴파일합니다.
2단계: 앱에 Performance Monitoring 플러그인 추가
Performance Monitoring Gradle 플러그인을 추가하면 Firebase에서 HTTP/S 네트워크 요청에 대한 데이터를 자동으로 수집합니다. 또한 이 플러그인을 사용하면 @AddTrace 주석을 통해 커스텀 코드 trace를 계측할 수 있습니다.
모듈(앱 수준) Gradle 파일(일반적으로
app/build.gradle
)에서 Performance Monitoring 플러그인을 적용합니다.apply plugin: 'com.android.application' apply plugin: 'com.google.gms.google-services' // Apply the Performance Monitoring plugin apply plugin: 'com.google.firebase.firebase-perf' android { // ... }
루트 수준(프로젝트 수준) Gradle 파일(
build.gradle
)에서 Performance Monitoring 플러그인을 포함하는 규칙을 추가합니다.buildscript { repositories { // Check that you have the following line (if not, add it): google() // Google's Maven repository // Add the Bintray repository jcenter() } dependencies { // ... // To benefit from the latest Performance Monitoring plugin features, // update your Android Gradle Plugin dependency to at least v3.4.0 classpath 'com.android.tools.build:gradle:3.4.0' classpath 'com.google.gms:google-services:4.3.5' // Google Services plugin // Add the dependency for the Performance Monitoring plugin classpath 'com.google.firebase:perf-plugin:1.3.4' // Performance Monitoring plugin } }
앱을 다시 컴파일합니다.
3단계: 초기 데이터 표시를 위한 성능 이벤트 생성
Firebase는 앱에서 이벤트 정보(예: 앱 상호작용)를 수신하면 앱에 SDK가 성공적으로 추가된 것으로 간주합니다. 로컬에서 개발 중인 경우에는 앱과 상호작용하여 SDK 감지는 물론 초기 데이터 수집 및 처리 이벤트를 생성할 수 있습니다.
앱을 백그라운드와 포그라운드 간에 여러 번 전환하고, 화면을 탐색하여 앱과 상호작용하거나, 네트워크 요청을 트리거하여 이벤트를 생성합니다.
Firebase Console의 성능 대시보드로 이동하여 Firebase가 SDK를 감지했는지 확인합니다.
SDK를 앱에 추가한 후 몇 분 내에 'SDK 감지됨' 메시지가 표시되지 않으면 문제 해결 팁을 검토하세요.
Performance Monitoring은 성능 이벤트 데이터를 성능 대시보드에 표시하기 전에 먼저 처리합니다. SDK 감지 메시지가 표시된 후 24시간 이내에 초기 데이터가 표시됩니다.
초기 데이터가 표시되지 않으면 문제 해결 팁을 검토하세요.
4단계: (선택사항) 성능 이벤트의 로그 메시지 보기
앱의
AndroidManifest.xml
파일에 다음과 같이<meta-data>
요소를 추가하여 빌드 시 Performance Monitoring에 디버그 로깅을 사용 설정합니다.<application> <meta-data android:name="firebase_performance_logcat_enabled" android:value="true" /> </application>
로그 메시지에서 오류 메시지가 있는지 확인합니다.
Performance Monitoring은 로그 메시지에
FirebasePerformance
로 태그를 지정합니다. logcat 필터링을 사용하면 다음 명령어를 실행하여 기간 trace 및 HTTP/S 네트워크 요청 로깅을 구체적으로 확인할 수 있습니다.adb logcat -s FirebasePerformance
Performance Monitoring에서 성능 이벤트를 로깅 중임을 나타내는 다음 유형의 로그를 확인합니다.
Logging trace metric: TRACE_NAME
Logging network request trace: URL
앱에서 성능 이벤트를 로깅하고 있지 않으면 문제 해결 팁을 검토하세요.
5단계: (선택사항) 특정 코드의 커스텀 모니터링 추가
앱의 특정 코드에 연결된 성능 데이터를 모니터링하려면 커스텀 코드 trace를 계측하면 됩니다.
커스텀 코드 trace를 사용하면 앱이 특정 작업 또는 일련의 작업을 완료하는 데 걸리는 시간을 파악할 수 있습니다. 예를 들면 이미지 모음을 로드하거나 데이터베이스를 쿼리하는 작업이 있습니다. 커스텀 코드 trace의 기본 측정항목은 기간이지만 캐시 적중 및 메모리 경고와 같은 커스텀 측정항목도 추가할 수 있습니다.
코드에서는 Performance Monitoring SDK에서 제공하는 API를 사용하여 커스텀 코드 trace의 시작과 끝을 정의하고 원하는 커스텀 측정항목을 추가합니다. Android 앱의 경우 @AddTrace 주석을 사용하여 특정 메서드의 기간을 모니터링할 수도 있습니다.
이러한 기능에 대한 정보와 앱에 기능을 추가하는 방법을 자세히 알아보려면 특정 코드에 대한 모니터링 추가를 참조하세요.
6단계: 앱 배포 후 결과 확인
하나 이상의 테스트 기기를 사용하여 Performance Monitoring을 검증한 후 업데이트된 앱 버전을 사용자에게 배포할 수 있습니다.
Firebase Console의 성능 대시보드에서 성능 데이터를 모니터링할 수 있습니다.
알려진 문제
Performance Monitoring Gradle 플러그인 v1.1.0에서 Guava 종속 항목의 불일치로 인해 다음과 같은 오류가 발생할 수 있습니다.
Error:Execution failed for task ':app:packageInstantRunResourcesDebug'. > com.google.common.util.concurrent.MoreExecutors.directExecutor()Ljava/util/concurrent/Executor;
이 오류가 표시되면 다음 중 하나를 수행하세요.
Performance Monitoring 플러그인을 v1.1.1 이상(최신 버전은 v1.3.4)으로 업그레이드합니다.
루트 수준(프로젝트 수준) Gradle 파일(
build.gradle
)의 Performance Monitoring 플러그인 종속 항목 줄을 다음과 같이 바꿉니다.buildscript { // ... dependencies { // ... // Replace the standard Performance Monitoring plugin dependency line, as follows: classpath ('com.google.firebase:perf-plugin:1.1.0') { exclude group: 'com.google.guava', module: 'guava-jdk5' } } }
Performance Monitoring은 HTTP 콘텐츠 길이 헤더에 설정된 값을 기반으로 HTTP 네트워크 요청의 총 페이로드 크기를 보고합니다. 이 값은 정확하지 않을 수도 있습니다.
Performance Monitoring은 다중 프로세스 Android 앱의 메인 프로세스만 지원합니다.
다음 단계
다음과 같이 Performance Monitoring에서 자동으로 수집하는 데이터에 대해 자세히 알아보세요.
- 앱 시작 시간과 같은 앱의 수명 주기와 관련된 데이터
- 앱의 화면 렌더링 데이터
- 앱에서 실행한 HTTP/S 네트워크 요청 데이터
Firebase Console에서 성능 데이터를 조회, 추적, 필터링하세요.
커스텀 코드 trace를 계측하여 앱의 특정 작업 또는 워크플로에 대한 모니터링을 추가하세요.