This tutorial explains how to
profile Java code running with Java Web Server 2.0 and JDK 1.1.x or JDK
1.2
In this document:
<OptItDir> is the directory where
OptimizeIt has been installed. (ex:
c:\OptimizeIt\OptimizeIt40D)
<JavaWebServer> is the directory
where Java Web Server has been installed (ex: c:\JavaWebServer2.0)
1) Configuring the Java Web Server
-
Modify your CLASSPATH and PATH environment variables
to include the following directories:
CLASSPATH: <OptItDir>\lib\optit.jar
-
Copy the OptimizeIt servlet (<OpItDir>\lib\servlet\OptimizeIt.class)
into the Java Web Server servlet directory (<JavaWebServer>\servlets)
-
If you are using JDK 1.2:
-
edit the file <JavaWebServer>\security\jserv.policy and append
at the end of the file:
/* Permissions for OptimizeIt */
grant codeBase "file:<OptItDir>/lib/optit.jar" {
permission java.security.AllPermission;
};
Important note: the <OptItDir> of the line grant
codeBase "file:<OptItDir>/lib/optit.jar" should use / (slash) as
file separator instead of \ (backslash).
-
Also edit the file <JavaWebServer>\properties\server\javawebserver\vmargs.txt
and append at the end:
# OptimizeIt arguments (JDK 1.2)
-Xrunoii
-Xnoclassgc
-Djava.compiler=NONE
-DOPTITDIR="<OptItDir>"
-
If you are using JDK 1.1.x, edit the file <JavaWebServer>\properties\server\javawebserver\vmargs.txt
file and append at the end:
# OptimizeIt arguments (JDK 1.1)
-noclassgc
-Djava.compiler=NONE
-DOPTITDIR="<OptItDir>"
2) Launching the Java Web Server
-
From the command line, go to the bin directory of the Java Web Server:
-
If you want to start the Java Web Server with the JRE 1.1.7 (installed
with Java Web Server 2.0), invoke jserv:
-
If you want to start the Java Web Server with another virtual machine,
invoke jserv with the following option:
jserv -javahome <JavaHome>
Where <JavaHome> is the path to your JDK (c:\jdk1.2.2
for example).
Make sure to have the correct options in the vmargs.txt file matching
your vm version .
3) Start the OptimizeIt servlet
-
Invoke the servlet from a web browser. The URL should
look like http://localhost:8080/servlet/OptimizeIt
-
In the HTML page that the servlet provides, change
the port number if necessary.
-
Select the "Disable memory profiler" option if you
only want to focus on CPU usage.
-
Select "Enable OptimizeIt's audit system API" if
your code enables/disables the profiler by using OptimizeIt's audit system
API.
-
Press the "Start OptimizeIt Audit System" button
to start the profiler.
Once this operation is done, you should see a message
in your web browser indicating that OptimizeIt's audit system is running.
4) Attaching from OptimizeIt
Now that Java Web Server is running with OptimizeIt profiler, you can start
OptimizeIt and attach to the virtual machine.
-
Start OptimizeIt from the Start menu.
-
Close the Edit Settings panel by pressing the OK button.
-
From the Program menu, select Attach.
-
Change the port number and the hostname if necessary.
-
Press the Attach button.
Note: OptimizeIt does not have a "detach" function. If you press the stop
button in OptimizeIt, the Java Web Server is stopped. You will have to
restart it from the administrator page (http://localhost:9090)
and to invoke the OptimizeIt servlet to restart the profiler.
5) Filtering resources used by the Java Web Server
OptimizeIt provides filters for filtering resources used by the Java Web
Server. In order to use filters, you must create an OptimizeIt setting
for the profiling session, turn on the the Java Web Server filter,
and then attach by using the Attach now button or pressing the play button.
-
Start OptimizeIt's audit system by using OptimizeIt's
servlet.
-
Start OptimizeIt from the Start menu.
-
Close the settings editor by pressing OK.
-
From the File menu, select New
-
In the Edit Settings panel select Remote
Application in the Program type part.
-
Change the hostname or the port number if necessary.
-
Switch to the Filters section by clicking the
Filters
tab.
-
In the table, find the line with the name Java
Web Server.
-
If you want to ignore CPU or time consumed by
the Java Web Server, check the Ignore CPU usage column on that line.
-
If you want to ignore object allocations performed
by the Java Web Sever, check the Ignore Memory usage column on that
line.
-
Press the Attach now button.
Note: OptimizeIt settings can be saved for subsequent usage. This is done
by using the save menu.
6) Starting OptimizeIt profiler from your Java code
While the OptimizeIt servlet is convenient to start profiling quickly,
you may want to automatically start OptimizeIt profiler with one of your
servlet. That way, you don't have to invoke the OptimizeIt servlet to start
the audit system before testing your servlets.
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
servlet:
import intuitive.audit.Audit;
...
static boolean isProfilerStarted = false;
if(!isProfilerStarted) {
/* Start OptimizeIt's profiler */
Audit.start(1470, Audit.PROFILERS_ALWAYS_ENABLED);
isProfilerStarted = true;
}
...
Note: you will need to add <OptItDir>\lib\optit.jar to your
CLASSPATH to compile this code
Once OptimizeIt's profiler is running, you can start OptimizeIt and
attach to the servlet engine.
Copyright (c) 1997, 1998, 1999, 2000 ,2001 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.