Merge branch 'eclair' into eclair-release
This commit is contained in:
@@ -96,6 +96,10 @@ public class SearchDialog extends Dialog implements OnItemClickListener, OnItemS
|
||||
|
||||
// The extra key used in an intent to the speech recognizer for in-app voice search.
|
||||
private static final String EXTRA_CALLING_PACKAGE = "calling_package";
|
||||
|
||||
// The string used for privateImeOptions to identify to the IME that it should not show
|
||||
// a microphone button since one already exists in the search dialog.
|
||||
private static final String IME_OPTION_NO_MICROPHONE = "nm";
|
||||
|
||||
private static final int SEARCH_PLATE_LEFT_PADDING_GLOBAL = 12;
|
||||
private static final int SEARCH_PLATE_LEFT_PADDING_NON_GLOBAL = 7;
|
||||
@@ -543,6 +547,14 @@ public class SearchDialog extends Dialog implements OnItemClickListener, OnItemS
|
||||
mSearchAutoComplete.setInputType(inputType);
|
||||
mSearchAutoCompleteImeOptions = mSearchable.getImeOptions();
|
||||
mSearchAutoComplete.setImeOptions(mSearchAutoCompleteImeOptions);
|
||||
|
||||
// If the search dialog is going to show a voice search button, then don't let
|
||||
// the soft keyboard display a microphone button if it would have otherwise.
|
||||
if (mSearchable.getVoiceSearchEnabled()) {
|
||||
mSearchAutoComplete.setPrivateImeOptions(IME_OPTION_NO_MICROPHONE);
|
||||
} else {
|
||||
mSearchAutoComplete.setPrivateImeOptions(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -107,6 +107,36 @@ public class PerformanceCollector {
|
||||
* @see PerformanceCollector#stopTiming(String)
|
||||
*/
|
||||
public void writeStopTiming(Bundle results);
|
||||
|
||||
/**
|
||||
* Callback invoked as last action in
|
||||
* {@link PerformanceCollector#addMeasurement(String, long)} for
|
||||
* reporting an integer type measurement.
|
||||
*
|
||||
* @param label short description of the metric that was measured
|
||||
* @param value long value of the measurement
|
||||
*/
|
||||
public void writeMeasurement(String label, long value);
|
||||
|
||||
/**
|
||||
* Callback invoked as last action in
|
||||
* {@link PerformanceCollector#addMeasurement(String, float)} for
|
||||
* reporting a float type measurement.
|
||||
*
|
||||
* @param label short description of the metric that was measured
|
||||
* @param value float value of the measurement
|
||||
*/
|
||||
public void writeMeasurement(String label, float value);
|
||||
|
||||
/**
|
||||
* Callback invoked as last action in
|
||||
* {@link PerformanceCollector#addMeasurement(String, String)} for
|
||||
* reporting a string field.
|
||||
*
|
||||
* @param label short description of the metric that was measured
|
||||
* @param value string summary of the measurement
|
||||
*/
|
||||
public void writeMeasurement(String label, String value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -385,6 +415,39 @@ public class PerformanceCollector {
|
||||
return mPerfMeasurement;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an integer type measurement to the collector.
|
||||
*
|
||||
* @param label short description of the metric that was measured
|
||||
* @param value long value of the measurement
|
||||
*/
|
||||
public void addMeasurement(String label, long value) {
|
||||
if (mPerfWriter != null)
|
||||
mPerfWriter.writeMeasurement(label, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a float type measurement to the collector.
|
||||
*
|
||||
* @param label short description of the metric that was measured
|
||||
* @param value float value of the measurement
|
||||
*/
|
||||
public void addMeasurement(String label, float value) {
|
||||
if (mPerfWriter != null)
|
||||
mPerfWriter.writeMeasurement(label, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a string field to the collector.
|
||||
*
|
||||
* @param label short description of the metric that was measured
|
||||
* @param value string summary of the measurement
|
||||
*/
|
||||
public void addMeasurement(String label, String value) {
|
||||
if (mPerfWriter != null)
|
||||
mPerfWriter.writeMeasurement(label, value);
|
||||
}
|
||||
|
||||
/*
|
||||
* Starts tracking memory usage, binder transactions, and real & cpu timing.
|
||||
*/
|
||||
|
||||
@@ -423,7 +423,8 @@ static bool copybit(GLint x, GLint y,
|
||||
COPYBIT_ENABLE : COPYBIT_DISABLE);
|
||||
clipRectRegion it(c);
|
||||
|
||||
LOGD("dst={%d, %d, %d, %p, %p}, "
|
||||
LOGD_IF(0,
|
||||
"dst={%d, %d, %d, %p, %p}, "
|
||||
"src={%d, %d, %d, %p, %p}, "
|
||||
"drect={%d,%d,%d,%d}, "
|
||||
"srect={%d,%d,%d,%d}, "
|
||||
|
||||
@@ -68,7 +68,7 @@ int main(int argc, char** argv)
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
||||
glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
||||
glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
|
||||
@@ -77,7 +77,9 @@ int main(int argc, char** argv)
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
glColor4f(1,1,1,1);
|
||||
|
||||
const uint16_t t16[64] = { 0xFFFF, 0xF800, 0x07E0, 0x001F };
|
||||
|
||||
// default pack-alignment is 4
|
||||
const uint16_t t16[64] = { 0xFFFF, 0, 0xF800, 0, 0x07E0, 0, 0x001F, 0 };
|
||||
|
||||
const GLfloat vertices[4][2] = {
|
||||
{ w/2, 0 },
|
||||
|
||||
@@ -211,13 +211,19 @@ class PowerManagerService extends IPowerManager.Stub
|
||||
private long mScreenOnStartTime;
|
||||
private boolean mPreventScreenOn;
|
||||
private int mScreenBrightnessOverride = -1;
|
||||
private boolean mHasHardwareAutoBrightness;
|
||||
private boolean mUseSoftwareAutoBrightness;
|
||||
private boolean mAutoBrightessEnabled;
|
||||
private int[] mAutoBrightnessLevels;
|
||||
private int[] mLcdBacklightValues;
|
||||
private int[] mButtonBacklightValues;
|
||||
private int[] mKeyboardBacklightValues;
|
||||
|
||||
/*
|
||||
* WARNING - DO NOT USE THE HARDWARE AUTO-BRIGHTNESS FEATURE
|
||||
* Hardware auto brightness support is deprecated and will be removed in the next release.
|
||||
*/
|
||||
private boolean mUseHardwareAutoBrightness;
|
||||
|
||||
// Used when logging number and duration of touch-down cycles
|
||||
private long mTotalTouchDownTime;
|
||||
private long mLastTouchDown;
|
||||
@@ -438,9 +444,22 @@ class PowerManagerService extends IPowerManager.Stub
|
||||
mScreenOffIntent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
|
||||
|
||||
Resources resources = mContext.getResources();
|
||||
mHasHardwareAutoBrightness = resources.getBoolean(
|
||||
|
||||
// read settings for auto-brightness
|
||||
mUseSoftwareAutoBrightness = resources.getBoolean(
|
||||
com.android.internal.R.bool.config_automatic_brightness_available);
|
||||
|
||||
/*
|
||||
* WARNING - DO NOT USE THE HARDWARE AUTO-BRIGHTNESS FEATURE
|
||||
* Hardware auto brightness support is deprecated and will be removed in the next release.
|
||||
*/
|
||||
mUseHardwareAutoBrightness = resources.getBoolean(
|
||||
com.android.internal.R.bool.config_hardware_automatic_brightness_available);
|
||||
if (!mHasHardwareAutoBrightness) {
|
||||
if (mUseHardwareAutoBrightness) {
|
||||
mUseSoftwareAutoBrightness = false;
|
||||
}
|
||||
|
||||
if (mUseSoftwareAutoBrightness) {
|
||||
mAutoBrightnessLevels = resources.getIntArray(
|
||||
com.android.internal.R.array.config_autoBrightnessLevels);
|
||||
mLcdBacklightValues = resources.getIntArray(
|
||||
@@ -479,7 +498,7 @@ class PowerManagerService extends IPowerManager.Stub
|
||||
// And explicitly do the initial update of our cached settings
|
||||
updateGservicesValues();
|
||||
|
||||
if (mAutoBrightessEnabled && !mHasHardwareAutoBrightness) {
|
||||
if (mUseSoftwareAutoBrightness) {
|
||||
// turn the screen on
|
||||
setPowerState(SCREEN_BRIGHT);
|
||||
} else {
|
||||
@@ -581,7 +600,7 @@ class PowerManagerService extends IPowerManager.Stub
|
||||
switch (wl.flags & LOCK_MASK)
|
||||
{
|
||||
case PowerManager.FULL_WAKE_LOCK:
|
||||
if (mAutoBrightessEnabled && !mHasHardwareAutoBrightness) {
|
||||
if (mUseSoftwareAutoBrightness) {
|
||||
wl.minState = SCREEN_BRIGHT;
|
||||
} else {
|
||||
wl.minState = (mKeyboardVisible ? ALL_BRIGHT : SCREEN_BUTTON_BRIGHT);
|
||||
@@ -887,7 +906,8 @@ class PowerManagerService extends IPowerManager.Stub
|
||||
pw.println(" mLightSensorEnabled=" + mLightSensorEnabled);
|
||||
pw.println(" mLightSensorValue=" + mLightSensorValue);
|
||||
pw.println(" mLightSensorPendingValue=" + mLightSensorPendingValue);
|
||||
pw.println(" mHasHardwareAutoBrightness=" + mHasHardwareAutoBrightness);
|
||||
pw.println(" mUseHardwareAutoBrightness=" + mUseHardwareAutoBrightness);
|
||||
pw.println(" mUseSoftwareAutoBrightness=" + mUseSoftwareAutoBrightness);
|
||||
pw.println(" mAutoBrightessEnabled=" + mAutoBrightessEnabled);
|
||||
mScreenBrightness.dump(pw, " mScreenBrightness: ");
|
||||
mKeyboardBrightness.dump(pw, " mKeyboardBrightness: ");
|
||||
@@ -1290,8 +1310,8 @@ class PowerManagerService extends IPowerManager.Stub
|
||||
|
||||
private int setScreenStateLocked(boolean on) {
|
||||
int err = Power.setScreenState(on);
|
||||
if (err == 0 && !mHasHardwareAutoBrightness) {
|
||||
enableLightSensor(on && mAutoBrightessEnabled);
|
||||
if (err == 0 && mUseSoftwareAutoBrightness) {
|
||||
enableLightSensor(on);
|
||||
if (!on) {
|
||||
// make sure button and key backlights are off too
|
||||
mHardware.setLightBrightness_UNCHECKED(HardwareService.LIGHT_ID_BUTTONS, 0);
|
||||
@@ -1337,7 +1357,7 @@ class PowerManagerService extends IPowerManager.Stub
|
||||
return;
|
||||
}
|
||||
|
||||
if (!mDoneBooting && !(mAutoBrightessEnabled && !mHasHardwareAutoBrightness)) {
|
||||
if (!mDoneBooting && !mUseSoftwareAutoBrightness) {
|
||||
newState |= ALL_BRIGHT;
|
||||
}
|
||||
|
||||
@@ -1758,7 +1778,7 @@ class PowerManagerService extends IPowerManager.Stub
|
||||
try {
|
||||
if (mScreenBrightnessOverride >= 0) {
|
||||
return mScreenBrightnessOverride;
|
||||
} else if (mLightSensorBrightness >= 0 && !mHasHardwareAutoBrightness) {
|
||||
} else if (mLightSensorBrightness >= 0 && mUseSoftwareAutoBrightness) {
|
||||
return mLightSensorBrightness;
|
||||
}
|
||||
final int brightness = Settings.System.getInt(mContext.getContentResolver(),
|
||||
@@ -1849,8 +1869,7 @@ class PowerManagerService extends IPowerManager.Stub
|
||||
if ((mUserActivityAllowed && !mProximitySensorActive) || force) {
|
||||
// Only turn on button backlights if a button was pressed
|
||||
// and auto brightness is disabled
|
||||
if (eventType == BUTTON_EVENT &&
|
||||
!(mAutoBrightessEnabled && !mHasHardwareAutoBrightness)) {
|
||||
if (eventType == BUTTON_EVENT && !mUseSoftwareAutoBrightness) {
|
||||
mUserState = (mKeyboardVisible ? ALL_BRIGHT : SCREEN_BUTTON_BRIGHT);
|
||||
} else {
|
||||
// don't clear button/keyboard backlights when the screen is touched.
|
||||
@@ -1908,14 +1927,17 @@ class PowerManagerService extends IPowerManager.Stub
|
||||
Log.d(TAG, "lightSensorChangedLocked " + value);
|
||||
}
|
||||
|
||||
if (mHasHardwareAutoBrightness) return;
|
||||
|
||||
if (mLightSensorValue != value) {
|
||||
mLightSensorValue = value;
|
||||
if ((mPowerState & BATTERY_LOW_BIT) == 0) {
|
||||
int lcdValue = getAutoBrightnessValue(value, mLcdBacklightValues);
|
||||
int buttonValue = getAutoBrightnessValue(value, mButtonBacklightValues);
|
||||
int keyboardValue = getAutoBrightnessValue(value, mKeyboardBacklightValues);
|
||||
int keyboardValue;
|
||||
if (mKeyboardVisible) {
|
||||
keyboardValue = getAutoBrightnessValue(value, mKeyboardBacklightValues);
|
||||
} else {
|
||||
keyboardValue = 0;
|
||||
}
|
||||
mLightSensorBrightness = lcdValue;
|
||||
|
||||
if (mDebugLightSensor) {
|
||||
@@ -1925,7 +1947,7 @@ class PowerManagerService extends IPowerManager.Stub
|
||||
}
|
||||
|
||||
boolean startAnimation = false;
|
||||
if (mScreenBrightnessOverride < 0) {
|
||||
if (mAutoBrightessEnabled && mScreenBrightnessOverride < 0) {
|
||||
if (ANIMATE_SCREEN_LIGHTS) {
|
||||
if (mScreenBrightness.setTargetLocked(lcdValue,
|
||||
AUTOBRIGHTNESS_ANIM_STEPS, INITIAL_SCREEN_BRIGHTNESS,
|
||||
@@ -2037,6 +2059,14 @@ class PowerManagerService extends IPowerManager.Stub
|
||||
// will take care of turning on due to a true change to the lid
|
||||
// switch and synchronized with the lock screen.
|
||||
if ((mPowerState & SCREEN_ON_BIT) != 0) {
|
||||
if (mUseSoftwareAutoBrightness) {
|
||||
// force recompute of backlight values
|
||||
if (mLightSensorValue >= 0) {
|
||||
int value = (int)mLightSensorValue;
|
||||
mLightSensorValue = -1;
|
||||
lightSensorChangedLocked(value);
|
||||
}
|
||||
}
|
||||
userActivity(SystemClock.uptimeMillis(), false, BUTTON_EVENT, true);
|
||||
}
|
||||
}
|
||||
@@ -2057,18 +2087,20 @@ class PowerManagerService extends IPowerManager.Stub
|
||||
boolean enabled = (mode == SCREEN_BRIGHTNESS_MODE_AUTOMATIC);
|
||||
if (mAutoBrightessEnabled != enabled) {
|
||||
mAutoBrightessEnabled = enabled;
|
||||
// reset computed brightness
|
||||
mLightSensorValue = -1;
|
||||
mLightSensorBrightness = -1;
|
||||
|
||||
if (mHasHardwareAutoBrightness) {
|
||||
if (mUseHardwareAutoBrightness) {
|
||||
// When setting auto-brightness, must reset the brightness afterwards
|
||||
mHardware.setAutoBrightness_UNCHECKED(enabled);
|
||||
if (screenIsOn()) {
|
||||
setBacklightBrightness((int)mScreenBrightness.curValue);
|
||||
}
|
||||
} else {
|
||||
enableLightSensor(screenIsOn() && enabled);
|
||||
} else if (mUseSoftwareAutoBrightness && screenIsOn()) {
|
||||
// force recompute of backlight values
|
||||
if (mLightSensorValue >= 0) {
|
||||
int value = (int)mLightSensorValue;
|
||||
mLightSensorValue = -1;
|
||||
lightSensorChangedLocked(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2222,9 +2254,9 @@ class PowerManagerService extends IPowerManager.Stub
|
||||
mSensorManager = new SensorManager(mHandlerThread.getLooper());
|
||||
mProximitySensor = mSensorManager.getDefaultSensor(Sensor.TYPE_PROXIMITY);
|
||||
// don't bother with the light sensor if auto brightness is handled in hardware
|
||||
if (!mHasHardwareAutoBrightness) {
|
||||
if (mUseSoftwareAutoBrightness) {
|
||||
mLightSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_LIGHT);
|
||||
enableLightSensor(mAutoBrightessEnabled);
|
||||
enableLightSensor(true);
|
||||
}
|
||||
|
||||
synchronized (mLocks) {
|
||||
@@ -2266,7 +2298,8 @@ class PowerManagerService extends IPowerManager.Stub
|
||||
// Don't let applications turn the screen all the way off
|
||||
brightness = Math.max(brightness, Power.BRIGHTNESS_DIM);
|
||||
mHardware.setLightBrightness_UNCHECKED(HardwareService.LIGHT_ID_BACKLIGHT, brightness);
|
||||
mHardware.setLightBrightness_UNCHECKED(HardwareService.LIGHT_ID_KEYBOARD, brightness);
|
||||
mHardware.setLightBrightness_UNCHECKED(HardwareService.LIGHT_ID_KEYBOARD,
|
||||
(mKeyboardVisible ? brightness : 0));
|
||||
mHardware.setLightBrightness_UNCHECKED(HardwareService.LIGHT_ID_BUTTONS, brightness);
|
||||
long identity = Binder.clearCallingIdentity();
|
||||
try {
|
||||
|
||||
@@ -226,18 +226,23 @@ public class InstrumentationTestRunner extends Instrumentation implements TestSu
|
||||
* identifies the path to the generated code coverage file.
|
||||
*/
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,8 +19,9 @@ package com.android.unit_tests.os;
|
||||
import android.os.Bundle;
|
||||
import android.os.Parcelable;
|
||||
import android.os.PerformanceCollector;
|
||||
import android.os.Process;
|
||||
import android.os.PerformanceCollector.PerformanceResultsWriter;
|
||||
import android.test.suitebuilder.annotation.LargeTest;
|
||||
import android.test.suitebuilder.annotation.SmallTest;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
@@ -44,6 +45,7 @@ public class PerformanceCollectorTest extends TestCase {
|
||||
mPerfCollector = null;
|
||||
}
|
||||
|
||||
@SmallTest
|
||||
public void testBeginSnapshotNoWriter() throws Exception {
|
||||
mPerfCollector.beginSnapshot("testBeginSnapshotNoWriter");
|
||||
|
||||
@@ -54,15 +56,16 @@ public class PerformanceCollectorTest extends TestCase {
|
||||
assertEquals(2, snapshot.size());
|
||||
}
|
||||
|
||||
@LargeTest
|
||||
@SmallTest
|
||||
public void testEndSnapshotNoWriter() throws Exception {
|
||||
mPerfCollector.beginSnapshot("testEndSnapshotNoWriter");
|
||||
sleepForRandomLongPeriod();
|
||||
workForRandomLongPeriod();
|
||||
Bundle snapshot = mPerfCollector.endSnapshot();
|
||||
|
||||
verifySnapshotBundle(snapshot);
|
||||
}
|
||||
|
||||
@SmallTest
|
||||
public void testStartTimingNoWriter() throws Exception {
|
||||
mPerfCollector.startTiming("testStartTimingNoWriter");
|
||||
|
||||
@@ -73,21 +76,23 @@ public class PerformanceCollectorTest extends TestCase {
|
||||
verifyTimingBundle(measurement, new ArrayList<String>());
|
||||
}
|
||||
|
||||
@SmallTest
|
||||
public void testAddIterationNoWriter() throws Exception {
|
||||
mPerfCollector.startTiming("testAddIterationNoWriter");
|
||||
sleepForRandomTinyPeriod();
|
||||
workForRandomTinyPeriod();
|
||||
Bundle iteration = mPerfCollector.addIteration("timing1");
|
||||
|
||||
verifyIterationBundle(iteration, "timing1");
|
||||
}
|
||||
|
||||
@SmallTest
|
||||
public void testStopTimingNoWriter() throws Exception {
|
||||
mPerfCollector.startTiming("testStopTimingNoWriter");
|
||||
sleepForRandomTinyPeriod();
|
||||
workForRandomTinyPeriod();
|
||||
mPerfCollector.addIteration("timing2");
|
||||
sleepForRandomTinyPeriod();
|
||||
workForRandomTinyPeriod();
|
||||
mPerfCollector.addIteration("timing3");
|
||||
sleepForRandomShortPeriod();
|
||||
workForRandomShortPeriod();
|
||||
Bundle timing = mPerfCollector.stopTiming("timing4");
|
||||
|
||||
ArrayList<String> labels = new ArrayList<String>();
|
||||
@@ -97,6 +102,7 @@ public class PerformanceCollectorTest extends TestCase {
|
||||
verifyTimingBundle(timing, labels);
|
||||
}
|
||||
|
||||
@SmallTest
|
||||
public void testBeginSnapshot() throws Exception {
|
||||
MockPerformanceResultsWriter writer = new MockPerformanceResultsWriter();
|
||||
mPerfCollector.setPerformanceResultsWriter(writer);
|
||||
@@ -110,19 +116,20 @@ public class PerformanceCollectorTest extends TestCase {
|
||||
assertEquals(2, snapshot.size());
|
||||
}
|
||||
|
||||
@LargeTest
|
||||
@SmallTest
|
||||
public void testEndSnapshot() throws Exception {
|
||||
MockPerformanceResultsWriter writer = new MockPerformanceResultsWriter();
|
||||
mPerfCollector.setPerformanceResultsWriter(writer);
|
||||
mPerfCollector.beginSnapshot("testEndSnapshot");
|
||||
sleepForRandomLongPeriod();
|
||||
workForRandomLongPeriod();
|
||||
Bundle snapshot1 = mPerfCollector.endSnapshot();
|
||||
Bundle snapshot2 = writer.snapshotResults;
|
||||
|
||||
assertTrue(snapshot1.equals(snapshot2));
|
||||
assertEqualsBundle(snapshot1, snapshot2);
|
||||
verifySnapshotBundle(snapshot1);
|
||||
}
|
||||
|
||||
@SmallTest
|
||||
public void testStartTiming() throws Exception {
|
||||
MockPerformanceResultsWriter writer = new MockPerformanceResultsWriter();
|
||||
mPerfCollector.setPerformanceResultsWriter(writer);
|
||||
@@ -136,21 +143,23 @@ public class PerformanceCollectorTest extends TestCase {
|
||||
verifyTimingBundle(measurement, new ArrayList<String>());
|
||||
}
|
||||
|
||||
@SmallTest
|
||||
public void testAddIteration() throws Exception {
|
||||
mPerfCollector.startTiming("testAddIteration");
|
||||
sleepForRandomTinyPeriod();
|
||||
workForRandomTinyPeriod();
|
||||
Bundle iteration = mPerfCollector.addIteration("timing5");
|
||||
|
||||
verifyIterationBundle(iteration, "timing5");
|
||||
}
|
||||
|
||||
@SmallTest
|
||||
public void testStopTiming() throws Exception {
|
||||
mPerfCollector.startTiming("testStopTiming");
|
||||
sleepForRandomTinyPeriod();
|
||||
workForRandomTinyPeriod();
|
||||
mPerfCollector.addIteration("timing6");
|
||||
sleepForRandomTinyPeriod();
|
||||
workForRandomTinyPeriod();
|
||||
mPerfCollector.addIteration("timing7");
|
||||
sleepForRandomShortPeriod();
|
||||
workForRandomShortPeriod();
|
||||
Bundle timing = mPerfCollector.stopTiming("timing8");
|
||||
|
||||
ArrayList<String> labels = new ArrayList<String>();
|
||||
@@ -160,28 +169,90 @@ public class PerformanceCollectorTest extends TestCase {
|
||||
verifyTimingBundle(timing, labels);
|
||||
}
|
||||
|
||||
// TODO: flaky test
|
||||
// @LargeTest
|
||||
@SmallTest
|
||||
public void testAddMeasurementLong() throws Exception {
|
||||
MockPerformanceResultsWriter writer = new MockPerformanceResultsWriter();
|
||||
mPerfCollector.setPerformanceResultsWriter(writer);
|
||||
mPerfCollector.startTiming("testAddMeasurementLong");
|
||||
mPerfCollector.addMeasurement("testAddMeasurementLongZero", 0);
|
||||
mPerfCollector.addMeasurement("testAddMeasurementLongPos", 348573);
|
||||
mPerfCollector.addMeasurement("testAddMeasurementLongNeg", -19354);
|
||||
mPerfCollector.stopTiming("");
|
||||
|
||||
assertEquals("testAddMeasurementLong", writer.timingLabel);
|
||||
Bundle results = writer.timingResults;
|
||||
assertEquals(4, results.size());
|
||||
assertTrue(results.containsKey("testAddMeasurementLongZero"));
|
||||
assertEquals(0, results.getLong("testAddMeasurementLongZero"));
|
||||
assertTrue(results.containsKey("testAddMeasurementLongPos"));
|
||||
assertEquals(348573, results.getLong("testAddMeasurementLongPos"));
|
||||
assertTrue(results.containsKey("testAddMeasurementLongNeg"));
|
||||
assertEquals(-19354, results.getLong("testAddMeasurementLongNeg"));
|
||||
}
|
||||
|
||||
@SmallTest
|
||||
public void testAddMeasurementFloat() throws Exception {
|
||||
MockPerformanceResultsWriter writer = new MockPerformanceResultsWriter();
|
||||
mPerfCollector.setPerformanceResultsWriter(writer);
|
||||
mPerfCollector.startTiming("testAddMeasurementFloat");
|
||||
mPerfCollector.addMeasurement("testAddMeasurementFloatZero", 0.0f);
|
||||
mPerfCollector.addMeasurement("testAddMeasurementFloatPos", 348573.345f);
|
||||
mPerfCollector.addMeasurement("testAddMeasurementFloatNeg", -19354.093f);
|
||||
mPerfCollector.stopTiming("");
|
||||
|
||||
assertEquals("testAddMeasurementFloat", writer.timingLabel);
|
||||
Bundle results = writer.timingResults;
|
||||
assertEquals(4, results.size());
|
||||
assertTrue(results.containsKey("testAddMeasurementFloatZero"));
|
||||
assertEquals(0.0f, results.getFloat("testAddMeasurementFloatZero"));
|
||||
assertTrue(results.containsKey("testAddMeasurementFloatPos"));
|
||||
assertEquals(348573.345f, results.getFloat("testAddMeasurementFloatPos"));
|
||||
assertTrue(results.containsKey("testAddMeasurementFloatNeg"));
|
||||
assertEquals(-19354.093f, results.getFloat("testAddMeasurementFloatNeg"));
|
||||
}
|
||||
|
||||
@SmallTest
|
||||
public void testAddMeasurementString() throws Exception {
|
||||
MockPerformanceResultsWriter writer = new MockPerformanceResultsWriter();
|
||||
mPerfCollector.setPerformanceResultsWriter(writer);
|
||||
mPerfCollector.startTiming("testAddMeasurementString");
|
||||
mPerfCollector.addMeasurement("testAddMeasurementStringNull", null);
|
||||
mPerfCollector.addMeasurement("testAddMeasurementStringEmpty", "");
|
||||
mPerfCollector.addMeasurement("testAddMeasurementStringNonEmpty", "Hello World");
|
||||
mPerfCollector.stopTiming("");
|
||||
|
||||
assertEquals("testAddMeasurementString", writer.timingLabel);
|
||||
Bundle results = writer.timingResults;
|
||||
assertEquals(4, results.size());
|
||||
assertTrue(results.containsKey("testAddMeasurementStringNull"));
|
||||
assertNull(results.getString("testAddMeasurementStringNull"));
|
||||
assertTrue(results.containsKey("testAddMeasurementStringEmpty"));
|
||||
assertEquals("", results.getString("testAddMeasurementStringEmpty"));
|
||||
assertTrue(results.containsKey("testAddMeasurementStringNonEmpty"));
|
||||
assertEquals("Hello World", results.getString("testAddMeasurementStringNonEmpty"));
|
||||
}
|
||||
|
||||
@SmallTest
|
||||
public void testSimpleSequence() throws Exception {
|
||||
MockPerformanceResultsWriter writer = new MockPerformanceResultsWriter();
|
||||
mPerfCollector.setPerformanceResultsWriter(writer);
|
||||
mPerfCollector.beginSnapshot("testSimpleSequence");
|
||||
mPerfCollector.startTiming("testSimpleSequenceTiming");
|
||||
sleepForRandomTinyPeriod();
|
||||
workForRandomTinyPeriod();
|
||||
mPerfCollector.addIteration("iteration1");
|
||||
sleepForRandomTinyPeriod();
|
||||
workForRandomTinyPeriod();
|
||||
mPerfCollector.addIteration("iteration2");
|
||||
sleepForRandomTinyPeriod();
|
||||
workForRandomTinyPeriod();
|
||||
mPerfCollector.addIteration("iteration3");
|
||||
sleepForRandomTinyPeriod();
|
||||
workForRandomTinyPeriod();
|
||||
mPerfCollector.addIteration("iteration4");
|
||||
sleepForRandomShortPeriod();
|
||||
workForRandomShortPeriod();
|
||||
Bundle timing = mPerfCollector.stopTiming("iteration5");
|
||||
sleepForRandomLongPeriod();
|
||||
workForRandomLongPeriod();
|
||||
Bundle snapshot1 = mPerfCollector.endSnapshot();
|
||||
Bundle snapshot2 = writer.snapshotResults;
|
||||
|
||||
assertTrue(snapshot1.equals(snapshot2));
|
||||
assertEqualsBundle(snapshot1, snapshot2);
|
||||
verifySnapshotBundle(snapshot1);
|
||||
|
||||
ArrayList<String> labels = new ArrayList<String>();
|
||||
@@ -193,60 +264,59 @@ public class PerformanceCollectorTest extends TestCase {
|
||||
verifyTimingBundle(timing, labels);
|
||||
}
|
||||
|
||||
// TODO: flaky test
|
||||
// @LargeTest
|
||||
@SmallTest
|
||||
public void testLongSequence() throws Exception {
|
||||
MockPerformanceResultsWriter writer = new MockPerformanceResultsWriter();
|
||||
mPerfCollector.setPerformanceResultsWriter(writer);
|
||||
mPerfCollector.beginSnapshot("testLongSequence");
|
||||
mPerfCollector.startTiming("testLongSequenceTiming1");
|
||||
sleepForRandomTinyPeriod();
|
||||
workForRandomTinyPeriod();
|
||||
mPerfCollector.addIteration("iteration1");
|
||||
sleepForRandomTinyPeriod();
|
||||
workForRandomTinyPeriod();
|
||||
mPerfCollector.addIteration("iteration2");
|
||||
sleepForRandomShortPeriod();
|
||||
workForRandomShortPeriod();
|
||||
Bundle timing1 = mPerfCollector.stopTiming("iteration3");
|
||||
sleepForRandomLongPeriod();
|
||||
workForRandomLongPeriod();
|
||||
|
||||
mPerfCollector.startTiming("testLongSequenceTiming2");
|
||||
sleepForRandomTinyPeriod();
|
||||
workForRandomTinyPeriod();
|
||||
mPerfCollector.addIteration("iteration4");
|
||||
sleepForRandomTinyPeriod();
|
||||
workForRandomTinyPeriod();
|
||||
mPerfCollector.addIteration("iteration5");
|
||||
sleepForRandomShortPeriod();
|
||||
workForRandomShortPeriod();
|
||||
Bundle timing2 = mPerfCollector.stopTiming("iteration6");
|
||||
sleepForRandomLongPeriod();
|
||||
workForRandomLongPeriod();
|
||||
|
||||
mPerfCollector.startTiming("testLongSequenceTiming3");
|
||||
sleepForRandomTinyPeriod();
|
||||
workForRandomTinyPeriod();
|
||||
mPerfCollector.addIteration("iteration7");
|
||||
sleepForRandomTinyPeriod();
|
||||
workForRandomTinyPeriod();
|
||||
mPerfCollector.addIteration("iteration8");
|
||||
sleepForRandomShortPeriod();
|
||||
workForRandomShortPeriod();
|
||||
Bundle timing3 = mPerfCollector.stopTiming("iteration9");
|
||||
sleepForRandomLongPeriod();
|
||||
workForRandomLongPeriod();
|
||||
|
||||
mPerfCollector.startTiming("testLongSequenceTiming4");
|
||||
sleepForRandomTinyPeriod();
|
||||
workForRandomTinyPeriod();
|
||||
mPerfCollector.addIteration("iteration10");
|
||||
sleepForRandomTinyPeriod();
|
||||
workForRandomTinyPeriod();
|
||||
mPerfCollector.addIteration("iteration11");
|
||||
sleepForRandomShortPeriod();
|
||||
workForRandomShortPeriod();
|
||||
Bundle timing4 = mPerfCollector.stopTiming("iteration12");
|
||||
sleepForRandomLongPeriod();
|
||||
workForRandomLongPeriod();
|
||||
|
||||
mPerfCollector.startTiming("testLongSequenceTiming5");
|
||||
sleepForRandomTinyPeriod();
|
||||
workForRandomTinyPeriod();
|
||||
mPerfCollector.addIteration("iteration13");
|
||||
sleepForRandomTinyPeriod();
|
||||
workForRandomTinyPeriod();
|
||||
mPerfCollector.addIteration("iteration14");
|
||||
sleepForRandomShortPeriod();
|
||||
workForRandomShortPeriod();
|
||||
Bundle timing5 = mPerfCollector.stopTiming("iteration15");
|
||||
sleepForRandomLongPeriod();
|
||||
workForRandomLongPeriod();
|
||||
Bundle snapshot1 = mPerfCollector.endSnapshot();
|
||||
Bundle snapshot2 = writer.snapshotResults;
|
||||
|
||||
assertTrue(snapshot1.equals(snapshot2));
|
||||
assertEqualsBundle(snapshot1, snapshot2);
|
||||
verifySnapshotBundle(snapshot1);
|
||||
|
||||
ArrayList<String> labels1 = new ArrayList<String>();
|
||||
@@ -280,57 +350,53 @@ public class PerformanceCollectorTest extends TestCase {
|
||||
* Verify that snapshotting and timing do not interfere w/ each other,
|
||||
* by staggering calls to snapshot and timing functions.
|
||||
*/
|
||||
@LargeTest
|
||||
@SmallTest
|
||||
public void testOutOfOrderSequence() {
|
||||
MockPerformanceResultsWriter writer = new MockPerformanceResultsWriter();
|
||||
mPerfCollector.setPerformanceResultsWriter(writer);
|
||||
mPerfCollector.startTiming("testOutOfOrderSequenceTiming");
|
||||
sleepForRandomShortPeriod();
|
||||
workForRandomShortPeriod();
|
||||
mPerfCollector.beginSnapshot("testOutOfOrderSequenceSnapshot");
|
||||
sleepForRandomShortPeriod();
|
||||
workForRandomShortPeriod();
|
||||
Bundle timing1 = mPerfCollector.stopTiming("timing1");
|
||||
sleepForRandomShortPeriod();
|
||||
workForRandomShortPeriod();
|
||||
Bundle snapshot1 = mPerfCollector.endSnapshot();
|
||||
|
||||
Bundle timing2 = writer.timingResults;
|
||||
Bundle snapshot2 = writer.snapshotResults;
|
||||
|
||||
assertTrue(snapshot1.equals(snapshot2));
|
||||
assertEqualsBundle(snapshot1, snapshot2);
|
||||
verifySnapshotBundle(snapshot1);
|
||||
|
||||
assertTrue(timing1.equals(timing2));
|
||||
assertEqualsBundle(timing1, timing2);
|
||||
ArrayList<String> labels = new ArrayList<String>();
|
||||
labels.add("timing1");
|
||||
verifyTimingBundle(timing1, labels);
|
||||
}
|
||||
|
||||
private void sleepForRandomPeriod(int minDuration, int maxDuration) {
|
||||
private void workForRandomPeriod(int minDuration, int maxDuration) {
|
||||
Random random = new Random();
|
||||
int period = minDuration + random.nextInt(maxDuration - minDuration);
|
||||
int slept = 0;
|
||||
// Generate random positive amount of work, so cpu time is measurable in
|
||||
long start = Process.getElapsedCpuTime();
|
||||
// Generate positive amount of work, so cpu time is measurable in
|
||||
// milliseconds
|
||||
while (slept < period) {
|
||||
int step = random.nextInt(minDuration/5);
|
||||
try {
|
||||
Thread.sleep(step);
|
||||
} catch (InterruptedException e ) {
|
||||
// eat the exception
|
||||
while (Process.getElapsedCpuTime() - start < period) {
|
||||
for (int i = 0, temp = 0; i < 50; i++ ) {
|
||||
temp += i;
|
||||
}
|
||||
slept += step;
|
||||
}
|
||||
}
|
||||
|
||||
private void sleepForRandomTinyPeriod() {
|
||||
sleepForRandomPeriod(25, 50);
|
||||
private void workForRandomTinyPeriod() {
|
||||
workForRandomPeriod(2, 5);
|
||||
}
|
||||
|
||||
private void sleepForRandomShortPeriod() {
|
||||
sleepForRandomPeriod(100, 250);
|
||||
private void workForRandomShortPeriod() {
|
||||
workForRandomPeriod(10, 25);
|
||||
}
|
||||
|
||||
private void sleepForRandomLongPeriod() {
|
||||
sleepForRandomPeriod(500, 1000);
|
||||
private void workForRandomLongPeriod() {
|
||||
workForRandomPeriod(50, 100);
|
||||
}
|
||||
|
||||
private void verifySnapshotBundle(Bundle snapshot) {
|
||||
@@ -411,6 +477,13 @@ public class PerformanceCollectorTest extends TestCase {
|
||||
}
|
||||
}
|
||||
|
||||
private void assertEqualsBundle(Bundle b1, Bundle b2) {
|
||||
assertEquals(b1.keySet(), b2.keySet());
|
||||
for (String key : b1.keySet()) {
|
||||
assertEquals(b1.get(key), b2.get(key));
|
||||
}
|
||||
}
|
||||
|
||||
private Object readPrivateField(String fieldName, Object object) throws Exception {
|
||||
Field f = object.getClass().getDeclaredField(fieldName);
|
||||
f.setAccessible(true);
|
||||
@@ -429,7 +502,7 @@ public class PerformanceCollectorTest extends TestCase {
|
||||
}
|
||||
|
||||
public void writeEndSnapshot(Bundle results) {
|
||||
snapshotResults = results;
|
||||
snapshotResults.putAll(results);
|
||||
}
|
||||
|
||||
public void writeStartTiming(String label) {
|
||||
@@ -437,7 +510,19 @@ public class PerformanceCollectorTest extends TestCase {
|
||||
}
|
||||
|
||||
public void writeStopTiming(Bundle results) {
|
||||
timingResults = results;
|
||||
timingResults.putAll(results);
|
||||
}
|
||||
|
||||
public void writeMeasurement(String label, long value) {
|
||||
timingResults.putLong(label, value);
|
||||
}
|
||||
|
||||
public void writeMeasurement(String label, float value) {
|
||||
timingResults.putFloat(label, value);
|
||||
}
|
||||
|
||||
public void writeMeasurement(String label, String value) {
|
||||
timingResults.putString(label, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user