Chapter 6. Validation, Tuning and Troubleshooting of the Development Runtime Envionment

Use tracing and profiling tools to analyze and tune applications

Launch the sample application

The sample application will be launched from the Profiling and Logging perspective.

  1. Switch to the Profiling and Logging perspective by selecting Window > Open perspective > Other > Profiling and Logging.

  2. Click on the launch profiling button Launch profiling configuration icon and select Profile...

  3. In the Profile configuration dialog, double-click on Java Application. A new configuration is created and the details are shown in the right pane.

  4. Specify the project name as CarModel.

  5. Click on Search for the main class. The wizard should automatically detect the CarModel class.

  6. Select the CarModel class and click OK.

    Profile configuration

Specifiying profiling filters

Profiling filters allow users to limit the amount of data that is collecting in a profiling session. Follow these steps to set up filters for the sample application:

  1. In your profiing configuration, under the Profiling tab, select the Overview tab.

  2. Click Add to add your own profiling set. The Add Profiling Set wizard opens.

  3. On the Profiling Set page, specify a name and a description for your profiling set (IBM Test 257 Profiling Set). Click Next.

    Profiling set

  4. On the Profiling Type page, expand the Memory Analysis check box.

  5. Check the Basic Memory Analysis. The details of this profiling set are shown in the right pane.

  6. Select the Show instance level information option.

    Basic Memory Analysis

  7. Click Next.

  8. On the Filter Set page, specify the filter set that you want applied by selecting from the Select a filter set list. You can use the Default set.

  9. Under Contents of selected filter set, click Add.

  10. Specify by* as the Class and main as the Method Name.

  11. Select INCLUDE from the Rule list.

    Filter Set

  12. Click OK. The filter criterion is added to the contents list.

  13. Click Finish.

  14. Click Apply to save the changes.

    Filter created

  15. Click Profile to start profiling your application. The Profiling Monitor will show the CarModel application started.

    NOTE: You should have RAServer running:

    D:\AgentController\bin>RAServer.exe								
    								

Memory Statistics view

  1. From the Profiling Monitor view, using the pop-up menu of the profiling agent, select Open with > Memory Statistics.

  2. In the Memory Statistics view, expand the by.iba.rad257 package.

  3. Select CarModel. Notice the information provided for the class:

    CarModel

    • Total instances: The total number of instances of the CarModel class.

    • Live instances: The number of instances that are alive (i.e. instances that were not collected by the garbage collector).

    • Collected: The number of instances that have been garbage collected.

    • Total Size (bytes): The size of an instances associated with a specific type.

    • Active Size (bytes): The size of an instances associated with a specific type.

  4. From the toolbar, select Class Level Information icon to open the class level information. Notice that all the non-filtered invoked methods of the CarModel class appear under its name. The filtered main method which has already been invoked at this point, does not appear under the class.

    Class level

  5. Select Instance Level Information icon from the toolbar to open the instance level information. The number of instances associated with a specific object type are listed beneath the object.

    Instance level

Java memory leak detection using RAD 6

IBM Rational Application Developer can identify potential leaks by analyzing heap dumps. A heap dump is the state of heap memory at a given point in time, and RAD has the ability to profile an application and collect heap dumps. Alternatively, you can import heap dumps with tools taken on various platforms. RAD can then analyze these heap dumps and find Java leaks.

Before collecting heap dumps, make sure that the IBM Agent Controller is running. It is packaged and gets installed with RAD.

Heap dumps can be collected by profiling a program, using these steps in the Profiling dialog.

  1. To start the Profiling dialog, from the Run menu, click Profile...

  2. You want to collect heap dumps for LeakExample program. You will have to create a Configuration for it under the Java Application.

    Configuration

  3. Then go to the Profiling tab and select the Memory Leak Analysis - Manual heap dumps profiling set.

    Memory Leak Analysis

  4. Once you click the Profile button, RAD will switch to the Profiling and Logging Perspective. RAD will start your application and begin profiling. It will be shown in the Profiling Monitor View in the perspective.

  5. You can collect a heap dump by clicking the Capture Heap Dump button. Collect at least two heap dumps. Typically, you should take these heap dumps just before and after the sequence of operations suspected to cause leak. Or it could just be at the beginning and end of the program.

    Capture Heap Dump

  6. When you have collected the dumps, terminate the program.

Once you have collected the heap dumps, you can analyze them for leaks by clicking the Analyze for Leaks button.

Analyze for Leaks

It will bring up the Select Leak Analysis Options dialog, in which you should select two heap dumps, set the threshold value to 1, and click the OK button.

Select Leak Analysis Options

RAD will perform leak analysis and bring up the Leak Candidate view. RAD found that there are two potential leak candidates: first is a Vector in LeakExample accumulating String, and the second is a HashMap.

Leak Candidates

RAD allows you to browse the Object Reference Graph in a heap dump. If you right click a leak candidate in the Leak Candidate view and select Show Object References, it will bring up the Object Reference Graph with a highlighted path characterizing the leak.

For example, if you click the first leak candidate (that is, LeakExample class having a Vector that is leaking String objects), RAD will bring up the Object Reference Graph with the path from LeakExample to Vector to String highlighted. This is very helpful for non-trivial programs having complex object containment and ownership. By looking at this path, you can start from the class that is the root of the leak (LeakExample) and trace down to the object that is leaking.

Object Reference Graph

BOOT.BY - Tech Industry News         Free SCBCD 1.3 Study Guide     Free SCDJWS 1.4 Study Guide     SCDJWS 1.4 Quiz     Free IBM Certified Associate Developer Study Guide     Free SCJP 5.0 (Tiger) Study Guide     Free Mock Exam Engine     Free SCWCD 1.4 Study Guide     IBM Test 000-287. Enterprise Application Development with IBM WebSphere Studio, V5.0 Study Guide     Free SCBCD 5.0 Study Guide