Update MotionPredictorBenchmark.

* Use realistic durations and moving events to ensure the model is
  fully exercised.
* The requested prediction time is only a target, and it is valid for
  predictions to fall short of it.

com.android.perftests.core (2 Tests)
[1/2] android.input.MotionPredictorBenchmark#timeRecordAndPredict: PASSED (8.392s)
	perfetto_file_path: /sdcard/test_results/android.input.MotionPredictorBenchmark_timeRecordAndPredict/PerfettoListener/perfetto_android.input.MotionPredictorBenchmark_timeRecordAndPredict-1.perfetto-trace
	timeRecordAndPredict_mean (ns): 84059
	timeRecordAndPredict_median (ns): 82093
	timeRecordAndPredict_min (ns): 77361
	timeRecordAndPredict_standardDeviation: 5402
[2/2] android.input.MotionPredictorBenchmark#timeCreatePredictor: PASSED (7.650s)
	perfetto_file_path: /sdcard/test_results/android.input.MotionPredictorBenchmark_timeCreatePredictor/PerfettoListener/perfetto_android.input.MotionPredictorBenchmark_timeCreatePredictor-1.perfetto-trace
	timeCreatePredictor_mean (ns): 104809
	timeCreatePredictor_median (ns): 105000
	timeCreatePredictor_min (ns): 101148
	timeCreatePredictor_standardDeviation: 2837

Bug: 167946763
Test: atest MotionPredictorBenchmark
Change-Id: I2861a2f377a34eff6571a6ecdc4a34c46fcd753b
This commit is contained in:
Philip Quinn
2023-02-10 12:51:42 -08:00
parent e773b5b455
commit fb5f9b86bf

View File

@@ -34,6 +34,7 @@ import androidx.test.ext.junit.runners.AndroidJUnit4
import org.junit.After
import org.junit.Assert.assertEquals
import org.junit.Assert.assertTrue
import org.junit.Before
import org.junit.Rule
import org.junit.Test
@@ -89,7 +90,6 @@ class MotionPredictorBenchmark {
private val initialPropertyValue =
SystemProperties.get("persist.input.enable_motion_prediction")
private var eventTime = Duration.ofMillis(1)
@Before
fun setUp() {
@@ -109,22 +109,31 @@ class MotionPredictorBenchmark {
*/
@Test
fun timeRecordAndPredict() {
val offset = Duration.ofMillis(1)
val offset = Duration.ofMillis(20)
var eventTime = Duration.ofMillis(0)
val eventInterval = Duration.ofMillis(4) // 240 Hz
var eventPosition = 0f
val positionInterval = 10f
val predictor = MotionPredictor(getPredictionContext(offset, /*enablePrediction=*/true))
// ACTION_DOWN t=0 x=0 y=0
predictor.record(getStylusMotionEvent(eventTime, ACTION_DOWN, /*x=*/0f, /*y=*/0f))
predictor.record(getStylusMotionEvent(
eventTime, ACTION_DOWN, /*x=*/eventPosition, /*y=*/eventPosition))
val state = perfStatusReporter.getBenchmarkState()
while (state.keepRunning()) {
eventTime += Duration.ofMillis(1)
eventTime += eventInterval
eventPosition += positionInterval
// Send MOVE event and then call .predict
val moveEvent = getStylusMotionEvent(eventTime, ACTION_MOVE, /*x=*/1f, /*y=*/2f)
val moveEvent = getStylusMotionEvent(
eventTime, ACTION_MOVE, /*x=*/eventPosition, /*y=*/eventPosition)
predictor.record(moveEvent)
val predictionTime = eventTime + Duration.ofMillis(2)
val predictionTime = eventTime + eventInterval
val predicted = predictor.predict(predictionTime.toNanos())
assertEquals(1, predicted.size)
assertEquals((predictionTime + offset).toMillis(), predicted[0].eventTime)
assertTrue(predicted[0].eventTime <= (predictionTime + offset).toMillis())
}
}
@@ -135,7 +144,7 @@ class MotionPredictorBenchmark {
@Test
fun timeCreatePredictor() {
val context = getPredictionContext(
/*offset=*/Duration.ofMillis(1), /*enablePrediction=*/true)
/*offset=*/Duration.ofMillis(20), /*enablePrediction=*/true)
val state = perfStatusReporter.getBenchmarkState()
while (state.keepRunning()) {