-
Notifications
You must be signed in to change notification settings - Fork 41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support running jmh profilers #217
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -60,15 +60,23 @@ The options listed in the following sections allow you to tailor the benchmark e | |
| `advanced("nativeGCAfterIteration", value)` | Whether to trigger garbage collection after each iteration. | `true`, `false` | `false` | | ||
|
||
### Kotlin/JVM | ||
| Option | Description | Possible Values | Default Value | | ||
|---------------------------------------------|------------------------------------------------------------|----------------------------------------|----------------| | ||
| `advanced("jvmForks", value)` | Specifies the number of times the harness should fork. | Non-negative Integer, `"definedByJmh"` | `1` | | ||
| Option | Description | Possible Values | Default Value | | ||
|---------------------------------------------|--------------------------------------------------------|----------------------------------------|----------------------| | ||
| `advanced("jvmForks", value)` | Specifies the number of times the harness should fork. | Non-negative Integer, `"definedByJmh"` | `1` | | ||
| `advanced("jvmProfiler", "value")` | Specifies the profiler to be used during benchmarking. | String identifier of the profiler | `null` (No profiler) | | ||
|
||
**Notes on "jvmForks":** | ||
- **0** - "no fork", i.e., no subprocesses are forked to run benchmarks. | ||
- A positive integer value – the amount used for all benchmarks in this configuration. | ||
- **"definedByJmh"** – Let JMH determine the amount, using the value in the [`@Fork` annotation](https://javadoc.io/doc/org.openjdk.jmh/jmh-core/latest/org/openjdk/jmh/annotations/Fork.html) for the benchmark function or its enclosing class. If not specified by `@Fork`, it defaults to [Defaults.MEASUREMENT_FORKS (`5`)](https://javadoc.io/doc/org.openjdk.jmh/jmh-core/latest/org/openjdk/jmh/runner/Defaults.html#MEASUREMENT_FORKS). | ||
|
||
**Notes on "jvmProfiler":** | ||
- This option corresponds to the `-prof` command line option when running JMH benchmarks from console. | ||
Some examples of possible values include `gc`, `stack`, `cl`, `perf`, and `dtraceasm`. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Currently, for asm-annotating profilers ( On macOS, you can't put a library into We may consider bypassing library path to the runner process or suggest users to build benchmark's JAR and use it directly, when perfasm profilers are needed. |
||
- You can learn about profilers provided by the latest JMH [here](https://javadoc.io/doc/org.openjdk.jmh/jmh-core/latest/org/openjdk/jmh/profile/package-summary.html). | ||
- A sample illustrating the output format of the profilers can be found [here](https://github.com/openjdk/jmh/blob/1.37/jmh-samples/src/main/java/org/openjdk/jmh/samples/JMHSample_35_Profilers.java). | ||
- Some profilers may require root privileges. | ||
|
||
The library offers the flexibility to specify the version of the Java Microbenchmark Harness (JMH) to use when running benchmarks on the JVM. | ||
The default version is set to `1.21`, but you can customize it while registering a JVM target for benchmarking: | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package kotlinx.benchmark.integration | ||
|
||
import kotlin.test.* | ||
|
||
class JvmProfilerTest : GradleTest() { | ||
|
||
@Test | ||
fun testGcProfiler() { | ||
val runner = project("kotlin-multiplatform") { | ||
configuration("gcProfiler") { | ||
iterations = 1 | ||
iterationTime = 100 | ||
iterationTimeUnit = "ms" | ||
advanced("jvmProfiler", "gc") | ||
} | ||
} | ||
|
||
runner.run("jvmGcProfilerBenchmark") { | ||
assertOutputContains("gc.alloc.rate") | ||
assertOutputContains("BUILD SUCCESSFUL") | ||
} | ||
} | ||
|
||
@Test | ||
fun testStackProfilerEffect() { | ||
val runner = project("kotlin-multiplatform") { | ||
configuration("stackProfiler") { | ||
iterations = 1 | ||
iterationTime = 100 | ||
iterationTimeUnit = "ms" | ||
advanced("jvmProfiler", "stack") | ||
} | ||
} | ||
|
||
runner.run("jvmStackProfilerBenchmark") { | ||
assertOutputContains("stack") | ||
assertOutputContains("BUILD SUCCESSFUL") | ||
} | ||
} | ||
|
||
@Test | ||
fun testClProfiler() { | ||
val runner = project("kotlin-multiplatform") { | ||
configuration("clProfiler") { | ||
iterations = 1 | ||
iterationTime = 100 | ||
iterationTimeUnit = "ms" | ||
advanced("jvmProfiler", "cl") | ||
} | ||
} | ||
|
||
runner.run("jvmClProfilerBenchmark") { | ||
assertOutputContains("class.unload.norm") | ||
assertOutputContains("BUILD SUCCESSFUL") | ||
} | ||
} | ||
|
||
@Test | ||
fun testCompProfilerEffect() { | ||
val runner = project("kotlin-multiplatform") { | ||
configuration("compProfiler") { | ||
iterations = 1 | ||
iterationTime = 100 | ||
iterationTimeUnit = "ms" | ||
advanced("jvmProfiler", "comp") | ||
} | ||
} | ||
|
||
runner.run("jvmCompProfilerBenchmark") { | ||
assertOutputContains("compiler.time.profiled") | ||
assertOutputContains("BUILD SUCCESSFUL") | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How one can specify profiler's options?
Something like
advance("jvmProfiler", "gc:churn=true")
fails with: