Android에서 Performance Monitoring 시작하기

시작하기 전에

먼저 Android 프로젝트에 Firebase를 추가합니다.

1단계: 앱에 Performance Monitoring SDK 추가

Performance Monitoring SDK를 추가하면 Firebase에서 앱의 화면 렌더링과 앱의 수명 주기(예: 앱 시작 시간)에 관련된 데이터를 자동으로 수집하기 시작합니다. Firebase가 네트워크 요청을 모니터링하도록 사용 설정하려면 Performance Monitoring Gradle 플러그인 추가해야 합니다(다음 단계).

  1. 모듈(앱 수준) Gradle 파일(일반적으로 <project>/<app-module>/build.gradle.kts 또는 <project>/<app-module>/build.gradle)에서 Android용 Performance Monitoring 라이브러리의 종속 항목을 추가합니다. 라이브러리 버전 관리 제어에는 Firebase Android BoM을 사용하는 것이 좋습니다.

    dependencies {
        // Import the BoM for the Firebase platform
        implementation(platform("com.google.firebase:firebase-bom:32.7.1"))
    
        // 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.5.1")
    }
    
    Kotlin 전용 라이브러리 모듈을 찾고 계신가요? 2023년 10월(Firebase BoM 32.5.0)부터 Kotlin 및 Java 개발자 모두 기본 라이브러리 모듈을 사용할 수 있습니다. 자세한 내용은 이 이니셔티브에 관한 FAQ를 참조하세요.

  2. 앱을 다시 컴파일합니다.

2단계: 앱에 Performance Monitoring Gradle 플러그인 추가

Performance Monitoring Gradle 플러그인을 추가하면 Firebase에서 HTTP/S 네트워크 요청에 대한 데이터를 자동으로 수집합니다. 또한 이 플러그인을 사용하면 @AddTrace 주석을 통해 커스텀 코드 trace를 계측할 수 있습니다.

  1. 루트 수준(프로젝트 수준) Gradle 파일(<project>/build.gradle.kts 또는 <project>/build.gradle)에서 Performance Monitoring Gradle 플러그인을 추가합니다.

    Kotlin

    plugins {
        // To benefit from the latest Performance Monitoring plugin features,
        // update your Android Gradle plugin dependency to at least v3.4.0
        id("com.android.application") version "7.3.0" apply false
    
        // Make sure that you have the Google services Gradle plugin dependency
        id("com.google.gms.google-services") version "4.4.0" apply false
    
        // Add the dependency for the Performance Monitoring Gradle plugin
        id("com.google.firebase.firebase-perf") version "1.4.2" apply false
    }
    

    Groovy

    plugins {
        // To benefit from the latest Performance Monitoring plugin features,
        // update your Android Gradle plugin dependency to at least v3.4.0
        id 'com.android.application' version '7.3.0' apply false
    
        // Make sure that you have the Google services Gradle plugin dependency
        id 'com.google.gms.google-services' version '4.4.0' apply false
    
        // Add the dependency for the Performance Monitoring Gradle plugin
        id 'com.google.firebase.firebase-perf' version '1.4.2' apply false
    }
    
  2. 모듈(앱 수준) Gradle 파일(일반적으로 <project>/<app-module>/build.gradle.kts 또는 <project>/<app-module>/build.gradle)에서 Performance Monitoring Gradle 플러그인을 추가합니다.

    Kotlin

    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")
        ...
    }
    

    Groovy

    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. 앱을 다시 컴파일합니다.

3단계: 초기 데이터 표시를 위한 성능 이벤트 생성

앱에 SDK를 성공적으로 추가하면 Firebase에서 이벤트 처리를 시작합니다. 로컬에서 개발 중인 경우에는 앱과 상호작용하여 초기 데이터 수집 및 처리를 위한 이벤트를 생성합니다.

  1. 앱을 백그라운드와 포그라운드 간에 여러 번 전환하고, 화면을 탐색하여 앱과 상호작용하거나, 네트워크 요청을 트리거하여 이벤트를 생성합니다.

  2. Firebase Console의 성능 대시보드로 이동합니다. 몇 분 이내에 초기 데이터가 표시됩니다.

    초기 데이터가 표시되지 않으면 문제 해결 팁을 검토하세요.

4단계: (선택사항) 성능 이벤트의 로그 메시지 보기

  1. 앱의 AndroidManifest.xml 파일에 다음과 같이 <meta-data> 요소를 추가하여 빌드 시 Performance Monitoring에 디버그 로깅을 사용 설정합니다.

    <application>
        <meta-data
          android:name="firebase_performance_logcat_enabled"
          android:value="true" />
    </application>
    
  2. 로그 메시지에 오류 메시지가 있는지 확인합니다.

  3. Performance Monitoring은 로그 메시지에 FirebasePerformance로 태그를 지정합니다. logcat 필터링을 사용하면 다음 명령어를 실행하여 기간 trace 및 HTTP/S 네트워크 요청 로깅을 구체적으로 확인할 수 있습니다.

    adb logcat -s FirebasePerformance
  4. Performance Monitoring에서 성능 이벤트를 로깅 중임을 나타내는 다음 유형의 로그를 확인합니다.

    • Logging trace metric: TRACE_NAME, FIREBASE_PERFORMANCE_CONSOLE_URL
    • Logging network request trace: URL
  5. URL을 클릭하여 Firebase Console에서 데이터를 확인합니다. 대시보드에서 데이터를 업데이트하는 데 몇 분 정도 걸릴 수 있습니다.

앱에서 성능 이벤트를 로깅하고 있지 않으면 문제 해결 팁을 검토하세요.

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.4.2)으로 업그레이드합니다.

    • 루트 수준(프로젝트 수준) Gradle 파일(<project>/build.gradle.kts 또는 <project>/build.gradle)의 Performance Monitoring 플러그인 종속 항목 줄을 다음과 같이 바꿉니다.

      Kotlin

      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")
          }
        }
      }
      

      Groovy

      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 앱의 메인 프로세스만 지원합니다.

다음 단계