Skip to content

Commit 98ead98

Browse files
authored
Add task to put jmh benchmarks results to teamcity statistics (#1568)
1 parent 4982507 commit 98ead98

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,3 +173,4 @@ subprojects {
173173

174174
apply from: rootProject.file('gradle/compiler-version.gradle')
175175
apply from: rootProject.file("gradle/dokka.gradle")
176+
apply from: rootProject.file("gradle/benchmark-parsing.gradle")

gradle/benchmark-parsing.gradle

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import groovy.json.JsonSlurper
2+
import org.gradle.api.*
3+
4+
/**
5+
* Utility for printing benchmark results.
6+
* Results can be obtained with JMH flags
7+
* -rf json -rff serialization-benchmark-results.json
8+
*/
9+
class PrintBenchmarksTask extends DefaultTask {
10+
private String fileName = "serialization-benchmark-results.json"
11+
12+
@TaskAction
13+
def printBenchmarkJsonAsTeamcityStats() {
14+
File jsonFile = project.file(fileName)
15+
if (!jsonFile.exists()) throw new TaskExecutionException(this, new FileNotFoundException("File $fileName not found"))
16+
def parsedJson = new JsonSlurper().parseText(jsonFile.text)
17+
18+
parsedJson.each { v ->
19+
def name = (v.benchmark - "kotlinx.benchmarks.")
20+
def score = v.primaryMetric.score
21+
println("##teamcity[buildStatisticValue key='" + name + "' value='" + score + "']")
22+
}
23+
}
24+
}
25+
26+
rootProject.tasks.register("printBenchmarksJsonAsTeamcityStats", PrintBenchmarksTask)

0 commit comments

Comments
 (0)