From f54f570fbfc786c16d71d25738c83979715530ca Mon Sep 17 00:00:00 2001 From: Elena Lepilkina Date: Wed, 30 Jan 2019 15:14:56 +0300 Subject: [PATCH] Added measuring code size for full application --- performance/build.gradle | 15 ++++++++++----- .../buildSrc/src/main/kotlin/MPPTools.kt | 18 +++++++++++++++++- .../kotlin-js/org/jetbrains/analyzer/Utils.kt | 1 - .../org/jetbrains/analyzer/Statistics.kt | 2 +- 4 files changed, 28 insertions(+), 8 deletions(-) diff --git a/performance/build.gradle b/performance/build.gradle index b1db3080952..647b16376ef 100644 --- a/performance/build.gradle +++ b/performance/build.gradle @@ -41,6 +41,7 @@ private def determinePreset() { } def hostPreset = determinePreset() +def applicationName = 'Ring' kotlin { sourceSets { @@ -104,13 +105,15 @@ task jvmRun(type: JavaExec) { task konanJsonReport { doLast { - def nativeCompileTime = MPPTools.getNativeCompileTime('Ring') + def nativeExecutable = MPPTools.getKotlinNativeExecutable(kotlin.targets.native, "RELEASE") + def nativeCompileTime = MPPTools.getNativeCompileTime(applicationName) String benchContents = new File("${buildDir.absolutePath}/${nativeBenchResults}").text def properties = getCommonProperties() + ['type' : 'native', 'compilerVersion': "${konanVersion}".toString(), - 'flags' : kotlin.targets.native.compilations.main.extraOpts.collect{ '"' + it + '"'}, + 'flags' : kotlin.targets.native.compilations.main.extraOpts.collect{ "\"$it\"" }, 'benchmarks' : benchContents, - 'compileTime' : nativeCompileTime] + 'compileTime' : nativeCompileTime, + 'codeSize' : MPPTools.getCodeSizeBenchmark(applicationName, nativeExecutable) ] def output = MPPTools.createJsonReport(properties) new File("${buildDir.absolutePath}/${nativeJson}").write(output) uploadBenchmarkResultToBintray(nativeJson) @@ -119,12 +122,14 @@ task konanJsonReport { task jvmJsonReport { doLast { - def jvmCompileTime = MPPTools.getJvmCompileTime('Ring') + def jarPath = project.getTasks().getByName("jvmJar").archivePath + def jvmCompileTime = MPPTools.getJvmCompileTime(applicationName) String benchContents = new File("${buildDir.absolutePath}/${jvmBenchResults}").text def properties = getCommonProperties() + ['type' : 'jvm', 'compilerVersion': "${buildKotlinVersion}".toString(), 'benchmarks' : benchContents, - 'compileTime' : jvmCompileTime] + 'compileTime' : jvmCompileTime, + 'codeSize' : MPPTools.getCodeSizeBenchmark(applicationName, "${jarPath}") ] def output = MPPTools.createJsonReport(properties) new File("${buildDir.absolutePath}/${jvmJson}").write(output) uploadBenchmarkResultToBintray(jvmJson) diff --git a/performance/buildSrc/src/main/kotlin/MPPTools.kt b/performance/buildSrc/src/main/kotlin/MPPTools.kt index 528e499234c..10e555ab8a5 100644 --- a/performance/buildSrc/src/main/kotlin/MPPTools.kt +++ b/performance/buildSrc/src/main/kotlin/MPPTools.kt @@ -76,6 +76,21 @@ fun getNativeProgramExtension(): String = when { else -> error("Unknown host") } +fun getKotlinNativeExecutable(target: KotlinTarget, buildType: String) = + target.compilations.main.getBinary("EXECUTABLE", buildType).toString() + +fun getFileSize(filePath: String): Long? { + val file = File(filePath) + return if (file.exists()) file.length() else null +} + +fun getCodeSizeBenchmark(programName: String, filePath: String): BenchmarkResult { + val codeSize = getFileSize(filePath) + return BenchmarkResult("$programName.codeSize", + codeSize?. let { BenchmarkResult.Status.PASSED } ?: run { BenchmarkResult.Status.FAILED }, + codeSize?.toDouble() ?: 0.0, codeSize?.toDouble() ?: 0.0, 1, 0) +} + // Create benchmarks json report based on information get from gradle project fun createJsonReport(projectProperties: Map): String { fun getValue(key: String): String = projectProperties[key] as? String ?: "unknown" @@ -89,7 +104,8 @@ fun createJsonReport(projectProperties: Map): String { val benchDesc = getValue("benchmarks") val benchmarksArray = JsonTreeParser.parse(benchDesc) val benchmarks = BenchmarksReport.parseBenchmarksArray(benchmarksArray) - .union(listOf(projectProperties["compileTime"] as BenchmarkResult)).toList() + .union(listOf(projectProperties["compileTime"] as BenchmarkResult, + projectProperties["codeSize"] as BenchmarkResult)).toList() val report = BenchmarksReport(env, benchmarks, kotlin) return report.toJson() } diff --git a/tools/benchmarksAnalyzer/src/main/kotlin-js/org/jetbrains/analyzer/Utils.kt b/tools/benchmarksAnalyzer/src/main/kotlin-js/org/jetbrains/analyzer/Utils.kt index f8bd61ed13e..1e6fad63d76 100644 --- a/tools/benchmarksAnalyzer/src/main/kotlin-js/org/jetbrains/analyzer/Utils.kt +++ b/tools/benchmarksAnalyzer/src/main/kotlin-js/org/jetbrains/analyzer/Utils.kt @@ -20,7 +20,6 @@ import org.w3c.xhr.* import kotlin.browser.* import kotlin.js.* - actual fun readFile(fileName: String): String { error("Reading from local file for JS isn't supported") } diff --git a/tools/benchmarksAnalyzer/src/main/kotlin/org/jetbrains/analyzer/Statistics.kt b/tools/benchmarksAnalyzer/src/main/kotlin/org/jetbrains/analyzer/Statistics.kt index 41f5bb5a5e9..b42005e7d98 100644 --- a/tools/benchmarksAnalyzer/src/main/kotlin/org/jetbrains/analyzer/Statistics.kt +++ b/tools/benchmarksAnalyzer/src/main/kotlin/org/jetbrains/analyzer/Statistics.kt @@ -38,7 +38,7 @@ data class MeanVarianceBenchmark(val meanBenchmark: BenchmarkResult, val varianc fun calcPercentageDiff(other: MeanVarianceBenchmark): MeanVariance { assert(other.meanBenchmark.score >= 0 && other.varianceBenchmark.score >= 0 && - abs(other.meanBenchmark.score - other.varianceBenchmark.score) != 0.0, + other.meanBenchmark.score - other.varianceBenchmark.score != 0.0, { "Mean and variance should be positive and not equal!" }) val mean = (meanBenchmark.score - other.meanBenchmark.score) / other.meanBenchmark.score val maxValueChange = abs(meanBenchmark.score + varianceBenchmark.score -