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