profiling

Gary Adams gary.adams at oracle.com
Tue Jan 26 15:13:35 UTC 2016


Here's a short writeup about using the hprof agent
from one of our earlier developers. The only tricky part is
that you need to specify the output file location explicitly.
====

See http://docs.oracle.com/javase/7/docs/technotes/samples/hprof.html 
for more information on hprof options.

The default location for the hprof output file is usually not writable 
on iOS and Android devices.
The output file must be specified to the VM when running hrpof on these 
devices.

-agentlib:hprof=file=<writabledirectory>/file

Add the option to the options passed to JNI_CreateJavaVM.

On iOS the Sandbox, the Documents directory and the tmp
directory are writable. On iOS 
"[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, 
NSUserDomainMask, YES)" can be used
to get the documents directory and " NSTemporaryDirectory()" to get the 
tmp directory.

On Android "Context.getFilesDir()" provides a writable area.

% java -agentlib:hprof=help

      HPROF: Heap and CPU Profiling Agent (JVMTI Demonstration Code)

hprof usage: java -agentlib:hprof=[help]|[<option>=<value>, ...]

Option Name and Value Description Default
--------------------- ----------- -------
heap=dump|sites|all heap profiling all
cpu=samples|times|old CPU usage off
monitor=y|n monitor contention n
format=a|b text(txt) or binary output a
file=<file> write data to file java.hprof[{.txt}]
net=<host>:<port> send data over a socket off
depth=<size> stack trace depth 4
interval=<ms> sample interval in ms 10
cutoff=<value> output cutoff point 0.0001
lineno=y|n line number in traces? y
thread=y|n thread in traces? n
doe=y|n dump on exit? y
msa=y|n Solaris micro state accounting n
force=y|n force output to <file> y
verbose=y|n print messages about dumps y

Obsolete Options
----------------
gc_okay=y|n

Examples
--------
   - Get sample cpu information every 20 millisec, with a stack depth of 3:
       java -agentlib:hprof=cpu=samples,interval=20,depth=3 classname
   - Get heap usage information based on the allocation sites:
       java -agentlib:hprof=heap=sites classname

Notes
-----
   - The option format=b cannot be used with monitor=y.
   - The option format=b cannot be used with cpu=old|times.
   - Use of the -Xrunhprof interface can still be used, e.g.
        java -Xrunhprof:[help]|[<option>=<value>, ...]
     will behave exactly the same as:
        java -agentlib:hprof=[help]|[<option>=<value>, ...]

Warnings
--------
   - This is demonstration code for the JVMTI interface and use of BCI,
     it is not an official product or formal part of the JDK.
   - The -Xrunhprof interface will be removed in a future release.
   - The option format=b is considered experimental, this format may change
     in a future release.

On 01/26/16 08:43, Johan Vos wrote:
> Now that I have a pretty complex application running on a real iOS device,
> I would like to investigate (and improve) performance.
> However, I only see addresses and no function names using
> XCode/Instruments.
> Any advice on how to profile the VM on iOS?
>
> Thanks,
>
> - Johan



More information about the mobile-dev mailing list