[K/N][perf] Add possibility to cross compile benchmarks and run them on remote machine

This commit is contained in:
Elena Lepilkina
2021-11-19 17:26:19 +03:00
committed by Space
parent 9ba6683472
commit 74260bc138
4 changed files with 48 additions and 7 deletions
@@ -39,6 +39,9 @@ internal val NamedDomainObjectCollection<KotlinTargetPreset<*>>.linuxX64: Kotlin
internal val NamedDomainObjectCollection<KotlinTargetPreset<*>>.mingwX64: KotlinTargetPreset<*>
get() = getByName(::mingwX64.name)
internal val NamedDomainObjectCollection<KotlinTargetPreset<*>>.linuxArm64: KotlinTargetPreset<*>
get() = getByName(::linuxArm64.name)
internal val NamedDomainObjectContainer<out KotlinCompilation<*>>.main: 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}.")
}
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 {
PlatformInfo.isMac() -> ".kexe"
PlatformInfo.isLinux() -> ".kexe"
@@ -13,6 +13,7 @@ import org.jetbrains.report.json.*
import org.gradle.api.tasks.TaskAction
import org.gradle.api.tasks.options.Option
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.Internal
import java.io.ByteArrayOutputStream
import java.io.File
import javax.inject.Inject
@@ -54,15 +55,26 @@ open class RunKotlinNativeTask @Inject constructor(private val linkTask: Task,
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 {
val output = ByteArrayOutputStream()
val useCset = project.findProperty("useCset")?.toString()?.toBoolean() ?: false
project.exec {
if (useCset) {
executable = "cset"
args("shield", "--exec", "--", this@RunKotlinNativeTask.executable)
} else {
executable = this@RunKotlinNativeTask.executable
when {
useCset -> {
executable = "cset"
args("shield", "--exec", "--", this@RunKotlinNativeTask.executable)
}
remoteHost != null -> {
executable = "ssh"
args (remoteHost, "$remoteHostFolder/${this@RunKotlinNativeTask.executable}")
}
else -> executable = this@RunKotlinNativeTask.executable
}
args(argumentsList)
@@ -103,8 +115,19 @@ open class RunKotlinNativeTask @Inject constructor(private val linkTask: Task,
@TaskAction
fun run() {
val output = ByteArrayOutputStream()
remoteHost?.let {
project.exec {
executable = "scp"
args(this@RunKotlinNativeTask.executable, "$it:$remoteHostFolder")
}
}
project.exec {
executable = this@RunKotlinNativeTask.executable
if (remoteHost != null) {
executable = "ssh"
args (remoteHost, "$remoteHostFolder/${this@RunKotlinNativeTask.executable}")
} else {
executable = this@RunKotlinNativeTask.executable
}
args("list")
standardOutput = output
}
@@ -50,6 +50,9 @@ internal val Project.jvmJson: String
internal val Project.buildType: NativeBuildType
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>
get() = mapOf(
"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 open fun Project.determinePreset(): AbstractKotlinNativeTargetPreset<*> =
(crossTarget?.let { targetHostPreset(this, it) } ?:
defaultHostPreset(this).also { preset ->
logger.quiet("$project has been configured for ${preset.name} platform.")
} as AbstractKotlinNativeTargetPreset<*>
}) as AbstractKotlinNativeTargetPreset<*>
protected abstract fun NamedDomainObjectContainer<KotlinSourceSet>.configureSources(project: Project)