From f47feb9d85f73c9d95257e636670e6991a297f43 Mon Sep 17 00:00:00 2001 From: Elena Lepilkina Date: Tue, 29 Jan 2019 16:43:42 +0300 Subject: [PATCH] Added JS target for benchmarksAnalyzer --- .../src/main/kotlin/RegressionsReporter.kt | 4 +- tools/benchmarksAnalyzer/build.gradle | 35 ++++++++++++ .../kotlin-js/org/jetbrains/analyzer/Utils.kt | 53 +++++++++++++++++++ .../org/jetbrains/analyzer/Statistics.kt | 10 ++-- 4 files changed, 96 insertions(+), 6 deletions(-) create mode 100644 tools/benchmarksAnalyzer/src/main/kotlin-js/org/jetbrains/analyzer/Utils.kt diff --git a/performance/buildSrc/src/main/kotlin/RegressionsReporter.kt b/performance/buildSrc/src/main/kotlin/RegressionsReporter.kt index 8b68bda6f3b..eee36ce7bc6 100644 --- a/performance/buildSrc/src/main/kotlin/RegressionsReporter.kt +++ b/performance/buildSrc/src/main/kotlin/RegressionsReporter.kt @@ -216,7 +216,9 @@ open class RegressionsReporter : DefaultTask() { "Please check files existance and their correctness.") } - val reportLink = tabUrl(buildId, buildTypeId, "report_project170_Benchmarks") + val reportLink = "http://kotlin-native-performance.labs.jb.gg/?" + + "report=bintray:$buildNumber:$target:$bintrayFileName&" + + "compareTo=bintray:$compareToBuildNumber:$target:$bintrayFileName" val title = "\n*Performance report for target $target (build $buildNumber)* - $reportLink\n" val header = "$title\n$changesInfo\n\nCompare to build $compareToBuildNumber: $compareToBuildLink\n\n" diff --git a/tools/benchmarksAnalyzer/build.gradle b/tools/benchmarksAnalyzer/build.gradle index 126e3872775..48f2e3d5df8 100644 --- a/tools/benchmarksAnalyzer/build.gradle +++ b/tools/benchmarksAnalyzer/build.gradle @@ -55,6 +55,11 @@ kotlin { implementation "org.jetbrains.kotlin:kotlin-test-junit:$kotlinVersion" } } + jsTest { + dependencies { + implementation "org.jetbrains.kotlin:kotlin-test-js:$kotlinVersion" + } + } nativeMain { dependsOn commonMain kotlin.srcDir 'src/main/kotlin-native' @@ -65,6 +70,12 @@ kotlin { } kotlin.srcDir 'src/main/kotlin-jvm' } + jsMain { + dependencies { + implementation "org.jetbrains.kotlin:kotlin-stdlib-js:$kotlinVersion" + } + kotlin.srcDir 'src/main/kotlin-js' + } linuxMain { dependsOn nativeMain } windowsMain { dependsOn nativeMain } macosMain {dependsOn nativeMain } @@ -104,6 +115,11 @@ kotlin { } } } + fromPreset(presets.js, 'js') { + compilations.main.kotlinOptions { + main = "noCall" + } + } configure([windows, linux, macos]) { binaries { @@ -123,4 +139,23 @@ def getMingwPath() { if (directory == null) directory = "c:/msys64/mingw64" return directory +} + +task assembleWeb(type: Sync) { + def runtimeDependencies = kotlin.targets.js.compilations.main.runtimeDependencyFiles + from(files { + runtimeDependencies.collect { File file -> + zipTree(file.absolutePath) + } + }.builtBy(runtimeDependencies)) { + includeEmptyDirs = false + include { fileTreeElement -> + def path = fileTreeElement.path + path.endsWith(".js") && (path.startsWith("META-INF/resources/") || + !path.startsWith("META-INF/")) + } + } + + from compileKotlinJs.destinationDir + into "${projectDir}/web" } \ No newline at end of file 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 new file mode 100644 index 00000000000..f8bd61ed13e --- /dev/null +++ b/tools/benchmarksAnalyzer/src/main/kotlin-js/org/jetbrains/analyzer/Utils.kt @@ -0,0 +1,53 @@ +/* + * Copyright 2010-2018 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jetbrains.analyzer + +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") +} + +actual fun Double.format(decimalNumber: Int): String = + this.asDynamic().toFixed(decimalNumber) + +actual fun writeToFile(fileName: String, text: String) { + if (fileName != "html") + error("Writing to local file for JS isn't supported") + val bodyPart = text.substringAfter("").substringBefore("") + document.body?.innerHTML = bodyPart +} + +actual fun assert(value: Boolean, lazyMessage: () -> Any) { + if (!value) error(lazyMessage) +} + +actual fun sendGetRequest(url: String, user: String?, password: String?, followLocation: Boolean) : String { + val proxyServerAddress = "https://perf-proxy.labs.jb.gg/" + val newUrl = proxyServerAddress + url + val request = XMLHttpRequest() + + request.open("GET", newUrl, false, user, password) + request.send() + if (request.status == 200.toShort()) { + return request.responseText + } + error("Request to $url has status ${request.status}") +} \ No newline at end of file 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 1c425d64d6d..41f5bb5a5e9 100644 --- a/tools/benchmarksAnalyzer/src/main/kotlin/org/jetbrains/analyzer/Statistics.kt +++ b/tools/benchmarksAnalyzer/src/main/kotlin/org/jetbrains/analyzer/Statistics.kt @@ -36,9 +36,9 @@ data class MeanVarianceBenchmark(val meanBenchmark: BenchmarkResult, val varianc // Calculate difference in percentage compare to another. fun calcPercentageDiff(other: MeanVarianceBenchmark): MeanVariance { - assert(other.meanBenchmark.score > 0 && - other.varianceBenchmark.score > 0 && - other.meanBenchmark.score - other.varianceBenchmark.score != 0.0, + assert(other.meanBenchmark.score >= 0 && + other.varianceBenchmark.score >= 0 && + abs(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 - @@ -55,8 +55,8 @@ data class MeanVarianceBenchmark(val meanBenchmark: BenchmarkResult, val varianc // Calculate ratio value compare to another. fun calcRatio(other: MeanVarianceBenchmark): MeanVariance { - assert(other.meanBenchmark.score > 0 && - other.varianceBenchmark.score > 0 && + assert(other.meanBenchmark.score >= 0 && + other.varianceBenchmark.score >= 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