Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why won't the VisualVM Profiler profile my application?

I've created a simple 1 file java application that iterates through a loop, calls some functions, allocates some memory, adds some numbers, etc. I run that application via eclipse's Run As->Java Application.

The running application shows up in Java VisualVM under Local.

I double click on that application and go to the Profiler tab.

The default settings are:

Start profiling from classes: my.main.package.**

Do not profile classes: java.*, javax.*, sun.*, sunw.*, com.sun.*

I click on CPU. The CPU and Memory buttons gray out. Nothing happens.

The Status says profiling inactive.

When my application terminates the Status says application terminated.

What am I doing wrong here? Are there some settings I need to tweak? Do I need to set a VM flag when I launch my application?

like image 393
Luke Avatar asked Feb 15 '12 15:02

Luke


People also ask

Does VisualVM work with Java 11?

Use VisualVM bundled with GraalVMGraalVM contains a fully compliant Java SE 8, Java SE 11, and Java SE 17 JDK distribution based on Oracle JDK and OpenJDK. It features an innovative JIT compiler which may noticeably improve performance of Java applications, compared to the standard Oracle JDK or OpenJDK.

How do I connect to VisualVM?

Connecting to a Remote Host To add a remote host, right-click the Remote node in the Applications window, choose Add Remote Host and type the host name or IP address in the Add Remote Host dialog box. (You can also specify a display name that will be used to refer to the host when listed under the Remote node.)

How do I add apps to VisualVM?

To install a VisualVM plugin:Choose Tools > Plugins from the main menu. In the Available Plugins tab, select the Install checkbox for the plugin. Click Install. Step through and complete the plugin installer.

Is VisualVM included in JDK?

Various optional tools, including Java VisualVM, are provided with the Java Development Kit (JDK) for retrieving different types of data about running JVM software instances.


2 Answers

I had the same issue after java 1.7.0_45 update. I had to delete the following folder:

C:\users\'username'\AppData\Local\Temp\hsperfdata_'username' 

After doing so, everything works like a charm.

like image 89
Kuba Avatar answered Oct 03 '22 07:10

Kuba


I'd guess the issue relates to the application being started from within Eclipse, this is because JVisualVM expects to find data in the java.io.tmpdir directory (usually C:\Users\[your username]\AppData\Local\Temp\hsperfdata_[your username] on a Windows system).

I assume rather than in the normal location where JPS, JVisualVM etc. expects it, Eclipse puts the data in it's own temp folder?

If so, try invoking JVisualVM using jvisualvm -J-Djava.io.tmpdir=[Eclipse's temp directory] to explicitly tell it where that data is.

If you can't find the hsperfdata_$USER folder, try just running your application outside Eclipse in the usual command line Java way.

Also note that there was a bug affecting the temp folder (case sensitivity) introduced around 1.6.0_23, so maybe you'd benefit by updating to a more recent Java 6 (or 7) build?

like image 31
Michael Avatar answered Oct 03 '22 07:10

Michael