Sen başlamadan önce
Henüz yapmadıysanız Android projenize Firebase'i ekleyin .
Step 1 : Add the Performance Monitoring SDK to your app
After you've added the Performance Monitoring SDK, Firebase automatically starts collecting data for your app's screen rendering and data related to your app's lifecycle (like app start time ). To enable Firebase to monitor network requests, you must also add the Performance Monitoring Gradle plugin (next step).
In your module (app-level) Gradle file (usually
<project>/<app-module>/build.gradle.kts
or<project>/<app-module>/build.gradle
), add the dependency for the Performance Monitoring Android için kütüphane. Kitaplık sürümlerini kontrol etmek için Firebase Android BoM'yi kullanmanızı öneririz.dependencies { // Import the BoM for the Firebase platform implementation(platform("com.google.firebase:firebase-bom:32.8.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'yi kullandığınızda uygulamanız her zaman Firebase Android kitaplıklarının uyumlu sürümlerini kullanır.
Kotlin'e özgü bir kütüphane modülü mü arıyorsunuz? Ekim 2023'ten itibaren (Firebase BoM 32.5.0) hem Kotlin hem de Java geliştiricileri ana kütüphane modülüne güvenebilecekler (ayrıntılar için bu girişimle ilgili SSS'ye bakın).(Alternatif) BoM'yi kullanmadan Firebase kitaplığı bağımlılıklarını ekleyin
Firebase BoM'yi kullanmamayı tercih ederseniz her Firebase kitaplığı sürümünü bağımlılık satırında belirtmeniz gerekir.
Uygulamanızda birden fazla Firebase kitaplığı kullanıyorsanız kitaplık sürümlerini yönetmek için tüm sürümlerin uyumlu olmasını sağlayan BoM'yi kullanmanızı önemle tavsiye ettiğimizi unutmayın.
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.2") }
Uygulamanızı yeniden derleyin.
Step 2 : Add the Performance Monitoring Gradle plugin to your app
After you've added the Performance Monitoring Gradle plugin, Firebase automatically starts collecting data for HTTP/S network requests . The plugin also enables you to instrument custom code traces using @AddTrace annotation .
In your root-level (project-level) Gradle file (
<project>/build.gradle.kts
or<project>/build.gradle
), add the Performance Monitoring Gradle plugin: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.1" 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.1' apply false // Add the dependency for the Performance Monitoring Gradle plugin id 'com.google.firebase.firebase-perf' version '1.4.2' apply false }
In your module (app-level) Gradle file (usually
<project>/<app-module>/build.gradle.kts
or<project>/<app-module>/build.gradle
), add the Performance Monitoring Gradle plugin: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' ... }
Uygulamanızı yeniden derleyin.
3. Adım : İlk veri görüntüleme için performans olaylarını oluşturun
Firebase, SDK'yı uygulamanıza başarıyla eklediğinizde etkinlikleri işlemeye başlar. Hala yerel olarak geliştirme yapıyorsanız, ilk veri toplama ve işlemeye yönelik etkinlikler oluşturmak için uygulamanızla etkileşim kurun.
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.
Firebase konsolunun Performans kontrol paneline gidin. Birkaç dakika içinde ilk verilerinizin görüntülendiğini görmelisiniz.
Başlangıç verilerinizin görüntüsünü görmüyorsanız sorun giderme ipuçlarını inceleyin.
4. Adım : (İsteğe bağlı) Performans etkinliklerine ilişkin günlük mesajlarını görüntüleyin
Uygulamanızın
AndroidManifest.xml
dosyasına aşağıdaki gibi bir<meta-data>
öğesi ekleyerek Performans İzleme için hata ayıklama günlüğünü etkinleştirin:<application> <meta-data android:name="firebase_performance_logcat_enabled" android:value="true" /> </application>
Check your log messages for any error messages.
Performance Monitoring, günlük mesajlarını
FirebasePerformance
ile etiketler. Using logcat filtering, you can specifically view duration trace and HTTP/S network request logging by running the following command:adb logcat -s FirebasePerformance
Check for the following types of logs which indicate that Performance Monitoring is logging performance events:
-
Logging trace metric: TRACE_NAME , FIREBASE_PERFORMANCE_CONSOLE_URL
-
Logging network request trace: URL
-
Verilerinizi Firebase konsolunda görüntülemek için URL'yi tıklayın. It may take a few moments for the data to update in the dashboard.
If your app isn't logging performance events, review the troubleshooting tips .
Step 5 : (Optional) Add custom monitoring for specific code
To monitor performance data associated with specific code in your app, you can instrument custom code traces .
With a custom code 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 code 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 code 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 @AddTrace annotation .
Visit Add monitoring for specific code to learn more about these features and how to add them to your app.
Step 6 : Deploy your app then review results
Performans İzlemeyi bir veya daha fazla test cihazı kullanarak doğruladıktan sonra uygulamanızın güncellenmiş sürümünü kullanıcılarınıza dağıtabilirsiniz.
Performans verilerini Firebase konsolunun Performans kontrol panelinden izleyebilirsiniz.
Bilinen Sorunlar
Performance Monitoring Gradle eklentisi v1.1.0, Guava bağımlılıklarında bir uyumsuzluğa neden olabilir ve bu da aşağıdaki hataya neden olabilir:
Error:Execution failed for task ':app:packageInstantRunResourcesDebug'. > com.google.common.util.concurrent.MoreExecutors.directExecutor()Ljava/util/concurrent/Executor;
Bu hatayı görürseniz aşağıdakilerden birini yapabilirsiniz:
Performans İzleme eklentisini v1.1.1 veya sonraki bir sürüme yükseltin (en yenisi v1.4.2'dir).
Kök düzeyindeki (proje düzeyi) Gradle dosyanızdaki (
<project>/build.gradle.kts
veya<project>/build.gradle
) Performans İzleme eklentisi bağımlılık satırını aşağıdaki gibi değiştirin: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' } } }
Performans İzleme, HTTP içerik uzunluğu üstbilgisinde ayarlanan değere dayalı olarak HTTP ağ istekleri için toplam yük boyutunu bildirir. Bu değer her zaman doğru olmayabilir.
Performans İzleme, çok işlemli Android uygulamalarında yalnızca ana işlemi destekler.
Sonraki adımlar
GitHub'da Performance Monitoring Android kod örneğini inceleyin ve çalıştırın.
Performans İzleme tarafından otomatik olarak toplanan veriler hakkında daha fazla bilgi edinin:
- Uygulama başlangıç zamanı gibi uygulamanızın yaşam döngüsüyle ilgili veriler
- Uygulamanızda ekran oluşturmaya ilişkin veriler
- Uygulamanız tarafından yayınlanan HTTP/S ağ isteklerine ilişkin veriler
Performans verilerinizi Firebase konsolunda görüntüleyin, izleyin ve filtreleyin .
Özel kod izlerini kullanarak uygulamanıza belirli görevler veya iş akışları için izleme ekleyin.
Performans verilerini filtrelemek için nitelikleri kullanın .