Geertjan is a DZone Zone Leader and has posted 457 posts at DZone. You can read more from them at their website. View Full User Profile

VisualVM: Free and Open Source Java Troubleshooter

02.21.2008
| 56400 views |
  • submit to reddit

The 3rd milestone of VisualVM was released a few days ago. That release marks the open sourcing of this troubleshooting tool, together with the further polishing of its API. Perhaps this is therefore an opportune moment to spend some time exploring its main features. The key to understanding VisualVM is to see it as a bundling of a number of JDK tools, such as JConsole, jstack, and jinfo, combined with several new and advanced profiling capabilities. The tool is designed for both production and development use and further enhances the capabilities of monitoring and performance analysis for the Java SE platform.

All Java applications running on the same system as the VisualVM are listed in the "Applications" tab on the left side of the tool. Java applications on remote systems are also shown, under the "Remote" node. Information specific to each of the applications, which includes VisualVM itself, is displayed in the main part of the tool. For each application, there is an "Overview" tab showing general information, such as process ID and the Java version used to run the application.

The "Monitor" tab shows graphs for the application's heap, permanent generation, threads, and classes. The total heap space is shown in one color and the amount of heap space in use is shown in another. Below, you see the "Threads" tab, shwoing thread visualization for VisualVM itself:

VisualVM can read and interpret binary heap dump files. You can either generate a heap dump from within the VisualVM or you can open one, via the "Profile" menu at the top of the tool. The heapwalker part of the tool can then provide information about the dump, as shown in the next two screenshots:

The heapwalker can help you track down memory leaks. The instances view, shown above, shows all object instances of a class, from where you can find the nearest garbage collection root points.

VisualVM is pluggable. It comes with a Plugin Manager which already contains three plugins:

The VisualVM-MBeans plugin gives you an MBean Browser. It does the same as JConsole's MBeans tab: "The MBeans tab allows you to access the full set of the platform MXBean instrumentation. In addition, you can monitor and manage your application's MBeans using the MBeans tab." It lets you get and set MBean attributes and invoke MBean operations as well as subscribing for MBean notifications. Here's how it looks, once you've installed the plugin:

The Visual GC plugin gives you a graphic overview of information relevant to garbage collection:

Finally, your investment in JConsole plugins is protected, because they can be loaded into the VisualVM, in the same way as how they were loaded into the JConsole. First, you'd need to install "VisualVM-JConsole" plugin that is shown in the 4th pic above. Then, VisualVM is receptive to any JConsole plugin. For example, let's take the JTop plugin. JTop is a JDK demo that shows the thread CPU usage of all threads running in the application. This demo is helpful in identifying the threads that have high CPU consumption. This is how it is installed in the JConsole:

<JDK6>/bin/jconsole -pluginpath <JDK6>/demo/management/JTop/JTop.jar

 

And, to install that same plugin into VisualVM, you simply open the etc/visualvm.conf file and then add the following to the "default_options" setting:

-J-Djconsole.plugin.path=<JDK6>/demo/management/JTop/JTop.jar

 

For JTop, you'd then end up with the following, in a new tab, that is, the JConsole tab, provided by the aforementioned VisualVM-JConsole plugin:

With the release of the 3rd milestone, you can try out the APIs and create your own plugins. When you go to the download page for VisualVM, you'll see a link for the VisualVM binary as well as a Milestone 3 API Docs link. That gives you access to the Javadoc, as well as an overview of the entrypoints to VisualVM. However, note that the API is still in progress and cannot be considered stable yet.

You are welcome to join the mailing list and provide your feedback there.

Published at DZone with permission of its author, Geertjan Wielenga.

Comments

Mike P(Okidoky) replied on Thu, 2008/02/21 - 12:09pm

Very cool.  This will definitely come in handy.  I just downloaded it and it just starts up, without no need for an installer.   Just unzip and run.

I couldn't immediately find a way to see a stack trace of the waiting threads, but I haven't looked very hard yet.

I'm especially looking forward to using it for hunting memory leaks.  I take it, you run the app, do a heap dump, run it some more, heap dump again, and visualvm shows the differences between the two heap dumps?

 

Luis-Miguel Alv... replied on Thu, 2008/02/21 - 5:10pm

Hi Mike,

