Chapter 8. Profiling using the Builder

Table of Contents
Creating a profile
Using a profile with the Builder
Interpreting the profiling output

Profiling information is important for the Jamaica compiler to perform optimization of an application. We strongly recommended building applications using profiling information gathered using a profiling run.

Creating a profile

The builder's -profile option and the jamaicavmp command provide simple means to profile an application. Setting the -profile option enables profiling. The builder will then link the application with the profiling version of the JamaicaVM libraries.

During profiling the Jamaica Virtual Machine counts, among other things, the number of bytecode instructions executed within every method of the application. The number of instructions can be used as a measure for the time spent in each method.

At the end of execution, the total number of bytecode instructions executed by each method is written to a file with the name of the main class of the Java application and the suffix .prof, such that it can be used for further processing. 'Hot spots' (the most likely sources for further performance enhancements by optimization) in the application can easily be determined using this file.

Creating a profiling application

The compilation technology of Jamaica's builder is able to use the data generated during profile runs using the -profile option to guide the compilation process, producing optimal performance with a minimum increase in code size.

Here is a demonstration of the profiler using the HelloWorld example previously presented in Figure 6-2. First, it is built using the -profile option:

  > jamaica -profile -interpret HelloWorld
      
Reading configuration from '/usr/local/jamaica/target/linux-x86/...                                                                             
Reading configuration from '/usr/local/jamaica/etc/jamaica.conf'...                                                                                              
Jamaica Builder Tool 3.4 Release 1
Generating code for target 'linux-x86', optimisation 'none'                                                                                                                     
 + tmp/HelloWorld__.c                                                                                                                                                  
 + tmp/HelloWorld__.h
Class file compaction gain: 75.02608% (14567448 ==> 3638063)
 * C compiling 'tmp/HelloWorld__.c'
 + tmp/HelloWorld__nc.o
 * linking
 * stripping
Application memory demand will be as follows:
                       initial               max
Thread C    stacks:     512KB (=   8*  64KB)   31MB (= 511*  64KB)
Thread Java stacks:     128KB (=   8*  16KB) 8176KB (= 511*  16KB)
Heap Size:             2048KB                 256MB
GC data:                128KB                  16MB
TOTAL:                 2816KB                 311MB
    
  

The generated executable HelloWorld now prints the profiling information after execution. The output may look like this [1]:

  > ./HelloWorld 10000
      
              Hello        World!
           Hello       World!
        Hello     World!
     Hello    World!
   Hello   World!
 Hello  World!
...
                         Hello             World!
                       Hello            World!
                    Hello           World!
                 Hello         World!
Start writing profile data into file 'HelloWorld.prof'
 Write threads data...
 Write invocation data...
Done writing profile data
    
  

Using the profiling VM

Alternatively, in simple cases, the profile can also be created using the jamaicavmp command on the host without first building a stand-alone executable:

  > jamaicavmp HelloWorld 10000
      
              Hello        World!
           Hello       World!
        Hello     World!
     Hello    World!
   Hello   World!
 Hello  World!
...
                         Hello             World!
                       Hello            World!
                    Hello           World!
                 Hello         World!
Start writing profile data into file 'HelloWorld.prof'
 Write threads data...
 Write invocation data...
Done writing profile data
    
  

The use of jamaicavmp is subject to the following restrictions:

  • It can generate a profile for the host only.

  • Setting builder options for the application to be profiled is not possible.

Dumping a profile via network

If the application does not exit or writing a profile is very slow on the target, you can request a profile dump with the jamaica_remoteprofile command. You need to set the jamaica.profile_request_port property when building the application or using the profiling VM to an open TCP/IP port and then request a dump remotely:

  > jamaica_remoteprofile <IP address> <port>
  
DUMPING...
DONE.

Per default, the profile is written on the target to a file with the name of the main class and the suffix .prof. You can change the file name with the -file option or you can send the profile over the network and write it to the file system (with an absolute path or relative to the current directory) of the host with the -net option:

  > jamaica_remoteprofile -net=<file name> <IP address> <port>

Creating a micro profile

To speed up the performance of critical sections in the application, you can use micro profiles that only contain profiling information of such a section (see the Section called Building with multiple profiles). You need to reset the profile just before the critical part is executed and dump a profile directly after. To reset a profile, you can use the jamaica_remoteprofile command with the -reset option:

  > jamaica_remoteprofile -reset <IP address> <port>

Notes

[1]

For better results, we run the application with the command line argument 10000 such that startup code does not dominate