Merge "Benchmark fix." into tm-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
05ada2e0bf
@@ -17,10 +17,12 @@
|
|||||||
package android.content.pm;
|
package android.content.pm;
|
||||||
|
|
||||||
import android.Manifest;
|
import android.Manifest;
|
||||||
|
import android.app.UiAutomation;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.IntentSender;
|
import android.content.IntentSender;
|
||||||
import android.os.HandlerThread;
|
import android.os.HandlerThread;
|
||||||
|
import android.os.ParcelFileDescriptor;
|
||||||
import android.perftests.utils.BenchmarkState;
|
import android.perftests.utils.BenchmarkState;
|
||||||
import android.perftests.utils.PerfStatusReporter;
|
import android.perftests.utils.PerfStatusReporter;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
@@ -39,7 +41,10 @@ import org.junit.Before;
|
|||||||
import org.junit.Rule;
|
import org.junit.Rule;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.OutputStream;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.CountDownLatch;
|
import java.util.concurrent.CountDownLatch;
|
||||||
@@ -203,13 +208,33 @@ public class PackageInstallerBenchmark {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void uninstallSession(BenchmarkState state, String...packageNames)
|
private void uninstallSession(BenchmarkState state, String...packageNames)
|
||||||
throws InterruptedException {
|
throws Exception {
|
||||||
state.pauseTiming();
|
state.pauseTiming();
|
||||||
uninstall(true /* stop at fail */, packageNames);
|
uninstall(true /* stop at fail */, packageNames);
|
||||||
mPackageInstaller.unregisterSessionCallback(mSessionCallback);
|
mPackageInstaller.unregisterSessionCallback(mSessionCallback);
|
||||||
|
executeShellCommand("pm gc");
|
||||||
state.resumeTiming();
|
state.resumeTiming();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static String executeShellCommand(String command) throws IOException {
|
||||||
|
UiAutomation uiAutomation = InstrumentationRegistry.getInstrumentation().getUiAutomation();
|
||||||
|
final ParcelFileDescriptor stdout = uiAutomation.executeShellCommand(command);
|
||||||
|
try (InputStream inputStream = new ParcelFileDescriptor.AutoCloseInputStream(stdout);
|
||||||
|
ByteArrayOutputStream result = new ByteArrayOutputStream()) {
|
||||||
|
writeFullStream(inputStream, result);
|
||||||
|
return result.toString("UTF-8");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void writeFullStream(InputStream inputStream, OutputStream outputStream)
|
||||||
|
throws IOException {
|
||||||
|
final byte[] buffer = new byte[1024];
|
||||||
|
int length;
|
||||||
|
while ((length = inputStream.read(buffer)) != -1) {
|
||||||
|
outputStream.write(buffer, 0, length);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test(timeout = 600_000L)
|
@Test(timeout = 600_000L)
|
||||||
public void commit_aSingleApkSession_untilFinishBenchmark() throws Exception {
|
public void commit_aSingleApkSession_untilFinishBenchmark() throws Exception {
|
||||||
uninstall(false /* stop at fail */, TestApp.A);
|
uninstall(false /* stop at fail */, TestApp.A);
|
||||||
@@ -247,8 +272,7 @@ public class PackageInstallerBenchmark {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test(timeout = 600_000L)
|
@Test(timeout = 600_000L)
|
||||||
public void commit_aMultiplePackagesSession_untilFinishBenchmark()
|
public void commit_aMultiplePackagesSession_untilFinishBenchmark() throws Exception {
|
||||||
throws IOException, InterruptedException {
|
|
||||||
uninstall(false /* stop at fail */, TestApp.A, TestApp.B, TestApp.C);
|
uninstall(false /* stop at fail */, TestApp.A, TestApp.B, TestApp.C);
|
||||||
|
|
||||||
final BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
|
final BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
|
||||||
@@ -269,8 +293,7 @@ public class PackageInstallerBenchmark {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test(timeout = 600_000L)
|
@Test(timeout = 600_000L)
|
||||||
public void commit_threeMultiplePackageSessions_untilFinishBenchmark()
|
public void commit_threeMultiplePackageSessions_untilFinishBenchmark() throws Exception {
|
||||||
throws Exception {
|
|
||||||
uninstall(false /* stop at fail */, TestApp.A, TestApp.B, TestApp.C);
|
uninstall(false /* stop at fail */, TestApp.A, TestApp.B, TestApp.C);
|
||||||
|
|
||||||
final BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
|
final BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
|
||||||
@@ -293,8 +316,7 @@ public class PackageInstallerBenchmark {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test(timeout = 600_000L)
|
@Test(timeout = 600_000L)
|
||||||
public void commit_aMultipleApksSession_untilFinishBenchmark()
|
public void commit_aMultipleApksSession_untilFinishBenchmark() throws Exception {
|
||||||
throws IOException, InterruptedException {
|
|
||||||
uninstall(false /* stop at fail */, TestApp.A);
|
uninstall(false /* stop at fail */, TestApp.A);
|
||||||
|
|
||||||
final BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
|
final BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
|
||||||
|
|||||||
@@ -188,6 +188,8 @@ class PackageManagerShellCommand extends ShellCommand {
|
|||||||
return runDump();
|
return runDump();
|
||||||
case "list":
|
case "list":
|
||||||
return runList();
|
return runList();
|
||||||
|
case "gc":
|
||||||
|
return runGc();
|
||||||
case "resolve-activity":
|
case "resolve-activity":
|
||||||
return runResolveActivity();
|
return runResolveActivity();
|
||||||
case "query-activities":
|
case "query-activities":
|
||||||
@@ -687,6 +689,13 @@ class PackageManagerShellCommand extends ShellCommand {
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private int runGc() throws RemoteException {
|
||||||
|
Runtime.getRuntime().gc();
|
||||||
|
final PrintWriter pw = getOutPrintWriter();
|
||||||
|
pw.println("Ok");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
private int runListFeatures() throws RemoteException {
|
private int runListFeatures() throws RemoteException {
|
||||||
final PrintWriter pw = getOutPrintWriter();
|
final PrintWriter pw = getOutPrintWriter();
|
||||||
final List<FeatureInfo> list = mInterface.getSystemAvailableFeatures().getList();
|
final List<FeatureInfo> list = mInterface.getSystemAvailableFeatures().getList();
|
||||||
|
|||||||
Reference in New Issue
Block a user