Using VisualVM with IntelliJ - java

I'm trying to use VisualVM with IntelliJ to profile a Java application. I have the VisualVM Launcher plugin installed inside of IntelliJ. I press the play button with the orange circle in IntelliJ that launches VisualVM and opens the process when I start the run. However, when I try to profile the CPU, it doesn't seem to profile the methods in my program. I've tried with several different programs and can't seem to get any of them to work with VisualVM. This is what VisualVM looks like this:
The profiler seems to think that the total time is 857 ms or 6.21 ms when in reality my program takes about a minute to run. It seems to be capturing "DestroyJavaVM" which is not my program. I'm using VisualVM because it is the only free Java profiler I could find. Any suggestions? Here are my VisualVM settings:

As others have suggested, take a look at your "Start profiling from class" setting.
But you might want to consider it being a timing issue. As you can see in the background, the process you want to debug is already finished.
Check in the call tree and in the list of processes to the left what you are debugging. In your screenshot you are debugging the destruction of the JVM. That does not include your code, so you should not see it there.

Related

How to profile a Java program run from start to finish?

I have a Java program that runs for only about 20-30 seconds and I want to profile it.
Firing up the jvisualvm profiler manually at each start is not reliable, because you lose several seconds operating the UI.
Is there a way to profile the entire exectution, like the old -Xhprof:cpu=samples which no longer works?
With Flight Recorder you can add to the command line
-XX:+UnlockCommercialFeatures -XX:+FlightRecorder
-XX:FlightRecorderOptions=defaultrecording=true,dumponexit=true,settings=profile
https://docs.oracle.com/javacomponents/jmc-5-5/jfr-runtime-guide/run.htm#JFRRT176
It only records the memory allocation on a new TLAB, so I make it much smaller than the default to get more samples.
-XX:TLABSize=128k
You need to run jmc from the $JAVA_HOME/bin directory to open the .jfr file created.
I find this harder to use than VisualVM, but produces much more detailed results with less noise. i.e. you get far fewer allocations causes by the profiler itself.

High CPU usage in Eclipse when nothing in progress

I have this problem with eclipse Mars.2
Build Automatically is disabled and nothing is in progress.
Each time I start eclipse, there is a high CPU usage. Here is what JProfiler says:
Eclipse seems to be compiling something, by why?
Another strange thing is that if I try to quit Eclipse, the process does not terminate.
Thanks
Are you working on Javascript files using Eclipse JavaScript Editor? - Seems to be it's indexing javascript files (JSDT - JavaScript development tools) during the eclipse startup, usually indexing will take some amount of time to parse the files,index the functions and variables for content assist/proposals purpose.

Eclipse: Java Monitor won't show cpu statistics

I am profiling a java application using jvisualvm. The CPU profile from jvisualvm has narrowed down the slow part of the code to one particular method. It doesn't say which part of the method is slow though.
To get more information I tried debugging through Eclipse using Java Monitor (available through Eclipse Marketplace). Java Monitor will attach to the application but it won't display CPU statistics. I don't know why. I have modified the JVM options using:
-agentlib:jdwp=transport=dt_socket,address=8000,server=y,suspend=y
Then I create a profile in Eclipse using:
Remote Java Application > myapplication
Here I select the source code for the project I am profiling. I start the application and it waits for the debugger to attach:
Listening for transport dt_socket at address: 8000
I right click the PID under local host and click 'Start Monitoring'
Then in Eclipse I press F11 to kick off the application. It starts running, but under 'Properties' I get everything except CPU. Any ideas greatly appreciated..
I don't know any Java profiler which can tell you which part of a method eats most of the time. If you can't tell by looking at the method, then your method is probably too big to understand anyway. Try to refactor it into several methods.
If you have lots of local variables, use a worker object and turn local variables into fields of the worker. That way, you can avoid writing methods with a dozen parameters and still cut a overly complex method to size.
As for why Java Monitor doesn't do what you want: You need to tell it which packages to monitor and which profiling method to use. See the documentation for details.

VisualVM "Sampler->Cpu->CpuSettings" is grayed out. How come?

I am unable to filter what specific packages I want to look at, since the cpusettings menu is grayed out.
I am running my application from eclipse using the VisualVM runner.
CPU settings cannot be changed when a sampling is in progress. Set them before you start CPU sampling.

How to gather profiling information for a Java 1.4 application?

A Java application I support that runs on JRE 1.4.2_12 is hanging near midnight every night. I'd like to try and record as much profiling information as I can to discover if there is an issue in the JVM or external to the app.
I'd like to use HPROF to collect as much information as possible.
Is there a way to have HPROF dump its cpu sample and memory allocation report every minute instead of at the termination of the JVM?
Is there a different, more appropriate profiler that can collect information like this?
Rather than relying on dump files, I would try hooking up a profiler to the VM and leave it attached until the hang up occurs. Then use the profiler to introspect the state of the threads.
The use of Java 1.4 is a minor issue here, since 1.4's debug interface is not great, but some profilers still support it. I can particularly recommend YourKit, which is commercial, but offers an evaluation licence. It's the best profiler I've used, but some margin.
First things first: did you analyze the thread dump when your application hangs? A lot of the time that has enough information to troubleshoot a hanging java app...
Ctrl-Break in the process window on Windows, or kill -QUIT [pid] on Linux.
I would first try to determine if its actually your app or something else.
Are there any other apps on the box, if so do they run any batch around midnight. It could be a situation of your app suffering from a lack of resources due to other things running on the box or chewing up bandwidth.
Was this always the case or did it start recently. If this is new look at what changed on the box as a whole not just your own app.

Categories

Resources