Added usage of benchmarksAnalyzer for analysis of performance, so removed extra code from benchmark application and gradle. (#2501)
This commit is contained in:
@@ -122,4 +122,9 @@ fun collectMeanResults(benchmarks: Map<String, List<BenchmarkResult>>): Benchmar
|
||||
currentWarmup)
|
||||
name to MeanVarianceBenchmark(meanBenchmark, varianceBenchmark)
|
||||
}.toMap()
|
||||
}
|
||||
}
|
||||
|
||||
fun collectBenchmarksDurations(benchmarks: Map<String, List<BenchmarkResult>>): Map<String, Double> =
|
||||
benchmarks.map { (name, resultsSet) ->
|
||||
name to resultsSet.sumByDouble { it.runtimeInUs }
|
||||
}.toMap()
|
||||
+16
@@ -34,6 +34,7 @@ class SummaryBenchmarksReport (val currentReport: BenchmarksReport,
|
||||
val meaningfulChangesValue: Double = 0.5) {
|
||||
// Report created by joining comparing reports.
|
||||
val mergedReport: Map<String, SummaryBenchmark>
|
||||
val benchmarksDurations: Map<String, Pair<Double?, Double?>>
|
||||
|
||||
// Lists of benchmarks in different status.
|
||||
private val benchmarksWithChangedStatus = mutableListOf<FieldChange<BenchmarkResult.Status>>()
|
||||
@@ -70,6 +71,9 @@ class SummaryBenchmarksReport (val currentReport: BenchmarksReport,
|
||||
val currentMeanVarianceBenchmarks: List<MeanVarianceBenchmark>
|
||||
get() = mergedReport.filter { it.value.first != null }.map { it.value.first!! }
|
||||
|
||||
val currentBenchmarksDuration: Map<String, Double>
|
||||
get() = benchmarksDurations.filter{ it.value.first != null }.map { it.key to it.value.first!! }.toMap()
|
||||
|
||||
init {
|
||||
// Count avarage values for each benchmark.
|
||||
val currentBenchmarksTable = collectMeanResults(currentReport.benchmarks)
|
||||
@@ -77,6 +81,7 @@ class SummaryBenchmarksReport (val currentReport: BenchmarksReport,
|
||||
collectMeanResults(previousReport.benchmarks)
|
||||
}
|
||||
mergedReport = createMergedReport(currentBenchmarksTable, previousBenchmarksTable)
|
||||
benchmarksDurations = calculateBenchmarksDuration(currentReport, previousReport)
|
||||
geoMeanBenchmark = calculateGeoMeanBenchmark(currentBenchmarksTable, previousBenchmarksTable)
|
||||
if (previousReport != null) {
|
||||
// Check changes in environment and tools.
|
||||
@@ -101,6 +106,17 @@ class SummaryBenchmarksReport (val currentReport: BenchmarksReport,
|
||||
return MeanVarianceBenchmark(meanBenchmark, varianceBenchmark)
|
||||
}
|
||||
|
||||
// Generate map with summary durations of each benchmark.
|
||||
private fun calculateBenchmarksDuration(currentReport: BenchmarksReport, previousReport: BenchmarksReport?):
|
||||
Map<String, Pair<Double?, Double?>> {
|
||||
val currentDurations = collectBenchmarksDurations(currentReport.benchmarks)
|
||||
val previousDurations = previousReport?.let {
|
||||
collectBenchmarksDurations(previousReport.benchmarks)
|
||||
} ?: mapOf<String, Double>()
|
||||
return currentDurations.keys.union(previousDurations.keys)
|
||||
.map { it to Pair(currentDurations[it], previousDurations[it]) }.toMap()
|
||||
}
|
||||
|
||||
// Merge current and compare to report.
|
||||
private fun createMergedReport(currentBenchmarks: BenchmarksTable, previousBenchmarks: BenchmarksTable?):
|
||||
Map<String, SummaryBenchmark> {
|
||||
|
||||
+28
-8
@@ -25,20 +25,40 @@ class TeamCityStatisticsRender: Render {
|
||||
private var content = StringBuilder()
|
||||
|
||||
override fun render(report: SummaryBenchmarksReport, onlyChanges: Boolean): String {
|
||||
val currentDurations = report.currentBenchmarksDuration
|
||||
|
||||
content.append("##teamcity[testSuiteStarted name='Benchmarks']\n")
|
||||
|
||||
// For current benchmarks print score as TeamCity Test Metadata
|
||||
report.currentMeanVarianceBenchmarks.forEach { benchmark ->
|
||||
content.append(renderBenchmark(benchmark.meanBenchmark, "Mean"))
|
||||
content.append(renderBenchmark(benchmark.varianceBenchmark, "Variance"))
|
||||
renderBenchmark(benchmark.meanBenchmark, currentDurations[benchmark.meanBenchmark.name]!!)
|
||||
renderSummaryBecnhmarkValue(benchmark.meanBenchmark, "Mean")
|
||||
renderSummaryBecnhmarkValue(benchmark.varianceBenchmark, "Variance")
|
||||
}
|
||||
content.append("##teamcity[testSuiteFinished name='Benchmarks']\n")
|
||||
|
||||
// Report geometric mean as build statistic value
|
||||
content.append(renderGeometricMean(report.geoMeanBenchmark.first!!))
|
||||
renderGeometricMean(report.geoMeanBenchmark.first!!)
|
||||
|
||||
return content.toString()
|
||||
}
|
||||
|
||||
private fun renderBenchmark(benchmark: BenchmarkResult, metric: String): String =
|
||||
"##teamcity[testMetadata testName='${benchmark.name}' name='$metric' type='number' value='${benchmark.score}']\n"
|
||||
private fun renderSummaryBecnhmarkValue(benchmark: BenchmarkResult, metric: String) =
|
||||
content.append("##teamcity[testMetadata testName='${benchmark.name}' name='$metric'" +
|
||||
" type='number' value='${benchmark.score}']\n")
|
||||
|
||||
private fun renderGeometricMean(geoMeanBenchmark: MeanVarianceBenchmark): String =
|
||||
"##teamcity[buildStatisticValue key='Geometric mean' value='${geoMeanBenchmark.meanBenchmark.score}']\n" +
|
||||
"##teamcity[buildStatisticValue key='Geometric mean variance' value='${geoMeanBenchmark.varianceBenchmark.score}']\n"
|
||||
// Produce benchmark as test in TeamCity
|
||||
private fun renderBenchmark(benchmark: BenchmarkResult , duration: Double) {
|
||||
content.append("##teamcity[testStarted name='${benchmark.name}']\n")
|
||||
if (benchmark.status == BenchmarkResult.Status.FAILED) {
|
||||
content.append("##teamcity[testFailed name='${benchmark.name}']\n")
|
||||
}
|
||||
// test_duration_in_milliseconds is set for TeamCity
|
||||
content.append("##teamcity[testFinished name='${benchmark.name}' duration='${(duration / 1000).toInt()}']\n")
|
||||
}
|
||||
|
||||
private fun renderGeometricMean(geoMeanBenchmark: MeanVarianceBenchmark) {
|
||||
content.append("##teamcity[buildStatisticValue key='Geometric mean' value='${geoMeanBenchmark.meanBenchmark.score}']\n")
|
||||
content.append("##teamcity[buildStatisticValue key='Geometric mean variance' value='${geoMeanBenchmark.varianceBenchmark.score}']\n")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user