how to profile application startup with visualvm

JavaProfilingVisualvm

Java Problem Overview


As far as i can tell, you can only profile a running application using VisualVM.

Does anyone know of a way to profile the launch and startup of a java application using VisualVM?

I'm convinced there must be a way, otherwise it would be a major oversight.

Hoping I've just misread the documentation.

Thanks, p.

Java Solutions


Solution 1 - Java

Use the eclipse launcher, and set a breakpoint at an appropriate place in the main method.

Then, start in debug mode, enable profiling in visualVM, and then resume using eclipse.

That won't profile class loading and stuff, but it's good enough for me.

Solution 2 - Java

Are you setting up the profiling using the `-Xrunjdwp" command-line option? If so, that option has a "suspend" parameter for just this purpose:

>True if the target VM is to be suspended immediately before the main class is loaded; false otherwise.

Example from my own config:

-Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n

I use this with the YourKit profiler, but I think the principle is the same.

Solution 3 - Java

I found Startup Profiler helpful:

> Startup Profiler plugin for VisualVM 1.3.6 enables instrumented > profiling of local Java 5+ applications from their startup. It is also > helpful when profiling short-running processes.

Solution 4 - Java

Both common Java development environments (NetBeans/Eclipse) support application execution directly with attached VisualVM. In case of Eclipse you have to install a plugin. In case of NetBeans the support is AFAIK already integrated.
Even if do not have the sources you can still run the JAR file(s) via both environments and therefore start your app connected with VisualVM.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionpstantonView Question on Stackoverflow
Solution 1 - JavaKarlPView Answer on Stackoverflow
Solution 2 - JavaskaffmanView Answer on Stackoverflow
Solution 3 - JavaHaim RamanView Answer on Stackoverflow
Solution 4 - JavaRobertView Answer on Stackoverflow