Search code examples
javaintellij-ideajprofiler

Profiling junit tests with intellij and jprofiler


I'm trying to profile a junit test - all I care about is hot spots and call tree - I want to see where the test is taking time. I'm running the test by right clicking in intellij idea and saying "profile ..." The test runs in less than a second, and then finishes - even if I can get there quick enough to click call tree and click start recording (haven't found any way of getting it recording immediately) - anything I haven't managed to open by the time it finishes is not available, saying things along the lines of "no data was received because the profiled JVM has terminated.

How do I right click and run a test, have it capture all call history and timings in such a way that I can browse it all once the test has completed? (or is there an alternative/better way of doing this?)


Solution

  • In the profiling settings, on the "Miscellaneous" tab, there is a setting called "Keep VM alive". If you select that check box, the VM will not terminate as long as the JProfiler GUI is connected to it.


    Update 2017-11-28

    Since JProfiler 10, this setting is no longer in the profiling settings, but in the startup dialog. Also, there is now an option to automatically save a snapshot when the JVM exits. This has the advantage of not blocking the test runner in the IDE.

    enter image description here