melix / jmh-gradle-plugin

Integrates the JMH benchmarking framework with Gradle
Apache License 2.0
662 stars 88 forks source link

Adds environment variables #212

Closed bric3 closed 2 years ago

bric3 commented 2 years ago

This proposed change is about the support of environment variables when launching the jmh jar. (Because the org.openjdk.jmh.annotations.Fork don't allow to pass environments).

The jmh block is of type JmhParameters and WithJavaToolchain so in order to support a similar API as JavaExecSpec it has to be explicitly exposed.

Current alternative The currently API does not allow this so we have to executes the jmh jar outside gradle.

$ ./gradlew :jmh-panama:jmhJar
$ env JAVA_LIBRARY_PATH=$(grealpath jmh-panama/jni) \
  java -jar jmh-panama/build/libs/jmh-panama-jmh.jar \
  -jvmArgs '-Xms256m -Xmx256m -Djmh.separateClasspathJAR=true --add-modules=jdk.incubator.foreign --enable-native-access=ALL-UNNAMED'

Note I didn't see a functional test with jmh options so I'm not sure how you'd want to test that.

bric3 commented 2 years ago

I'd like something closer to the JavaExecSpec, but the jmh block is not extending it.

environment(mapOf("JAVA_HOME" to System.getenv("JAVA_HOME")))
environment("JAVA_HOME", System.getenv("JAVA_HOME"))

And I am not sure how best to proceed. Same for the tests.

bric3 commented 2 years ago

Wow I wonder how the PR description was empty, was it me that forgot 🤔🤦 ? I just rebased this pr on the latest from master.

bric3 commented 2 years ago

Would be great to have a test of some kind. Could be a benchmark which spits out an environment variable via System.out and that the test would search for in the output.

Done