1# simpleprofile
2
3simpleprofile is a JVMTI agent that lets one get simple JSON profiles with JVMTI
4
5# Usage
6### Build
7>    `m libsimpleprofile`  # or 'm libsimpleprofiled' with debugging checks enabled
8
9For binaries with NDK shared libraries only.
10>    `m libsimpleprofiled` # or `m libsimpleprofileds` with debugging checks enabled.
11
12The libraries will be built for 32-bit, 64-bit, host and target. Below examples
13assume you want to use the 64-bit version.
14
15### Command Line
16
17The agent is loaded using -agentpath like normal. It takes arguments in the
18following format:
19>     `file-output[,dump_on_shutdown][,dump_on_main_stop]`
20
21
22#### ART
23>    `art -Xplugin:$ANDROID_HOST_OUT/lib64/libopenjdkjvmti.so '-agentpath:libsimpleprofiled.so=/proc/self/fd/2,dump_on_main_stop' -cp tmp/java/helloworld.dex -Xint helloworld`
24
25* `-Xplugin` and `-agentpath` need to be used, otherwise the agent will fail during init.
26* If using `libartd.so`, make sure to use the debug version of jvmti.
27
28#### Device
29```
30% adb root
31% adb shell setenforce 0
32% adb push $OUT/system/lib64/libsimpleprofileds.so /data/local/tmp/libsimpleprofileds.so
33% adb shell
34blueline:/data/data/com.google.android.apps.maps # cp /data/local/tmp/libsimpleprofileds.so .
35blueline:/data/data/com.google.android.apps.maps # ps -A | grep maps
36u0_a178        9143    927 15691440 190132 SyS_epoll_wait     0 S com.google.android.apps.maps
37blueline:/data/data/com.google.android.apps.maps # cmd activity attach-agent com.google.android.apps.maps $PWD/libsimpleprofileds.so=$PWD/maps.json
38blueline:/data/data/com.google.android.apps.maps # # Do things on the app.
39blueline:/data/data/com.google.android.apps.maps # kill -3 9143
40blueline:/data/data/com.google.android.apps.maps # wc -l maps.json
4117901 maps.json
42blueline:/data/data/com.google.android.apps.maps # ^D
43% adb pull /data/data/com.google.android.apps.maps/maps.json
44```
45
46#### RI
47>    `java '-agentpath:libsimpleprofiled.so=/proc/self/fd/2,dump_on_main_stop' -cp tmp/helloworld/classes helloworld`
48
49### Output
50A normal run will look something like this:
51
52    % ./test/run-test --64 --host --dev --with-agent $ANDROID_HOST_OUT/lib64/libsimpleprofiled.so=dump_on_main_stop,/proc/self/fd/1 001-HelloWorld
53    <normal output removed>
54    Hello, world!
55    ...
56    {"class_name":"Ljava/util/HashMap$KeySet;","method_name":"iterator","method_descriptor":"()Ljava/util/Iterator;","count":6},
57    {"class_name":"Ljava/util/HashMap$KeyIterator;","method_name":"<init>","method_descriptor":"(Ljava/util/HashMap;)V","count":6},
58    {"class_name":"Ljava/util/HashMap$HashIterator;","method_name":"<init>","method_descriptor":"(Ljava/util/HashMap;)V","count":6},
59    {"class_name":"Ljava/lang/String;","method_name":"equals","method_descriptor":"(Ljava/lang/Object;)Z","count":128},
60    {"class_name":"Ljava/util/Collections$UnmodifiableCollection$1;","method_name":"next","method_descriptor":"()Ljava/lang/Object;","count":38},
61    {"class_name":"Ljava/util/HashMap$KeyIterator;","method_name":"next","method_descriptor":"()Ljava/lang/Object;","count":38},
62    {"class_name":"Lsun/misc/Cleaner;","method_name":"add","method_descriptor":"(Lsun/misc/Cleaner;)Lsun/misc/Cleaner;","count":1},
63    ...
64