Skip to content

Commit b17cf1e

Browse files
committed
Convert native to infra, use kotlinx-cli to pass data to the benchmark process
1 parent 79d666a commit b17cf1e

File tree

10 files changed

+105
-132
lines changed

10 files changed

+105
-132
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ buildscript {
88

99
dependencies {
1010
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
11-
classpath "kotlinx.team:kotlinx.team.infra:0.1.0-dev-26"
11+
classpath "kotlinx.team:kotlinx.team.infra:0.1.0-dev-27"
1212
}
1313
}
1414

examples/kotlin-multiplatform/build.gradle

Lines changed: 9 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import org.jetbrains.kotlin.konan.target.HostManager
21

32
buildscript {
43
repositories {
@@ -13,9 +12,6 @@ plugins {
1312
id 'kotlinx.team.node'
1413
}
1514

16-
project.ext.hostManager = new HostManager()
17-
apply from: rootProject.file("gradle/utility.gradle")
18-
1915
node {
2016
version = '10.15.1'
2117
}
@@ -26,6 +22,12 @@ allOpen {
2622
}
2723

2824
kotlin {
25+
infra {
26+
target('macosX64')
27+
target('linuxX64')
28+
target('mingwX64')
29+
}
30+
2931
jvm {
3032
compilations.all {
3133
kotlinOptions {
@@ -42,17 +44,7 @@ kotlin {
4244
}
4345
}
4446
}
45-
46-
if (project.ext.ideaActive) {
47-
targets {
48-
project.ext.nativeTarget = fromPreset(project.ext.ideaPreset, 'native')
49-
}
50-
} else {
51-
macosX64('macosX64')
52-
linuxX64('linuxX64')
53-
mingwX64('windowsX64')
54-
}
55-
47+
5648
sourceSets.all {
5749
languageSettings {
5850
progressiveMode = true
@@ -96,25 +88,9 @@ kotlin {
9688
}
9789
}
9890

99-
if (ideaActive) {
100-
nativeMain {
101-
kotlin.srcDir("src/${project.ext.nativeTarget.preset.name}Main")
102-
}
103-
} else {
104-
nativeMain {}
105-
nativeTest {}
106-
107-
configure([linuxX64Main, macosX64Main, windowsX64Main]) {
108-
dependsOn nativeMain
109-
}
110-
111-
configure([linuxX64Test, macosX64Test, windowsX64Test]) {
112-
dependsOn nativeTest
91+
nativeMain {
92+
dependencies {
11393
}
114-
}
115-
116-
nativeMain.dependencies {
117-
11894
}
11995
}
12096
}

plugin/main/src/org/jetbrains/gradle/benchmarks/JsNodeTasks.kt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,14 @@ fun Project.createJsBenchmarkExecTask(
3232
val reportFile = reportsDir.resolve("${config.name}.json")
3333

3434
script = nodeModulesDir.resolve(compilation.compileKotlinTask.outputFile.name).absolutePath
35-
arguments(reportFile.toString(), config.iterations().toString(), config.iterationTime().toString()) // TODO: configure!
36-
//setWorkingDir(nodeModulesDir)
35+
arguments("-r", reportFile.toString())
36+
arguments("-i", config.iterations().toString())
37+
arguments("-ti", config.iterationTime().toString())
3738
dependsOn("${config.name}${BenchmarksPlugin.BENCHMARK_DEPENDENCIES_SUFFIX}")
3839
doFirst {
3940
val ideaActive = (extensions.extraProperties.get("idea.internal.test") as? String)?.toBoolean() ?: false
40-
arguments(if (ideaActive) "xml" else "text")
41+
arguments("-t", if (ideaActive) "xml" else "text")
42+
arguments("-n", config.name)
4143
reportsDir.mkdirs()
4244
logger.lifecycle("Running benchmarks for ${config.name}")
4345
logger.info(" I:${config.iterations()} T:${config.iterationTime()}")

plugin/main/src/org/jetbrains/gradle/benchmarks/JvmTasks.kt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,15 @@ fun Project.createJvmBenchmarkExecTask(
7878
)
7979

8080
//args = "-w 5 -r 5 -wi 1 -i 1 -f 1
81-
args(listOf(reportFile.toString(), config.iterations(), config.iterationTime())) // TODO: configure!
81+
args("-r", reportFile.toString())
82+
args("-i", config.iterations().toString())
83+
args("-ti", config.iterationTime().toString())
8284

8385
dependsOn("${config.name}${BenchmarksPlugin.BENCHMARK_COMPILE_SUFFIX}")
8486
doFirst {
8587
val ideaActive = (extensions.extraProperties.get("idea.internal.test") as? String)?.toBoolean() ?: false
86-
args(if (ideaActive) "xml" else "text")
87-
args(config.name)
88+
args("-t", if (ideaActive) "xml" else "text")
89+
args("-n", config.name)
8890
reportsDir.mkdirs()
8991
logger.lifecycle("Running benchmarks for ${config.name}")
9092
logger.info(" I:${config.iterations()} T:${config.iterationTime()}")

plugin/main/src/org/jetbrains/gradle/benchmarks/NativeMultiplatformTasks.kt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,14 +99,16 @@ fun Project.createNativeBenchmarkExecTask(
9999
val reportFile = reportsDir.resolve("${config.name}.json")
100100

101101
executable = linkTask.outputFile.get().absolutePath
102-
103-
// TODO: configure!
104-
args(listOf(reportFile.toString(), config.iterations(), config.iterationTime()))
102+
103+
args("-r", reportFile.toString())
104+
args("-i", config.iterations().toString())
105+
args("-ti", config.iterationTime().toString())
105106

106107
dependsOn(linkTask)
107108
doFirst {
108109
val ideaActive = (extensions.extraProperties.get("idea.internal.test") as? String)?.toBoolean() ?: false
109-
args(if (ideaActive) "xml" else "text")
110+
args("-t", if (ideaActive) "xml" else "text")
111+
args("-n", config.name)
110112
reportsDir.mkdirs()
111113
logger.lifecycle("Running benchmarks for ${config.name}")
112114
logger.info(" I:${config.iterations()} T:${config.iterationTime()}")

runtime/build.gradle

Lines changed: 10 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import org.jetbrains.kotlin.konan.target.HostManager
2-
31
buildscript {
42
repositories {
53
mavenCentral()
@@ -8,13 +6,9 @@ buildscript {
86
}
97

108
plugins {
11-
id 'maven-publish'
12-
id 'org.jetbrains.kotlin.multiplatform'
9+
id 'org.jetbrains.kotlin.multiplatform'
1310
}
1411

15-
project.ext.hostManager = new HostManager()
16-
apply from: rootProject.file("gradle/utility.gradle")
17-
1812
repositories {
1913
mavenCentral()
2014
maven { url 'https://dl.bintray.com/kotlin/kotlin-eap' }
@@ -23,6 +17,12 @@ repositories {
2317
}
2418

2519
kotlin {
20+
infra {
21+
target('macosX64')
22+
target('linuxX64')
23+
target('mingwX64')
24+
}
25+
2626
jvm {
2727
compilations.all {
2828
kotlinOptions {
@@ -40,16 +40,6 @@ kotlin {
4040
}
4141
}
4242

43-
if (project.ext.ideaActive) {
44-
targets {
45-
project.ext.nativeTarget = fromPreset(project.ext.ideaPreset, 'native')
46-
}
47-
} else {
48-
macosX64('macosX64')
49-
linuxX64('linuxX64')
50-
mingwX64('windowsX64')
51-
}
52-
5343
sourceSets.all {
5444
kotlin.srcDirs = ["$it.name/src"]
5545
resources.srcDirs = ["$it.name/resources"]
@@ -64,6 +54,7 @@ kotlin {
6454
commonMain {
6555
dependencies {
6656
implementation 'org.jetbrains.kotlin:kotlin-stdlib-common'
57+
implementation 'org.jetbrains.kotlinx:kotlinx-cli:0.1.0-dev-3'
6758
}
6859
}
6960
commonTest {
@@ -94,27 +85,11 @@ kotlin {
9485
implementation 'org.jetbrains.kotlin:kotlin-test-js'
9586
}
9687
}
97-
98-
99-
if (ideaActive) {
100-
nativeMain {
101-
kotlin.srcDir("${project.ext.nativeTarget.preset.name}Main/src")
102-
}
103-
} else {
104-
nativeMain {}
105-
nativeTest {}
106-
107-
configure([linuxX64Main, macosX64Main, windowsX64Main]) {
108-
dependsOn nativeMain
109-
}
11088

111-
configure([linuxX64Test, macosX64Test, windowsX64Test]) {
112-
dependsOn nativeTest
89+
nativeMain {
90+
dependencies {
11391
}
11492
}
115-
116-
nativeMain.dependencies {
117-
}
11893
}
11994
}
12095

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package org.jetbrains.gradle.benchmarks
2+
3+
import kotlinx.cli.*
4+
5+
class RunnerCommandLine : CommandLineInterface("Client") {
6+
val name by onFlagValue("-n", "name", "Name of the configuration").store()
7+
val reportFile by onFlagValue("-r", "reportFile", "File to save report to").store()
8+
val traceFormat by onFlagValue("-t", "traceFormat", "Format of tracing report (text or xml)").store("text")
9+
val iterations by onFlagValue("-i", "iterations", "Number of iterations per benchmark").map { it.toInt() }.store(10)
10+
val iterationTime by onFlagValue("-ti", "iterationTime", "Time to run one iteration in milliseconds").map { it.toLong() }.store(1000L)
11+
}

runtime/jsMain/src/org/jetbrains/gradle/benchmarks/js/JsBenchmarkSuite.kt

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.jetbrains.gradle.benchmarks.js
22

3+
import kotlinx.cli.*
34
import org.jetbrains.gradle.benchmarks.*
45
import kotlin.math.*
56

@@ -9,60 +10,57 @@ private val fs = require("fs");
910
private val process = require("process");
1011

1112
class Suite(val title: String, @Suppress("UNUSED_PARAMETER") dummy_args: Array<out String>) {
12-
private val args = (process["argv"] as Array<String>).drop(2)
13-
private val iterations = args[1].toInt()
14-
private val iterationTime = args[2].toInt()
15-
private val format = args[3]
16-
private val reportFile = args.first()
13+
private val args = RunnerCommandLine().also { it.parse((process["argv"] as Array<String>).drop(2)) }
1714
private val suite: dynamic = benchmarkJs.Suite()
1815
val results = mutableListOf<ReportBenchmarkResult>()
1916

2017
fun run() {
2118
suite.on("complete") {
22-
when (format) {
19+
when (args.traceFormat) {
2320
"xml" -> {
2421
println(ijLogFinish(title, ""))
2522
}
2623
"text" -> {
2724
println()
2825
}
29-
else -> throw UnsupportedOperationException("Format $format is not supported.")
26+
else -> throw UnsupportedOperationException("Format ${args.traceFormat} is not supported.")
3027
}
3128
}
32-
when (format) {
29+
when (args.traceFormat) {
3330
"xml" -> {
3431
println(ijLogStart(title, ""))
3532
}
36-
"text" -> {}
37-
else -> throw UnsupportedOperationException("Format $format is not supported.")
33+
"text" -> {
34+
}
35+
else -> throw UnsupportedOperationException("Format ${args.traceFormat} is not supported.")
3836
}
3937
suite.run()
40-
fs.writeFile(reportFile, results.toJson()) { err -> if (err) throw err }
38+
fs.writeFile(args.reportFile, results.toJson()) { err -> if (err) throw err }
4139
}
4240

4341
fun add(name: String, function: () -> Any?, setup: () -> Unit, teardown: () -> Unit) {
4442
suite.add(name, function)
4543
val benchmark = suite[suite.length - 1] // take back last added benchmark and subscribe to events
46-
44+
4745
// TODO: Configure properly
4846
// initCount: The default number of times to execute a test on a benchmark’s first cycle
4947
// minTime: The time needed to reduce the percent uncertainty of measurement to 1% (secs).
5048
// maxTime: The maximum time a benchmark is allowed to run before finishing (secs).
51-
52-
benchmark.options.minTime = iterationTime / 1000.0
53-
benchmark.options.maxTime = iterationTime * iterations / 1000.0
49+
50+
benchmark.options.minTime = args.iterationTime / 1000.0
51+
benchmark.options.maxTime = args.iterationTime * args.iterations / 1000.0
5452

5553
benchmark.on("start") { event ->
5654
val benchmarkFQN = event.target.name
57-
when (format) {
55+
when (args.traceFormat) {
5856
"xml" -> {
5957
println(ijLogStart(benchmarkFQN, title))
6058
}
6159
"text" -> {
6260
println()
6361
println("$benchmarkFQN")
6462
}
65-
else -> throw UnsupportedOperationException("Format $format is not supported.")
63+
else -> throw UnsupportedOperationException("Format ${args.traceFormat} is not supported.")
6664
}
6765

6866
setup()
@@ -78,15 +76,15 @@ class Suite(val title: String, @Suppress("UNUSED_PARAMETER") dummy_args: Array<o
7876
" ~ ${score.format(d)} ops/sec ±${(error / score * 100).format(2)}%"
7977
}
8078

81-
when (format) {
79+
when (args.traceFormat) {
8280
"xml" -> {
8381
println(ijLogFinish(benchmarkFQN, title))
8482
println(ijLogOutput(benchmarkFQN, title, message))
8583
}
8684
"text" -> {
8785
println(" $message")
8886
}
89-
else -> throw UnsupportedOperationException("Format $format is not supported.")
87+
else -> throw UnsupportedOperationException("Format ${args.traceFormat} is not supported.")
9088
}
9189

9290

0 commit comments

Comments
 (0)