This tutorial explains how to profile a Java Applet running in a web browser with JavaSoft's Java Plug-In 1.3.
Follow the instructions below to start the profiler in your web browser.

1) Prerequisites

2) Configuring the Java Plug-in

Opening the Java Plug-in Properties window

Selecting a supported virtual machine

The Java Plug-in uses by default the virtual machine of the Java 2 RE v1.3 (JRE 1.3). This virtual machine is not yet supported by OptimizeIt. You must configure the Java plug-in to use a supported Java 2 virtual machine. OptimizeIt supports the JDK 1.2.x and the Java 2 SDK v 1.3 (JDK 1.3). In order to configure the Java plug-in to use a different virtual machine:

Adding the required parameters

In order to start your applet with the Java Plug-In, you need to change your HTML file to use the <OBJECT> tag or the <EMBED> tag. The Java Plug-In HTML specification explains how to do this. JavaSoft also provides a tool to convert html files to use the Java Plug-In.

3) Configuring your computer

To profile an applet in your web browser, you need to modify the system CLASSPATH to add OptimizeIt classes and modify the system PATH to add OptimizeIt native code. Here is how to do this:

4) Configuring your .java.policy file

In order to execute correctly, the OptimizeIt classes need to be given the correct rights. This is done in the .java.policy file. The location of that file depends on the version of Windows you are running, the following table shows the different locations:
 
Windows version Location of the .java.policy file
single-user Windows 95/98 C:\WINDOWS
multi-user Windows 95/98 C:\WINDOWS\Profiles\<UserName>
Windows NT C:\WINNT\Profiles\<UserName>

Open the .java.policy file with your favorite text-editor (if the file does not exist create it in the right directory for your Windows version), and append the following lines at the end of the file:

// Permissions for OptimizeIt
grant codeBase "file:<OptItDir>/lib/optit.jar" {
  permission java.security.AllPermission;
};

Note: <OptItDir> should be replaced by the directory where OptimizeIt has been installed on your machine and should use only forward slash / instead of backslash \ (ex: c:/OptimizeIt40D).

5) Starting OptimizeIt audit system

The following applet starts OptimizeIt audit system. Once OptimizeIt's audit system is running you can attach with OptimizeIt and profile all applets running in your web browser.

If the applet below does not start or is invisible, make sure that:

Click on the the Start audit system button below to start OptimizeIt's audit system.
</COMMENT>No JDK 1.1 support for APPLET!!&nbsp;
  • Change the port number if the default port number is already used on your machine. 
  • Disable the memory profiler if you only want to focus on CPU/Time usage. 
  • Enable audit API, if you want to profile a subset of your application and your code calls enableCPUProfiler() or/and enableMemoryProfiler()

Important notes:

6) Attaching from OptimizeIt

After attaching, OptimizeIt displays performance data for all applets running in the web browser with the Java Plug-In. Use the web browser to start your applet and begin the profiling session.

Each time you restart the web browser, you need to come back to this page to start the profiler.

7) Starting OptimizeIt profiler from your Java code

While the applet on this page is convenient to start profiling quickly, you may want to automatically start OptimizeIt's profiler with your applet. That way, you don't have to go to this page to start the profiler before starting your applet.

Starting OptimizeIt profiler can be easily done by using OptimizeIt's API. OptimizeIt's API is documented in OptimizeIt user manual, chapter 9. The following code demonstrates how to start the profiler from your applet's init method.
import intuitive.audit.Audit;
...
...
public void init() {
...
 /* Start OptimizeIt's profiler */
 Audit.start(1470, Audit.PROFILERS_ALWAYS_ENABLED);
...
}

Note: you need to add <OptItDir>/lib/optit.jar to your CLASSPATH in order to compile this code.

Once OptimizeIt's profiler is running, you can attach to the virtual machine from OptimizeIt.

Copyright (c) 1997, 1998, 1999, 2000 Intuitive Systems Inc. All rights reserved. Specifications subject to change without notice.
OptimizeIt is a trademark of Intuitive Systems, Inc.
Java and all Java-based trademarks and logos are trademarks or registered trademarks of Sun Microsystems, Inc. All other brand names and products are trademarks or registered trademarks of their respective holders.