You can get thread dumps either by selecting an application node in the tree and right-clicking on the Thread dump action or by clicking on the Thread dump button in the Threads view.

The tool provides a lightweight memory profiler that you can use to take memory snapshots at different intervals and compare them later on.

Regards,
Luis-Miguel Alventosa - VisualVM dev team - http://blogs.sun.com/lmalventosa

replied on Tue, 2008/02/26 - 11:24am

this post was so much more useful than the tons of "10 tips how to become a senior engineer overnight" post bullshit that dzone is full of :)

 

Mark Ashworth replied on Thu, 2008/02/28 - 3:59am

Hi,

I was looking at the source code to see how other developer design NB 6.0 applications and I noticed that Visual VM does not make use of the Nodes API, is there a specific reason for this?

Regards,

Mark P Ashworth

Geertjan Wielenga replied on Tue, 2008/03/04 - 6:37am

Hi Mark. That's an extremely good question. The answer is that VisualVM is a business layer on top of the NetBeans Platform. The objects you work with in VisualVM are "DataSource", "Application", "Host", "DataSourceView", "ThreadDump", etc. That is a business layer on top of the typical NetBeans Platform concepts of "Node", "DataObject", "TopComponent", etc. In other words, life is much easier for you without the Nodes API because the business layer lets you work on a higher (and more logical) level.

Dennis Chen replied on Mon, 2008/06/16 - 10:11am

Hi, mark.

Have you tried visual vm on windows to monitor tomcat6 which run on service mode?

When I running tomcat on service mode, I got a 'not supported for this JVM' message in the JVM arguments tab.

But when tomccat running on console mode, it has no probelm.

My JDK is 1.6

Regards.

Dennis

 

amit kumar replied on Wed, 2008/12/24 - 9:59am

Hi All,

I am new to Java Development and using the VisualVm for the first time.  I am facing some problem in Connecting a Remote Host from the VisualVm interface.

I have JDK 1.6 running in the remote host and also started jstatd server on the same. When I am connecting the remote host from  VisualVm interface running in local machine, its getting connected but the Profiler tab and Threads tab are missing from the interface. What can likely be the problem.

My OS is SUSE Linux.

 Thanks,

Jiri Sedlacek replied on Thu, 2008/12/25 - 5:48am in response to: amit kumar

Hi.

there's no problem, VisualVM works fine. Look at the feature matrix at the bottom of https://visualvm.dev.java.net/features.html, profiling is available only for local JDK 1.6 applications. You can monitor threads of a remote application, but since JMX is used to get this information, you need to add the application using the Add JMX Connection action instead of defining remote host and using jstatd.

Jiri

Raja Kannan replied on Sun, 2009/07/26 - 8:03pm

Check on how to use visual vm through ssh proxy in production systems http://webspherehelp.blogspot.com/2009/07/visualvm-remote-application-monitoring.html

Ian Harrigan replied on Fri, 2010/07/02 - 4:07am

Hi there, Ive just stumbled across VisualVM and im blown away, a really REALLY brilliant tool! One thing: do you know of a way to compare heap dumps? Is there a plugin or something available for VisualVM? Failing that do you know of any other tool that will allow that? Cheers, Ian Harrigan

Carla Brian replied on Sun, 2012/04/15 - 2:25am

This is really helpful. Designed for both production and development time use, it further enhances the capability of monitoring and performance analysis for the Java SE platform. - Marla Ahlgrimm

James Walker replied on Wed, 2012/06/20 - 7:23am

Good thing I saw your post. If not I would not know about the problems of Oracle. Thanks for sharing this one Depron

Passion Lab replied on Sun, 2012/08/19 - 5:45am

That gives you access to the Javadoc, as well as an overview of the entrypoints to VisualVM. However, note that the API is still in progress and cannot be considered stable yet. Bridesmaid jewelry sets

Wendy Hosty replied on Fri, 2012/10/05 - 6:23am

These are the applications I needed for my computers. Right now I need an application that can monitor the progress of blogs that I have because by knowing that, I can come to know how I need to take to be able to develop my blog becomes larger. site

James Walker replied on Fri, 2012/11/16 - 1:20pm

The tool document control software provides a lightweight memory profiler that you can use to take memory snapshots at different intervals and compare them later on.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.