Performance measurement framework:
+ For bug 1810508
- Added PerformanceCollector class to collect runtime and memory usage data
* Moved performance snapshotting from Intrumentation to PerformanceCollector
- Added PerformanceResultsWriter interface which defines functions for
reporting performance data
+ Framework integration
- Added TimedTest annotation to automatically time tests and write results
to instrumentation output
- Modified PerformanceTestBase to add collection hooks and wrapper methods
- Modified WatcherResultPrinter in InstrumentationTestRunner to implement
PerformanceResultsWriter for instrumentation output of performance data
- Modified InstrumentationTestRunner and AndroidTestRunner to pass writer
instance to test
diff --git a/test-runner/android/test/AndroidTestRunner.java b/test-runner/android/test/AndroidTestRunner.java
index 358b7e9..0f1599a 100644
--- a/test-runner/android/test/AndroidTestRunner.java
+++ b/test-runner/android/test/AndroidTestRunner.java
@@ -18,6 +18,8 @@
import android.app.Instrumentation;
import android.content.Context;
+import android.os.PerformanceCollector.PerformanceResultsWriter;
+
import com.google.android.collect.Lists;
import junit.framework.Test;
import junit.framework.TestCase;
@@ -39,6 +41,7 @@
private List<TestListener> mTestListeners = Lists.newArrayList();
private Instrumentation mInstrumentation;
+ private PerformanceResultsWriter mPerfWriter;
@SuppressWarnings("unchecked")
public void setTestClassName(String testClassName, String testMethodName) {
@@ -162,6 +165,7 @@
for (TestCase testCase : mTestCases) {
setContextIfAndroidTestCase(testCase, mContext, testContext);
setInstrumentationIfInstrumentationTestCase(testCase, mInstrumentation);
+ setPerformanceWriterIfPerformanceTestCase(testCase, mPerfWriter);
testCase.run(mTestResult);
}
}
@@ -184,6 +188,13 @@
}
}
+ private void setPerformanceWriterIfPerformanceTestCase(
+ Test test, PerformanceResultsWriter writer) {
+ if (PerformanceTestBase.class.isAssignableFrom(test.getClass())) {
+ ((PerformanceTestBase) test).setPerformanceResultsWriter(writer);
+ }
+ }
+
public void setInstrumentation(Instrumentation instrumentation) {
mInstrumentation = instrumentation;
}
@@ -197,6 +208,13 @@
setInstrumentation(instrumentation);
}
+ /**
+ * {@hide} Pending approval for public API.
+ */
+ public void setPerformanceResultsWriter(PerformanceResultsWriter writer) {
+ mPerfWriter = writer;
+ }
+
@Override
protected Class loadSuiteClass(String suiteClassName) throws ClassNotFoundException {
return mContext.getClassLoader().loadClass(suiteClassName);