ऐप्लिकेशन डेवलपमेंट और टेस्टिंग के दौरान, Performance Monitoring को बंद करना आपके लिए फ़ायदेमंद हो सकता है.
उदाहरण के लिए, ऐप्लिकेशन बनाने की प्रोसेस के दौरान Performance Monitoring को बंद करके, ये काम किए जा सकते हैं:
अपनी डीबग बिल्ड में, Performance Monitoring की कुछ सुविधाओं को बंद करें. जैसे, Performance Monitoring Gradle प्लगिन की ओर से दी जाने वाली सुविधाएं. हालांकि, रिलीज़ बिल्ड के लिए इन सुविधाओं को फिर से चालू करें.
ऐप्लिकेशन बनाते समय, Performance Monitoring को बंद करें. हालांकि, अपने ऐप्लिकेशन को रनटाइम के दौरान इसे फिर से चालू करने की अनुमति दें.
ऐप्लिकेशन बनाते समय, Performance Monitoring को बंद करें. साथ ही, अपने ऐप्लिकेशन को रनटाइम के दौरान इसे फिर से चालू करने की अनुमति न दें.
Performance Monitoring चालू करके भी अपना ऐप्लिकेशन बनाया जा सकता है. हालांकि, Firebase Remote Config का इस्तेमाल करें, ताकि प्रोडक्शन ऐप्लिकेशन में Performance Monitoring को बंद (और फिर से चालू) करने की सुविधा मिल सके. इस विकल्प की मदद से, अपने ऐप्लिकेशन को इस तरह कॉन्फ़िगर किया जा सकता है कि उपयोगकर्ता Performance Monitoring का इस्तेमाल करने के लिए ऑप्ट-इन या ऑप्ट-आउट कर सकें.
ऐप्लिकेशन बनाने की प्रोसेस के दौरान, Performance Monitoring को बंद करना
बिल्ड प्रोसेस के दौरान, Performance Monitoring को बंद किया जा सकता है. इसके लिए, Performance Monitoring Gradle प्लग इन को बंद करें और/या Performance Monitoring Android लाइब्रेरी को बंद करें.
डेवलपमेंट और डीबग करने के दौरान, प्लगिन को बंद करना फ़ायदेमंद होता है, क्योंकि प्लगिन के ज़रिए इंस्ट्रुमेंटेशन से बिल्ड टाइम बढ़ सकता है. हालांकि, आपको लाइब्रेरी चालू रखनी चाहिए, ताकि ऐप्लिकेशन शुरू होने, ऐप्लिकेशन फ़ोरग्राउंड में होने, और ऐप्लिकेशन बैकग्राउंड में होने के ट्रेस के साथ-साथ, अपने ऐप्लिकेशन में कस्टम कोड के ट्रेस का परफ़ॉर्मेंस डेटा भी देखा जा सके.
Performance Monitoring Gradle प्लगिन बंद करना
इन विकल्पों का इस्तेमाल करके, Performance Monitoring प्लगिन को बंद किया जा सकता है. इसके लिए, instrumentationEnabled
फ़्लैग जोड़ें:
Extension Property — इससे कंपाइल टाइम पर, किसी खास बिल्ड वैरिएंट के लिए प्लगिन बंद हो जाता है
प्रोजेक्ट प्रॉपर्टी — कंपाइल करने के समय, यह सभी बिल्ड वैरिएंट के लिए प्लगिन बंद कर देती है
एक्सटेंशन प्रॉपर्टी फ़्लैग का इस्तेमाल करके प्लगिन बंद करना
Extensions Property फ़्लैग का इस्तेमाल करके, कंपाइल करने के समय किसी बिल्ड वैरिएंट के लिए Performance Monitoring प्लगिन बंद किया जा सकता है.
अपनी रूट-लेवल (प्रोजेक्ट-लेवल) Gradle फ़ाइल (
<project>/build.gradle.kts
या<project>/build.gradle
) में, पक्का करें कि Android Gradle प्लग इन की डिपेंडेंसी को v3.4.0 या इसके बाद के वर्शन के तौर पर तय किया गया हो.Android Gradle प्लगिन के पुराने वर्शन के लिए, अब भी किसी खास बिल्ड वैरिएंट के लिए Performance Monitoring प्लगिन को बंद किया जा सकता है. हालांकि, उस वैरिएंट के लिए बिल्ड टाइम का योगदान पूरी तरह से खत्म नहीं होगा.
अपनी मॉड्यूल (ऐप्लिकेशन-लेवल) Gradle फ़ाइल (आम तौर पर
<project>/<app-module>/build.gradle.kts
या<project>/<app-module>/build.gradle
) में यह फ़्लैग जोड़ें. इसके बाद, Performance Monitoring प्लगिन को बंद करने के लिए, इसेfalse
पर सेट करें.Kotlin
import com.google.firebase.perf.plugin.FirebasePerfExtension // ... android { // ... buildTypes { getByName("debug") { configure<FirebasePerfExtension> { // Set this flag to 'false' to disable @AddTrace annotation processing and // automatic monitoring of HTTP/S network requests // for a specific build variant at compile time. setInstrumentationEnabled(false) } } } }
Groovy
android { // ... buildTypes { debug { FirebasePerformance { // Set this flag to 'false' to disable @AddTrace annotation processing and // automatic monitoring of HTTP/S network requests // for a specific build variant at compile time. instrumentationEnabled false } } } }
प्रोजेक्ट प्रॉपर्टी फ़्लैग के ज़रिए प्लगिन बंद करना
प्रोजेक्ट प्रॉपर्टी फ़्लैग का इस्तेमाल करके, कंपाइल टाइम पर सभी बिल्ड वैरिएंट के लिए Performance Monitoring प्लगिन बंद किया जा सकता है.
अपनी gradle.properties
फ़ाइल में यह फ़्लैग जोड़ें. इसके बाद, Performance Monitoring प्लगिन को बंद करने के लिए, इसे false
पर सेट करें.
// ... // Set this flag to 'false' to disable @AddTrace annotation processing and // automatic monitoring of HTTP/S network requests // for all build variants at compile time. firebasePerformanceInstrumentationEnabled=false
Performance Monitoring Android लाइब्रेरी बंद करना
अगर कंपाइल करने के समय Performance Monitoring लाइब्रेरी बंद कर दी जाती है, तो आपके पास यह चुनने का विकल्प होता है कि क्या आपके ऐप्लिकेशन को रनटाइम के दौरान लाइब्रेरी चालू करने की अनुमति देनी है.
कंपाइल टाइम पर लाइब्रेरी को बंद करें, लेकिन अपने ऐप्लिकेशन को रनटाइम पर इसे चालू करने की अनुमति दें
अपने ऐप्लिकेशन की AndroidManifest.xml
फ़ाइल में यह <meta-data>
एलिमेंट जोड़ें:
<application> <meta-data android:name="firebase_performance_collection_enabled" android:value="false" /> </application>
कंपाइल करते समय लाइब्रेरी को बंद करें, लेकिन अपने ऐप्लिकेशन को रनटाइम के दौरान इसे चालू करने की अनुमति न दें
अपने ऐप्लिकेशन की AndroidManifest.xml
फ़ाइल में यह <meta-data>
एलिमेंट जोड़ें:
<application> <meta-data android:name="firebase_performance_collection_deactivated" android:value="true" /> </application>
Remote Config का इस्तेमाल करके, रनटाइम के दौरान अपने ऐप्लिकेशन को बंद करना
Firebase Remote Config की मदद से, ऐप्लिकेशन के काम करने के तरीके और लुक में बदलाव किया जा सकता है. इसलिए, यह आपके लिए Performance Monitoring को बंद करने का सबसे सही तरीका है. ऐसा ऐप्लिकेशन के डिप्लॉय किए गए इंस्टेंस में किया जा सकता है.
अगर आपको अगली बार Android ऐप्लिकेशन शुरू होने पर Performance Monitoring डेटा कलेक्शन बंद करना है, तो यहां दिए गए उदाहरण कोड का इस्तेमाल करें. Android ऐप्लिकेशन में Remote Config इस्तेमाल करने के बारे में ज़्यादा जानने के लिए, Android पर Firebase Remote Config इस्तेमाल करना लेख पढ़ें.
पक्का करें कि Remote Config, आपकी मॉड्यूल (ऐप्लिकेशन-लेवल) की Gradle फ़ाइल के
dependencies
सेक्शन में मौजूद हो. आम तौर पर, यह<project>/<app-module>/build.gradle.kts
या<project>/<app-module>/build.gradle
होता है:Kotlin
implementation("com.google.firebase:firebase-config-ktx:23.0.0")
Java
implementation("com.google.firebase:firebase-config:23.0.0")
Remote Config सेट अप करें और अगर
perf_disable
कोtrue
पर सेट किया गया है, तो Performance Monitoring बंद करें:Kotlin
// Setup remote config val config = Firebase.remoteConfig // You can uncomment the following two statements to permit more fetches when // validating your app, but you should comment out or delete these lines before // distributing your app in production. // val configSettings = remoteConfigSettings { // minimumFetchIntervalInSeconds = 3600 // } // config.setConfigSettingsAsync(configSettings) // Load in-app defaults from an XML file that sets perf_disable to false until you update // values in the Firebase Console // Observe the remote config parameter "perf_disable" and disable Performance Monitoring if true config.setDefaultsAsync(R.xml.remote_config_defaults) .addOnCompleteListener { task -> if (task.isSuccessful) { Firebase.performance.isPerformanceCollectionEnabled = !config.getBoolean("perf_disable") } else { // An error occurred while setting default parameters } }
Java
// Setup remote config final FirebaseRemoteConfig config = FirebaseRemoteConfig.getInstance(); // You can uncomment the following two statements to permit more fetches when // validating your app, but you should comment out or delete these lines before // distributing your app in production. // FirebaseRemoteConfigSettings configSettings = new FirebaseRemoteConfigSettings.Builder() // .setMinimumFetchIntervalInSeconds(3600) // .build(); // config.setConfigSettingsAsync(configSettings); // Load in-app defaults from an XML file that sets perf_disable to false until you update // values in the Firebase Console //Observe the remote config parameter "perf_disable" and disable Performance Monitoring if true config.setDefaultsAsync(R.xml.remote_config_defaults) .addOnCompleteListener(new OnCompleteListener<Void>() { @Override public void onComplete(@NonNull Task<Void> task) { if (task.isSuccessful()) { if (config.getBoolean("perf_disable")) { FirebasePerformance.getInstance().setPerformanceCollectionEnabled(false); } else { FirebasePerformance.getInstance().setPerformanceCollectionEnabled(true); } } else { // An error occurred while setting default parameters } } });
MainActivity.java
की वैल्यू फ़ेच और चालू करने के लिए,MainActivity.java
में यह कोड जोड़ें:Remote ConfigKotlin
// Remote Config fetches and activates parameter values from the service val config = Firebase.remoteConfig config.fetch(3600) .continueWithTask { task -> if (!task.isSuccessful) { task.exception?.let { throw it } } config.activate() } .addOnCompleteListener(this) { task -> if (task.isSuccessful) { // Parameter values successfully activated // ... } else { // Handle errors } }
Java
//Remote Config fetches and activates parameter values from the service final FirebaseRemoteConfig config = FirebaseRemoteConfig.getInstance(); config.fetch(3600) .continueWithTask(new Continuation<Void, Task<Boolean>>() { @Override public Task<Boolean> then(@NonNull Task<Void> task) throws Exception { if (!task.isSuccessful()) { throw task.getException(); } return config.activate(); } }) .addOnCompleteListener(new OnCompleteListener<Boolean>() { @Override public void onComplete(@NonNull Task<Boolean> task) { if (task.isSuccessful()) { // Parameter values successfully activated // ... } else { // Handle errors } } });
Firebase कंसोल में Performance Monitoring को बंद करने के लिए, अपने ऐप्लिकेशन के प्रोजेक्ट में perf_disable पैरामीटर बनाएं. इसके बाद, इसकी वैल्यू को
true
पर सेट करें.इस बदलाव से, Performance Monitoring SDK टूल को किए जाने वाले कॉल "नो ऑपरेशन" कॉल (NOOP) बन जाएंगे. इससे, आपके ऐप्लिकेशन की परफ़ॉर्मेंस पर Performance Monitoring SDK टूल के इस्तेमाल का कोई खास असर नहीं पड़ेगा.
perf_disable एट्रिब्यूट की वैल्यू
false
पर सेट करने पर, Performance Monitoring चालू रहता है.