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 Guide, a PDF document included in the OptimizeIt package. Note that an HTML version of this document is also available. If you have any questions not answered in the documentation, please contact us at support@intuisys.com. |
This tutorial contains an demonstration program that uses Swing.
That program requires JDK 1.2 or later. For information about installing
and configuring OptimizeIt, see Configuring
OptimizeIt.
This tutorial assumes that Java Developer's Kit (JDK) version 1.2 has been installed at its default location (c:\jdk1.2). If you installed the JDK somewhere else, make sure to point to the installed location when instructed to in the tutorial. To be able to view JDK source code, you must extract the source files from the src.jar file located in your JDK home directory. To perform this operation, type the following lines from the command line (change c:\jdk1.2 to your JDK location if it is installed somewhere else): cd c:\jdk1.2
|
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 application for profiling.
To launch an application
The Edit settings dialog box opens automatically when you first invoke OptimizeIt. If you already have OptimizeIt open, select New from the File menu The Edit settings dialog box closes, OptimizeIt launches the audit system and the example application, and the OptimizeIt window fills with profiling information. |
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 analyze how the example application uses memory. To use the memory profiler
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 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. ![]() Notice that this method is responsible for almost all allocated colors. 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(), and those methods create a new instance of Color at each call. 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.2\src\java\awt\XXX.java and respond "Yes" to a prompt to save the source code location. In the QuickTour example, we use the method Graphics2D.fill3DRect() to paint the colored squares. This method uses Color.brighter() and Color.darker() to get the colors of the borders of the square, to obtain the 3D look. As we always create squares of the same colors, a workaround for this would be to draw 3D rectangles ourselves and reuse colors. The OptimizeIt 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
Click the Show Heap icon. ![]() Click the Show Instance Display icon. ![]() The bottom section displays the allocation backtrace for the instance selected in the middle section. In this case, note that the instance was allocated in the constructor of the QuickTourApp. This image is the OptimizeIt logo displayed on the background of the application. |
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
Click the CPU profiler icon. ![]() Click the Start/stop CPU profiler icon. ![]() Click the Start/stop CPU profiler icon again. The CPU profiler displays profiling information about the recorded session. 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. Notice that the lines are marked with two icons:
Notice that if you leave the mouse cursor above a method called by JComponent.paintWithBuffer(), OptimizeIt displays how much time is spent in that method relative to the total time spent in JComponent.paintWithBuffer(). This can be very useful for fine granularity optimizations after resolving major bottlenecks. Notice that the method JComponent.paint() consumes CPU. It draws the colored squares. The method WGraphics.drawImage() also consumes CPU, to display the OptimizeIt background logo. To display elapsed time and CPU usage together
Click the Inspector button. ![]() |
OptimizeIt can display in real-time high-level performance related
data about the program being tested. Using this feature, you can understand
if a performance problem is related to CPU, memory or both.
To use the virtual machine informationSwitch to the virtual machine information display by clicking the virtual machine mode icon![]() This mode displays in 4 charts real-time information about virtual machine.
|
OptimizeIt allows to generate at any time a snapshot
of the current profiling. The snapshot can then be reloaded in OptimizeIt
for later analysis.
Generating a snapshot
Opening a snapshot
For more information about OptimizeIt, see the OptimizeIt User Guide. |