Profiling a Java Application

This section demonstrates how to analyze a Java program using a time-based profile. The application program used in this section is the SciMark 2.0 benchmark from the National Institute of Standards and Technology (NIST). Source code for the benchmark can be downloaded from http://math.nist.gov/scimark2/scimark2src.zip. You will need a Java compiler in order to compile the benchmark. CodeAnalyst supports both the Sun Microsystems and IBM versions of the Java Virtual Machine (JVM).

Before starting, ensure that a CodeAnalyst project is open and ready for use. The tutorial section Creating a CodeAnalyst Project demonstrates how to create a new project.

  1. Click the New button in the toolbar or select File > New from the file menu to create a new project, or click the Open button in the toolbar to open an existing project or select File > Open from the file menu. The session settings are slightly different for a Java application.
  2. With an open CodeAnalyst project, select Time-based profile from the drop-down list of profile configurations in the toolbar.
  1. Click the Session Settings button in the toolbar to change the session settings. You may alternately select Tools > Session Settings from the file menu. A dialog box appears asking for session settings.
  2. Change the session name to JavaSession. Java programs are executed by the JVM, which is started by the Java application launcher tool ("/usr/java/latest/bin/java").
  3. In the Launch field, enter the path /usr/java/latest/bin/java or browse to it by clicking the Browse button located next to the Launch field.

Note: The Java application launcher tool can usually be found in the installation directory for Java.

  1. After the path to "/usr/java/latest/bin/java" enter jnt.scimark2.commandline (the name of the Java application program to be launched) .

Note: CodeAnalyst automatically checks for the Java application launcher tool and inserts the –agentlib option into the Launch field. You do not need to enter this option yourself. The agent connects the JVM to CodeAnalyst.

  1. Enter the path to the working directory, or browse to the working directory by clicking the Browse) button next to the working directory field.
  2. Click the Show Options button, if necessary, to display the extended settings. Ensure the checkbox is selected to enable Terminate the app after the profile, Stop data collection when the app exits, and Profile the duration of the app execution options. CodeAnalyst collects data for the entire duration of the benchmark run. Click OK to confirm the session settings and to dismiss the dialog box.
  1. Click the Start button in the toolbar, or select Profile > Start from the menu.

CodeAnalyst starts data collection and launches the Java application program through the Java application launcher tool. When the benchmark program terminates and data collection is finished, CodeAnalyst displays results in three tabbed panels—System Data, System Graph and Processes. The System Data table shows a module-by-module breakdown of timer samples. Each timer sample represents approximately 1 millisecond of execution time (when using the default timer interval of 1 millisecond).

Reviewing Results

Performance data for this example was collected on a dual-core AMD Athlon™ 64 processor. The benchmark program is single-threaded and keeps only one core busy. The other core is available for other processes in the system. In this case, the System Data table attributes roughly 98% of the timer samples to the application program (jnt.scimark2.commandline).

Note: Due to scheduling decisions made by the operating system, the application program may execute on either core and may even migrate between cores.

The System Graph shows the module-by-module breakdown of timer samples in the form of a bar chart.

The Processes table displays the distribution of timer samples across the software processes that were active during data collection. CodeAnalyst monitors activity on a system-wide basis. It collects data on any active software component—application programs, libraries, device drivers or kernel modules. Time spent idle is ascribed to the system-idle process.

CodeAnalyst displays a new tabbed panel containing the annotated assembly code for the function transform_internal. The number of timer samples for each instruction is shown.

Note: CodeAnalyst Linux® does not provide source view for Java application. CodeAnalyst monitors the execution of just-in-time (JIT) compiled code.

 

Launching a Java Program from the Command Line

You may also use CodeAnalyst to collect data on a Java program (or any other application program) that is launched from a command line. This is sometimes more convenient than launching the application from within CodeAnalyst.

  1. Click the Session Settings button in the toolbar to change the session settings or, alternately, select Tools > Session Settings from the menu. A dialog box appears asking for changes to the session settings.
  2. Delete the information in the Launch and Working directory fields to empty these fields. CodeAnalyst disables the “Stop data collection when the app exits” and “Profile the duration of the app execution” options.
  3. Change the Profile duration field to 40 seconds.
  4. Click OK to confirm the changes and to dismiss the dialog box.
  1. Click the Start button in the toolbar or select Profile > Start from the menu. CodeAnalyst starts to collect data and will do so for the next 40 seconds as specified by the Profile duration field in the session settings dialog box.

At the shell command line, enter the following command to start the benchmark program:

java -agentpath:/opt/CodeAnalyst//bin/libCAJVMTIA64.so jnt.scimark2.commandline

You must use the CodeAnalyst profiling agent that is appropriate for the JVM. After 40 seconds has expired, CodeAnalyst stops data collection and displays results in its workspace.

Some versions of the JVM have deprecated the use of the -XrunCAJVMPIA option. Java -X options are non-standard and are subject to change without notice.