VisualVM – a neat little tool for Java profiling

In the last couple of weeks, I had to do lots of profiling of our server code. Normally I use YourKit, easy to setup, and it has all the tools I need to do profiling such as CPU and Heap display graphs, force GC option, display of objects with their instance counts and sizes and so on. This time though I had to do profiling when server was under load and YourKit did not behave as I expected. I could see the memory usage in the main graph but when I took a snapshot of the heap, the snapshot took a while, and it didn’t match with the graph I was observing. I’m guessing that since the server is under load, by the time YourKit could take the snapshot, the data was not relevant anymore. This didn’t help me of course, so I turned to other tools.

Luckily, a coworker recommend Sun’s free VisualVM. I think it comes with JDK on Windows, but not on Mac OS, so I had to download it. I was pleasantly surprised with the VisualVM. First, I didn’t have to do anything special to use it, no JVM options or anything like that to make it detect my running Tomcat, it was just displayed under applications:

VisualVM Applications View

The main view included CPU, memory, classes and threads graph as you would expect from a profiler.

VisualVM Main View

The Heap and Thread dump is as easy as right clicking on the application and it was fast and seemed accurate.

VisualVM Thread and Heap Dump

And finally, the Heap Dump showed me the classes taking up the memory, just what I needed…

VisualVM Classes View

One thing that was missing in VisualVM was the “GC roots” option in YourKit. I also did not see much Thread blocking information displayed but I didn’t spend too much time with VisualVM, maybe it’s there. Overall, I’m glad that there’s another free tool out there for Java profiling.

Advertisements

Charles is great!

I mean the Charles Web Debugging tool 🙂 I used it many times before to view HTTP requests/responses but last week, I had to not only view requests but had to slightly change the request to match an edge case. Turns out that, you can do this in Charles. Just right click on the request, click Edit, change the request to whatever you want and Repeat.

charles

Within couple of minutes, I could reproduce the issue. Thanks Charles!