Kavi Gupta | 2d84ae7 | 2019-06-11 09:19:35 -0700 | [diff] [blame] | 1 | # dumpcoverage |
| 2 | |
| 3 | libdumpcoverage.so is a JVMTI agent designed to dump coverage information for a process, where the binaries have been instrumented by JaCoCo. JaCoCo automatically starts recording data on process start, and we need a way to trigger the resetting or dumping of this data. |
| 4 | |
| 5 | The JVMTI agent is used to make the calls to JaCoCo in its process. |
| 6 | |
| 7 | # Usage |
| 8 | |
| 9 | Note that these examples assume you have an instrumented build (userdebug_coverage). Here is, for example, how to dump coverage information regarding the default clock app. First some setup is necessary: |
| 10 | |
| 11 | ``` |
| 12 | adb root # necessary to copy files in/out of the /data/data/{package} folder |
| 13 | adb shell 'mkdir /data/data/com.android.deskclock/folder-to-use' |
| 14 | ``` |
| 15 | |
| 16 | Then we can run the command to dump the data: |
| 17 | |
| 18 | ``` |
Oliver Nguyen | 05b1c06 | 2019-07-16 14:09:38 -0700 | [diff] [blame] | 19 | adb shell 'am attach-agent com.android.deskclock /system/lib/libdumpcoverage.so=dump:/data/data/com.android.deskclock/folder-to-use/coverage-file.ec' |
Kavi Gupta | 2d84ae7 | 2019-06-11 09:19:35 -0700 | [diff] [blame] | 20 | ``` |
| 21 | |
| 22 | We can also reset the coverage information with |
| 23 | |
| 24 | ``` |
| 25 | adb shell 'am attach-agent com.android.deskclock /system/lib/libdumpcoverage.so=reset' |
| 26 | ``` |
| 27 | |
| 28 | then perform more actions, then dump the data again. To get the files, we can get |
| 29 | |
| 30 | ``` |
Oliver Nguyen | 05b1c06 | 2019-07-16 14:09:38 -0700 | [diff] [blame] | 31 | adb pull /data/data/com.android.deskclock/folder-to-use/coverage-file.ec ~/path-on-your-computer |
Kavi Gupta | 2d84ae7 | 2019-06-11 09:19:35 -0700 | [diff] [blame] | 32 | ``` |
| 33 | |
Oliver Nguyen | 05b1c06 | 2019-07-16 14:09:38 -0700 | [diff] [blame] | 34 | And you should have `coverage-file.ec` on your machine under the folder `~/path-on-your-computer` |
Kavi Gupta | 2d84ae7 | 2019-06-11 09:19:35 -0700 | [diff] [blame] | 35 | |
| 36 | # Details |
| 37 | |
| 38 | In dump mode, the agent makes JNI calls equivalent to |
| 39 | |
| 40 | ``` |
| 41 | Agent.getInstance().getExecutionData(/*reset = */ false); |
| 42 | ``` |
| 43 | |
| 44 | and then saves the result to a file specified by the passed in directory |
| 45 | |
| 46 | In reset mode, it makes a JNI call equivalent to |
| 47 | |
| 48 | ``` |
| 49 | Agent.getInstance().reset(); |
| 50 | ``` |