I have a java application that I'd like to profile using async-profiler. In particular, I want to run a test case using mvn test -Dtest=SomeTest
and have async-profiler automatically launched in the background to profile the executed code.
Right now, I am achieving that by launching the test case, identifying the pid
and separately invoking async-profiler
:
mvn test -DargLine="-XX:+UnlockDiagnosticVMOptions -XX:+DebugNonSafepoints" -Dtest=SomeTest
profiler.sh -e cpu -d 30 -f profiles/cpu_profile_$(date +%F_%T).html $(pgrep -f 'Unlock')
I am looking for a way (a maven plugin, a class that I can include in the test case) to automatically launch async-profiler when running the application with maven. I know that there are a lot different ways described in the async-profiler README, but they are assuming too much knowledge to be actionable for me...