ऐप्लिकेशन डेवलपमेंट और टेस्टिंग के दौरान, बंद करना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
फ़्लैग जोड़ा जा सकता है:
एक्सटेंशन प्रॉपर्टी — कंपाइल टाइम पर, किसी खास बिल्ड वैरिएंट के लिए प्लग इन को बंद करती है
प्रोजेक्ट प्रॉपर्टी — कंपाइल टाइम पर, सभी बिल्ड वैरिएंट के लिए प्लग इन को बंद करती है
एक्सटेंशन प्रॉपर्टी फ़्लैग की मदद से प्लग इन को बंद करना
एक्सटेंशन प्रॉपर्टी फ़्लैग का इस्तेमाल करके, कंपाइल टाइम पर, किसी खास बिल्ड वैरिएंट के लिए, 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:23.1.0")Java
implementation("com.google.firebase:firebase-config:23.1.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 } } });
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 } } });
Performance Monitoring को Firebase कंसोल में बंद करने के लिए, अपने ऐप्लिकेशन के प्रोजेक्ट में perf_disable पैरामीटर बनाएं. इसके बाद, इसकी वैल्यू
trueपर सेट करें.इस बदलाव से, Performance Monitoring एसडीके टूल के कॉल, "कोई कार्रवाई नहीं" वाले कॉल (एनओओपी) बन जाएंगे. इससे, आपके ऐप्लिकेशन में Performance Monitoring एसडीके टूल का इस्तेमाल करने से, ऐप्लिकेशन की परफ़ॉर्मेंस पर कोई खास असर नहीं पड़ेगा.
अगर perf_disable की वैल्यू
falseपर सेट की जाती है, तो Performance Monitoring चालू रहती है.