Add getTextClassifier perf test

This helps us to evaluate the fix.

BUG: 129695635

Test: frameworks/base/apct-tests/perftests/textclassifier/run.sh

Change-Id: I7d2d019faecb3721c044a43e24d86d98a08be64b
This commit is contained in:
Tony Mak
2019-04-02 18:23:54 +01:00
parent 0454f3b8ae
commit 751afc9821
4 changed files with 87 additions and 6 deletions

View File

@@ -1,4 +1,8 @@
set -e
make TextClassifierPerfTests
make TextClassifierPerfTests perf-setup.sh
adb install ${OUT}/testcases/TextClassifierPerfTests/arm64/TextClassifierPerfTests.apk
adb shell cmd package compile -m speed -f com.android.perftests.textclassifier
adb shell am instrument -w -e class android.view.textclassifier.TextClassifierPerfTest com.android.perftests.textclassifier/androidx.test.runner.AndroidJUnitRunner
adb push ${OUT}/obj/EXECUTABLES/perf-setup.sh_intermediates/perf-setup.sh /data/local/tmp/
adb shell chmod +x /data/local/tmp/perf-setup.sh
adb shell /data/local/tmp/perf-setup.sh
adb shell am instrument -w -e package android.view.textclassifier com.android.perftests.textclassifier/androidx.test.runner.AndroidJUnitRunner

View File

@@ -0,0 +1,74 @@
/*
* Copyright (C) 2018 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package android.view.textclassifier;
import android.content.Context;
import android.perftests.utils.BenchmarkState;
import android.perftests.utils.PerfStatusReporter;
import android.perftests.utils.SettingsHelper;
import android.provider.Settings;
import androidx.test.InstrumentationRegistry;
import androidx.test.filters.LargeTest;
import org.junit.After;
import org.junit.Rule;
import org.junit.Test;
@LargeTest
public class TextClassificationManagerPerfTest {
@Rule
public PerfStatusReporter mPerfStatusReporter = new PerfStatusReporter();
@After
public void tearDown() {
SettingsHelper.delete(
SettingsHelper.NAMESPACE_GLOBAL, Settings.Global.TEXT_CLASSIFIER_CONSTANTS);
}
@Test
public void testGetTextClassifier_systemTextClassifierDisabled() {
Context context = InstrumentationRegistry.getTargetContext();
SettingsHelper.set(
SettingsHelper.NAMESPACE_GLOBAL,
Settings.Global.TEXT_CLASSIFIER_CONSTANTS,
"system_textclassifier_enabled=false");
TextClassificationManager textClassificationManager =
context.getSystemService(TextClassificationManager.class);
BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
while (state.keepRunning()) {
textClassificationManager.getTextClassifier();
textClassificationManager.invalidate();
}
}
@Test
public void testGetTextClassifier_systemTextClassifierEnabled() {
Context context = InstrumentationRegistry.getTargetContext();
SettingsHelper.set(
SettingsHelper.NAMESPACE_GLOBAL,
Settings.Global.TEXT_CLASSIFIER_CONSTANTS,
"system_textclassifier_enabled=true");
TextClassificationManager textClassificationManager =
context.getSystemService(TextClassificationManager.class);
BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
while (state.keepRunning()) {
textClassificationManager.getTextClassifier();
textClassificationManager.invalidate();
}
}
}

View File

@@ -18,19 +18,19 @@ package android.perftests.utils;
import android.content.Context;
import android.provider.Settings;
import android.text.TextUtils;
import java.util.Objects;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import java.util.Objects;
/**
* Provides utilities to interact with the device's {@link Settings}.
*/
public final class SettingsHelper {
public static final String NAMESPACE_SECURE = "secure";
public static final String NAMESPACE_GLOBAL = "global";
private static int DEFAULT_TIMEOUT_MS = 5000;

View File

@@ -30,6 +30,7 @@ import android.service.textclassifier.TextClassifierService;
import android.view.textclassifier.TextClassifier.TextClassifierType;
import com.android.internal.annotations.GuardedBy;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.util.IndentingPrintWriter;
import com.android.internal.util.Preconditions;
@@ -247,7 +248,9 @@ public final class TextClassificationManager {
&& TextClassifierService.getServiceComponentName(mContext) != null;
}
private void invalidate() {
/** @hide */
@VisibleForTesting
public void invalidate() {
synchronized (mLock) {
mSettings = null;
mLocalTextClassifier = null;