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