From cb46a8c0f187e09c92a0008640562d3a44d280d6 Mon Sep 17 00:00:00 2001 From: Adrian Cojocaru Date: Wed, 27 Nov 2024 13:04:23 +0200 Subject: [PATCH 1/2] Add thermal status to benchmark results --- .../activity/benchmark/BenchmarkActivity.kt | 17 ++++++++++++++++- .../android/testapp/utils/BenchmarkUtils.kt | 4 +++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/platform/android/MapLibreAndroidTestApp/src/main/java/org/maplibre/android/testapp/activity/benchmark/BenchmarkActivity.kt b/platform/android/MapLibreAndroidTestApp/src/main/java/org/maplibre/android/testapp/activity/benchmark/BenchmarkActivity.kt index 9682789cb8b..42e291d3175 100644 --- a/platform/android/MapLibreAndroidTestApp/src/main/java/org/maplibre/android/testapp/activity/benchmark/BenchmarkActivity.kt +++ b/platform/android/MapLibreAndroidTestApp/src/main/java/org/maplibre/android/testapp/activity/benchmark/BenchmarkActivity.kt @@ -2,10 +2,12 @@ package org.maplibre.android.testapp.activity.benchmark import android.annotation.SuppressLint import android.app.Activity +import android.content.Context import android.os.Build import android.os.Bundle import android.os.Environment import android.os.Handler +import android.os.PowerManager import android.view.View import android.view.WindowManager import androidx.appcompat.app.AppCompatActivity @@ -189,6 +191,13 @@ class BenchmarkActivity : AppCompatActivity() { } private fun setupMapView() { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { + val powerManager = getSystemService(Context.POWER_SERVICE) as PowerManager + powerManager.addThermalStatusListener { + status -> println("Thermal status changed $status") + } + } + mapView = findViewById(R.id.mapView) as MapView mapView.getMapAsync { maplibreMap: MapLibreMap -> val benchmarkResult = BenchmarkResult(arrayListOf()) @@ -254,7 +263,13 @@ class BenchmarkActivity : AppCompatActivity() { mapView.removeOnDidFinishRenderingFrameListener(listener) - return BenchmarkRunResult(fps, encodingTimeStore, renderingTimeStore) + var thermalStatus = -1; + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { + val powerManager = getSystemService(Context.POWER_SERVICE) as PowerManager + thermalStatus = powerManager.currentThermalStatus + } + + return BenchmarkRunResult(fps, encodingTimeStore, renderingTimeStore, thermalStatus) } override fun onStart() { diff --git a/platform/android/MapLibreAndroidTestApp/src/main/java/org/maplibre/android/testapp/utils/BenchmarkUtils.kt b/platform/android/MapLibreAndroidTestApp/src/main/java/org/maplibre/android/testapp/utils/BenchmarkUtils.kt index f49a1d014d1..6f07bf49e80 100644 --- a/platform/android/MapLibreAndroidTestApp/src/main/java/org/maplibre/android/testapp/utils/BenchmarkUtils.kt +++ b/platform/android/MapLibreAndroidTestApp/src/main/java/org/maplibre/android/testapp/utils/BenchmarkUtils.kt @@ -31,7 +31,8 @@ data class BenchmarkRun( data class BenchmarkRunResult( val fps: Double, val encodingTimeStore: FrameTimeStore, - val renderingTimeStore: FrameTimeStore + val renderingTimeStore: FrameTimeStore, + val thermalState: Int ) data class BenchmarkResult ( @@ -46,6 +47,7 @@ fun jsonPayload(benchmarkResult: BenchmarkResult): JsonObject { addJsonObject { put("styleName", JsonPrimitive(run.first.styleName)) put("syncRendering", JsonPrimitive(run.first.syncRendering)) + put("thermalState", JsonPrimitive(run.second.thermalState)) put("fps", JsonPrimitive(run.second.fps)) put("avgEncodingTime", JsonPrimitive(run.second.encodingTimeStore.average())) put("avgRenderingTime", JsonPrimitive(run.second.renderingTimeStore.average())) From 8ce7679d6e4fee90c17547133dc5e3bb8fe0adc7 Mon Sep 17 00:00:00 2001 From: Adrian Cojocaru Date: Wed, 27 Nov 2024 14:24:25 +0200 Subject: [PATCH 2/2] Add getThermalStatus() --- .../activity/benchmark/BenchmarkActivity.kt | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/platform/android/MapLibreAndroidTestApp/src/main/java/org/maplibre/android/testapp/activity/benchmark/BenchmarkActivity.kt b/platform/android/MapLibreAndroidTestApp/src/main/java/org/maplibre/android/testapp/activity/benchmark/BenchmarkActivity.kt index 42e291d3175..2f30dacf724 100644 --- a/platform/android/MapLibreAndroidTestApp/src/main/java/org/maplibre/android/testapp/activity/benchmark/BenchmarkActivity.kt +++ b/platform/android/MapLibreAndroidTestApp/src/main/java/org/maplibre/android/testapp/activity/benchmark/BenchmarkActivity.kt @@ -190,6 +190,15 @@ class BenchmarkActivity : AppCompatActivity() { } } + private fun getThermalStatus(): Int { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { + val powerManager = getSystemService(Context.POWER_SERVICE) as PowerManager + return powerManager.currentThermalStatus + } + + return -1; + } + private fun setupMapView() { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { val powerManager = getSystemService(Context.POWER_SERVICE) as PowerManager @@ -263,13 +272,7 @@ class BenchmarkActivity : AppCompatActivity() { mapView.removeOnDidFinishRenderingFrameListener(listener) - var thermalStatus = -1; - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { - val powerManager = getSystemService(Context.POWER_SERVICE) as PowerManager - thermalStatus = powerManager.currentThermalStatus - } - - return BenchmarkRunResult(fps, encodingTimeStore, renderingTimeStore, thermalStatus) + return BenchmarkRunResult(fps, encodingTimeStore, renderingTimeStore, getThermalStatus()) } override fun onStart() {