Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FPS added to Android benchmark #2944

Merged
merged 7 commits into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,13 @@ import org.maplibre.android.camera.CameraUpdateFactory
import org.maplibre.android.geometry.LatLng
import org.maplibre.android.log.Logger
import org.maplibre.android.log.Logger.INFO
import org.maplibre.android.maps.*
import org.maplibre.android.maps.MapLibreMap
import org.maplibre.android.maps.MapLibreMap.CancelableCallback
import org.maplibre.android.maps.MapView
import org.maplibre.android.testapp.BuildConfig
import org.maplibre.android.testapp.R
import org.maplibre.android.testapp.utils.FpsStore
import org.maplibre.android.testapp.utils.BenchmarkResults
import org.maplibre.android.testapp.utils.FpsStore
import org.maplibre.android.testapp.utils.FrameTimeStore
import java.io.File

Expand Down Expand Up @@ -84,6 +85,7 @@ fun jsonPayload(styleNames: List<String>, fpsResults: BenchmarkResults, encoding
*/
class BenchmarkActivity : AppCompatActivity() {
private val TAG = "BenchmarkActivity"
private val RUNS = 5

private lateinit var mapView: MapView
private var handler: Handler? = null
Expand All @@ -94,8 +96,10 @@ class BenchmarkActivity : AppCompatActivity() {
private var fpsResults = BenchmarkResults()
private var encodingTimeResults = BenchmarkResults()
private var renderingTimeResults = BenchmarkResults()
private var runsLeft = 5
private var measureFrameTime = true
private var runsLeft = RUNS
private var syncRendering = true
private var startTime: Long = 0
private var numFrames = 0

// the styles used for the benchmark
// can be overridden adding with developer-config.xml
Expand Down Expand Up @@ -195,20 +199,18 @@ class BenchmarkActivity : AppCompatActivity() {

private fun setupMapView() {
mapView = findViewById<View>(R.id.mapView) as MapView
if (measureFrameTime) {
mapView.addOnDidFinishRenderingFrameListener { _: Boolean, frameEncodingTime: Double, frameRenderingTime: Double ->
encodingTimeStore.add(frameEncodingTime * 1e3)
renderingTimeStore.add(frameRenderingTime * 1e3)
}
mapView.addOnDidFinishRenderingFrameListener { _: Boolean, frameEncodingTime: Double, frameRenderingTime: Double ->
encodingTimeStore.add(frameEncodingTime * 1e3)
renderingTimeStore.add(frameRenderingTime * 1e3)
numFrames++;
louwers marked this conversation as resolved.
Show resolved Hide resolved
}
mapView.addOnDidFinishLoadingStyleListener {
numFrames = 0;
startTime = System.nanoTime();
}
mapView.getMapAsync { maplibreMap: MapLibreMap ->
maplibreMap.setStyle(inputData.styleURLs[0])
maplibreMap.setSwapBehaviorFlush(measureFrameTime)
if (!measureFrameTime) {
maplibreMap.setOnFpsChangedListener { fps: Double ->
fpsStore.add(fps)
}
}
maplibreMap.setSwapBehaviorFlush(syncRendering)

// Start an animation on the map as well
flyTo(maplibreMap, 0, 0,14.0)
Expand All @@ -232,39 +234,57 @@ class BenchmarkActivity : AppCompatActivity() {

override fun onFinish() {
if (place == PLACES.size - 1) { // done with tour
if (measureFrameTime) {
encodingTimeResults.addResult(
inputData.styleNames[style],
encodingTimeStore
)
encodingTimeStore.reset()

println("Encoding time results $encodingTimeResults")

renderingTimeResults.addResult(
inputData.styleNames[style],
renderingTimeStore
)
renderingTimeStore.reset()

println("Rendering time results $renderingTimeResults")
} else {
fpsResults.addResult(inputData.styleNames[style], fpsStore)
fpsStore.reset()
val endTime = System.nanoTime();
val fps = (numFrames * 1E9) / (endTime - startTime);
fpsStore.add(fps)

fpsResults.addResult(inputData.styleNames[style], fpsStore)
fpsStore.reset()

println("FPS results $fpsResults")

encodingTimeResults.addResult(
inputData.styleNames[style],
encodingTimeStore
)
encodingTimeStore.reset()

println("Encoding time results $encodingTimeResults")

renderingTimeResults.addResult(
inputData.styleNames[style],
renderingTimeStore
)
renderingTimeStore.reset()

println("Rendering time results $renderingTimeResults")

println("FPS results $fpsResults")
}
println("Benchmark ${jsonPayload(inputData.styleNames, fpsResults, encodingTimeResults, renderingTimeResults)}")

if (style < inputData.styleURLs.size - 1) { // continue with next style
maplibreMap.setStyle(inputData.styleURLs[style + 1])
flyTo(maplibreMap, 0, style + 1, zoom)
} else if (runsLeft > 0) { // start over
--runsLeft
} else if (--runsLeft > 0) { // start over
maplibreMap.setStyle(inputData.styleURLs[0])
flyTo(maplibreMap, 0, 0, zoom)
} else {
benchmarkDone()
if (syncRendering) {
storeResults()

fpsResults.clear()
encodingTimeResults.clear()
renderingTimeResults.clear()
runsLeft = RUNS

syncRendering = false
maplibreMap.setSwapBehaviorFlush(syncRendering)

maplibreMap.setStyle(inputData.styleURLs[0])
flyTo(maplibreMap, 0, 0, zoom)
} else {
storeResults()
benchmarkDone()
}
}
return
}
Expand Down Expand Up @@ -318,12 +338,11 @@ class BenchmarkActivity : AppCompatActivity() {
val payload = jsonPayload(inputData.styleNames, fpsResults, encodingTimeResults, renderingTimeResults)

val dataDir = this.filesDir
val benchmarkResultsFile = File(dataDir, "benchmark_results.json")
val benchmarkResultsFile = File(dataDir, if (syncRendering) "benchmark_results_sync_rendering.json" else "benchmark_results_async_rendering.json")
benchmarkResultsFile.writeText(Json.encodeToString(payload))
}

private fun benchmarkDone() {
storeResults()
setResult(Activity.RESULT_OK)
finish()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,8 @@ data class BenchmarkResults(
)
resultsPerStyle[styleName] = newResults
}

fun clear() {
resultsPerStyle.clear()
}
}
Loading