ऐप्लिकेशन डेवलपमेंट और टेस्टिंग के दौरान, आपको Performance Monitoring को बंद करना मददगार लग सकता है.
उदाहरण के लिए, ऐप्लिकेशन बनाने की प्रोसेस के दौरान Performance Monitoring को बंद करके, ये काम किए जा सकते हैं:
डीबग के लिए बिल्ड में, Performance Monitoring की कुछ सुविधाओं को बंद करें. जैसे, Performance Monitoring Gradle प्लग इन से मिलने वाली सुविधाएं. हालांकि, रिलीज़ के लिए तैयार बिल्ड के लिए, इन सुविधाओं को फिर से चालू करें.
ऐप्लिकेशन बनाते समय Performance Monitoring को बंद करें. हालांकि, रनटाइम के दौरान ऐप्लिकेशन को इसे फिर से चालू करने की अनुमति दें.
अपना ऐप्लिकेशन बनाते समय Performance Monitoring को बंद करें. साथ ही, अपने ऐप्लिकेशन को रनटाइम के दौरान इसे फिर से चालू करने की अनुमति न दें.
Performance Monitoring को चालू करके भी अपना ऐप्लिकेशन बनाया जा सकता है. हालांकि, अपने प्रोडक्शन ऐप्लिकेशन में Performance Monitoring को बंद करने और फिर से चालू करने की सुविधा पाने के लिए, Firebase Remote Config का इस्तेमाल करें. इस विकल्प की मदद से, अपने ऐप्लिकेशन को इस तरह कॉन्फ़िगर किया जा सकता है कि उपयोगकर्ता Performance Monitoring का इस्तेमाल करने के लिए ऑप्ट-इन या ऑप्ट-आउट कर सकें.
ऐप्लिकेशन बनाने की प्रोसेस के दौरान Performance Monitoring को बंद करना
बिल्ड प्रोसेस के दौरान Performance Monitoring को बंद किया जा सकता है. इसके लिए, Performance Monitoring Gradle प्लग इन को बंद करें और/या Performance Monitoring Android लाइब्रेरी को बंद करें.
डेवलपमेंट और डीबग करने के दौरान, प्लग इन को बंद करना फ़ायदेमंद होता है. इसकी वजह यह है कि प्लग इन की मदद से इंस्ट्रुमेंटेशन करने से, बिल्ड टाइम बढ़ सकता है. हालांकि, लाइब्रेरी को चालू रखा जा सकता है, ताकि आपको ऐप्लिकेशन के शुरू होने, फ़ोरग्राउंड में ऐप्लिकेशन, और बैकग्राउंड में ऐप्लिकेशन के ट्रेस के साथ-साथ, ऐप्लिकेशन में मौजूद किसी भी कस्टम कोड ट्रेस का परफ़ॉर्मेंस डेटा दिखता रहे.
Performance Monitoring Gradle प्लग इन को बंद करना
Performance Monitoring प्लग इन को बंद करने के लिए, इनमें से किसी विकल्प का इस्तेमाल करके instrumentationEnabled फ़्लैग जोड़ें:
Extension 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 फ़ाइल (आम तौर पर
<project>/<app-module>/build.gradle.ktsया<project>/<app-module>/build.gradle) केdependenciesसेक्शन में हो:Kotlin
implementation("com.google.firebase:firebase-config-ktx:24.0.0")Java
implementation("com.google.firebase:firebase-config:24.0.0")अगर
perf_disableकोtrueपर सेट किया गया है, तो Remote Config को सेट अप करें और 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 } } });
Remote Config वैल्यू को फ़ेच और चालू करने के लिए,
MainActivity.javaमें यह कोड जोड़ें:Kotlin
// 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 टूल को किए जाने वाले कॉल, "कोई कार्रवाई नहीं" कॉल (एनओओपी) बन जाएंगे. इससे आपके ऐप्लिकेशन में Performance Monitoring SDK टूल का इस्तेमाल करने पर, ऐप्लिकेशन की परफ़ॉर्मेंस पर कोई खास असर नहीं पड़ेगा.
अगर perf_disable की वैल्यू को
falseपर सेट किया जाता है, तो Performance Monitoring चालू रहता है.