0

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...

94621
  • 53
  • 4
  • There are 3 ways to run async-profiler: 1) as a standalone program `profiler.sh`/`asprof`; 2) as an [agent](https://github.com/async-profiler/async-profiler#launching-as-an-agent) which starts with the JVM; 3) using [Java API](https://github.com/apangin/java-profiling-presentation/blob/master/src/demo8/FileConverter2.java#L19-L27). The simplest way in your case is (2) - to add a JVM argument. Alternatively, the test code may start async-profiler programmatically using Java API. – apangin Aug 22 '23 at 21:46

0 Answers0