This tutorial explains how to profile Java code with ServletExec 2.2.
In this document, <OptItDir> is the directory where OptimizeIt has been installed. (ex: c:\OptimizeIt\OptimizeIt302D)
1) Configuring ServletExec for OptimizeIt
If you use ServletExec for Microsoft IIS or Netscape/NSAPI
- Modify your PATH environment variable to include <OptItDir>\lib
- Use your browser to go the ServletExec VM Settings admin page (http://localhost/servlet/admin).
- Make sure you use a Sun 1.1.x VM, by reading the JAVA VM line on the top of the page. When using ServletExec
for Netscape NES or Microsoft IIS, OptimizeIt only allows to profile servlets running in Sun 1.1.x VM. The
reason is ServletExec doesn't allow to start the JVMPI with those servers, which is necessary to profile 1.2 VM.
In order to change the VM used by ServletExec, report to the ServletExec User Guide, in the Appendices, look for
the "JDK/JRE Installation" section.
- Disable Class GC, disable the JITC, select Sun Classic for Java VM and add <OptItDir>\lib\optit.jar
to the classpath.
- Submit your changes by clicking the Submit button.
- Re-initialize ServletExec by restarting the web server, this requires stopping the service. In order to restart
the service :
- From the start menu, select Settings/Control Panel.
- In the control panel, double click on the Services icon.
- In the Services property window, find in the service list the service of your server (Netscape Enterprise
Server or IIS) and select it.
- Click on stop, then on start.
If you use ServletExec for Apache
- Modify your PATH environment variable to include <OptItDir>\lib
- Edit the ServletExecApache.bat located at ServletExec base directory. This file contains one line which should
look like this :
"<JavaHome>\lib\java" -classpath "..." ServletApache -root "..." -mimetypes
"..."
Where <JavaHome> is the directory that contains the vm that will execute the servlets, and "..."
stands for various paths separated by semicolons ";".
Add the following options before the -classpath :
- if vm is jdk 1.1 : -noclassgc -Djava.compiler=NONE -DOPTITDIR=<OptitDir>
- if vm is jdk 1.2 : -classic -Xrunoii -Xnoclassgc -Djava.compiler=NONE -DOPTITDIR=<OptitDir>
In both cases, add <OptItDir>\lib\optit.jar to the classpath specified after the -classpath.
2) Installing and starting the OptimizeIt servlet
OptimizeIt includes a simple servlet that allows you to start OptimizeIt profiler in the servlet engine. Once
the profiler runs in the servlet engine, you can attach to the servlet engine from OptimizeIt.
- Copy the OptimizeIt Servlet class file <OptItDir>\lib\servlet\OptimizeIt.class
into your ServletExec servlet classes directory. (ex: c:\Apache\ServletExec\Servlets)
- If you use Apache, start Apache server and then start ServletExec by running ServletExecApache.bat.
- Invoke the servlet from a web browser. (ex: http://localhost/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.
3) Attaching from OptimizeIt
Now that ServletExec 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
servlet engine exits and automatically restarts. After doing this, you need to invoke the OptimizeIt servlet to
restart the profiler.
4) Filtering resources used by ServletExec
OptimizeIt provides filters for filtering resources used by ServletExec. In order to use filters, you must create
an OptimizeIt setting for the profiling session, turn on the ServletExec 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 NewAtlanta ServletExec.
- If you want to ignore CPU or time consumed by ServletExec, check the Ignore CPU
usage column on that line.
- If you want to ignore object allocations performed by ServletExec, 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.
5) 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 compile this code
Once OptimizeIt's profiler is running, you can start OptimizeIt and attach to the servlet engine.
Copyright (c) 1997, 1998, 1999 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.