A JUnit 5 Extension leveraging the capabilities of the Async Profiler This extension allows profiling of JUnit Jupiter test methods using Async Profiler including CPU usage, memory allocation, and lock contention.
For detailed profiler configuration see Async Profiler
With support for warm-up iterations and repeated test executions, it provides results independent of any IDE plugins. This project is inspired by the JfrUnit project and IntelliJ profiler plugin.
- Warm-up Iterations: Configure a number of warm-up iterations for your tests to ensure the JVM is optimally prepared, providing more accurate profiling results.
- Repeated Test Executions: Repeat your tests a specific number of times to gather comprehensive performance data.
- Configure Async Profiler Events: Profile CPU, memory allocation and others
- Output Compatibility: Generate profiling data in Java Flight Recorder (JFR) format or as flame graphs
- Run from IDE or in command line
- IDE Independent: No dependency on any IDE plugins, making it versatile and easy to integrate into any development workflow.
Execute the following commands to make profiling possible
sysctl kernel.perf_event_paranoid=1
sysctl kernel.kptr_restrict=0
Clone the repository and run mvn install
, then add the dependency in your pom.xml
<dependency>
<groupId>io.github.vkn</groupId>
<artifactId>profiling-unit</artifactId>
<version>0.0.1</version>
<scope>test</scope>
</dependency>
To get started, annotate your test class with @ProfilingUnit
and your test methods with @ProfiledTest
instead of junit@Test
. Configure the @ProfiledTest
annotation to specify warm-up iterations,
the number of repetitions, and the profiling events you're interested in.
@ProfilingUnit
public class MyTest {
@ProfiledTest(warmup = 5, repeat = 10, event = "cpu,alloc,lock", type = Type.JFR)
public void myMethod() {
// Your test code here
}
}
This setup will run MyTest.myMethod
with 5 warm-up iterations followed by 10 repetitions,
profiling CPU usage, memory allocation, and lock contention, with the results output in JFR format.
The result file will be stored under target/profiling/
directory
The @ProfilingUnit
can also be combined with @QuarkusTest
Contributions are welcome! If you have suggestions for improvements or encounter any issues, please feel free to open an issue or submit a pull request.
This project is licensed under the Apache Licence 2.0. See the LICENSE file for more details.