Saturday, December 1, 2007

Java Profilers

Why is it so hard to find a good Java Profiler?  My friend and I have a pretty neat Java project at the moment, but it seems that finding a good solution for profiling is difficult.  All I want is something that can tell me what percentage of time is spent in which pieces of my code, maybe create a nice little call graph, and maybe even provide some insight into the memory usage of my app.  Preferably this solution is open source and available for my OS X system.

My first and most promising result was an open source profiler for Eclipse known as TPTP.  Setup was a breeze, but when it comes time to perform, I consistently get the following error: "Agent Controller is unavailable under port 10002.  Make sure that the service is started and the port number is correct under preferences. "  A fix for this problem is supposedly to download an Agent Controller and configure it to use a different port, other than 1002.  This is of absolutely no use to me, as the controller is a windows executable.  As an aside, I haven't found a good way to see what ports are in use on my OS X system.  This is disappointing because from what I can tell, TPTP integrates very nicely with Eclipse, and provides all sorts of great profiling information.  Oh well, the search continues...

Another quick search resulted in Extensible Java Profiler.  This seemed promising at first, but a lack of a binary for my Intel Mac, and an apparent lack in development for the past two years leaves me wary.  I downloaded the source, but had some problems building it.  The documentation is kind of lacking, and despite setting the appropriate environmental variables and following the README, I had no luck building it.

A slightly less open source solution exists in the form of YourKit Java Profiler.  This has a nice interface that is easy to interpret, if not a little bit daunting at first.  I like this solution because it worked right out of the box with Eclipse, and actually contains some nifty monitor and thread monitoring tools.  It also will show you the various performance metrics during run time, which turns out to be an invaluable debugging tool.  Licenses are pretty pricey, but they do offer a free license for open source projects if you contact their sales department.

One solution that is simple, free, and works as advertised is JRat.  Invoking it is simply a matter of adding an extra option to the java command.  This will save its profiling data to a file once your program finishes execution.  From this you can launch their included GUI to see a basic call graph, complete with various performance metrics.  I like this solution because it works and is simple, however it doesn't provide for dynamic analysis (that is, you can't see profiling information while running your app).  It also lacks information regarding memory usage, but, again, I'm partial to solutions that work.

Ultimately, I'm going to stick with YourKit for my open source project, as it has a nice, professional feel to it.  I would have loved to have used TPTP, but its cryptic error with no work-around for my system leaves YourKit a clear winner, in my opinion.  JRat is a great utility if all you are looking for is your typical call graph, complete with execution times.  I hope that the state of open source profilers improves in the near future, but until then, I'll sell out to commercial software.

Introduction

I thought I might take a quick moment to explain the purpose of this blog.  

This is an outlet for technical problems that I come across (and hopefully overcome) in the field of computer science.  Lots of times I find answers to my questions in other people's blogs, and so I hope that someone (even if it's just me ten minutes after I forget my solution) will find this useful for solving their problems.  If anyone stumbles upon this and gains anything from it, please let me know!