Java Profilers - Which One Are You Using?
splitPersonality asks: "Our Java programmers are researching various profilers to use in-house. We would appreciate some feedback from other shops that are using Java profilers. Along with the specific product, would you please include reasons behind your choice? If you now have misgivings about the one you or your shop chose, please let me know about those, as well."
Believe it or not, I do most of my profiling by running by using:
r ead=y'
alias java-prof='java -agentlib:hprof=cpu=samples,depth=8,interval=1,th
And then I view the results with PerfAnal.jar (google will find it for you), an extremely old (and even ugly) GUI that is also clean and mean. It's also free (beer? not sure.)
I've tried a number of other profilers (JFluid, YAJP, etc.), and they usually prove to be too much of a pain in the ass, or just give nonsense data.
Mind you, I'm usually interested in pure CPU performance-- tightening inner loops and things like that. I don't care too much about memory profiling or garbage collector behavior since I've long since eliminated most allocations in my performance-sensitive code.
Sadly, no profiler really satisfy me. Usually, line-by-line CPU usage just can't be computed given the optimization performed by HotSpot: you'll see trace-by-trace CPU usage, where a trace covers several lines of code. It makes it hard to know exactly where the CPU time is being spent. (You can run with -Xint, but the performance is so different without HotSpot that it's not helpful.)
I've used the Eclipse Test & Performance Tools Platform with pretty good results:
i ling-Tool/tptpProfilingArticle.html
http://www.eclipse.org/articles/Article-TPTP-Prof
My Web Page
I have used JMeter a couple of times to detect bottlenecks and synchronization problems with web apps. Very simple to set up and run just using a GUI. Apart from http/https it can appearently call java methods, EJBs etc too, but I haven't tried that. I think this tool is easier to use for stress testing rather than going through a whole use case. Also, when running against a web server of course it just tells you that something is slow, not what.
:-)
At Java One I talked to some fellow Swedes who were a bit disappointed with JProbe, they claimed it was a bit of a resource hog and that they had found a better more light weight open source library to use instead. I've looked through my notes, but it seems I didn't write down the name of the one they recommended. Darn.
Symantec had an app that seemed pretty impressive, though I don't know how much they charge for it. I think it was this one. I remember them because unlike most who just had a lottery for prizes, you actually had to run the demo to be able to answer their quiz. Pretty clever, made people remember and gave you a better chance of winning because most people wouldn't bother. I won a PSP.
Also at Java One this year Sun had loads of labs and talks on profiling tools and frameworks that come with the JDK itself these days - JMX (especially in combination with DTrace if you run on Solaris), jconsole, jmap, jhat.
And then of course there is this whole site...
Being bitter is drinking poison and hoping someone else will die
Interesting to see this question come up just a week after I was in deperate need of a profiler. I downloaded JProfiler 4.2 and got a test-license (for 10 days or so). (oh, and I work on a Mac, and it has downloads for 3 platforms).
The problem I had was the following. We upgraded our system from the previous stable release of our opensource CMS to the new stable release. We knew a lot had changed in the internals, so we did a good functional testround and fixed quite a few issues. Quite confident in the new software (it appeared faster) we deployed on our live environment. Looked fine, until after a few hours it didn't stop Full-GC-ing, the symptoms of a memory leak. (and yes, I know how to tune my VM to optimum GC performance).
All I can say about JProfiler is that after only 3 or 4 days, I found all memory leaks, several performance issues (even things like 'for (int i=0; istr.length(); i++)'), and got a real good feel about the bottlenecks inside the application. My manager just bought me a $400 or so license, and it's money very well spent.
So next week we'll go live again, but now with a piece of software of which we exactly know how it behaves.
I suggest you download the evaluation version and just give it a try. I can't imagine putting a release live anymore, without having profiled it for at least a day.
--
If code was hard to write, it should be hard to read
Oh, I saw I forget to mention the features I used:
- attach the profiler to a remote machine (in our case a test environment)
- trace memory allocations: you can see live which objects live in the JVM
- memory snapshot, this makes a snapshot in which you can see which objects live, which other objects have references to it, where it was allocated etc. So if you have a mem-leak, you can find out exactly why the object wasn't GC'ed
- cpu profiling: see which methods take how many percent of your processing, and fold open the call-tree for such a method to see which methods it calls and how much time is spent there.
--
If code was hard to write, it should be hard to read
I second this recommendation. I haven't used it for a few years, but the first time I did I was blown away by the level of detail you could get. Very easy to drill down to just about any level of detail you could want. ISTR it also had breakpoints on garbage collection, so you could examine the heap before and after GC. Very handy for making sure that something you thought should be reclaimed actually was, and very easy to trace the errant references if it wasn't.
It seemed expensive at first, but in two days I was able to get a 30% speed improvement in the main body of our code, and found a nasty resource leak in the in-house framework we were using that I know they had spent several developer-weeks trying to track down.
I'm not sure who owns it now (I think it was JProbe Inc when we ordered it, but by the time it shipped it was already owned by someone else, and I'm sure it's been sold at least once since then), but it's definitely one worth checking out.
Just junk food for thought...
It also works in concert with other performance tools from Symantec for other tiers in the enterprise, database tools, network tools, web server tools, web client tools. Then the tool suite combines all this 'tier level' information into an enterprise view and gives you a view of performance of the entire data center so you can determine which tier in the enterprise is the performance hog.