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
You need to have the Java Plugin 1.3 installed. The plugin is installed
when you install the Java 2 SDK v 1.3 (JDK 1.3) or the Java 2 Runtime Environment
v 1.3 (JRE 1.3). You can download this software from http://java.sun.com/j2se/.
You also need to have one of the following browser installed:
Netscape Communicator 4.x or later
Internet Explorer 4 or 5
2) Configuring the Java Plug-in
Opening the Java Plug-in Properties window
From the start menu, select Settings/Control Panel.
In the control panel, double click on the Java Plug-in icon.
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:
Click on the Advanced tab in the Java Plug-in Properties window
In the list box of the Java Runtime Environment section, select
the virtual machine you want to use. If it does not appear in the list
box, select Other... and enter the path to your virtual machine
directory in the Path field (example: e:\jdk1.3).
If you have selected the JDK 1.2 make sure to unselect the option Enable
Just In Time Compiler. If you are using the JDK 1.3, make sure it is
selected.
Adding the required parameters
Click on the Basic tab of the Java Plug-in Properties window.
Make sure that Enable Java Plug-In option is selected. It is also
recommended to select the option Show Java Console.
If you are using JDK 1.2, enter the following line in the Java Run Time
Parameters field:
-classic -Xrunoii -Xnoclassgc
If you are using JDK 1.3, enter the following line in the Java Run Time
Parameters field:
-classic -Xrunoii
When done, press the Apply button and close the Java Plug-in Properties
window.
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:
Opening the environment settings
From the start menu, select Settings/Control Panel.
In the control panel, double click on the System icon.
In the system property window, select the Environment tab.
Changing the PATH environment variable to include OptimizeIt native
code.
In the top section, select the row starting with Path.
Click on the Value text field. Use the right arrow key to scroll
to the end of the text.
Type ;<OptItDir>\lib, where <OptItDir>
is the directory where OptimizeIt has been installed on your machine. (ex:
C:\OptimizeIt40D)
Click on the Set button.
Changing the CLASSPATH environment variable to include OptimizeIt
classes.
In the User variables list, select the CLASSPATH environment
variable. If this variable does not exist yet, click on the first row in
the list and type CLASSPATH in the Variable field,
then select the value and delete all characters to reset the value.
In the Value field, insert in front of the current value <OptItDir>\lib\optit.jar
where <OptItDir> is the directory where OptimizeIt has
been installed on your machine. (ex: C:\OptimizeIt40D)
Click on the Set button.
After changing PATH and CLASSPATH, you need to restart your web
browser.
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:
you have properly installed JavaSoft's Java Plug-In (step 1 above)
you have properly changed your CLASSPATH environment variable. (step
2.3 above).
Click on the the Start audit system button below to start OptimizeIt's
audit system.
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:
Some web browsers destroy applets almost immediately after switching to
another page. Create a new browser window to load your applet and keep
this page visible.
With Internet Explorer, you should only create a new browser using the
menu File->New->Window in Internet Explorer. Creating a new browser from
another location (from the shortcut on the desktop, from the start menu...)
leads to the creation of a new virtual machine where the audit system has
not been started and which is therefore not profiled.
6) Attaching from OptimizeIt
Start OptimizeIt
Close the info panel and the Edit settings window by pressing the
OK
button.
From the Program menu, select Attach...
Change the port number if you have changed it in the applet
Press the attach button
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.