xref: /aosp_15_r20/frameworks/base/tests/ActivityManagerPerfTests/README.txt (revision d57664e9bc4670b3ecf6748a746a57c557b6bc9e)
1*d57664e9SAndroid Build Coastguard WorkerActivityManagerPerfTests
2*d57664e9SAndroid Build Coastguard Worker
3*d57664e9SAndroid Build Coastguard WorkerPerformance tests for various ActivityManager components, e.g. Services, Broadcasts
4*d57664e9SAndroid Build Coastguard Worker* These are only for tests that don't require a target package to test against
5*d57664e9SAndroid Build Coastguard Worker* Self-contained perf tests should go in frameworks/base/apct-tests/perftests
6*d57664e9SAndroid Build Coastguard Worker
7*d57664e9SAndroid Build Coastguard WorkerCommand to run tests
8*d57664e9SAndroid Build Coastguard Worker* atest -v ActivityManagerPerfTests
9*d57664e9SAndroid Build Coastguard Worker
10*d57664e9SAndroid Build Coastguard WorkerOverview
11*d57664e9SAndroid Build Coastguard Worker* The numbers we are trying to measure are end-to-end numbers
12*d57664e9SAndroid Build Coastguard Worker  * For example, the time it takes from sending an Intent to start a Service
13*d57664e9SAndroid Build Coastguard Worker    to the time the Service runs its callbacks
14*d57664e9SAndroid Build Coastguard Worker* System.nanoTime() is monotonic and consistent between processes, so we use that for measuring time
15*d57664e9SAndroid Build Coastguard Worker* If the test app is involved, it will measure the time and send it back to the instrumentation test
16*d57664e9SAndroid Build Coastguard Worker  * The time is sent back through a Binder interface in the Intent with the help of Utils.sendTime()
17*d57664e9SAndroid Build Coastguard Worker  * Each sent time is tagged with an id since there can be multiple events that send back a time
18*d57664e9SAndroid Build Coastguard Worker* Each test will run multiple times to account for variation in test runs
19*d57664e9SAndroid Build Coastguard Worker
20*d57664e9SAndroid Build Coastguard WorkerStructure
21*d57664e9SAndroid Build Coastguard Worker* tests
22*d57664e9SAndroid Build Coastguard Worker  * Instrumentation test which runs the various performance tests and reports the results
23*d57664e9SAndroid Build Coastguard Worker* test-app
24*d57664e9SAndroid Build Coastguard Worker  * Target package which contains the Services, BroadcastReceivers, etc. to test against
25*d57664e9SAndroid Build Coastguard Worker  * Sends the time it measures back to the test package
26*d57664e9SAndroid Build Coastguard Worker* utils
27*d57664e9SAndroid Build Coastguard Worker  * Utilities that both the instrumentation test and test app can use
28*d57664e9SAndroid Build Coastguard Worker
29*d57664e9SAndroid Build Coastguard WorkerAdding tests
30*d57664e9SAndroid Build Coastguard Worker* Example
31*d57664e9SAndroid Build Coastguard Worker  * Look at tests/src/com/android/frameworks/perftests/am/BroadcastPerfTest and
32*d57664e9SAndroid Build Coastguard Worker    test-app/src/com/android/frameworks/perftests/amteststestapp/TestBroadcastReceiver
33*d57664e9SAndroid Build Coastguard Worker    for simple examples using this framework
34*d57664e9SAndroid Build Coastguard Worker* Steps
35*d57664e9SAndroid Build Coastguard Worker  * Add any components you will test against in the target package under
36*d57664e9SAndroid Build Coastguard Worker    test-app/src/com/android/frameworks/perftests/amteststestapp/
37*d57664e9SAndroid Build Coastguard Worker  * Add the test class under tests/src/com/android/frameworks/perftests/am/tests/
38*d57664e9SAndroid Build Coastguard Worker    * The class should extend BasePerfTest
39*d57664e9SAndroid Build Coastguard Worker    * Each test should call runPerfFunction() returning the elapsed time for a single iteration
40*d57664e9SAndroid Build Coastguard Worker    * The test has access to a Context through mContext
41*d57664e9SAndroid Build Coastguard Worker  * If you are measuring the time elapsed of something that either starts or ends in the target
42*d57664e9SAndroid Build Coastguard Worker    package
43*d57664e9SAndroid Build Coastguard Worker    * The target package can report the time it measures through an ITimeReceiverCallback passed
44*d57664e9SAndroid Build Coastguard Worker      through an Intent through Utils.sendTime(intent, "tag")
45*d57664e9SAndroid Build Coastguard Worker      (or however a Binder needs to be passed to the target package)
46*d57664e9SAndroid Build Coastguard Worker    * The instrumentation test can collect that time by calling getReceivedTimeNs("tag") and
47*d57664e9SAndroid Build Coastguard Worker      calculate the elapsed time
48*d57664e9SAndroid Build Coastguard Worker    * Each timestamp sent to the instrumentation test is tagged with a tag since multiple timestamps
49*d57664e9SAndroid Build Coastguard Worker      can be reported in an iteration
50*d57664e9SAndroid Build Coastguard Worker  * If the target package should be running before your test logic starts, add startTargetPackage();
51*d57664e9SAndroid Build Coastguard Worker    at the beginning of the iteration
52*d57664e9SAndroid Build Coastguard Worker
53*d57664e9SAndroid Build Coastguard Worker* Reporting
54*d57664e9SAndroid Build Coastguard Worker  * Look at internal documentation for how to add new tests to dashboards and receive notification
55*d57664e9SAndroid Build Coastguard Worker    on regressions
56