From 9b9d5e3d82b09f44fc7e902d9feeca0a3053b088 Mon Sep 17 00:00:00 2001 From: Inderpal Singh Aulakh <73618019+iaulakh@users.noreply.github.com> Date: Fri, 11 Feb 2022 13:44:14 -0800 Subject: [PATCH] [Feature] fps diagnostics (#55) --- .../CallLauncherActivity.kt | 30 ++++++++++----- .../diagnostics/FpsDiagnostics.kt | 37 +++++++++++++++++++ .../res/layout/activity_call_launcher.xml | 6 +-- .../src/main/res/values-night/themes.xml | 5 +++ .../src/main/res/values/features.xml | 8 ++++ .../src/main/res/values/strings.xml | 7 +++- .../src/main/res/values/themes.xml | 5 +++ 7 files changed, 85 insertions(+), 13 deletions(-) create mode 100644 azure-communication-ui/azure-communication-ui-demo-app/src/main/java/com/azure/android/communication/ui/callingcompositedemoapp/diagnostics/FpsDiagnostics.kt create mode 100644 azure-communication-ui/azure-communication-ui-demo-app/src/main/res/values/features.xml diff --git a/azure-communication-ui/azure-communication-ui-demo-app/src/main/java/com/azure/android/communication/ui/callingcompositedemoapp/CallLauncherActivity.kt b/azure-communication-ui/azure-communication-ui-demo-app/src/main/java/com/azure/android/communication/ui/callingcompositedemoapp/CallLauncherActivity.kt index d2701044b..861496e0f 100644 --- a/azure-communication-ui/azure-communication-ui-demo-app/src/main/java/com/azure/android/communication/ui/callingcompositedemoapp/CallLauncherActivity.kt +++ b/azure-communication-ui/azure-communication-ui-demo-app/src/main/java/com/azure/android/communication/ui/callingcompositedemoapp/CallLauncherActivity.kt @@ -11,6 +11,7 @@ import androidx.activity.viewModels import androidx.appcompat.app.AlertDialog import androidx.appcompat.app.AppCompatActivity import com.azure.android.communication.ui.callingcompositedemoapp.databinding.ActivityCallLauncherBinding +import com.azure.android.communication.ui.callingcompositedemoapp.diagnostics.FpsDiagnostics import com.azure.android.communication.ui.callingcompositedemoapp.diagnostics.MemoryViewer import com.azure.android.communication.ui.callingcompositedemoapp.launcher.CallingCompositeLauncher import java.util.UUID @@ -113,12 +114,19 @@ class CallLauncherActivity : AppCompatActivity() { } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { - memoryDiagnosticsCheckBox.visibility = View.VISIBLE - memoryDiagnosticsCheckBox.setOnCheckedChangeListener { _, isChecked -> - if (isChecked) { - MemoryViewer.getMemoryViewer(application).show() - } else { - MemoryViewer.getMemoryViewer(application).hide() + val diagnostics = + applicationContext.resources.getBoolean(R.bool.diagnostics) + + if (diagnostics) { + diagnosticsCheckBox.visibility = View.VISIBLE + diagnosticsCheckBox.setOnCheckedChangeListener { _, isChecked -> + if (isChecked) { + MemoryViewer.getMemoryViewer(application).show() + FpsDiagnostics.getFpsDiagnostics(application).start() + } else { + MemoryViewer.getMemoryViewer(application).hide() + FpsDiagnostics.getFpsDiagnostics(application).stop() + } } } } @@ -148,9 +156,10 @@ class CallLauncherActivity : AppCompatActivity() { override fun onResume() { super.onResume() - // helps to turn on memory profiling when permissions change - if (binding.memoryDiagnosticsCheckBox.isChecked) { + // helps to turn on memory, fps profiling when permissions change + if (binding.diagnosticsCheckBox.isChecked) { MemoryViewer.getMemoryViewer(application).show() + FpsDiagnostics.getFpsDiagnostics(application).start() } } @@ -216,7 +225,10 @@ class CallLauncherActivity : AppCompatActivity() { } private fun saveState(outState: Bundle?) { - outState?.putBoolean(isTokenFunctionOptionSelected, callLauncherViewModel.isTokenFunctionOptionSelected) + outState?.putBoolean( + isTokenFunctionOptionSelected, + callLauncherViewModel.isTokenFunctionOptionSelected + ) outState?.putBoolean(isKotlinLauncherOptionSelected, callLauncherViewModel.isKotlinLauncher) } } diff --git a/azure-communication-ui/azure-communication-ui-demo-app/src/main/java/com/azure/android/communication/ui/callingcompositedemoapp/diagnostics/FpsDiagnostics.kt b/azure-communication-ui/azure-communication-ui-demo-app/src/main/java/com/azure/android/communication/ui/callingcompositedemoapp/diagnostics/FpsDiagnostics.kt new file mode 100644 index 000000000..fbe7dc1f6 --- /dev/null +++ b/azure-communication-ui/azure-communication-ui-demo-app/src/main/java/com/azure/android/communication/ui/callingcompositedemoapp/diagnostics/FpsDiagnostics.kt @@ -0,0 +1,37 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +package com.azure.android.communication.ui.callingcompositedemoapp.diagnostics + +import android.app.Application +import com.microsoft.office.outlook.magnifierlib.Magnifier +import com.microsoft.office.outlook.magnifierlib.frame.FPSMonitorConfig + +class FpsDiagnostics private constructor( + private val context: Application, +) { + + companion object { + private lateinit var fpsDiagnostics: FpsDiagnostics + fun getFpsDiagnostics(context: Application): FpsDiagnostics { + if (!::fpsDiagnostics.isInitialized) { + fpsDiagnostics = FpsDiagnostics(context) + } + return fpsDiagnostics + } + } + + fun start() { + Magnifier.startMonitorFPS( + FPSMonitorConfig.Builder(context) + .lowPercentage(40 / 60f) // show red tips, (2.0f / 3.0f) by default + .mediumPercentage(50 / 60f) // show yellow tips, (5.0f / 6.0f) by default + .refreshRate(60f) // defaultDisplay.refreshRate by default + .build() + ) + } + + fun stop() { + Magnifier.stopMonitorFPS() + } +} diff --git a/azure-communication-ui/azure-communication-ui-demo-app/src/main/res/layout/activity_call_launcher.xml b/azure-communication-ui/azure-communication-ui-demo-app/src/main/res/layout/activity_call_launcher.xml index 9ce18dd65..a1f0023c3 100644 --- a/azure-communication-ui/azure-communication-ui-demo-app/src/main/res/layout/activity_call_launcher.xml +++ b/azure-communication-ui/azure-communication-ui-demo-app/src/main/res/layout/activity_call_launcher.xml @@ -138,9 +138,9 @@ diff --git a/azure-communication-ui/azure-communication-ui-demo-app/src/main/res/values-night/themes.xml b/azure-communication-ui/azure-communication-ui-demo-app/src/main/res/values-night/themes.xml index 6ad3bc0f2..3f5b9b2bd 100644 --- a/azure-communication-ui/azure-communication-ui-demo-app/src/main/res/values-night/themes.xml +++ b/azure-communication-ui/azure-communication-ui-demo-app/src/main/res/values-night/themes.xml @@ -1,3 +1,8 @@ + +