Why won't the VisualVM Profiler profile my application?
Asked Answered
B

7

38

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?

Baggy answered 15/2, 2012 at 15:34 Comment(8)
@Mikaveli I would consider it. However, as I described below, it actually didn't work. I have still not been able to use the -J-D... option to point jvisualvm at something launched from eclipse. I appreciate your insight and attempt to help, but sadly it did not work. Also note that this question has been closed.Baggy
The notes about the hsperfdata is where JVisualVM (and other apps) get the process info from - learning that will help you and others debug any issues in the future. If the -J option didn't work, this can only be because you haven't pointed it to the actual java.io.tmdir (Eclipse overrides the standard location). That's the documented way to pass JVM arguments to JVisualVM. The reason it works now could easily be related to the bug I mentioned (case-sensitivty of the folder location) which 'cures itself' depending on the case of the username you log on with. Worth 15 rep? :)Emory
I disagree with this being closed, since I had the exact same issue! I tried the suggestions here without luck, and wanted to add my own Answer: you might be better off installing the Eclipse plugin, at visualvm.java.net/eclipse-launcher.html . It worked for me.Giacomo
@KevinPauli I asked for it to be closed because I could no longer reproduce the issue. I haven't had the issue since either. I'm not entirely sure what the situation was that caused the issue.Baggy
This question gets a lot of traffic still. Perhaps we can reopen it so it can help someone in the future?Baggy
If this thread isn't solving your problem, you can also look at this question for more solutionsFavien
How do you specify the arguments: "Start Profiling from classes" and "do not profile classes"?Bihar
@RRMadhav Under the Profiler tab you need to click the Settings checkbox on the right. You specify the options there.Baggy
E
23

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?

Emory answered 15/2, 2012 at 17:22 Comment(6)
I appreciate your suggestion. Adding the -J-D option to (j)visualvm only gave me an error that it could not find the local java process. However, I am now currently unable to reproduce my original issue. The profiler seems to be working just fine for me now...Baggy
You must use the visualvm executable (in the \bin folder). The -J option means pass to the JVM - the rest of the syntax is exactly as you'd normally add arguments to your JVM.Emory
I think you mean jvisualvm but yes, that's what I did. And when it launches it displays an error dialog popup that says Local Java applications cannot be detected. It refers me to the VisualVM Troubleshooting Guide for more information and steps to fix the problem.Baggy
It's probably not the correct path to the temp dir. When you start your application, if you also include -Djava.io.tmpdir=[Same place] when you start Java, the two folders must match and JVisualVM must be able to see the contents.Emory
I also ran into a similar problem on linux. In my case, I was running jvisualvm under a different group than the running java process. But same underlying problem - no access to java.io.tmpdir.Straighten
I too had this problem... starting a java app in Eclipse would not show up in JVMmonitor. I attempted to delete C:\users\'username\...\hsperfdata_'username' which only had one PID in it for Eclipse. But with Eclipse running, it could not delete the folder. I exited Eclipse, and re-started... and viola... now the PID for my ap shows up in the folder... I didn't do anything... unless there was a hidden file that was deleted. Wierd. Not working for hours (multiple eclipse invocations)...now it works. Likely a jvmMonitor bug but hard to reproduce.Henryhenryetta
H
35

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.

Horvath answered 6/11, 2013 at 9:49 Comment(2)
I was having this same issue and just went to the HDD properties -> disk cleanup and checked off to delete Temporary files, and ran disk cleanup and it took care of the issue. If you don't want to go hunting for the above file this will do the trick too.Dessertspoon
This is the only answer that worked for me : really delete this folder.Homestead
E
23

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?

Emory answered 15/2, 2012 at 17:22 Comment(6)
I appreciate your suggestion. Adding the -J-D option to (j)visualvm only gave me an error that it could not find the local java process. However, I am now currently unable to reproduce my original issue. The profiler seems to be working just fine for me now...Baggy
You must use the visualvm executable (in the \bin folder). The -J option means pass to the JVM - the rest of the syntax is exactly as you'd normally add arguments to your JVM.Emory
I think you mean jvisualvm but yes, that's what I did. And when it launches it displays an error dialog popup that says Local Java applications cannot be detected. It refers me to the VisualVM Troubleshooting Guide for more information and steps to fix the problem.Baggy
It's probably not the correct path to the temp dir. When you start your application, if you also include -Djava.io.tmpdir=[Same place] when you start Java, the two folders must match and JVisualVM must be able to see the contents.Emory
I also ran into a similar problem on linux. In my case, I was running jvisualvm under a different group than the running java process. But same underlying problem - no access to java.io.tmpdir.Straighten
I too had this problem... starting a java app in Eclipse would not show up in JVMmonitor. I attempted to delete C:\users\'username\...\hsperfdata_'username' which only had one PID in it for Eclipse. But with Eclipse running, it could not delete the folder. I exited Eclipse, and re-started... and viola... now the PID for my ap shows up in the folder... I didn't do anything... unless there was a hidden file that was deleted. Wierd. Not working for hours (multiple eclipse invocations)...now it works. Likely a jvmMonitor bug but hard to reproduce.Henryhenryetta
T
2

Mikaveli, Kuba and Somaiah Kumbera have provided great solutions. Just adding what I have done to make things work.

I first checked the location C:\users\'username'\AppData\Local\Temp\hsperfdata_'username'

There was no file named with the process ID of my program running inside eclipse.

I simply stopped the program and added the following parameter to the Run Configurations of the program (Run Configurations -> Arguments -> VM Arguments)

-Djava.io.tmpdir=C:\users\'username'\AppData\Local\Temp\hsperfdata_'username'

I started the program again. Still could not profile it. But now I have a file created for the process at the given temp directory.

Then, a simple restart of VisualVM did the trick.

Togo answered 5/6, 2014 at 2:22 Comment(0)
P
2

I had the same problem and running VisualVM with elevated privileges (admin rights) solved the issue.

Pauiie answered 17/4, 2016 at 0:45 Comment(1)
I can confirm that this is what allows Eclipse to be profiled with VisualVM in Windows 10, at least.Yore
R
1

I had the same issue, but with the following symptoms:

I started jetty, with the work directory in C:\Users\t852124\AppData\Local\Temp

Jetty was creating the hsperfdata_ directory but not setting a processID in it

So when I started visualVM, it could not get any java process info.

I solved this by starting jetty with the -Djava.io.tmpdir=C:/temp/java option.

Now when I started jetty, the process ID was created as a file in the hsperfdata_ directory. So when I started visualVM, it was able to see my local java process

Rachele answered 13/9, 2013 at 9:58 Comment(0)
S
0

On Linux with VisualVM 1.3.3 I have to remove local settings of application in ~/.visualvm/1.3.3/ to enable CPU Profiler and CPU Sampler.

Also note that /usr/bin/jvisualvm contains hardcoded path to OpenJDK (set with jdkhome variable), which seems to cause a lot of issues, comparing to running to Oracle JDK 1.7.

Stace answered 20/10, 2014 at 14:7 Comment(0)
F
0

Also note that if your application is using a recent non-Oracle JVM, you may need to download the "bleeding edge" VisualVM from github.

For example, the VisualVM bundled with JDK 1.8.0.111 doesn't seem to work with the IBM 1.8 JVM. Possibly the IBM JVM was simply released after the Oracle 1.8 JVM, so including the necessary changes wasn't possible at that time.

Fukuoka answered 3/2, 2017 at 16:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.