Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to profile application startup with visualvm

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.

like image 539
pstanton Avatar asked Dec 14 '10 00:12

pstanton


People also ask

What is Profiler in VisualVM?

Java VisualVM enables you to take profiler snapshots to capture the results of a profiling session. A profiler snapshot captures the results at the moment the snapshot is taken. To take a snapshot, click the Take Snapshot of Collected Results button in the toolbar while a profiling session is in progress.

How do I start Java VisualVM on Windows?

You can access VisualVM from the bin directory of the JDK: On a Windows system, start VisualVM by double-clicking jvisualvm.exe. You can also select VisualVM from the Start menu (if Windchill shortcuts are installed). On other systems, start VisualVM by invoking the jvisualvm script.

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.


2 Answers

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.

like image 130
KarlP Avatar answered Sep 18 '22 12:09

KarlP


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.

like image 22
skaffman Avatar answered Sep 21 '22 12:09

skaffman