I have a unit test that is running slowly, and I want a quick view of what is happening.
I can get a nice overview of where the code spends its time by adding this to the JVM arguments:
and running the test as normal.
Now I can look at the file that was created, hprof.samples.txt, and looking at the bottom section I can see how much time is spent in each method.
This worked for me within IntelliJ IDEA community edition by clicking “Run” then “Edit Configurations” and adding the above code to “VM options” for my test.
It should also work in Gradle by editing gradle.properties and adding something like this:
and should also work in Maven. In fact, I found this information in this stackoverflow question: How do you run maven unit tests with hprof?.