Search code examples
javaeclipsejunitvisualvm

Java JUnit profiling on MacOS doesn't work


I'm trying to profile a JUnit test with JavaVisualVM on MacOS El Capitan. My Java version is 1.8.0_45

So on this machine I do the following:

  1. set up the run configurations of my JUnit test in Eclipse so that it leaves the VM up after the first run.

  2. set a breakpoint within the code of the unit test, right before the part I want to profile

  3. launch the test in debug mode (Debug As JUnit test). It pauses at the breakpoint

  4. double click on the process in VisualVM, open the profile tab, click CPU profiling

  5. resum execution in Eclipse.

At this point VisualVM does indeed capture some CPU usage information, but the only methods shown here are those in the org.eclipse.jdt package itself. It doesn't capture information from running my application classes.

The only output I can see is a bunch of warning messages printed to the Eclipse console after I hook VisualVM to the JUnit process:

objc[89393]: Class JavaLaunchHelper is implemented in both /Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home/bin/java and /Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home/jre/lib/libinstrument.dylib. One of the two will be used. Which one is undefined.
Profiler Agent: Waiting for connection on port 5140 (Protocol version: 15)
Profiler Agent: Established connection with the tool
Profiler Agent: Local accelerated session
Profiler Agent Warning: JVMTI classLoadHook: class name is null.
Profiler Agent Warning: JVMTI classLoadHook: class name is null.
[... many more like these ...]

Profiler Agent: Connection with agent closed
Profiler Agent: JNI OnLoad Initializing...
Profiler Agent: JNI OnLoad Initialized successfully

This is probably something I'm supposed to investigate, but I don't really know what to do with it.
What bugs me is that I replicated this same process (apparently the same) on a Windows 10 machine and it does profile my application classes. I don't know what I'm doing wrong on Mac.

Thank you


Solution

  • You need to set "Start Profiling from Classes" to [your_package].** and uncheck "Profile new Runnables". More details about profiling settings can be found in Profiling With VisualVM, Part 1 and Profiling With VisualVM, Part 2.