• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
<lambda>null2  * Copyright 2017-2024 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
3  */
4 
5 import groovy.json.JsonSlurper
6 import java.io.FileNotFoundException
7 
8 /**
9  * Utility for printing benchmark results.
10  * Results can be obtained with JMH flags
11  * -rf json -rff serialization-benchmark-results.json
12  */
13 open class PrintBenchmarksTask: DefaultTask() {
14     private val fileName: String = "serialization-benchmark-results.json"
15 
16     @Suppress("UNCHECKED_CAST")
17     @TaskAction
18     fun printBenchmarkJsonAsTeamcityStats() {
19         val jsonFile = project.file(fileName)
20         if (!jsonFile.exists()) throw TaskExecutionException(this, FileNotFoundException("File $fileName not found"))
21         val parsedJson = JsonSlurper().parseText(jsonFile.readText()) as Iterable<Map<String, Any>>
22 
23         parsedJson.forEach { v ->
24             val name = (v["benchmark"] as String).substringAfter("kotlinx.benchmarks.")
25             val score = (v["primaryMetric"] as Map<String, String>)["score"]
26             println("##teamcity[buildStatisticValue key='$name' value='$score']")
27         }
28     }
29 }
30 
31 tasks.register<PrintBenchmarksTask>("printBenchmarksJsonAsTeamcityStats")
32