Code Analysis Tools

The following third-party analysis tools are not part of the normal development cycle, but are useful in helping to identify bugs and weaknesses in the source code.

Clover

Clover is a proprietary test coverage tool. After setting the environment variable CLOVER_JAR to point to your installation, you can use ant clover to generate a report.

Rice Java PLT

On the Rice Computer Science department network, CLOVER_JAR should point to /home/javaplt/packages/clover-ant-1.3.14/lib/clover.jar.

YourKit Java Profiler

The YourKit Java Profiler is a powerful proprietary profiler for Java programs that has been lincensed to the DrJava open source project free of charge. It may only be used for developing and improving DrJava and individual licenses for each individual developer are required; they also need to be renewed from time to time. All of this has been generally unproblematic by emailing sales@yourkit.com. Please do not jeopardize our very good relationship with YourKit by using it in ways not approved.

  1. Getting YourKitYou can download YourKit from the URL above, but have also installed YourKit into the javaplt account on CSnet. Here are instructions if you want to use it. Please note that this is for the Linux environment on CSnet. For Windows and MacOS, or away from CSnet, these steps don't apply.

  2. Location of YourKit on CSnetYourKit is located in the directory /home/javaplt/packages/yjp-6.0.11 . You should add the bin path to your PATH environment variable. Make the following directory accessible from everywhere: /home/javaplt/packages/yjp-6.0.11/bin . That gives you access to the two most important scripts, yjp.sh and yjpjava .

  3. Adding the LibraryBefore you can use Yourkit, you have to set the following environment variable: export LD_LIBRARY_PATH="/home/javaplt/packages/yjp-6.0.11/bin/linux-x86-32" . If you already have an LD_LIBRARY_PATH variable, then you should extend it by adding a colon and the path: export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/home/javaplt/packages/yjp-6.0.11/bin/linux-x86-32" .

  4. Starting YourKitTo start YourKit, run the following script from the command line: yjp.sh & . The & at the end will make YourKit run in the background, i.e. you can still use the same command line window you've been using. The first time you start YourKit, it should ask you for your license information. If you are a member of the core DrJava development team, you should have by now received your personalized license key.

  5. Starting the Application to ProfileYou need to pass a special command line argument to your java executable when you're running a program that you want to profile: -agentlib:yjpagent . To make that easier to remember, I have written a script that passes that arguments, and all the argument passed to the script, to java. It's located in the same directory as Yourkit: /home/javaplt/packages/yjp-6.0.11/bin/yjpjava . If you added YourKit to your path in step 2, it should be directly accessible. If you want to use it to run a program that you would normally start with: java MyClass . now just use: yjpjava MyClass . Here is a more complicated example to start DrJava. Instead of writing java -cp drjava-15.jar edu.rice.cs.drjava.DrJava . now write the following, which avoids the restart, which may cause trouble: yjpjava -cp drjava-15.jar edu.rice.cs.drjava.DrJavaRoot . For this to work, you have to make sure that you have the tools.jar file on your Java CLASSPATH environment variable. Regardless, the application you just started should launch now.

  6. Starting to ProfileWhen you actually want to record usage times and counts, press the "Start CPU Profiling" button. That will open another pane. There are two selections, "Sampling" and "Tracing", and as far as I know, "Sampling" records times only and doesn't give you invocation counts and call stacks, but is faster. "Tracing" is a lot slower but gives you more information.

  7. Viewing DataWhen you want to view the data, i.e. when you're done performing the action you want to profile, press the "Capture Snapshot" button. That will bring up a dialog that tells you the file name as which the snapshot has been saved, and it asks you whether you want to open the snapshot. You probably want to press "Open" if you want to look at the data right now.

  8. Taking a Snapshot Stops ProfilingNote that taking a snapshot stops profiling, so if you want to continue to profile, you need to press the "Start CPU Profiling" button again.

  9. Sorting MethodsOn the page that displays CPU snapshot informations, there are lots of ways to gather information. I haven't explored everything. I found selecting "Method List" on the left the most useful. That will give you a lsit of all methods that were called, and you can sort by name, time, own time, and invocation count (if you used tracing). Time includes time spent in calls to other methods, i.e. the time from method entry to method exit. Own time is only the time spent in the actual method, i.e. the time from method entry to method exit EXCLUDING the time spent in other methods that were called.

  10. Finding the HotspotUsually I found a very sharp break between the times, i.e. going from 40 seconds in some methods (that were probably in a call chain) to 5 seconds. My intuition tells me that the last method to have a lot of time spent is one of the "hot spots". You should also look at the invocation count: The program may spend a lot of time in a method, but if it's called very often, that may not mean very much.

FindBugs

FindBugs is an open-source static analysis tool that tries to identify Java bugs. After setting the environment variable FINDBUGS_HOME to point to your installation, you can use ant findbugs to generate a summary of possible bugs.

Rice Java PLT

On the Rice Computer Science department network, FINDBUGS_HOME should point to /home/javaplt/packages/findbugs.

If necessary, the findbugs-excludes property in the Ant script can be edited to filter out unwanted warnings.