OptimizeIt quick tour

 

Welcome to the OptimizeIt Java profiler. 

This tutorial guides you through the basic features of OptimizeIt software. More information is available in the OptimizeIt User Manual, an HTML document included in the OptimizeIt package. If you have any questions not answered in the documentation, please contact us at support@intuisys.com.


Installing OptimizeIt

This tutorial assumes that OptimizeIt has been installed and is properly configured with the Java virtual machine. For information about installing and configuring OptimizeIt, see Configuring OptimizeIt.

This tutorial also assumes that Java Developer's Kit (JDK) version 1.1.7 has been installed at its default location (c:\jdk1.1.7). If you installed the JDK somewhere else, make sure to point to the installed location when instructed to in the tutorial.


Profiling a Java program

To profile a Java program, OptimizeIt launches your Java program and the OptimizeIt audit system. The audit system runs in the test virtual machine and reports profiling information to OptimizeIt. The following steps show how to launch a simple applet for profiling.

To launch an applet

  1. Run OptimizeIt.
    The Edit settings dialog box opens automatically when you first invoke OptimizeIt. If you already have OptimizeIt open, select New from the File menu. 
  2. Select Applet in Part 1 of the dialog box. 
  3. Click the Browse button at the right of the Applet HTML file or URL box. 
  4. Select C:\jdk1.1.7\demo\awt-1.1\lightweight\Gauge\example.html 
  5. Click the OK button to return to the Edit settings dialog box. 
  6. Click the Start Now button.
    The Edit settings dialog box closes, OptimizeIt launches the audit system and the example applet, and the OptimizeIt window fills with profiling information. 


Using the memory profiler

When you first launch a test program, the OptimizeIt window opens to the memory profiler. The window can also display the CPU profiler, as the tutorial describes later.

The memory profiler lists the classes included in the test program and the real-time count of the number of instances allocated for each class. This is Heap mode. It allows you to see object allocations as they occur. The following steps show how to use the controls in the memory profiler to analyse how the example applet uses memory. 

To use the memory profiler

  1. Click the Instance count column header to sort classes by number of allocated instance. 
  2. Limit the class list to java.awt classes.
    The Filter box at the bottom of the window shows the classes being displayed. To show only java.awt classes, type java.awt.* followed by a Return in the box. 
  3. Display backtrace information for the java.awt.Color class.
    The backtrace information shows the methods involved in the allocation of instances of this class.
    To switch to Allocation Backtrace mode, double-click the class name in the list. You can also click the Allocation Backtrace button.
  4. Expand the line EventDispatcherThread.run().
    Expand the top-level method to show all of the methods involved in the allocation. 
  5. Select the line Gauge.paint().
    Notice that this method is responsible for almost 99% of all allocated colors.
    At the bottom of the window, OptimizeIt lists the line responsible the instance allocations. 
  6. Double-click the line Graphics.fill3DRect() to show the source code which allocates the instances of Color.
    The source code can help you understand why this drawing routine allocates so many instances of the class. The fill3DRect method allocates many colors because it calls Color.brighter() and Color.darker().
    Note: The first time you use OptimizeIt it may not have the path to the example source code. If OptimizeIt prompts you for the source code location, browse to c:\jdk1.1.7\src\java\awt\XXX.java and respond "Yes" to a prompt to save the source code location. 

Using the memory profiler allows you to minimize temporary object allocations. Temporary objects are usually quick to allocate, however they keep the garbage collector busy. With most available Java virtual machines, any Java program may freeze for several hundred milliseconds when the garbage collector is busy. If too many temporary objects are allocated, the application can feel really slow to the user because of these interruptions.

The OptimizeIt Professional Edition memory profiler also allows you to understand why an object is not freed by the garbage collector. For example, this can be useful to verify that a document storage is really garbage collected when a document is closed.

The following steps describe using the memory profiler to determine whether an instance is being or can be garbage collected.

To display information about a specific instance

  1. Return to Heap mode in the memory profiler.
    Click the Show Heap icon.
  2. Select the row java.awt.MenuItem
  3. Display the instance information.
    Click the Show Instance Display icon.

 

OptimizeIt displays the string representation of the instance in the top section of the window. The middle section displays which objects reference the selected instance and recursively which objects reference the object that references the instance. In this case, because the MenuItem object is referenced, it cannot be garbage collected. 

The bottom section displays the allocation backtrace for the instance selected in the middle section. In this case, note that many of these MenuItems were allocated during the initialization of the AppletViewer method. These are the menu items for the menu "Applet" in the example program.


Using the CPU profiler

While the memory profiler allows you to understand how to minimize object allocations, the CPU profiler allows you to understand how time is spent by objects. The CPU profiler can be seen as a recording device inside the Java virtual machine. The following steps describe how to produce time and CPU-usage information for your test program.

To use the CPU profiler

  1. Switch to the CPU profiler display.
    Click the CPU profiler icon.
  2. Start recording the CPU usage of the example program.
    Click the Start/stop CPU profiler icon.
  3. Let the applet run for approximately one minute. 
  4. Stop the recording.
    Click the Start/stop CPU profiler icon again.
    The CPU profiler displays profiling information about the recorded session. 
  5. Select a specific thread to examine.
    Click the drop-down box under the title "CPU profiler output". This drop-down box displays all threads currently running in the test virtual machine. Select the AWT-EventQueue-0 thread.
    The AWT-EventQueue-0 thread is the thread used by AWT to process events such as repaint events. 
  6. Expand the line EventDispatchThread.run().
    Notice that most of the time is spent dispatching events while some time is spent waiting for events. 
  7. Expand all of the methods under Component.dispatchEvent().
    Control-click the '+' icon of the line to expand all of the nested methods.
    Notice that the lines are marked with two icons:
    The method immediately calls another method.
    The method actually consumes time.
    In this example the AWT-EventQueue-0 thread always processes repaint events. Most of the time is spent in PrettyPanel.paint() 
  8. Select the line PrettyPanel.paint().
    Notice that if you leave the mouse cursor above a method called by PrettyPanel.paint(), OptimizeIt displays how much time is spent in that method relative to the total time spent in PrettyPanel.paint(). This can be very useful for fine granularity optimizations after resolving major bottlenecks. 

To analyse where a thread sits idle, the CPU profiler can display pure CPU use and time use at the same time. Use this feature to choose a caching strategy, for example. By default OptimizeIt displays pure CPU use information. 

To display elapsed time and CPU usage together

  1. Open the Inspector.
    Click the Inspector button.
  2. Unselect the option Display CPU usage only. 

For more information about OptimizeIt, see the OptimizeIt User Manual

Top