Enabling Java Performance Analysis on Android Devices Using Intel® VTune™ Amplifier 2014 for Systems

Intel® VTune™ Amplifier 2014 for Systems supports seeing Java functions and drilling into the JITted assembly, Java Source, or Dex* for those functions which were JITted on rooted Android* devices running an instrumented Java/Dalvik* VM.  Check back to this article later on how to enable a future version of VTune Amplifier for Systems to enable Java drill down in an ART* JVM.

If you are experiencing the following issues:

  • After collection - time(samples) is associated to the function/module: [dalvik-jit-code-cache (deleted)] in "Basic Hotspots"
  • After collection - time(samples) is associated to the function/module: [Outside any known Module] in "Advanced Hotspots" or other Hardware Event-based Sampling types
  • Drill down into a Java function goes to assembly (or something you didn't want)

Then likely you need to (re)setup your Android device, in order for VTune Amplifier to work with Java code.  The device needs the following 4 items:

  1. Rootable Android device
  2. Dalvik JVM which has VTune Amplifier instrumentation
  3. Start the Dalvik virtual machine with instrumentation enabled
  4. Perform an Analysis with VTune Amplifier and specify the process(es) to see Java info

For more information see:

Intel® VTune™ Amplifier User's GuideRunning Analysis RemotelyPreparing a Target Android* System for Remote Analysis

1) Rootable Android Device

Check to make sure your device is rootable.  Issue the following command from an adb attached host.

adb root

If you get:

adbd is already running as root

or

restarting adbd as root

Then the device is rootable, userdebug and eng images of the android OS are easily rootable.  It is generally not possible to make user images rootable.  To get a publicly available rootable device see http://www.intel.com/mdk or http://01.org/android-ia.

2) Getting a Dalvik JVM which has VTune Amplifier instrumentation

Many Intel® Atom Processor based Android devices ship with instrumented Dalvik engines.  Some noteworthy exceptions are:

Determining if the Dalvik engine on your device is intrumented

Issue the command:

adb shell dalvikvm -get Help

look for –Xjitvtuneinfo in the list of potential options.

If not found then instrumentation support for VTune is not in the dalvik engine on the device and you will need to replace it

Replacing libdvm.so on your device

NOTE: replacing of libdvm.so is only needed if your device is Dell Venue* 8 tablet based on Intel® Atom™ Processor Z2580, and you use VTune Amplifier 2014 Update 1 for Systems. A newer VTune Amplifier for Systems version replaces libdvm.so on Dell Venue* 8 tablet automatically.

Intel VTune Amplifier 2014 for Systems update 1 has an instrumented version of libdvm.so in <path-to-vtune>/target/android_v3.10/prebuilt//DellVeune8.  To install it issue the following commands:

  1. adb root
  2. adb remount
  3. adb push <path-to-vtune>/target/android_v3.10/prebuilt/DellVeune8/libdvm.so /system/lib
  4. adb reboot

Update: Intel VTune Amplifier 2014 for Systems update 2 automatically copies libdvm.so to your device when it installs the target collection utilities to the device. (either on first collection or via the target install command (amplxe-androidreg.sh --package-command=install.)

3) Start the Dalvik JVM with VTune Amplifier instrumentation enabled

VTune Amplfier 2014 for Systems by default sets up the Dalvik VM for instrumentation when you:

Create a new project in the GUI with target system set to Android device (ADB) - and then run a collection for the first time on that device.  This method will set the instrumentation to JIT mode.  Which allows you to see functions in the GUI, but when you drill down into the function it will open the assembly (vs the Java Src or Dex Byte Code).

To change the default you must manually run the installer from the host device:

Linux: <path-to-vtune>/bin[32|64]/amplxe-androidreg.sh --package-command=install --xjitvtuneinfo=src

Windows: <path-to-vtune>\bin32\amplxe-androidreg.bat --package-command=install --xjitvtuneinfo=src

Where --xjitvtuneinfo=src can be one of:

  • Basic information about the compiled trace: -Xjitvtuneinfo=jit
  • Mapping from JIT code to Java source code and basic information about the compiled trace: -Xjitvtuneinfo=src
  • Mapping from JIT code to DEX code and basic information about the compiled trace: -Xjitvtuneinfo=dex
  • JIT data collection. By default, JIT collection is disabled if you do not supply any options: -Xjitvtuneinfo=none

By default the installer above will modify /data/local.prop as follows so that the JVM will be enabled for VTune on all subsequent reboots of the OS.

root@android:/ # cat /data/local.prop
dalvik.vm.extra-opts=-Xjitvtuneinfo:src

For the Dell Venue 8 and devices which cannot use /data/local.prop the following procedure will work from the host device.

adb shell setprop dalvik.vm.extra-opts -Xjitvtuneinfo:src

set the property to src or dex or jit or none

adb shell stop
adb shell start

Don’t reboot device. Check that the property is set by adb shell getprop.  The output should contain [dalvik.vm.extra-opts]: [-Xjitvtuneinfo:src]

4) Perform an Analysis with VTune Amplifier and specify the process(es) to see Java info

VTune Amplifier can associate samples to JITted code, using all available analysis types in VTune Amplifier,  but, a final step is needed.  This step is done for you when you run analysis types for a project setup as "Attach to Process" or "Launch Android Package".  It pulls only the .JIT files for the process that you specified in the project settings.

Two kinds of Analysis types in VTune Amplifier may require you to manually pull the .JIT files into your results directory.  If in the project properties you specified to "Profile System" or if you specified "Analyze System-Wide" for "Attach to Process" or "Launch Android Package" in the "Advanced Settings".  Then you may need to pull the .JIT files for processes you are interested in which were not specified.   See:  Intel® VTune™ Amplifier User's GuideCommand Line Interface SupportRunning Analysis from the Command Line for more information on how to do this.