Firebase পারফর্ম্যান্স মনিটরিং বন্ধ করুন


অ্যাপ ডেভেলপমেন্ট ও টেস্টিংয়ের সময়, আপনি হয়ত 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 প্লাগ-ইন বন্ধ করুন

আপনি নিম্নলিখিত বিকল্প ব্যবহার করে instrumentationEnabled ফ্ল্যাগ যোগ করার মাধ্যমে Performance Monitoring প্লাগ-ইন বন্ধ করতে পারবেন:

এক্সটেনশন প্রপার্টি ফ্ল্যাগের মাধ্যমে প্লাগ-ইন বন্ধ করুন

Extensions Property ফ্ল্যাগ ব্যবহার করে, আপনি কম্পাইল করার সময় নির্দিষ্ট বিল্ড ভেরিয়েন্টের জন্য 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. আপনার মডিউল (অ্যাপ-লেভেল) Gradle ফাইলের (সাধারণত <project>/<app-module>/build.gradle.kts বা <project>/<app-module>/build.gradle) dependencies বিভাগে Remote Config আছে কিনা তা নিশ্চিত করুন:

    Kotlin

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

    Java

      implementation("com.google.firebase:firebase-config:24.0.0")
    
  2. 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
                    }
                }
            });
  3. 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
                    }
                }
            });
  4. Firebase কনসোলে Performance Monitoring বন্ধ করতে, আপনার অ্যাপের প্রোজেক্টে একটি perf_disable প্যারামিটার তৈরি করুন, তারপর এর ভ্যালু true হিসেবে সেট করুন।

    এই পরিবর্তনের ফলে Performance Monitoring SDK-তে করা কল "কোনও অপারেশন নয়" কল (NOOPs) হিসেবে বিবেচিত হবে, যার ফলে আপনার অ্যাপে Performance Monitoring SDK ব্যবহার করার কারণে অ্যাপের পারফর্ম্যান্সে কোনও উল্লেখযোগ্য প্রভাব পড়বে না।

    আপনি perf_disable-এর ভ্যালু false-এ সেট করলে, Performance Monitoring চালু থাকে।