Tips on how you can speed up Java profiling
Tips on how you can speed up Java profiling

1.0 Introduction
Profilers typically collect large amounts of data from the application being monitored. Users must choose profiling options and filters carefully in order to have an effective profiling session. This document describes some of the ways users can speed up profiling with TPTP's Java profiler.

2.0 Profiling Filters
Proper filtration can significantly speed up a profiling session. Follow the steps below to change the filtering criteria used by TPTP's profiler:
  1. Click on the profile button and select 'Open Profile Dialog...' as indicated in figure 1.0

  2. Open Profile Dialog
    Figure 1.0: Profile list

  3. Select the desired launch configuration to the left
  4. Select the 'Monitor' tab as indicated in figure 1.1

  5. Monitor Tab
    Figure 1.1: Profile launch configuration

  6. The filter page can be accessed by either double clicking on 'Java Profiling' or by selecting 'Java Profiling' and clicking on 'Edit Options'
  7. Once this is done, the user is presented with the filter page indicated in figure 1.2. This page can be used to specify filters by using class names, method names, and a visibility rule. The * (asterisk) wildcard can be used for the class and method names to select multiple classes/methods. There is no need to specify method signature in the method name column.

  8. Filter Page
    Figure 1.2: Filters page

  9. The filters page should be used to exclude classes that are irrelevant in a profiling session. The best approach is by including the packages that should be profiled and excluding everything else. For example, if all classes that are to be profiled have the prefix 'org.mypackage', then the following filtering criteria can be used:

    Method Name

    Note that the filter list is order-dependent. Filters higher in the list take precedence over filters lower in the list.

3.0 Profiling Options
Selecting fewer profiling options can significantly speed up profiling. Here are the steps to alter the profiling options used by TPTP's profiler:
  1. Follow steps 1-3 in section 2.0 (Profiling Filters) to get to the screen in figure 1.1.
  2. The entries displayed under 'Java Profiling' are the profiling options that are available to the user. The settings for each profiling option can also be altered by selecting it and clicking on 'Edit Options'.
  3. Select 'Execution Time Analysis' and click on 'Edit Options'.
  4. The 'Show execution flow graphical details' option under 'Type of data' can significantly slow down profiling. This option requires graphical details to be collected in the model and rendered in the UI. By selecting the 'Show execution statistics (compressed)' option, the profiler will default to an aggregated mode, which will significantly speed up profiling.
  5. Collecting instance level information when profiling with either Memory Analysis or Execution Time Analysis can also slow things down.

4.0 Profiling to a File
The biggest overhead in TPTP is on the workbench side (specifically the loaders/model). As a last resort, users can choose to profile to a file instead of sending profiling data directly to the workbench. Users can then import this file on a faster machine for analyzing the profiling data or analyze the data manually by opening it in a text editor. To send profiling data to a file, follow the steps given below:
  1. Follow steps 1-2 of section 2.0 (Profiling Filters)
  2. Select the 'Destination' tab
  3. Select 'Send profiling data to a file'
  4. Specify a file with .trcxml file extension as indicated in figure 1.4.

  5. Figure 1.4 Profiling to a file

  6. Click on profile to start profiling to a file. The file generated can later be imported into the workbench by right clicking in the 'Profiling and Logging' perspective -> selecting Import... -> Profiling and Logging -> Profiling file -> Next -> Selecting the profiling file -> Specifying the type of data that should be imported in the 'Range' tab -> clicking on finish.

Another way to profile to a file is to run an application in standalone mode. On Java 1.5 or higher, this can be done by running the command:
java -agentlib:JPIBootLoader=JPIAgent:server=standalone,file=<filename>;<profiler> <Java_app to be profiled>
On Java 1.4.x or lower, this can be done by running the command:
-XrunpiAgent:server=standalone <VM argument>
Please see the 'Getting started with Agent Controller' document listed in the documentation page of TPTP for more information.

5.0 Profiling Limits
When using the Java profiling agent on Java 1.4.x and lower, you can also control profiling speed by specifying profiling limits:
  1. Follow steps 1-4 in section 2.0 (Profiling Filters) to get to the following screen:
  2. Filters page
    Figure 1.5: Filters page

  3. Click on next to get to the screenshot indicated in figure 1.5

  4. Figure 1.5: Profiling Limits

  5. This page can be used to halt profiling after a certain number of method invocations or after a certain amount of time.

6.0 Conclusion
In order to have an effective profiling session users must be cautious with the profiling filters and options that they use. Users have the power of specifying what should be profiled as well as how the profiling data should be presented. It's easy for a profiling session to consume a lot of data and hog all the system resources. The methods outlined in this document try to avoid such cases with TPTP's Java Profiler.