시작하기 전에
아직 추가하지 않았다면 Android 프로젝트에 Firebase를 추가합니다 .
1단계 : 앱에 Performance Monitoring SDK 추가
Performance Monitoring SDK를 추가하면 Firebase는 앱의 화면 렌더링 을 위한 데이터 및 앱의 수명 주기와 관련된 데이터(예: 앱 시작 시간 )를 자동으로 수집하기 시작합니다. Firebase가 네트워크 요청을 모니터링하도록 하려면 Performance Monitoring Gradle 플러그인 도 추가해야 합니다(다음 단계).
모듈(앱 수준) Gradle 파일 (일반적으로
<project>/<app-module>/build.gradle
)에서 Performance Monitoring Android 라이브러리에 대한 종속성을 추가합니다. Firebase Android BoM 을 사용하여 라이브러리 버전 관리를 제어하는 것이 좋습니다.Kotlin+KTX
dependencies { // Import the BoM for the Firebase platform implementation platform('com.google.firebase:firebase-bom:31.2.0') // Add 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 { // Add 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:20.3.1' }
Java
dependencies { // Import the BoM for the Firebase platform implementation platform('com.google.firebase:firebase-bom:31.2.0') // Add 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 { // Add 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:20.3.1' }
앱을 다시 컴파일합니다.
2단계 : 앱에 Performance Monitoring Gradle 플러그인 추가
Performance Monitoring Gradle 플러그인을 추가하면 Firebase가 자동으로 HTTP/S 네트워크 요청 에 대한 데이터 수집을 시작합니다. 플러그인을 사용하면 @AddTrace 주석 을 사용하여 사용자 지정 코드 추적을 계측할 수도 있습니다.
루트 수준(프로젝트 수준) Gradle 파일(
<project>/build.gradle
)에서 Performance Monitoring Gradle 플러그인을 buildscript 종속성으로 추가합니다.buildscript { repositories { // Make sure that you have the following two repositories google() // Google's Maven repository mavenCentral() // Maven Central repository } 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:7.2.0' // Make sure that you have the Google services Gradle plugin dependency classpath 'com.google.gms:google-services:4.3.15' // Add the dependency for the Performance Monitoring Gradle plugin classpath 'com.google.firebase:perf-plugin:1.4.2' } }
모듈(앱 수준) Gradle 파일(일반적으로
<project>/<app-module>/build.gradle
)에서 Performance Monitoring Gradle 플러그인을 추가합니다.plugins { id 'com.android.application' // Make sure that you have the Google services Gradle plugin id 'com.google.gms.google-services' // Add the Performance Monitoring Gradle plugin id 'com.google.firebase.firebase-perf' ... }
앱을 다시 컴파일합니다.
3단계 : 초기 데이터 표시를 위한 성능 이벤트 생성
앱에 SDK를 성공적으로 추가하면 Firebase가 이벤트 처리를 시작합니다. 여전히 로컬에서 개발 중인 경우 앱과 상호 작용하여 초기 데이터 수집 및 처리를 위한 이벤트를 생성합니다.
백그라운드와 포그라운드 간에 앱을 여러 번 전환하고, 화면을 탐색하여 앱과 상호작용하고, 네트워크 요청을 트리거하여 이벤트를 생성합니다.
Firebase 콘솔의 성능 대시보드 로 이동합니다. 몇 분 안에 초기 데이터가 표시되어야 합니다.
초기 데이터가 표시되지 않으면 문제 해결 팁 을 검토하십시오.
4단계 : (선택 사항) 성능 이벤트에 대한 로그 메시지 보기
다음과 같이 앱의
AndroidManifest.xml
파일에<meta-data>
요소를 추가하여 빌드 시 성능 모니터링에 대한 디버그 로깅을 활성화합니다.<application> <meta-data android:name="firebase_performance_logcat_enabled" android:value="true" /> </application>
오류 메시지에 대한 로그 메시지를 확인하십시오.
Performance Monitoring은 로그 메시지에
FirebasePerformance
태그를 지정합니다. logcat 필터링을 사용하면 다음 명령을 실행하여 기간 추적 및 HTTP/S 네트워크 요청 로깅을 구체적으로 볼 수 있습니다.adb logcat -s FirebasePerformance
Performance Monitoring이 성능 이벤트를 기록하고 있음을 나타내는 다음 유형의 로그를 확인하십시오.
-
Logging trace metric: TRACE_NAME , FIREBASE_PERFORMANCE_CONSOLE_URL
-
Logging network request trace: URL
-
Firebase 콘솔에서 데이터를 보려면 URL을 클릭하세요. 대시보드에서 데이터가 업데이트되는 데 몇 분 정도 걸릴 수 있습니다.
앱이 성능 이벤트를 기록하지 않는 경우 문제 해결 팁 을 검토하십시오.
5단계 : (선택 사항) 특정 코드에 대한 사용자 지정 모니터링 추가
앱의 특정 코드와 관련된 성능 데이터를 모니터링하기 위해 사용자 지정 코드 추적 을 계측할 수 있습니다.
사용자 지정 코드 추적을 사용하면 앱이 특정 작업 또는 일련의 작업(예: 이미지 집합 로드 또는 데이터베이스 쿼리)을 완료하는 데 걸리는 시간을 측정할 수 있습니다. 사용자 지정 코드 추적의 기본 메트릭은 기간이지만 캐시 적중 및 메모리 경고와 같은 사용자 지정 메트릭을 추가할 수도 있습니다.
코드에서 Performance Monitoring SDK에서 제공하는 API를 사용하여 사용자 지정 코드 추적의 시작과 끝을 정의하고 원하는 사용자 지정 메트릭을 추가합니다. Android 앱의 경우 @AddTrace 주석 을 사용하여 특정 메서드의 기간을 모니터링할 수도 있습니다.
이러한 기능과 앱에 기능을 추가하는 방법에 대해 자세히 알아보려면 특정 코드에 대한 모니터링 추가를 방문하세요.
6단계 : 앱 배포 후 결과 검토
하나 이상의 테스트 기기를 사용하여 Performance Monitoring의 유효성을 검사한 후 앱의 업데이트된 버전을 사용자에게 배포할 수 있습니다.
Firebase 콘솔의 성능 대시보드 에서 성능 데이터를 모니터링할 수 있습니다.
알려진 문제
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;
이 오류가 표시되면 다음 중 하나를 수행할 수 있습니다.
성능 모니터링 플러그인을 v1.1.1 이상으로 업그레이드하십시오(가장 최신 버전은 v1.4.2임).
다음과 같이 루트 수준(프로젝트 수준) 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 앱의 기본 프로세스만 지원합니다.
다음 단계
GitHub에서 Performance Monitoring Android 코드 샘플을 검토하고 실행합니다.
Performance Monitoring에서 자동으로 수집되는 데이터에 대해 자세히 알아보세요.
- 앱 시작 시간 과 같은 앱의 수명 주기와 관련된 데이터
- 앱의 화면 렌더링 을 위한 데이터
- 앱에서 발행한 HTTP/S 네트워크 요청 데이터
Firebase 콘솔에서 성능 데이터를 보고 추적하고 필터링 합니다.
사용자 지정 코드 추적을 계측 하여 앱의 특정 작업 또는 워크플로에 대한 모니터링을 추가합니다.