Google is committed to advancing racial equity for Black communities. See how.

Get started with Performance Monitoring for Android

Before you begin

If you haven't already, add Firebase to your Android project.

In your project-level build.gradle file, make sure to include Google's Maven repository in both your buildscript and allprojects sections.

Step 1: Add the Performance Monitoring SDK to your app

The Performance Monitoring SDK enables monitoring of automatic duration traces and any additional custom traces in your app.

  1. In your module (app-level) Gradle file (usually app/build.gradle):

    // ...
    
    dependencies {
      // ...
    
      // Add the dependency for the Performance Monitoring library
      implementation 'com.google.firebase:firebase-perf:19.0.7'
    }
    
  2. Recompile your app.

Step 2: Add the Performance Monitoring plugin to your app

The Performance Monitoring Gradle plugin enables instrumentation that provides @AddTrace annotation processing and automatic HTTP/S network request monitoring.

To add the Performance Monitoring plugin to your app:

  1. In your module (app-level) Gradle file (usually app/build.gradle), apply the Performance Monitoring plugin:

    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 {
      // ...
    }
    
  2. In your root-level (project-level) Gradle file (build.gradle), add the rules to include the Performance Monitoring plugin.

    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.3'  // Google Services plugin
    
          // Add the dependency for the Performance Monitoring plugin
          classpath 'com.google.firebase:perf-plugin:1.3.1'  // Performance Monitoring plugin
        }
    }
    
  3. Recompile your app.

Step 3: Generate performance events for initial data display

Firebase can detect that you've successfully added the SDK to your app when it receives event information (like app interactions) from your app. If you're still developing locally, interact with your app to generate events for SDK detection as well as initial data collection and processing.

  1. Continue to develop your app using an emulator or test device that meets the following requirements:

    • An Android emulator with a recent image and Google Play services 15.0.0 or later

    • A test device with Google Play services 15.0.0 or later

  2. Generate events by switching your app between background and foreground several times, interacting with your app by navigating across screens, and/or triggering network requests.

  3. Go to the Performance section of the Firebase console to see if Firebase has detected the SDK.

    If you don't see an "SDK detected" message within 2 hours of adding the SDK to your app, review the troubleshooting tips.

  4. Performance Monitoring processes performance event data before displaying it in the Performance dashboard. You should see your initial data display within 24 hours of seeing the SDK detection message.

    If you don't see a display of your initial data, review the troubleshooting tips.

Step 4: (Optional) View log messages for performance events

  1. Enable debug logging for Performance Monitoring at build time by adding a <meta-data> element to your app's AndroidManifest.xml file, like so:

    <application>
        <meta-data
          android:name="firebase_performance_logcat_enabled"
          android:value="true" />
    </application>
    
  2. Check your log messages for any error messages.

  3. Performance Monitoring tags its log messages with FirebasePerformance. Using logcat filtering, you can specifically view duration trace and HTTP/S network request logging by running the following command:

    adb logcat -s FirebasePerformance
  4. Check for the following types of logs which indicate that Performance Monitoring is logging performance events:

    • Logging TraceMetric
    • Logging NetworkRequestMetric

If your app isn't logging performance events, review the troubleshooting tips.

Step 5: (Optional) Add custom monitoring for specific code

You can create custom traces to monitor performance data associated with specific code in your app.

With a custom trace, you can measure how long it takes your app to complete a specific task or set of tasks, such as loading a set of images or querying your database. The default metric for a custom trace is its duration, but you can also add custom metrics, such as cache hits and memory warnings.

In your code, you define the beginning and the end of a custom trace (and add any desired custom metrics) using the API provided by the Performance Monitoring SDK. For Android apps, you can also monitor the duration of specific methods using the @AddTrace annotation.

Visit Add custom monitoring for specific app code to learn more about these features and how to add them to your app.

Step 6: Deploy your app then review results

After you've validated Performance Monitoring using one or more test devices, you can deploy the updated version of your app to your users.

You can monitor performance data in the Performance dashboard of the Firebase console.

Known issues

  • The Performance Monitoring Gradle plugin v1.1.0 can cause a mismatch in Guava dependencies, resulting in the following error:

    Error:Execution failed for task ':app:packageInstantRunResourcesDebug'.
    > com.google.common.util.concurrent.MoreExecutors.directExecutor()Ljava/util/concurrent/Executor;

    If you see this error, you can either:

    • Upgrade the Performance Monitoring plugin to v1.1.1 or later (the most recent is v1.3.1).

    • Replace the Performance Monitoring plugin dependency line in your root-level (project-level) Gradle file (build.gradle), as follows:

      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 reports the total payload size for HTTP/S network requests based on the value set in the HTTP content-length header. This value might not always be accurate.

  • Performance Monitoring only supports the main process in multi-process Android apps.

Next steps