Refactor benchmark report writer

This commit is contained in:
Iaroslav Postovalov 2021-06-19 20:52:26 +07:00
parent 65d0cbbe31
commit 7feb87ff05
4 changed files with 47 additions and 53 deletions

View File

@ -10,9 +10,7 @@ allprojects {
maven("http://logicrunch.research.it.uu.se/maven") { maven("http://logicrunch.research.it.uu.se/maven") {
isAllowInsecureProtocol = true isAllowInsecureProtocol = true
} }
maven("https://oss.sonatype.org/content/repositories/snapshots") { maven("https://oss.sonatype.org/content/repositories/snapshots")
}
mavenCentral() mavenCentral()
} }

View File

@ -4,13 +4,14 @@ plugins {
} }
repositories { repositories {
gradlePluginPortal() maven("https://repo.kotlin.link")
mavenCentral() mavenCentral()
gradlePluginPortal()
} }
dependencies { dependencies {
api("org.jetbrains.kotlinx:kotlinx-serialization-json:1.1.0") api("org.jetbrains.kotlinx:kotlinx-serialization-json:1.1.0")
api("ru.mipt.npm:gradle-tools:0.9.10") api("ru.mipt.npm:gradle-tools:0.10.0")
api("org.jetbrains.kotlinx:kotlinx-benchmark-plugin:0.3.1") api("org.jetbrains.kotlinx:kotlinx-benchmark-plugin:0.3.1")
} }

View File

@ -5,8 +5,11 @@
package space.kscience.kmath.benchmarks package space.kscience.kmath.benchmarks
import kotlinx.benchmark.gradle.BenchmarksExtension
import kotlinx.serialization.* import kotlinx.serialization.*
import kotlinx.serialization.json.*
import org.gradle.api.Project import org.gradle.api.Project
import ru.mipt.npm.gradle.KScienceReadmeExtension
import java.time.* import java.time.*
import java.time.format.* import java.time.format.*
import java.time.temporal.ChronoField.* import java.time.temporal.ChronoField.*
@ -42,63 +45,55 @@ private fun noun(number: Number, singular: String, plural: String) = if (number.
fun Project.addBenchmarkProperties() { fun Project.addBenchmarkProperties() {
val benchmarksProject = this val benchmarksProject = this
rootProject.subprojects.forEach { p -> rootProject.subprojects.forEach { p ->
p.extensions.findByType(ru.mipt.npm.gradle.KScienceReadmeExtension::class.java)?.run { p.extensions.findByType(KScienceReadmeExtension::class.java)?.run {
benchmarksProject.extensions.findByType(kotlinx.benchmark.gradle.BenchmarksExtension::class.java)?.configurations?.forEach { cfg -> benchmarksProject.extensions.findByType(BenchmarksExtension::class.java)?.configurations?.forEach { cfg ->
// TODO remove this hack when https://github.com/mipt-npm/gradle-tools/pull/15 is merged property("benchmark${cfg.name.replaceFirstChar(Char::uppercase)}") {
@Suppress("UNCHECKED_CAST") val launches = benchmarksProject.buildDir.resolve("reports/benchmarks/${cfg.name}")
(javaClass.getDeclaredField("properties")
.also {
it.isAccessible = true
}[this] as MutableMap<String, () -> Any?>)["benchmark${cfg.name.replaceFirstChar(Char::uppercase)}"] =
{
val launches = benchmarksProject.buildDir.resolve("reports/benchmarks/${cfg.name}")
val resDirectory = launches.listFiles()?.maxByOrNull { val resDirectory = launches.listFiles()?.maxByOrNull {
LocalDateTime.parse(it.name, ISO_DATE_TIME).atZone(ZoneId.systemDefault()).toInstant() LocalDateTime.parse(it.name, ISO_DATE_TIME).atZone(ZoneId.systemDefault()).toInstant()
} }
if (resDirectory == null) { if (resDirectory == null) {
"> **Can't find appropriate benchmark data. Try generating readme files after running benchmarks**." "> **Can't find appropriate benchmark data. Try generating readme files after running benchmarks**."
} else { } else {
val reports = val reports =
kotlinx.serialization.json.Json.decodeFromString<List<JmhReport>>( Json.decodeFromString<List<JmhReport>>(resDirectory.resolve("jvm.json").readText())
resDirectory.resolve("jvm.json").readText()
)
buildString { buildString {
appendLine("<details>") appendLine("<details>")
appendLine("<summary>") appendLine("<summary>")
appendLine("Report for benchmark configuration <code>${cfg.name}</code>") appendLine("Report for benchmark configuration <code>${cfg.name}</code>")
appendLine("</summary>") appendLine("</summary>")
appendLine() appendLine()
val first = reports.first() val first = reports.first()
appendLine("* Run on ${first.vmName} (build ${first.vmVersion}) with Java process:") appendLine("* Run on ${first.vmName} (build ${first.vmVersion}) with Java process:")
appendLine() appendLine()
appendLine("```") appendLine("```")
appendLine("${first.jvm} ${ appendLine("${first.jvm} ${
first.jvmArgs.joinToString(" ") first.jvmArgs.joinToString(" ")
}") }")
appendLine("```") appendLine("```")
appendLine("* JMH ${first.jmhVersion} was used in `${first.mode}` mode with ${first.warmupIterations} warmup ${ appendLine("* JMH ${first.jmhVersion} was used in `${first.mode}` mode with ${first.warmupIterations} warmup ${
noun(first.warmupIterations, "iteration", "iterations") noun(first.warmupIterations, "iteration", "iterations")
} by ${first.warmupTime} and ${first.measurementIterations} measurement ${ } by ${first.warmupTime} and ${first.measurementIterations} measurement ${
noun(first.measurementIterations, "iteration", "iterations") noun(first.measurementIterations, "iteration", "iterations")
} by ${first.measurementTime}.") } by ${first.measurementTime}.")
appendLine() appendLine()
appendLine("| Benchmark | Score |") appendLine("| Benchmark | Score |")
appendLine("|:---------:|:-----:|") appendLine("|:---------:|:-----:|")
reports.forEach { report -> reports.forEach { report ->
appendLine("|`${report.benchmark}`|${report.primaryMetric.score} &plusmn; ${report.primaryMetric.scoreError} ${report.primaryMetric.scoreUnit}|") appendLine("|`${report.benchmark}`|${report.primaryMetric.score} &plusmn; ${report.primaryMetric.scoreError} ${report.primaryMetric.scoreUnit}|")
}
appendLine("</details>")
} }
appendLine("</details>")
} }
} }
}
} }
} }
} }

View File

@ -5,7 +5,7 @@ pluginManagement {
gradlePluginPortal() gradlePluginPortal()
} }
val toolsVersion = "0.9.10" val toolsVersion = "0.10.0"
val kotlinVersion = "1.5.0" val kotlinVersion = "1.5.0"
plugins { plugins {