14
votes

I'm totally new to VisualVM.

Is there a way to automatically start CPU profiling? My issue is that I start a program from Eclipse which runs for approx. 20 seconds. By the time I can open up the tab and click on CPU profiling, the app has almost finished processing.

3
Any progress on this? - user445107

3 Answers

8
votes

I don't know how to automatically start profiling but I have a workaround.

You can set a breakpoint at the start of your program's main and start the program from Eclipse in debug mode. After beginning to profile in VisualVM resume your program in Eclipse.

0
votes

https://visualvm.github.io/startupprofiler.html

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

0
votes

I added a delay at the first line of the executing code, so I have time to start VisualVM profiling: TimeUnit.SECONDS.sleep(10);

Using VisualVM's Startup Profiler plugin was time consuming to configure, and I wasn't able to get the debug/breakpoint method working.