From 075997f12e2fb2b646172a92926be0f26f739099 Mon Sep 17 00:00:00 2001 From: Jack Wang Date: Tue, 27 Oct 2009 22:01:09 -0700 Subject: PerformanceCollector: Collect & report perf measurements in key/value form - Added new functions to PerformanceCollector and PerformanceResultsWriter - Modified unit tests to test new functionality and fix flakiness reported in 2218327 and 2118268 - Added PerformanceCollectorTest to small suite --- .../android/test/InstrumentationTestRunner.java | 29 ++++++++++++++++------ 1 file changed, 22 insertions(+), 7 deletions(-) (limited to 'test-runner') diff --git a/test-runner/android/test/InstrumentationTestRunner.java b/test-runner/android/test/InstrumentationTestRunner.java index b9978d6..773d7a9 100644 --- a/test-runner/android/test/InstrumentationTestRunner.java +++ b/test-runner/android/test/InstrumentationTestRunner.java @@ -227,17 +227,22 @@ public class InstrumentationTestRunner extends Instrumentation implements TestSu */ private static final String REPORT_KEY_COVERAGE_PATH = "coverageFilePath"; /** + * If included at the start of reporting keys, this prefix marks the key as a performance + * metric. + */ + private static final String REPORT_KEY_PREFIX = "performance."; + /** * If included in the status or final bundle sent to an IInstrumentationWatcher, this key * reports the cpu time in milliseconds of the current test. */ private static final String REPORT_KEY_PERF_CPU_TIME = - "performance." + PerformanceCollector.METRIC_KEY_CPU_TIME; + REPORT_KEY_PREFIX + PerformanceCollector.METRIC_KEY_CPU_TIME; /** * If included in the status or final bundle sent to an IInstrumentationWatcher, this key * reports the run time in milliseconds of the current test. */ private static final String REPORT_KEY_PERF_EXECUTION_TIME = - "performance." + PerformanceCollector.METRIC_KEY_EXECUTION_TIME; + REPORT_KEY_PREFIX + PerformanceCollector.METRIC_KEY_EXECUTION_TIME; /** * The test is starting. @@ -739,11 +744,9 @@ public class InstrumentationTestRunner extends Instrumentation implements TestSu } public void writeEndSnapshot(Bundle results) { - // Copy all snapshot data fields as type long into mResults, which - // is outputted via Instrumentation.finish - for (String key : results.keySet()) { - mResults.putLong(key, results.getLong(key)); - } + // Copy all snapshot data fields into mResults, which is outputted + // via Instrumentation.finish + mResults.putAll(results); } public void writeStartTiming(String label) { @@ -768,6 +771,18 @@ public class InstrumentationTestRunner extends Instrumentation implements TestSu } } + public void writeMeasurement(String label, long value) { + mTestResult.putLong(REPORT_KEY_PREFIX + label, value); + } + + public void writeMeasurement(String label, float value) { + mTestResult.putFloat(REPORT_KEY_PREFIX + label, value); + } + + public void writeMeasurement(String label, String value) { + mTestResult.putString(REPORT_KEY_PREFIX + label, value); + } + // TODO report the end of the cycle } } -- cgit v1.1