blob: 1040ed169c5b067a4dbc8191c0d1676b9033de68 [file] [log] [blame]
Arthur Eubanks263d6742017-12-18 13:46:59 -08001ActivityManagerPerfTests
2
3Performance tests for various ActivityManager components, e.g. Services, Broadcasts
Arthur Eubanks2dd67792018-02-07 15:55:10 -08004* These are only for tests that don't require a target package to test against
5* Self-contained perf tests should go in frameworks/base/apct-tests/perftests
Arthur Eubanks263d6742017-12-18 13:46:59 -08006
Arthur Eubanks2dd67792018-02-07 15:55:10 -08007Command to run tests
8* atest .../frameworks/base/tests/ActivityManagerPerfTests/tests/
9 * Command currently not working: b/71859981
Arthur Eubanks263d6742017-12-18 13:46:59 -080010* m ActivityManagerPerfTests ActivityManagerPerfTestsTestApp && \
Arthur Eubanks2dd67792018-02-07 15:55:10 -080011 adb install "$OUT"/data/app/ActivityManagerPerfTests/ActivityManagerPerfTests.apk && \
12 adb install "$OUT"/data/app/ActivityManagerPerfTestsTestApp/ActivityManagerPerfTestsTestApp.apk && \
Arthur Eubanks263d6742017-12-18 13:46:59 -080013 adb shell am instrument -w \
14 com.android.frameworks.perftests.amtests/android.support.test.runner.AndroidJUnitRunner
15
16Overview
17* The numbers we are trying to measure are end-to-end numbers
18 * For example, the time it takes from sending an Intent to start a Service
19 to the time the Service runs its callbacks
20* System.nanoTime() is monotonic and consistent between processes, so we use that for measuring time
Arthur Eubanks263d6742017-12-18 13:46:59 -080021* If the test app is involved, it will measure the time and send it back to the instrumentation test
Arthur Eubanks2dd67792018-02-07 15:55:10 -080022 * The time is sent back through a Binder interface in the Intent with the help of Utils.sendTime()
Arthur Eubanks263d6742017-12-18 13:46:59 -080023 * Each sent time is tagged with an id since there can be multiple events that send back a time
Arthur Eubanks2dd67792018-02-07 15:55:10 -080024* Each test will run multiple times to account for variation in test runs
Arthur Eubanks263d6742017-12-18 13:46:59 -080025
26Structure
27* tests
28 * Instrumentation test which runs the various performance tests and reports the results
Arthur Eubanks263d6742017-12-18 13:46:59 -080029* test-app
30 * Target package which contains the Services, BroadcastReceivers, etc. to test against
31 * Sends the time it measures back to the test package
Arthur Eubanks263d6742017-12-18 13:46:59 -080032* utils
33 * Utilities that both the instrumentation test and test app can use
Arthur Eubanks2dd67792018-02-07 15:55:10 -080034
35Adding tests
36* Example
37 * Look at tests/src/com/android/frameworks/perftests/am/BroadcastPerfTest and
38 test-app/src/com/android/frameworks/perftests/amteststestapp/TestBroadcastReceiver
39 for simple examples using this framework
40* Steps
41 * Add any components you will test against in the target package under
42 test-app/src/com/android/frameworks/perftests/amteststestapp/
43 * Add the test class under tests/src/com/android/frameworks/perftests/am/tests/
44 * The class should extend BasePerfTest
45 * Each test should call runPerfFunction() returning the elapsed time for a single iteration
46 * The test has access to a Context through mContext
47 * If you are measuring the time elapsed of something that either starts or ends in the target
48 package
49 * The target package can report the time it measures through an ITimeReceiverCallback passed
50 through an Intent through Utils.sendTime(intent, "tag")
51 (or however a Binder needs to be passed to the target package)
52 * The instrumentation test can collect that time by calling getReceivedTimeNs("tag") and
53 calculate the elapsed time
54 * Each timestamp sent to the instrumentation test is tagged with a tag since multiple timestamps
55 can be reported in an iteration
56 * If the target package should be running before your test logic starts, add startTargetPackage();
57 at the beginning of the iteration
58* Reporting
59 * Look at go/am-perf for how to add new tests to dashboards and receive notification on regression