Why won't the VisualVM Profiler profile my application?

别来无恙 提交于 2019-11-29 02:16:48

问题


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?


回答1:


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?




回答2:


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.




回答3:


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.




回答4:


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




回答5:


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.




回答6:


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




回答7:


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.



来源:https://stackoverflow.com/questions/9296258/why-wont-the-visualvm-profiler-profile-my-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!