[performance] enable project performance

(cherry picked from commit 947c3bd92b2ee8d252619cf987427a7e195191cb)
This commit is contained in:
Vasily Levchenko
2021-02-17 16:52:32 +01:00
committed by Stanislav Erokhin
parent f2524dbb8d
commit c9e0928038
29 changed files with 469 additions and 254 deletions
@@ -11,7 +11,6 @@ import org.gradle.api.Task
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.TaskAction
import org.jetbrains.kotlin.konan.target.AppleConfigurables
import org.jetbrains.kotlin.gradle.plugin.tasks.*
/**
* Test task for -Xcoverage and -Xlibraries-to-cover flags. Requires a binary to be built by the Konan plugin
@@ -62,7 +62,7 @@ open class RunKotlinNativeTask @Inject constructor(private val linkTask: Task,
executable = "cset"
args("shield", "--exec", "--", executable)
} else {
this.executable = executable
executable = this@RunKotlinNativeTask.executable
}
args(argumentsList)
@@ -104,7 +104,7 @@ open class RunKotlinNativeTask @Inject constructor(private val linkTask: Task,
fun run() {
val output = ByteArrayOutputStream()
project.exec {
executable = executable
executable = this@RunKotlinNativeTask.executable
args("list")
standardOutput = output
}
@@ -20,7 +20,6 @@ import java.util.concurrent.TimeUnit
import java.net.HttpURLConnection
import java.net.URL
import java.util.Base64
import org.jetbrains.report.json.*
import java.nio.file.Path
import org.jetbrains.kotlin.konan.file.File as KFile
import org.gradle.nativeplatform.toolchain.internal.*
@@ -97,7 +96,10 @@ val validPropertiesNames = listOf("kotlin.native.home",
"konan.home")
val Project.kotlinNativeDist
get() = rootProject.file(validPropertiesNames.firstOrNull{ hasProperty(it) }?.let{ findProperty(it) } ?: "dist")
get() = rootProject.currentKotlinNativeDist
val Project.currentKotlinNativeDist
get() = file(validPropertiesNames.firstOrNull{ hasProperty(it) }?.let{ findProperty(it) } ?: "dist")
val kotlinNativeHome
get() = validPropertiesNames.mapNotNull(System::getProperty).first()
@@ -255,31 +257,6 @@ data class Commit(val revision: String, val developer: String, val webUrlWithDes
val teamCityUrl = "http://buildserver.labs.intellij.net"
// List of commits.
class CommitsList(data: JsonElement): ConvertedFromJson {
val commits: List<Commit>
init {
if (data !is JsonObject) {
error("Commits description is expected to be a json object!")
}
val changesElement = data.getOptionalField("change")
commits = changesElement?.let {
if (changesElement !is JsonArray) {
error("Change field is expected to be an array. Please, check source.")
}
changesElement.jsonArray.map {
with(it as JsonObject) {
Commit(elementToString(getRequiredField("version"), "version"),
elementToString(getRequiredField("username"), "username"),
elementToString(getRequiredField("webUrl"), "webUrl")
)
}
}
} ?: listOf<Commit>()
}
}
fun buildsUrl(buildLocator: String) =
"$teamCityUrl/app/rest/builds/?locator=$buildLocator"
@@ -302,13 +279,6 @@ fun sendGetRequest(url: String, username: String? = null, password: String? = nu
return connection.inputStream.use { it.reader().use { reader -> reader.readText() } }
}
fun getBuildProperty(buildJsonDescription: String, property: String) =
with(JsonTreeParser.parse(buildJsonDescription) as JsonObject) {
if (getPrimitive("count").int == 0) {
error("No build information on TeamCity for $buildJsonDescription!")
}
(getArray("build").getObject(0).getPrimitive(property) as JsonLiteral).unquoted()
}
@JvmOverloads
fun compileSwift(project: Project, target: KonanTarget, sources: List<String>, options: List<String>,
@@ -125,16 +125,11 @@ abstract class BenchmarkingPlugin: Plugin<Project> {
protected open fun Project.configureSourceSets(kotlinVersion: String) {
with(kotlin.sourceSets) {
commonMain.dependencies {
implementation(project(":kotlin-stdlib-common"))
implementation(files("${project.findProperty("kotlin_dist")}/kotlinc/lib/kotlin-stdlib.jar"))
}
project.configurations.getByName(nativeMain.implementationConfigurationName).apply {
// Exclude dependencies already included into K/N distribution (aka endorsed libraries).
exclude(mapOf("module" to "kotlinx.cli"))
}
repositories.maven {
setUrl(kotlinStdlibRepo)
repositories.flatDir {
dir("${project.findProperty("kotlin_dist")}/kotlinc/lib")
}
additionalConfigurations(this@configureSourceSets)
@@ -268,7 +263,13 @@ abstract class BenchmarkingPlugin: Plugin<Project> {
pluginManager.apply("kotlin-multiplatform")
// Use Kotlin compiler version specified by the project property.
dependencies.add("kotlinCompilerClasspath", "org.jetbrains.kotlin:kotlin-compiler-embeddable:$kotlinVersion")
target.logger.info("BenchmarkingPlugin.kt:apply($kotlinVersion)")
dependencies.add(
"kotlinCompilerClasspath", files(
"${project.findProperty("kotlin_dist")}/kotlinc/lib/kotlin-compiler.jar",
"${project.findProperty("kotlin_dist")}/kotlinc/lib/kotlin-daemon.jar"
)
)
addTimeListener(this)
extensions.create(benchmarkExtensionName, benchmarkExtensionClass.java, this)
@@ -124,7 +124,9 @@ open class KotlinNativeBenchmarkingPlugin: BenchmarkingPlugin() {
override fun NamedDomainObjectContainer<KotlinSourceSet>.additionalConfigurations(project: Project) {
jvmMain.dependencies {
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8:${project.kotlinStdlibVersion}")
implementation(project.files("${project.findProperty("kotlin_dist")}/kotlinc/lib/kotlin-stdlib-jdk8.jar"))
println("implementation(${project.name}: ${project.projectDir}): ${project.currentKotlinNativeDist}/libs/kotlinx.cli-jvm-${project.kotlinVersion}.jar")
implementation(project.files("${project.currentKotlinNativeDist}/libs/kotlinx.cli-jvm-${project.kotlinVersion}.jar"))
}
}
@@ -0,0 +1,42 @@
/*
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin
import org.jetbrains.report.json.*
// List of commits.
class CommitsList(data: JsonElement): ConvertedFromJson {
val commits: List<Commit>
init {
if (data !is JsonObject) {
error("Commits description is expected to be a json object!")
}
val changesElement = data.getOptionalField("change")
commits = changesElement?.let {
if (changesElement !is JsonArray) {
error("Change field is expected to be an array. Please, check source.")
}
changesElement.jsonArray.map {
with(it as JsonObject) {
Commit(elementToString(getRequiredField("version"), "version"),
elementToString(getRequiredField("username"), "username"),
elementToString(getRequiredField("webUrl"), "webUrl")
)
}
}
} ?: listOf<Commit>()
}
}
fun getBuildProperty(buildJsonDescription: String, property: String) =
with(JsonTreeParser.parse(buildJsonDescription) as JsonObject) {
if (getPrimitive("count").int == 0) {
error("No build information on TeamCity for $buildJsonDescription!")
}
(getArray("build").getObject(0).getPrimitive(property) as JsonLiteral).unquoted()
}
@@ -1,95 +0,0 @@
/*
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.report.json
open class JsonSerializable
data class JsonObject(val content: Map<String, JsonElement>) : JsonElement(), Map<String, JsonElement> by content {
fun getOrNull(key: String): JsonElement? = null
fun getObject(key: String): JsonObject = JsonObject(emptyMap<String, JsonElement>())
fun getArray(key: String): JsonArray = JsonArray(emptyList())
fun getPrimitive(key: String): JsonPrimitive = JsonNull
}
data class JsonLiteral internal constructor(
private val body: Any,
private val isString: Boolean
) : JsonPrimitive() {
override val content = body.toString()
override val contentOrNull: String = content
constructor(number: Number) : this(number, false)
constructor(boolean: Boolean) : this(boolean, false)
constructor(string: String) : this(string, true)
fun unquoted() = ""
}
sealed class JsonPrimitive():JsonElement(){
abstract val content: String
abstract val contentOrNull: String?
val int: Int get() = 0
}
object JsonNull : JsonPrimitive() {
override val content: String = "null"
override val contentOrNull: String? = null
}
open class JsonElement:JsonSerializable() {
open val jsonObject: JsonObject
get() = error("JsonObject")
open val jsonArray: JsonArray
get() = error("JsonArray")
}
open class JsonTreeParser:JsonSerializable() {
companion object{
fun parse(benchDesc:String) = JsonElement()
}
}
open class JsonArray(val content: List<JsonElement>):JsonElement(), List<JsonElement> by content {
fun getObject(index: Int): JsonObject = JsonObject(emptyMap<String, JsonElement>())
}
open class BenchmarksReport(val env: Environment, benchmarksList: List<BenchmarkResult>, val compiler: Compiler) : JsonSerializable() {
constructor() : this(Environment(Environment.Machine("Pentium Pro", "Haiku OS"), Environment.JDKInstance("KaffeJVM", "Kaffe")),
emptyList<BenchmarkResult>(),
Compiler(Compiler.Backend(Compiler.BackendType.NATIVE, "1.0", emptyList()),"1.0"))
companion object {
fun create(data: JsonElement): BenchmarksReport = BenchmarksReport()
}
fun toJson() = "{}"
operator fun plus(other: BenchmarksReport): BenchmarksReport = this
}
open class BenchmarkResult(val name: String, val status: Status,
val score: Double, val metric: Metric, val runtimeInUs: Double,
val repeat: Int, val warmup: Int) : JsonSerializable() {
enum class Status(val value: String) {
PASSED("PASSED"),
FAILED("FAILED")
}
enum class Metric(val suffix: String, val value: String) {
EXECUTION_TIME("", "EXECUTION_TIME"),
CODE_SIZE(".codeSize", "CODE_SIZE"),
COMPILE_TIME(".compileTime", "COMPILE_TIME"),
BUNDLE_SIZE(".bundleSize", "BUNDLE_SIZE")
}
}
data class Environment(val machine: Machine, val jdk: JDKInstance) : JsonSerializable() {
data class Machine(val cpu: String, val os: String) : JsonSerializable()
data class JDKInstance(val version: String, val vendor: String) : JsonSerializable()
}
data class Compiler(val backend: Backend, val kotlinVersion: String) : JsonSerializable() {
enum class BackendType(val type: String) {
JVM("jvm"),
NATIVE("native")
}
data class Backend(val type: BackendType, val version: String, val flags: List<String>) : JsonSerializable()
companion object{
fun backendTypeFromString(ignored0:String? = null , ignored1:String? = null) = Compiler.BackendType.NATIVE
}
}
fun parseBenchmarksArray(data: JsonElement): List<BenchmarkResult> = emptyList<BenchmarkResult>()
@@ -1,41 +0,0 @@
/*
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.report.json
// Entity can be created from json description.
interface ConvertedFromJson {
// Methods for conversion to expected type with checks of possibility of such conversions.
fun elementToDouble(element: JsonElement, name: String): Double =
if (element is JsonPrimitive)
0.0
else
error("Field '$name' in '$element' is expected to be a double number. Please, check origin files.")
fun elementToInt(element: JsonElement, name: String): Int =
if (element is JsonPrimitive)
0
else
error("Field '$name' in '$element' is expected to be an integer number. Please, check origin files.")
fun elementToString(element: JsonElement, name:String): String =
if (element is JsonLiteral)
""
else
error("Field '$name' in '$element' is expected to be a string. Please, check origin files.")
fun elementToStringOrNull(element: JsonElement, name:String): String? =
when (element) {
else -> error("Field '$name' in '$element' is expected to be a string. Please, check origin files.")
}
}
fun JsonObject.getRequiredField(fieldName: String): JsonElement {
error("Field '$fieldName' doesn't exist in '$this'. Please, check origin files.")
}
fun JsonObject.getOptionalField(fieldName: String): JsonElement? {
return getOrNull(fieldName)
}