1*795d594fSAndroid Build Coastguard Worker# tiallocsample 2*795d594fSAndroid Build Coastguard Worker 3*795d594fSAndroid Build Coastguard Workertiallocsample is a JVMTI agent designed to track the call stacks of allocations 4*795d594fSAndroid Build Coastguard Workerin the heap. 5*795d594fSAndroid Build Coastguard Worker 6*795d594fSAndroid Build Coastguard Worker# Usage 7*795d594fSAndroid Build Coastguard Worker### Build 8*795d594fSAndroid Build Coastguard Worker> `m libtiallocsample` 9*795d594fSAndroid Build Coastguard Worker 10*795d594fSAndroid Build Coastguard WorkerThe libraries will be built for 32-bit, 64-bit, host and target. Below examples 11*795d594fSAndroid Build Coastguard Workerassume you want to use the 64-bit version. 12*795d594fSAndroid Build Coastguard Worker 13*795d594fSAndroid Build Coastguard WorkerUse `libtiallocsamples` if you wish to build a version without non-NDK dynamic dependencies. 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> `sample_rate,stack_depth_limit,log_path` 20*795d594fSAndroid Build Coastguard Worker 21*795d594fSAndroid Build Coastguard Worker* sample_rate is an integer specifying how frequently an event is reported. 22*795d594fSAndroid Build Coastguard Worker E.g., 10 means every tenth call to new will be logged. 23*795d594fSAndroid Build Coastguard Worker* stack_depth_limit is an integer that determines the number of frames the deepest stack trace 24*795d594fSAndroid Build Coastguard Worker can contain. It returns just the top portion if the limit is exceeded. 25*795d594fSAndroid Build Coastguard Worker* log_path is an absolute file path specifying where the log is to be written. 26*795d594fSAndroid Build Coastguard Worker 27*795d594fSAndroid Build Coastguard Worker#### Output Format 28*795d594fSAndroid Build Coastguard Worker 29*795d594fSAndroid Build Coastguard WorkerThe resulting file is a sequence of object allocations, with a limited form of 30*795d594fSAndroid Build Coastguard Workertext compression. For example a single stack frame might look like: 31*795d594fSAndroid Build Coastguard Worker 32*795d594fSAndroid Build Coastguard Worker``` 33*795d594fSAndroid Build Coastguard Worker+0,jthread[main], jclass[[I file: <UNKNOWN_FILE>], size[24, hex: 0x18] 34*795d594fSAndroid Build Coastguard Worker+1,main([Ljava/lang/String;)V 35*795d594fSAndroid Build Coastguard Worker+2,run()V 36*795d594fSAndroid Build Coastguard Worker+3,invoke(Ljava/lang/Object;[Ljava/lang/Object;)Ljava/lang/Object; 37*795d594fSAndroid Build Coastguard Worker+4,loop()V 38*795d594fSAndroid Build Coastguard Worker+5,dispatchMessage(Landroid/os/Message;)V 39*795d594fSAndroid Build Coastguard Worker+6,handleMessage(Landroid/os/Message;)V 40*795d594fSAndroid Build Coastguard Worker+7,onDisplayChanged(I)V 41*795d594fSAndroid Build Coastguard Worker+8,getState()I 42*795d594fSAndroid Build Coastguard Worker+9,updateDisplayInfoLocked()V 43*795d594fSAndroid Build Coastguard Worker+10,getDisplayInfo(I)Landroid/view/DisplayInfo; 44*795d594fSAndroid Build Coastguard Worker+11,createFromParcel(Landroid/os/Parcel;)Ljava/lang/Object; 45*795d594fSAndroid Build Coastguard Worker+12,createFromParcel(Landroid/os/Parcel;)Landroid/view/DisplayInfo; 46*795d594fSAndroid Build Coastguard Worker+13,<init>(Landroid/os/Parcel;Landroid/view/DisplayInfo$1;)V 47*795d594fSAndroid Build Coastguard Worker+14,<init>(Landroid/os/Parcel;)V 48*795d594fSAndroid Build Coastguard Worker+15,readFromParcel(Landroid/os/Parcel;)V 49*795d594fSAndroid Build Coastguard Worker=16,0;1;2;3;1;4;5;6;7;8;9;10;10;11;12;13;14;15 50*795d594fSAndroid Build Coastguard Worker16 51*795d594fSAndroid Build Coastguard Worker``` 52*795d594fSAndroid Build Coastguard Worker 53*795d594fSAndroid Build Coastguard WorkerLines starting with a + are key, value pairs. So, for instance, key 2 stands for 54*795d594fSAndroid Build Coastguard Worker``` 55*795d594fSAndroid Build Coastguard Workerrun()V 56*795d594fSAndroid Build Coastguard Worker``` 57*795d594fSAndroid Build Coastguard Worker. 58*795d594fSAndroid Build Coastguard Worker 59*795d594fSAndroid Build Coastguard WorkerThe line starting with 0 is the thread, type, and size (TTS) of an allocation. The 60*795d594fSAndroid Build Coastguard Workerremaining lines starting with + are stack frames (SFs), containing function signatures. 61*795d594fSAndroid Build Coastguard WorkerLines starting with = are stack traces (STs), and are again key, value pairs. In the 62*795d594fSAndroid Build Coastguard Workerexample above, an ST called 16 is the TTS plus sequence of SFs. Any line not starting 63*795d594fSAndroid Build Coastguard Workerwith + or = is a sample. It is a reference to an ST. Hence repeated samples are 64*795d594fSAndroid Build Coastguard Workerrepresented as just numbers. 65*795d594fSAndroid Build Coastguard Worker 66*795d594fSAndroid Build Coastguard Worker#### ART 67*795d594fSAndroid Build Coastguard Worker> `art -Xplugin:$ANDROID_HOST_OUT/lib64/libopenjdkjvmti.so '-agentpath:libtiallocsample.so=100' -cp tmp/java/helloworld.dex -Xint helloworld` 68*795d594fSAndroid Build Coastguard Worker 69*795d594fSAndroid Build Coastguard Worker* `-Xplugin` and `-agentpath` need to be used, otherwise the agent will fail during init. 70*795d594fSAndroid Build Coastguard Worker* If using `libartd.so`, make sure to use the debug version of jvmti. 71*795d594fSAndroid Build Coastguard Worker 72*795d594fSAndroid Build Coastguard Worker> `adb shell setenforce 0` 73*795d594fSAndroid Build Coastguard Worker> 74*795d594fSAndroid Build Coastguard Worker> `adb push $ANDROID_PRODUCT_OUT/system/lib64/libtiallocsample.so /data/local/tmp/` 75*795d594fSAndroid Build Coastguard Worker> 76*795d594fSAndroid Build Coastguard Worker> `adb shell am start-activity --attach-agent /data/local/tmp/libtiallocsample.so=100 some.debuggable.apps/.the.app.MainActivity` 77*795d594fSAndroid Build Coastguard Worker 78*795d594fSAndroid Build Coastguard Worker#### RI 79*795d594fSAndroid Build Coastguard Worker> `java '-agentpath:libtiallocsample.so=MethodEntry' -cp tmp/helloworld/classes helloworld` 80