diff options
author | gopinath <gelanchezhian@google.com> | 2018-03-15 19:24:38 -0700 |
---|---|---|
committer | Gopinath Elanchezhian <gelanchezhian@google.com> | 2018-03-16 19:08:09 +0000 |
commit | 63bf68d5c3eebe227fae099609eda2b470e20bf0 (patch) | |
tree | 9522b5d17a521309b2e3c06c0babc14b66721b9d /tests | |
parent | 6604af68c5606a64ec103c973e5dea43e52817a7 (diff) |
Add cycle-clean option in AppLaunch
If cycle-clean is enabled then all the apps will be
killed at the end of the cycle and cache will dropped.
Cycle time is also enabled to measure the sum of launch times
during each cycle.
Above two options will enable use to measure app launch time under
memeory pressue by not killing the app between the launches and
by killing all the apps and dropping the cache before each cycle
and measuring the cycle time.
Bug: b/73091210
Tested : Tested with nodropcache, no force stop between launches
and cycle clean option and the cycle time avg,min and max
is printed as expected.
Change-Id: I8fb22439a9fe191104ce024c8a85a2688068cd60
Diffstat (limited to 'tests')
-rw-r--r-- | tests/AppLaunch/src/com/android/tests/applaunch/AppLaunch.java | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/tests/AppLaunch/src/com/android/tests/applaunch/AppLaunch.java b/tests/AppLaunch/src/com/android/tests/applaunch/AppLaunch.java index f4b85b209e4f..dd56e0e41164 100644 --- a/tests/AppLaunch/src/com/android/tests/applaunch/AppLaunch.java +++ b/tests/AppLaunch/src/com/android/tests/applaunch/AppLaunch.java @@ -76,6 +76,7 @@ public class AppLaunch extends InstrumentationTestCase { private static final String KEY_DROP_CACHE = "drop_cache"; private static final String KEY_SIMPLEPERF_CMD = "simpleperf_cmd"; private static final String KEY_SIMPLEPERF_APP = "simpleperf_app"; + private static final String KEY_CYCLE_CLEAN = "cycle_clean"; private static final String KEY_TRACE_ITERATIONS = "trace_iterations"; private static final String KEY_LAUNCH_DIRECTORY = "launch_directory"; private static final String KEY_TRACE_DIRECTORY = "trace_directory"; @@ -137,6 +138,11 @@ public class AppLaunch extends InstrumentationTestCase { private BufferedWriter mBufferedWriter = null; private boolean mSimplePerfAppOnly = false; private String[] mCompilerFilters = null; + private String mLastAppName = ""; + private boolean mCycleCleanUp = false; + private boolean mIterationCycle = false; + private long mCycleTime = 0; + private StringBuilder mCycleTimes = new StringBuilder(); @Override protected void setUp() throws Exception { @@ -236,6 +242,7 @@ public class AppLaunch extends InstrumentationTestCase { // App launch times for trial launch will not be used for final // launch time calculations. if (launch.getLaunchReason().equals(TRIAL_LAUNCH)) { + mIterationCycle = false; // In the "applaunch.txt" file, trail launches is referenced using // "TRIAL_LAUNCH" String appPkgName = mNameToIntent.get(launch.getApp()) @@ -273,6 +280,7 @@ public class AppLaunch extends InstrumentationTestCase { // App launch times used for final calculation else if (launch.getLaunchReason().contains(LAUNCH_ITERATION_PREFIX)) { + mIterationCycle = true; AppLaunchResult launchResults = null; if (hasFailureOnFirstLaunch(launch)) { // skip if the app has failures while launched first @@ -286,6 +294,7 @@ public class AppLaunch extends InstrumentationTestCase { // if it fails once, skip the rest of the launches continue; } else { + mCycleTime += launchResults.mLaunchTime; addLaunchResult(launch, launchResults); } sleep(POST_LAUNCH_IDLE_TIMEOUT); @@ -294,6 +303,7 @@ public class AppLaunch extends InstrumentationTestCase { // App launch times for trace launch will not be used for final // launch time calculations. else if (launch.getLaunchReason().contains(TRACE_ITERATION_PREFIX)) { + mIterationCycle = false; AtraceLogger atraceLogger = AtraceLogger .getAtraceLoggerInstance(getInstrumentation()); // Start the trace @@ -314,6 +324,20 @@ public class AppLaunch extends InstrumentationTestCase { startHomeIntent(); } sleep(BETWEEN_LAUNCH_SLEEP_TIMEOUT); + + // If cycle clean up is enabled and last app launched is + // current app then the cycle is completed and eligible for + // cleanup. + if (LAUNCH_ORDER_CYCLIC.equalsIgnoreCase(mLaunchOrder) && mCycleCleanUp + && launch.getApp().equalsIgnoreCase(mLastAppName)) { + // Kill all the apps and drop all the cache + cleanUpAfterCycle(); + if (mIterationCycle) { + // Save the previous cycle time and reset the cycle time to 0 + mCycleTimes.append(String.format("%d,", mCycleTime)); + mCycleTime = 0; + } + } } } finally { if (null != mBufferedWriter) { @@ -321,6 +345,9 @@ public class AppLaunch extends InstrumentationTestCase { } } + if (mCycleTimes.length() != 0) { + mResult.putString("Cycle_Times", mCycleTimes.toString()); + } for (String app : mNameToResultKey.keySet()) { for (String compilerFilter : mCompilerFilters) { StringBuilder launchTimes = new StringBuilder(); @@ -453,6 +480,7 @@ public class AppLaunch extends InstrumentationTestCase { mNameToResultKey.put(parts[0], parts[1]); mNameToLaunchTime.put(parts[0], null); + mLastAppName = parts[0]; } String requiredAccounts = args.getString(KEY_REQUIRED_ACCOUNTS); if (requiredAccounts != null) { @@ -487,6 +515,7 @@ public class AppLaunch extends InstrumentationTestCase { mSimplePerfCmd = args.getString(KEY_SIMPLEPERF_CMD); mLaunchOrder = args.getString(KEY_LAUNCH_ORDER, LAUNCH_ORDER_CYCLIC); mSimplePerfAppOnly = Boolean.parseBoolean(args.getString(KEY_SIMPLEPERF_APP)); + mCycleCleanUp = Boolean.parseBoolean(args.getString(KEY_CYCLE_CLEAN)); mTrialLaunch = mTrialLaunch || Boolean.parseBoolean(args.getString(KEY_TRIAL_LAUNCH)); if (mSimplePerfCmd != null && mSimplePerfAppOnly) { @@ -597,6 +626,18 @@ public class AppLaunch extends InstrumentationTestCase { sleep(POST_LAUNCH_IDLE_TIMEOUT); } + private void cleanUpAfterCycle() { + // Kill all the apps + for (String appName : mNameToIntent.keySet()) { + Log.w(TAG, String.format("killing %s", appName)); + closeApp(appName); + } + // Drop all the cache. + assertNotNull("Issue in dropping the cache", + getInstrumentation().getUiAutomation() + .executeShellCommand(DROP_CACHE_SCRIPT)); + } + private void closeApp(String appName) { Intent startIntent = mNameToIntent.get(appName); if (startIntent != null) { |