From 433770fa0bacc897b2b6f00771a3f46f0889cc2e Mon Sep 17 00:00:00 2001 From: Arthur Eubanks Date: Tue, 9 Jan 2018 15:48:53 -0800 Subject: [PATCH] Add ContentProvider perf tests Add a stub ContentProvider in ActivityManagerPerfTestsTestApp. Add two tests for Context.getContentResolver().acquireContentProviderClient(PKG_NAME), one when target package is running, one when it isn't. Test: m ActivityManagerPerfTestsTestApp ActivityManagerPerfTests Test: adb install \ $OUT/data/app/ActivityManagerPerfTestsTestApp/ActivityManagerPerfTestsTestApp.apk Test: adb install \ $OUT/data/app/ActivityManagerPerfTests/ActivityManagerPerfTests.apk Test: adb shell am instrument -w -e class \ com.android.frameworks.perftests.am.tests.ContentProviderPerfTest \ com.android.frameworks.perftests.amtests/android.support.test.runner.AndroidJUnitRunner BUG: 67460485 Change-Id: Ia979832436a0d3923f6569bc52d22f17bb612a0e --- .../test-app/AndroidManifest.xml | 10 ++- .../amteststestapp/TestContentProvider.java | 55 +++++++++++++++ .../am/tests/ContentProviderPerfTest.java | 70 +++++++++++++++++++ 3 files changed, 132 insertions(+), 3 deletions(-) create mode 100644 tests/ActivityManagerPerfTests/test-app/src/com/android/frameworks/perftests/amteststestapp/TestContentProvider.java create mode 100644 tests/ActivityManagerPerfTests/tests/src/com/android/frameworks/perftests/am/tests/ContentProviderPerfTest.java diff --git a/tests/ActivityManagerPerfTests/test-app/AndroidManifest.xml b/tests/ActivityManagerPerfTests/test-app/AndroidManifest.xml index 71451101ac591..021e3861d882e 100644 --- a/tests/ActivityManagerPerfTests/test-app/AndroidManifest.xml +++ b/tests/ActivityManagerPerfTests/test-app/AndroidManifest.xml @@ -14,12 +14,16 @@ limitations under the License. --> + package="com.android.frameworks.perftests.amteststestapp"> + + android:name=".TestBroadcastReceiver" + android:exported="true"> diff --git a/tests/ActivityManagerPerfTests/test-app/src/com/android/frameworks/perftests/amteststestapp/TestContentProvider.java b/tests/ActivityManagerPerfTests/test-app/src/com/android/frameworks/perftests/amteststestapp/TestContentProvider.java new file mode 100644 index 0000000000000..0940578e4b28c --- /dev/null +++ b/tests/ActivityManagerPerfTests/test-app/src/com/android/frameworks/perftests/amteststestapp/TestContentProvider.java @@ -0,0 +1,55 @@ +/* + * 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 com.android.frameworks.perftests.amteststestapp; + +import android.content.ContentProvider; +import android.content.ContentValues; +import android.database.Cursor; +import android.net.Uri; + +public class TestContentProvider extends ContentProvider { + @Override + public Uri insert(Uri uri, ContentValues values) { + return null; + } + + @Override + public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, + String sortOrder) { + return null; + } + + @Override + public String getType(Uri uri) { + return null; + } + + @Override + public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) { + return 0; + } + + @Override + public boolean onCreate() { + return false; + } + + @Override + public int delete(Uri uri, String selection, String[] selectionArgs) { + return 0; + } +} diff --git a/tests/ActivityManagerPerfTests/tests/src/com/android/frameworks/perftests/am/tests/ContentProviderPerfTest.java b/tests/ActivityManagerPerfTests/tests/src/com/android/frameworks/perftests/am/tests/ContentProviderPerfTest.java new file mode 100644 index 0000000000000..3bf56ce8b085c --- /dev/null +++ b/tests/ActivityManagerPerfTests/tests/src/com/android/frameworks/perftests/am/tests/ContentProviderPerfTest.java @@ -0,0 +1,70 @@ +/* + * 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 com.android.frameworks.perftests.am.tests; + +import android.content.ContentProviderClient; +import android.support.test.filters.LargeTest; +import android.support.test.runner.AndroidJUnit4; + +import com.android.frameworks.perftests.am.util.TargetPackageUtils; + +import org.junit.Test; +import org.junit.runner.RunWith; + +@RunWith(AndroidJUnit4.class) +@LargeTest +public class ContentProviderPerfTest extends BasePerfTest { + /** + * Benchmark time to call ContentResolver.acquireContentProviderClient() when target package is + * running. + */ + @Test + public void contentProviderRunning() { + runPerfFunction(() -> { + startTargetPackage(); + + long startTimeNs = System.nanoTime(); + final ContentProviderClient contentProviderClient = + mContext.getContentResolver() + .acquireContentProviderClient(TargetPackageUtils.PACKAGE_NAME); + final long endTimeNs = System.nanoTime(); + + contentProviderClient.close(); + + return endTimeNs - startTimeNs; + }); + } + + /** + * Benchmark time to call ContentResolver.acquireContentProviderClient() when target package is + * not running. + */ + @Test + public void contentProviderNotRunning() { + runPerfFunction(() -> { + final long startTimeNs = System.nanoTime(); + final ContentProviderClient contentProviderClient = + mContext.getContentResolver().acquireContentProviderClient( + TargetPackageUtils.PACKAGE_NAME); + final long endTimeNs = System.nanoTime(); + + contentProviderClient.close(); + + return endTimeNs - startTimeNs; + }); + } +}