 |
AppPerfect Java Profiler |
Tutorial : Performance Bottleneck Detection
This tutorial provides instructions on how to use AppPerfect Java Profiler product for detecting performance
bottlenecks in a java application. This tutorial assumes you have successfully downloaded and installed
AppPerfect DevTest4J on your machine with the default options.
This document is divided into following sections
- Creating Common Project
- AppPerfect Java Profiler
Within each section, multiple exercises are listed. All exercises assume you have installed
the product in C:\AppPerfect\DevTest folder and will be referred as DEVTEST_HOME
henceforth in tutorial. If you have installed the product in some other folder, modify the instructions
below appropriately.
For this tutorial, create a java file called 'Person.java' copy-pasting the
code shown below and compile it.
import java.util.*;
import java.io.*;
public class Person
{
private final Date birthDate;
public Person(Date birthDate)
{
this.birthDate = birthDate;
}
public boolean isBabyBoomer()
{
Calendar gmtCal = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
gmtCal.set(1946, Calendar.JANUARY, 1, 0, 0, 0);
Date boomStart = gmtCal.getTime();
gmtCal.set(1965, Calendar.JANUARY, 1, 0, 0, 0);
Date boomEnd = gmtCal.getTime();
return birthDate.compareTo(boomStart) >= 0 &&
birthDate.compareTo(boomEnd) < 0;
}
public static void main(String[] args) throws IOException
{
final Person p = new Person(new Date());
new Thread(new Runnable()
{
public void run()
{
for(int i = 0; i < 1000; ++i)
{
p.isBabyBoomer();
}
}
}).start();
System.out.print("press any key to continue...");
InputStreamReader reader = new InputStreamReader(System.in);
reader.read();
reader.read();
}
}
Creating Common Project
Exercise 1: Launch AppPerfect DevTest4J
Action:
- Click on Start -> Programs ->AppPerfect DevTest4J x.x.x -> AppPerfect DevTest4J
- On launching AppPerfect DevTest4J a Welcome page will be displayed. Go through the brief description
given for each product and click on the product icon to view its perspective.
NB: Welcome page is displayed only when DevTest4J x.x.x is launched and last time no project
was opened.
- To switch between different product perspectives click on corresponding project button in toolsbar.
Exercise 2: Creating a Common Project
Action:
- Launch the Common Project Wizard by clicking File ->New... menu option.
The New Project wizard will be launched.
- Go through the instruction provided on top of the General tab.
- Keep the default project name and location for the purpose of this exercise. We don't have to provide
"Notification" settings or "Remote Application/AppServer" settings for this exercise.
Click on the Next button.
- In the Source tab provide the location of source file "Person.java". Click the Next button.
- Use the default JDK which is bundled with AppPerfect DevTest4J and click on the Next button.
- In the "Environment" tab provide the location of "
Person.class" file.
- Click on "Verify Classpath" button to validate the classpath.
- Classpath validation dialog will be launched and the classpath will be verified. A message saying
that the classpath specified is correct should be displayed. Click on the "OK" button.
Click on the Next button.
- In the "Target" tab select project type as "LOCAL".
- For working folder provide the path to the folder containing the the "
Person.class"
file.
- Specify the Main Class as "Person".
- Select the "Launch target application automatically" checkbox. Click on the Finish button.
- A confirmation message saying that the project is saved will be displayed. Click on the OK button.
AppPerfect Java Profiler
NB:Please follow the steps provided in the "Creating Common Project" section to first create a common project,
then proceed further.
Exercise 1: Define a Java Profiler project
Action:
- Once the common project is successfully created another dialog - Define Project Properties dialog -
will be displayed.
- Read the instructions at top of each tab.
- Go through the descriptions for Profiling Types. Keep the default Development Mode Profiling and
select Profiling Options tab.
- Study the descriptions of the three profiling options. You can configure Filters using Configure Filters
option.Use default values.
- Study the descriptions of Instrumentation Options. Use the default: Dynamic Instrumentation enabled.
- Study the changes indicated in the Launch Instructions tab. AppPerfect Java Profiler must modify
your application server's startup file to add instructions to load the profiling agent, etc. This tab
shows the exact changes that needs to be made to the startup script. AppPerfect Java Profiler
understands how to configure startup scripts for most commonly available application servers.
Also, since it does not modify the original file and instead makes a copy to store the modifications,
it is almost always desirable to let AppPerfect Java Profiler make the changes. Click OK button.
- Click through all the menu items to familiarize yourself with the available features and
how to access them.
- Click on Tools ->Options... menu item. Click on the JDKs tab and ensure that the JDK path has
been set correctly. This is the path provided for JDK during installation of AppPerfect DevTest4J. You may
modify the path or add new JDK through this dialog box. It is critical that a correct version of JDK is
available for AppPerfect DevTest4J to perform correctly.
- Click Help -> Table of Contents menu item to see AppPerfect DevTest4J product documentation.
Exercise 2: Start Profiling
Action:
- To start profiling click on Project -> Run from the menubar.
- A progress message will be shown while target application is launched.
- Observe the dynamic updation of data in the default (Summary) view. You can see various profiling
metrics such as heap memory usage, object instance count and Thread count.
- From the Navigational Tree select CPU Profiling node.
- On the right hand side, expand the Execution Time, Cumulative Execution Time and Number of Invocations
nodes and you will see that the isBabyBoomer() method has taken 343 ms to execute which is significant
as compared to the other methods and the cumulative execution time is 687ms.

- You can also check out Methods and
Invocation Tree views for further details.
You can view help to get more details about these views.
- Stop Profiling by selecting Project -> Stop.
- Click Yes to stop profiling.
- Click No to collect information from the target application.
- Now modify the Person.java file by replacing it with the following:
import java.util.*;
import java.io.*;
public class Person
{
private final Date birthDate;
public Person(Date birthDate)
{
this.birthDate = birthDate;
}
/**
* The starting and ending dates of the baby boom.
*/
private static final Date BOOM_START;
private static final Date BOOM_END;
static
{
Calendar gmtCal =
Calendar.getInstance(TimeZone.getTimeZone("GMT"));
gmtCal.set(1946, Calendar.JANUARY, 1, 0, 0, 0);
BOOM_START = gmtCal.getTime();
gmtCal.set(1965, Calendar.JANUARY, 1, 0, 0, 0);
BOOM_END = gmtCal.getTime();
}
public boolean isBabyBoomer()
{
return birthDate.compareTo(BOOM_START) >= 0 &&
birthDate.compareTo(BOOM_END) < 0;
}
public static void main(String[] args) throws IOException
{
final Person p = new Person(new Date());
new Thread(new Runnable()
{
public void run()
{
for(int i = 0; i < 1000; ++i)
{
p.isBabyBoomer();
}
}
}).start();
System.out.print("press any key to continue...");
InputStreamReader reader = new InputStreamReader(System.in);
reader.read();
reader.read();
}
}
- Recompile Person.java.
- Select Project -> Run to start profiling.
- From the Navigational Tree select CPU Profiling node.
- On the right hand side, expand the Execution Time, Cumulative Execution Time and
Number of Invocations nodes and you will see that the isBabyBoomer() method has taken 15 ms to execute
and the cumulative execution time has also fallen to 93ms.

- This indicates that isBabyBoomer() method was causing a performance
bottleneck, and by certain minor modifications, the execution time has reduced drastically!
- You can also check out Methods and
Invocation Tree views for further details.
You can view help to get more details about these views.
- Stop Profiling by selecting Project -> Stop.
- Click Yes to stop profiling.
- Click No to collect information from the target application.