xref: /aosp_15_r20/external/conscrypt/benchmark-jmh/build.gradle (revision cd0cc2e34ba52cdf454361820a14d744e4bd531d)
1plugins {
2    alias libs.plugins.jmh
3}
4
5description = 'Conscrypt: JMH on OpenJDK Benchmarks'
6
7evaluationDependsOn(':conscrypt-openjdk')
8
9ext {
10    preferredSourceSet = project(':conscrypt-openjdk').preferredSourceSet
11    preferredNativeFileDir = project(':conscrypt-openjdk').preferredNativeFileDir
12
13    genDir = "${buildDir}/jmh-generated-classes"
14    jmhInclude = System.getProperty('jmh.include')
15    jmhParams = System.getProperty('jmh.parameters')
16    jmhWarmupIterations = System.getProperty('jmh.wi', '10')
17    jmhIterations = System.getProperty('jmh.i', '10')
18    jmhFork = System.getProperty('jmh.f', '1')
19    jmhJvm = System.getProperty('jmh.jvm')
20    jmhJvmArgs = System.getProperty('jmh.jvmArgs', '-server -Xms2g -Xmx2g')
21}
22
23jmh {
24    jmhVersion = "$jmhVersion"
25    if (jmhInclude != null) {
26        setInclude(jmhInclude.toString())
27    }
28    if (jmhParams != null) {
29        setBenchmarkParameters(parseParams(jmhParams))
30    }
31    warmupIterations = "$jmhWarmupIterations".toInteger()
32    iterations = "$jmhIterations".toInteger()
33    fork = "$jmhFork".toInteger()
34    // jvmArgs = jmhJvmArgs
35    if (jmhJvm != null) {
36        jvm = jmhJvm
37    }
38    duplicateClassesStrategy = DuplicatesStrategy.WARN
39}
40
41configurations {
42    // The JMH plugin by defaults depends on all of the generators for an old version of JMH.
43    // Need to remove all the generators that we're not explicitly overriding to eliminate the
44    // dependency on the old version of JMH.
45    jmh.exclude module:'jmh-generator-asm'
46
47    jmhGeneratorAnnprocess
48}
49
50sourceSets {
51    sourceSets {
52        main {
53            resources {
54                // This shouldn't be needed but seems to help IntelliJ locate
55                // META_INF/BenchmarkList.
56                srcDirs += genDir
57
58                // This shouldn't be needed but seems to help IntelliJ locate the native artifact.
59                srcDirs += preferredNativeFileDir
60            }
61        }
62    }
63}
64
65dependencies {
66    implementation project(":conscrypt-openjdk"),
67            project(path: ":conscrypt-testing", configuration: "runtimeElements"),
68            project(':conscrypt-benchmark-base'),
69            // Add the preferred native openjdk configuration for this platform.
70            //project(':conscrypt-openjdk').sourceSets["$preferredSourceSet"].output,
71            libs.junit,
72            libs.netty.handler,
73            libs.netty.tcnative
74
75    jmhGeneratorAnnprocess libs.jmh.generator.annprocess
76
77    // Override the default JMH dependencies with the new versions.
78    jmh libs.jmh.core,
79            libs.jmh.generator.reflection,
80            libs.jmh.generator.bytecode
81}
82
83// Running benchmarks in IntelliJ seems broken without this.
84// See https://github.com/melix/jmh-gradle-plugin/issues/39
85// TODO(prb): Investigate and fix for Gradle 7+
86//idea.module {
87//    scopes.PROVIDED.plus += [ configurations.compile, configurations.jmh ]
88//}
89
90// Param strings are in the form "param:VAL1,VAL2;param2:VAL3,VAL4"
91static def parseParams(s) {
92    // It's really easy to type jmh.parameters=foo=bar instead of jmh.parameters=foo:bar,
93    // so check for that.
94    if (s.contains("=")) {
95        throw new IllegalArgumentException("jmh.parameters value shouldn't include '='.  (Did you mean ':'?)")
96    }
97    return s.split(";").collectEntries { entry ->
98        def pair = entry.split(":")
99        [ (pair.first().trim()) : pair.last().split(",").collect { it.trim() } ]
100    }
101}
102