From c8ccab6840ded90b57094a43a79eef8e04d7d97e Mon Sep 17 00:00:00 2001 From: Tony Mak Date: Wed, 12 Dec 2018 18:46:38 +0800 Subject: Add performance test for suggestConversationActions and detectLanguage This is the framework used by other system component like autofill. We will use this to answer system health question. We can also monitor the metric in this dashboard once it is submitted. https://blackbox.googleplex.com/#/custom/fw_other Result in pixel2 eng build (unit: nano second) (We will have more accurate result in the dashboard, we are advised not to run perf test in eng build) android.textclassifier.TextClassifierPerfTest:INSTRUMENTATION_STATUS: detectLanguage[size=0]_mean=15010771 INSTRUMENTATION_STATUS: detectLanguage[size=0]_median=15203514 INSTRUMENTATION_STATUS: detectLanguage[size=0]_min=10497747 INSTRUMENTATION_STATUS: detectLanguage[size=0]_standardDeviation=3061947 INSTRUMENTATION_STATUS_CODE: -1 .INSTRUMENTATION_STATUS: suggestConversationActions[size=0]_mean=39863316 INSTRUMENTATION_STATUS: suggestConversationActions[size=0]_median=41535711 INSTRUMENTATION_STATUS: suggestConversationActions[size=0]_min=35979326 INSTRUMENTATION_STATUS: suggestConversationActions[size=0]_standardDeviation=3297779 INSTRUMENTATION_STATUS_CODE: -1 .INSTRUMENTATION_STATUS: detectLanguage[size=10]_mean=14711781 INSTRUMENTATION_STATUS: detectLanguage[size=10]_median=13608035 INSTRUMENTATION_STATUS: detectLanguage[size=10]_min=12184472 INSTRUMENTATION_STATUS: detectLanguage[size=10]_standardDeviation=3144018 INSTRUMENTATION_STATUS_CODE: -1 .INSTRUMENTATION_STATUS: suggestConversationActions[size=10]_mean=43076381 INSTRUMENTATION_STATUS: suggestConversationActions[size=10]_median=43618067 INSTRUMENTATION_STATUS: suggestConversationActions[size=10]_min=38747603 INSTRUMENTATION_STATUS: suggestConversationActions[size=10]_standardDeviation=3502977 INSTRUMENTATION_STATUS_CODE: -1 .INSTRUMENTATION_STATUS: detectLanguage[size=100]_mean=20646733 INSTRUMENTATION_STATUS: detectLanguage[size=100]_median=20766674 INSTRUMENTATION_STATUS: detectLanguage[size=100]_min=19184218 INSTRUMENTATION_STATUS: detectLanguage[size=100]_standardDeviation=892559 INSTRUMENTATION_STATUS_CODE: -1 .INSTRUMENTATION_STATUS: suggestConversationActions[size=100]_mean=42126088 INSTRUMENTATION_STATUS: suggestConversationActions[size=100]_median=43709436 INSTRUMENTATION_STATUS: suggestConversationActions[size=100]_min=36636031 INSTRUMENTATION_STATUS: suggestConversationActions[size=100]_standardDeviation=4863678 INSTRUMENTATION_STATUS_CODE: -1 .INSTRUMENTATION_STATUS: detectLanguage[size=1,000]_mean=21721753 INSTRUMENTATION_STATUS: detectLanguage[size=1,000]_median=22690096 INSTRUMENTATION_STATUS: detectLanguage[size=1,000]_min=16252464 INSTRUMENTATION_STATUS: detectLanguage[size=1,000]_standardDeviation=3445673 INSTRUMENTATION_STATUS_CODE: -1 .INSTRUMENTATION_STATUS: suggestConversationActions[size=1,000]_mean=45968389 INSTRUMENTATION_STATUS: suggestConversationActions[size=1,000]_median=47465009 INSTRUMENTATION_STATUS: suggestConversationActions[size=1,000]_min=39389483 INSTRUMENTATION_STATUS: suggestConversationActions[size=1,000]_standardDeviation=3820288 INSTRUMENTATION_STATUS_CODE: -1 Test: Run commands below mmma -j ./frameworks/base/apct-tests/perftests/core/; adb install -r $OUT/data/app/CorePerfTests/CorePerfTests.apk; adb shell am instrument -w -e class android.textclassifier.TextClassifierPerfTest com.android.perftests.core/android.support.test.runner.AndroidJUnitRunner adb shell cmd package compile -m speed -f com.android.perftests.core; Change-Id: Ia2c746f48ed018269a230422a695caca05844a12 --- .../textclassifier/TextClassifierPerfTest.java | 113 +++++++++++++++++++++ 1 file changed, 113 insertions(+) create mode 100644 apct-tests/perftests/core/src/android/textclassifier/TextClassifierPerfTest.java diff --git a/apct-tests/perftests/core/src/android/textclassifier/TextClassifierPerfTest.java b/apct-tests/perftests/core/src/android/textclassifier/TextClassifierPerfTest.java new file mode 100644 index 000000000000..a482c4a6c2f7 --- /dev/null +++ b/apct-tests/perftests/core/src/android/textclassifier/TextClassifierPerfTest.java @@ -0,0 +1,113 @@ +/* + * 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.textclassifier; + +import android.content.Context; +import android.perftests.utils.BenchmarkState; +import android.perftests.utils.PerfStatusReporter; +import android.support.test.InstrumentationRegistry; +import android.support.test.filters.LargeTest; +import android.view.textclassifier.ConversationActions; +import android.view.textclassifier.TextClassificationManager; +import android.view.textclassifier.TextClassifier; +import android.view.textclassifier.TextLanguage; + +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; + +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.Random; + +@RunWith(Parameterized.class) +@LargeTest +public class TextClassifierPerfTest { + /** Request contains meaning text, rather than garbled text. */ + private static final int ACTUAL_REQUEST = 0; + private static final String RANDOM_CHAR_SET = "abcdefghijklmnopqrstuvwxyz0123456789"; + + @Rule + public PerfStatusReporter mPerfStatusReporter = new PerfStatusReporter(); + + @Parameterized.Parameters(name = "size={0}") + public static Collection data() { + return Arrays.asList(new Object[][]{{ACTUAL_REQUEST}, {10}, {100}, {1000}}); + } + + private TextClassifier mTextClassifier; + private final int mSize; + + public TextClassifierPerfTest(int size) { + mSize = size; + } + + @Before + public void setUp() { + Context context = InstrumentationRegistry.getTargetContext(); + TextClassificationManager textClassificationManager = + context.getSystemService(TextClassificationManager.class); + mTextClassifier = textClassificationManager.getTextClassifier(); + } + + @Test + public void testSuggestConversationActions() { + String text = mSize == ACTUAL_REQUEST ? "Where are you?" : generateRandomString(mSize); + ConversationActions.Request request = createConversationActionsRequest(text); + BenchmarkState state = mPerfStatusReporter.getBenchmarkState(); + while (state.keepRunning()) { + mTextClassifier.suggestConversationActions(request); + } + } + + @Test + public void testDetectLanguage() { + String text = mSize == ACTUAL_REQUEST + ? "これは日本語のテキストです" : generateRandomString(mSize); + TextLanguage.Request request = createTextLanguageRequest(text); + BenchmarkState state = mPerfStatusReporter.getBenchmarkState(); + while (state.keepRunning()) { + mTextClassifier.detectLanguage(request); + } + } + + private static ConversationActions.Request createConversationActionsRequest(CharSequence text) { + ConversationActions.Message message = + new ConversationActions.Message.Builder( + ConversationActions.Message.PERSON_USER_REMOTE) + .setText(text) + .build(); + return new ConversationActions.Request.Builder(Collections.singletonList(message)) + .build(); + } + + private static TextLanguage.Request createTextLanguageRequest(CharSequence text) { + return new TextLanguage.Request.Builder(text).build(); + } + + private static String generateRandomString(int length) { + Random random = new Random(); + StringBuilder stringBuilder = new StringBuilder(length); + for (int i = 0; i < length; i++) { + int index = random.nextInt(RANDOM_CHAR_SET.length()); + stringBuilder.append(RANDOM_CHAR_SET.charAt(index)); + } + return stringBuilder.toString(); + } +} -- cgit v1.2.3-59-g8ed1b