Skip to content

Commit

Permalink
Only enable support for tests.profile if jdk.jfr module is available …
Browse files Browse the repository at this point in the history
…in Gradle runtime (#12845)
  • Loading branch information
uschindler authored Nov 25, 2023
1 parent 74085cd commit 17bb733
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 9 deletions.
3 changes: 3 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ apply from: file('buildSrc/scriptDepVersions.gradle')

apply from: file('gradle/generation/local-settings.gradle')

// Make sure the build environment is consistent.
apply from: file('gradle/validation/check-environment.gradle')

// IDE support, settings and specials.
apply from: file('gradle/ide/intellij-idea.gradle')
apply from: file('gradle/ide/eclipse.gradle')
Expand Down
6 changes: 6 additions & 0 deletions buildSrc/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,9 @@ dependencies {
implementation "commons-codec:commons-codec:${scriptDepVersions['commons-codec']}"
}

if (!rootProject.hasJavaFlightRecorder) {
logger.warn('Module jdk.jfr is not available; skipping compilation of Java Flight Recorder support.')
tasks.named('compileJava').configure {
exclude('**/ProfileResults.java')
}
}
19 changes: 10 additions & 9 deletions gradle/testing/profiling.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,18 @@
* limitations under the License.
*/

import org.apache.lucene.gradle.ProfileResults;

def recordings = files()

allprojects {
plugins.withType(JavaPlugin) {
ext {
testOptions += [
[propName: 'tests.profile', value: false, description: "Enable java flight recorder profiling."]
[propName: 'tests.profile', value: false, description: "Enable Java Flight Recorder profiling."]
]
}

if (resolvedTestOption("tests.profile").toBoolean()) {
allprojects {
if (rootProject.hasJavaFlightRecorder) {
tasks.withType(Test) {
jvmArgs("-XX:StartFlightRecording=dumponexit=true,maxsize=250M,settings=" + rootProject.file("gradle/testing/profiling.jfc"),
"-XX:+UnlockDiagnosticVMOptions",
Expand All @@ -41,17 +39,20 @@ allprojects {
recordings = recordings.plus fileTree(dir: workingDir, include: '*.jfr')
}
}
} else {
throw new GradleException('Module jdk.jfr is not available; Java Flight Recorder profiles cannot be enabled.')
}
}
}
}

gradle.buildFinished {
if (!recordings.isEmpty()) {
ProfileResults.printReport(recordings.getFiles().collect { it.toString() },
propertyOrDefault(ProfileResults.MODE_KEY, ProfileResults.MODE_DEFAULT) as String,
Integer.parseInt(propertyOrDefault(ProfileResults.STACKSIZE_KEY, ProfileResults.STACKSIZE_DEFAULT)),
Integer.parseInt(propertyOrDefault(ProfileResults.COUNT_KEY, ProfileResults.COUNT_DEFAULT)),
Boolean.parseBoolean(propertyOrDefault(ProfileResults.LINENUMBERS_KEY, ProfileResults.LINENUMBERS_DEFAULT)))
def pr = org.apache.lucene.gradle.ProfileResults;
pr.printReport(recordings.getFiles().collect { it.toString() },
propertyOrDefault(pr.MODE_KEY, pr.MODE_DEFAULT) as String,
Integer.parseInt(propertyOrDefault(pr.STACKSIZE_KEY, pr.STACKSIZE_DEFAULT)),
Integer.parseInt(propertyOrDefault(pr.COUNT_KEY, pr.COUNT_DEFAULT)),
Boolean.parseBoolean(propertyOrDefault(pr.LINENUMBERS_KEY, pr.LINENUMBERS_DEFAULT)))
}
}
1 change: 1 addition & 0 deletions gradle/validation/check-environment.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import org.gradle.util.GradleVersion
configure(rootProject) {
ext {
expectedGradleVersion = '8.4'
hasJavaFlightRecorder = ModuleLayer.boot().findModule('jdk.jfr').map(this.class.module::canRead).orElse(false)
}

wrapper {
Expand Down
3 changes: 3 additions & 0 deletions lucene/CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,9 @@ Build

* GITHUB#12655: Upgrade to Gradle 8.4 (Kevin Risden)

* GITHUB#12845: Only enable support for tests.profile if jdk.jfr module is available
in Gradle runtime. (Uwe Schindler)

Other
---------------------

Expand Down

0 comments on commit 17bb733

Please sign in to comment.