Firebase प्रदर्शन मॉनिटर करना बंद करें


ऐप्लिकेशन डेवलपमेंट और टेस्टिंग के दौरान, 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 प्लग इन को बंद किया जा सकता है.

  1. अपनी रूट-लेवल (प्रोजेक्ट-लेवल) Gradle फ़ाइल (<project>/build.gradle.kts या <project>/build.gradle) में, पक्का करें कि Android Gradle प्लग इन की डिपेंडेंसी, v3.4.0 या इसके बाद के वर्शन के तौर पर बताई गई हो.

    Android Gradle प्लग इन के पुराने वर्शन के लिए, किसी खास बिल्ड वैरिएंट के लिए, Performance Monitoring प्लग इन को बंद किया जा सकता है. हालांकि, उस वैरिएंट के लिए बिल्ड में लगने वाला समय पूरी तरह से कम नहीं होगा.

  2. अपनी मॉड्यूल (ऐप्लिकेशन-लेवल) 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 का इस्तेमाल करना लेख पढ़ें.

  1. पक्का करें कि Remote Config आपके मॉड्यूल (ऐप्लिकेशन-लेवल) Gradle फ़ाइल (आम तौर पर <project>/<app-module>/build.gradle.kts या <project>/<app-module>/build.gradle) के dependencies सेक्शन में हो:

    Kotlin

      implementation("com.google.firebase:firebase-config-ktx:23.0.1")
    

    Java

      implementation("com.google.firebase:firebase-config:23.0.1")
    
  2. 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
                    }
                }
            });
  3. वैल्यू फ़ेच और चालू करने के लिए, MainActivity.java में यह कोड जोड़ें:Remote Config

    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
                    }
                }
            });
  4. Performance Monitoring को Firebase कंसोल में बंद करने के लिए, अपने ऐप्लिकेशन के प्रोजेक्ट में perf_disable पैरामीटर बनाएं. इसके बाद, इसकी वैल्यू true पर सेट करें.

    इस बदलाव से, Performance Monitoring एसडीके को किए जाने वाले कॉल, "कोई कार्रवाई नहीं" वाले कॉल (एनओओपी) बन जाएंगे. इससे, आपके ऐप्लिकेशन में Performance Monitoring एसडीके का इस्तेमाल करने से, ऐप्लिकेशन की परफ़ॉर्मेंस पर पड़ने वाले किसी भी बड़े असर को खत्म किया जा सकेगा.

    अगर perf_disable की वैल्यू false पर सेट की जाती है, तो Performance Monitoring की सुविधा चालू रहती है.