[K/N][perf] Add possibility to cross compile benchmarks and run them on remote machine
This commit is contained in:
@@ -39,6 +39,9 @@ internal val NamedDomainObjectCollection<KotlinTargetPreset<*>>.linuxX64: Kotlin
|
|||||||
internal val NamedDomainObjectCollection<KotlinTargetPreset<*>>.mingwX64: KotlinTargetPreset<*>
|
internal val NamedDomainObjectCollection<KotlinTargetPreset<*>>.mingwX64: KotlinTargetPreset<*>
|
||||||
get() = getByName(::mingwX64.name)
|
get() = getByName(::mingwX64.name)
|
||||||
|
|
||||||
|
internal val NamedDomainObjectCollection<KotlinTargetPreset<*>>.linuxArm64: KotlinTargetPreset<*>
|
||||||
|
get() = getByName(::linuxArm64.name)
|
||||||
|
|
||||||
internal val NamedDomainObjectContainer<out KotlinCompilation<*>>.main: KotlinNativeCompilation
|
internal val NamedDomainObjectContainer<out KotlinCompilation<*>>.main: KotlinNativeCompilation
|
||||||
get() = getByName(::main.name) as KotlinNativeCompilation
|
get() = getByName(::main.name) as KotlinNativeCompilation
|
||||||
|
|
||||||
|
|||||||
@@ -63,6 +63,17 @@ fun defaultHostPreset(
|
|||||||
throw Exception("Host OS '$hostOs' is not supported in Kotlin/Native ${subproject.displayName}.")
|
throw Exception("Host OS '$hostOs' is not supported in Kotlin/Native ${subproject.displayName}.")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun targetHostPreset(
|
||||||
|
subproject: Project,
|
||||||
|
crossTarget: String
|
||||||
|
): KotlinTargetPreset<*> {
|
||||||
|
return when(crossTarget) {
|
||||||
|
"linuxArm64" -> subproject.kotlin.presets.linuxArm64
|
||||||
|
"linuxX64" -> subproject.kotlin.presets.linuxX64
|
||||||
|
else -> throw Exception("Running becnhmarks on target $crossTarget isn't supported yet.")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun getNativeProgramExtension(): String = when {
|
fun getNativeProgramExtension(): String = when {
|
||||||
PlatformInfo.isMac() -> ".kexe"
|
PlatformInfo.isMac() -> ".kexe"
|
||||||
PlatformInfo.isLinux() -> ".kexe"
|
PlatformInfo.isLinux() -> ".kexe"
|
||||||
|
|||||||
+29
-6
@@ -13,6 +13,7 @@ import org.jetbrains.report.json.*
|
|||||||
import org.gradle.api.tasks.TaskAction
|
import org.gradle.api.tasks.TaskAction
|
||||||
import org.gradle.api.tasks.options.Option
|
import org.gradle.api.tasks.options.Option
|
||||||
import org.gradle.api.tasks.Input
|
import org.gradle.api.tasks.Input
|
||||||
|
import org.gradle.api.tasks.Internal
|
||||||
import java.io.ByteArrayOutputStream
|
import java.io.ByteArrayOutputStream
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
@@ -54,15 +55,26 @@ open class RunKotlinNativeTask @Inject constructor(private val linkTask: Task,
|
|||||||
argumentsList.addAll(arguments.toList())
|
argumentsList.addAll(arguments.toList())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Internal
|
||||||
|
val remoteHost = project.findProperty("remoteHost")?.toString()
|
||||||
|
@Internal
|
||||||
|
val remoteHostFolder = project.findProperty("remoteHostFolder")?.toString()
|
||||||
|
|
||||||
private fun execBenchmarkOnce(benchmark: String, warmupCount: Int, repeatCount: Int) : String {
|
private fun execBenchmarkOnce(benchmark: String, warmupCount: Int, repeatCount: Int) : String {
|
||||||
val output = ByteArrayOutputStream()
|
val output = ByteArrayOutputStream()
|
||||||
val useCset = project.findProperty("useCset")?.toString()?.toBoolean() ?: false
|
val useCset = project.findProperty("useCset")?.toString()?.toBoolean() ?: false
|
||||||
|
|
||||||
project.exec {
|
project.exec {
|
||||||
if (useCset) {
|
when {
|
||||||
executable = "cset"
|
useCset -> {
|
||||||
args("shield", "--exec", "--", this@RunKotlinNativeTask.executable)
|
executable = "cset"
|
||||||
} else {
|
args("shield", "--exec", "--", this@RunKotlinNativeTask.executable)
|
||||||
executable = this@RunKotlinNativeTask.executable
|
}
|
||||||
|
remoteHost != null -> {
|
||||||
|
executable = "ssh"
|
||||||
|
args (remoteHost, "$remoteHostFolder/${this@RunKotlinNativeTask.executable}")
|
||||||
|
}
|
||||||
|
else -> executable = this@RunKotlinNativeTask.executable
|
||||||
}
|
}
|
||||||
|
|
||||||
args(argumentsList)
|
args(argumentsList)
|
||||||
@@ -103,8 +115,19 @@ open class RunKotlinNativeTask @Inject constructor(private val linkTask: Task,
|
|||||||
@TaskAction
|
@TaskAction
|
||||||
fun run() {
|
fun run() {
|
||||||
val output = ByteArrayOutputStream()
|
val output = ByteArrayOutputStream()
|
||||||
|
remoteHost?.let {
|
||||||
|
project.exec {
|
||||||
|
executable = "scp"
|
||||||
|
args(this@RunKotlinNativeTask.executable, "$it:$remoteHostFolder")
|
||||||
|
}
|
||||||
|
}
|
||||||
project.exec {
|
project.exec {
|
||||||
executable = this@RunKotlinNativeTask.executable
|
if (remoteHost != null) {
|
||||||
|
executable = "ssh"
|
||||||
|
args (remoteHost, "$remoteHostFolder/${this@RunKotlinNativeTask.executable}")
|
||||||
|
} else {
|
||||||
|
executable = this@RunKotlinNativeTask.executable
|
||||||
|
}
|
||||||
args("list")
|
args("list")
|
||||||
standardOutput = output
|
standardOutput = output
|
||||||
}
|
}
|
||||||
|
|||||||
+5
-1
@@ -50,6 +50,9 @@ internal val Project.jvmJson: String
|
|||||||
internal val Project.buildType: NativeBuildType
|
internal val Project.buildType: NativeBuildType
|
||||||
get() = (findProperty("nativeBuildType") as String?)?.let { NativeBuildType.valueOf(it) } ?: NativeBuildType.RELEASE
|
get() = (findProperty("nativeBuildType") as String?)?.let { NativeBuildType.valueOf(it) } ?: NativeBuildType.RELEASE
|
||||||
|
|
||||||
|
internal val Project.crossTarget: String?
|
||||||
|
get() = findProperty("crossTarget") as String?
|
||||||
|
|
||||||
internal val Project.commonBenchmarkProperties: Map<String, Any>
|
internal val Project.commonBenchmarkProperties: Map<String, Any>
|
||||||
get() = mapOf(
|
get() = mapOf(
|
||||||
"cpu" to System.getProperty("os.arch"),
|
"cpu" to System.getProperty("os.arch"),
|
||||||
@@ -111,9 +114,10 @@ abstract class BenchmarkingPlugin: Plugin<Project> {
|
|||||||
protected val mingwPath: String = System.getenv("MINGW64_DIR") ?: "c:/msys64/mingw64"
|
protected val mingwPath: String = System.getenv("MINGW64_DIR") ?: "c:/msys64/mingw64"
|
||||||
|
|
||||||
protected open fun Project.determinePreset(): AbstractKotlinNativeTargetPreset<*> =
|
protected open fun Project.determinePreset(): AbstractKotlinNativeTargetPreset<*> =
|
||||||
|
(crossTarget?.let { targetHostPreset(this, it) } ?:
|
||||||
defaultHostPreset(this).also { preset ->
|
defaultHostPreset(this).also { preset ->
|
||||||
logger.quiet("$project has been configured for ${preset.name} platform.")
|
logger.quiet("$project has been configured for ${preset.name} platform.")
|
||||||
} as AbstractKotlinNativeTargetPreset<*>
|
}) as AbstractKotlinNativeTargetPreset<*>
|
||||||
|
|
||||||
protected abstract fun NamedDomainObjectContainer<KotlinSourceSet>.configureSources(project: Project)
|
protected abstract fun NamedDomainObjectContainer<KotlinSourceSet>.configureSources(project: Project)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user