This document provides a simple solution to profile Java code running with virtually any application server.

In this document:
     <OptItDir> is the directory where OptimizeIt has been installed. (ex: c:\OptimizeIt\OptimizeIt40D)

1) Requirements

2) How OptimizeIt works

OptimizeIt is divided in 2 parts: In order to integrate OptimizeIt with your application server, you need to start the audit system in the virtual machine of your application server. Once the audit system is started, you can start the OptimizeIt GUI and attach to the audit system. At that point, you get the profiling information for your servlets, JSPs and EJBs just by executing them.
The following chapters explain how to configure your application server to run with the audit system and how to add the OptimizeIt servlet to your application server. The OptimizeIt servlet is a small servlet that conveniently allows you to start the audit system in the virtual machine of your application server.

3) Changing how the virtual machine is started

Virtual machine startup parameters

In order to start profiling with OptimizeIt, the following parameters should be set when starting the virtual machine:

Common ways to set virtual machine startup parameters

These parameters may be set differently depending on your application server, here are different common ways:           CLASSPATH: <OptItDir>\lib\optit.jar
          PATH: <OptItDir>\lib
Examples

JDK 1.1:

    set PATH=C:\OptimizeIt\lib;%PATH%
    set CLASSPATH=C:\OptimizeIt\lib\optit.jar;%CLASSPATH%
    java -noclassgc -Djava.compiler=NONE server.Main

JDK 1.2 or later:

    set PATH=C:\OptimizeIt\lib;%PATH%
    set CLASSPATH=C:\OptimizeIt\lib\optit.jar;%CLASSPATH%
    java -classic -Xrunoii -Xnoclassgc -Djava.compiler=NONE server.Main

4) Adding OptimizeIt servlet to the Application Server

Copy the OptimizeIt servlet <OptItDir>\lib\servlet\OptimizeIt.class to the application server servlet directory.

Note about security issue

If you use a 1.2 or more later virtual machine, you may have to give all permissions to OptimizeIt library for correct execution. You may set these permissions using the administration tool of your application server if it provides one, or by modifying the policy file.

Example: Java Web Server 2.0 policy file is modified to execute OptimizeIt servlet without security exception. The following lines are added to the policy file:

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

5) Profiling with OptimizeIt servlet

Start OptimizeIt's audit system Once this operation is done, you should see a message in your web browser indicating that OptimizeIt's audit system is running.

Attach from OptimizeIt

Now that the application server is running with OptimizeIt profiler, you can start OptimizeIt and attach to the virtual machine.

Note: OptimizeIt does not have a "detach" function. If you press the stop button in OptimizeIt, the servlet engine exits. After doing this, you may need to start it again and to invoke the OptimizeIt servlet to restart the profiler.

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.