Preload font before TypefaceSerializationPerfTest.

This CL disables lazy font loading by preloading font in setUp(),
in order to stabilize testSerializeFontMap() results.

In testSerializeFontMap(), the first serializeFontMap() takes 20x time
due to lazy font loading (first call 40ms / avg 2ms on oriole).
This makes test results unstable by reducing the number of iterations.

ManualBenchmarkState calculates the number of iterations
('mMaxIterations') as follows:
    mMaxIterations = (int) (mTargetTestDurationNs / (warmupDuration / iterations));
where 'iterations' is the number of iterations done in warmup stage.
If the first iteration in warmup stage takes unusually long,
'iterations' becomes small and mMaxIterations will be smaller as well.

Bug: 239758440
Test: atest CorePerfTests:android.graphics.perftests.TypefaceSerializationPerfTest#testSerializeFontMap
Change-Id: I3181962a1807cb7b4ecbc8e26fe629b9f530e1c1
This commit is contained in:
Kohsuke Yatoh
2022-08-10 01:58:17 +00:00
parent 29705980bc
commit 23f1be2d5d

View File

@@ -28,6 +28,7 @@ import android.util.Log;
import androidx.test.filters.LargeTest;
import androidx.test.runner.AndroidJUnit4;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -50,6 +51,14 @@ public class TypefaceSerializationPerfTest {
@Rule
public PerfManualStatusReporter mPerfManualStatusReporter = new PerfManualStatusReporter();
@Before
public void setUp() {
// Parse and load the preinstalled fonts in the test process so that:
// (1) Updated fonts do not affect test results.
// (2) Lazy-loading of fonts does not affect test results (esp. testSerializeFontMap).
Typeface.loadPreinstalledSystemFontMap();
}
@ManualBenchmarkState.ManualBenchmarkTest(
warmupDurationNs = WARMUP_DURATION_NS,
targetTestDurationNs = TARGET_TEST_DURATION_NS)
@@ -61,8 +70,12 @@ public class TypefaceSerializationPerfTest {
long elapsedTime = 0;
while (state.keepRunning(elapsedTime)) {
long startTime = System.nanoTime();
Typeface.serializeFontMap(systemFontMap);
SharedMemory sharedMemory = Typeface.serializeFontMap(systemFontMap);
elapsedTime = System.nanoTime() - startTime;
sharedMemory.close();
android.util.Log.i(TAG,
"testSerializeFontMap isWarmingUp=" + state.isWarmingUp()
+ " elapsedTime=" + elapsedTime);
}
}