Skip to content

Commit

Permalink
Objective c interop benchmarks migration (JetBrains#3004)
Browse files Browse the repository at this point in the history
  • Loading branch information
LepilkinaElena authored Jun 3, 2019
1 parent 285bfc1 commit 69fd556
Show file tree
Hide file tree
Showing 46 changed files with 1,466 additions and 314 deletions.
15 changes: 7 additions & 8 deletions HACKING.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,33 +103,32 @@ To update the blackbox compiler tests set TeamCity build number in `gradle.prope

To measure performance of Kotlin/Native compiler on existing benchmarks:

cd performance
../gradlew konanRun
./gradlew :performance:konanRun

**konanRun** task can be run separately for one/several benchmark applications:

../gradlew :cinterop:konanRun
./gradlew :performance:cinterop:konanRun

**konanRun** task has parameter `filter` which allows to run only some subset of benchmarks:

../gradlew :cinterop:konanRun --filter=struct,macros
./gradlew :performance:cinterop:konanRun --filter=struct,macros

Or you can use `filterRegex` if you want to specify the filter as regexes:

../gradlew :ring:konanRun --filterRegex=String.*,Loop.*
./gradlew :performance:ring:konanRun --filterRegex=String.*,Loop.*

There are also tasks for running benchmarks on JVM (pay attention, some benchmarks e.g. cinterop benchmarks can't be run on JVM)

../gradlew jvmRun
./gradlew :performance:jvmRun

Files with results of benchmarks run are saved in `performance/build/nativeReport.json` for konanRun and `jvmReport.json` for jvmRun.
You can change the output filename by setting the `nativeJson` property for konanRun and `jvmJson` for jvmRun:

../gradlew :ring:konanRun --filter=String.*,Loop.* -PnativeJson=stringsAndLoops.json
./gradlew :performance:ring:konanRun --filter=String.*,Loop.* -PnativeJson=stringsAndLoops.json

You can use the `compilerArgs` property to pass flags to the compiler used to compile the benchmarks:

../gradlew konanRun -PcompilerArgs="--time -g"
./gradlew :performance:konanRun -PcompilerArgs="--time -g"

To compare different results run benchmarksAnalyzer tool:

Expand Down
8 changes: 4 additions & 4 deletions backend.native/tests/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3098,7 +3098,7 @@ kotlinNativeInterop {
defFile 'interop/basics/ccallbacksAndVarargs.def'
}

if (isAppleTarget(project)) {
if (PlatformInfo.isAppleTarget(project)) {
objcSmoke {
defFile 'interop/objc/objcSmoke.def'
headers "$projectDir/interop/objc/smoke.h"
Expand Down Expand Up @@ -3447,7 +3447,7 @@ task runKonanRegexTests(type: RunKonanTest) {

task coverage_basic_program(type: RunStandaloneKonanTest) {

disabled = getTarget(project).name != "ios_x64" && getTarget(project).name != "macos_x64"
disabled = PlatformInfo.getTarget(project).name != "ios_x64" && PlatformInfo.getTarget(project).name != "macos_x64"

description = "Test that `-Xcoverage` generates correct __llvm_coverage information"

Expand Down Expand Up @@ -3476,7 +3476,7 @@ task coverage_basic_program(type: RunStandaloneKonanTest) {

task coverage_basic_library(type: RunStandaloneKonanTest) {

disabled = getTarget(project).name != "ios_x64" && getTarget(project).name != "macos_x64"
disabled = PlatformInfo.getTarget(project).name != "ios_x64" && PlatformInfo.getTarget(project).name != "macos_x64"

description = "Test that `-Xlibrary-to-cover` generates correct __llvm_coverage information"

Expand All @@ -3486,7 +3486,7 @@ task coverage_basic_library(type: RunStandaloneKonanTest) {
doFirst {
def konancScript = isWindows() ? "konanc.bat" : "konanc"
def konanc = "$dist/bin/$konancScript"
"$konanc -target ${getTarget(project).name} $projectDir/coverage/basic/library/library.kt -p library -o $dir/lib_to_cover".execute().waitFor()
"$konanc -target ${PlatformInfo.getTarget(project).name} $projectDir/coverage/basic/library/library.kt -p library -o $dir/lib_to_cover".execute().waitFor()
}

flags = ["-Xcoverage-file=$dir/program.profraw", "-l", "$dir/lib_to_cover", "-Xlibrary-to-cover=$dir/lib_to_cover.klib", "-entry", "coverage.basic.library.main"]
Expand Down
56 changes: 10 additions & 46 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import org.jetbrains.kotlin.konan.target.*
import org.jetbrains.kotlin.konan.util.*
import org.jetbrains.kotlin.CopySamples
import org.jetbrains.kotlin.CopyCommonSources
import org.jetbrains.kotlin.PlatformInfo
import org.jetbrains.kotlin.konan.*

buildscript {
Expand All @@ -41,7 +42,7 @@ wrapper.distributionType = Wrapper.DistributionType.ALL

defaultTasks 'clean', 'dist'

convention.plugins.platformInfo = new PlatformInfo()
convention.plugins.platformInfo = PlatformInfo

ext {
distDir = file('dist')
Expand Down Expand Up @@ -161,43 +162,6 @@ void loadCommandLineProperties() {
ext.testTarget = project.hasProperty("test_target") ? ext.test_target : null
}

class PlatformInfo {
boolean isMac() {
return HostManager.hostIsMac
}

boolean isWindows() {
return HostManager.hostIsMingw
}

boolean isLinux() {
return HostManager.hostIsLinux
}

boolean isAppleTarget(Project project) {
def target = getTarget(project)
return target.family == Family.IOS || target.family == Family.OSX
}

boolean isWindowsTarget(Project project) {
return getTarget(project).family == Family.MINGW
}

boolean isWasmTarget(Project project) {
return getTarget(project).family == Family.WASM
}

KonanTarget getTarget(Project project) {
def platformManager = project.rootProject.platformManager
def targetName = project.project.testTarget ?: 'host'
return platformManager.targetManager(targetName).target
}

Throwable unsupportedPlatformException() {
return new TargetSupportException()
}
}

configurations {
ftpAntTask
kotlinCommonSources
Expand Down Expand Up @@ -343,7 +307,7 @@ task distCompiler(type: Copy) {
from(file('cmd')) {
fileMode(0755)
into('bin')
if (!isWindows()) {
if (!PlatformInfo.isWindows()) {
exclude('**/*.bat')
}
}
Expand Down Expand Up @@ -501,6 +465,12 @@ task samples {
dependsOn 'samplesZip', 'samplesTar'
}

task performance {
dependsOn 'dist'
dependsOn ':performance:clean'
dependsOn ':performance:konanRun'
}

task samplesZip(type: Zip)
task samplesTar(type: Tar) {
extension = 'tar.gz'
Expand Down Expand Up @@ -562,12 +532,6 @@ task uploadBundle {
}
}

// TODO return when problems with HostManagers will be solved
/*task performance {
dependsOn 'dist'
dependsOn ':performance:bench'
}*/

task teamcityKonanVersion {
doLast {
println("##teamcity[setParameter name='kotlin.native.version.base' value='$konanVersion']")
Expand All @@ -583,4 +547,4 @@ task clean {
delete distDir
delete bundle.outputs.files
}
}
}
7 changes: 5 additions & 2 deletions buildSrc/plugins/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ buildscript {
apply from: "$rootBuildDirectory/gradle/kotlinGradlePlugin.gradle"
dependencies{
classpath "org.jetbrains.kotlin:kotlin-serialization:$buildKotlinVersion"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
}

}
Expand All @@ -37,13 +38,15 @@ dependencies {
compile localGroovy()
compile "org.jetbrains.kotlin:kotlin-stdlib:$buildKotlinVersion"
compile "org.jetbrains.kotlin:kotlin-reflect:$buildKotlinVersion"
compile group: 'com.ullink.slack', name: 'simpleslackapi', version: '0.6.0'
compile group: 'com.ullink.slack', name: 'simpleslackapi', version: '1.2.0'
// An artifact from the included build 'shared' cannot be used here due to https://github.com/gradle/gradle/issues/3768
// TODO: Remove this hack when the bug is fixed
implementation "org.jetbrains.kotlin:kotlin-gradle-plugin"
compile project(':shared')
compile "org.jetbrains.kotlinx:kotlinx-serialization-runtime:0.10.0"
}

sourceSets.main.kotlin.srcDirs = ["src", "$projectDir/../../tools/benchmarks/shared/src"]

rootProject.dependencies {
runtime project(path)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
* that can be found in the license/LICENSE.txt file.
*/

package org.jetbrains.kotlin

import groovy.lang.Closure
import org.gradle.api.Action
import org.gradle.api.DefaultTask
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ open class FrameworkTest : DefaultTask() {
listOf(provider.toString(), swiftMain)
val options = listOf("-g", "-Xlinker", "-rpath", "-Xlinker", frameworkParentDirPath, "-F", frameworkParentDirPath)
val testExecutable = Paths.get(testOutput, frameworkName, "swiftTestExecutable")
swiftc(sources, options, testExecutable)
compileSwift(project, project.testTarget(), sources, options, testExecutable, fullBitcode)

runTest(testExecutable)
}
Expand Down Expand Up @@ -117,36 +117,6 @@ open class FrameworkTest : DefaultTask() {
check(exitCode == 0, { "Execution failed with exit code: $exitCode "})
}

private fun swiftc(sources: List<String>, options: List<String>, output: Path) {
val target = project.testTarget()
val platform = project.platformManager().platform(target)
assert(platform.configurables is AppleConfigurables)
val configs = platform.configurables as AppleConfigurables
val compiler = configs.absoluteTargetToolchain + "/usr/bin/swiftc"

val swiftTarget = when (target) {
KonanTarget.IOS_X64 -> "x86_64-apple-ios" + configs.osVersionMin
KonanTarget.IOS_ARM64 -> "arm64_64-apple-ios" + configs.osVersionMin
KonanTarget.MACOS_X64 -> "x86_64-apple-macosx" + configs.osVersionMin
else -> throw IllegalStateException("Test target $target is not supported")
}

val args = listOf("-sdk", configs.absoluteTargetSysRoot, "-target", swiftTarget) +
options + "-o" + output.toString() + sources +
if (fullBitcode) listOf("-embed-bitcode", "-Xlinker", "-bitcode_verify") else listOf("-embed-bitcode-marker")

val (stdOut, stdErr, exitCode) = runProcess(executor = localExecutor(project), executable = compiler, args = args)

println("""
|$compiler finished with exit code: $exitCode
|options: ${args.joinToString(separator = " ")}
|stdout: $stdOut
|stderr: $stdErr
""".trimMargin())
check(exitCode == 0, { "Compilation failed" })
check(output.toFile().exists(), { "Compiler swiftc hasn't produced an output file: $output" })
}

private fun validateBitcodeEmbedding(frameworkBinary: String) {
// Check only the full bitcode embedding for now.
if (!fullBitcode) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
* that can be found in the license/LICENSE.txt file.
*/

package org.jetbrains.kotlin

import org.gradle.api.NamedDomainObjectCollection
import org.gradle.api.NamedDomainObjectContainer
import org.gradle.api.Project
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@

@file:JvmName("MPPTools")

package org.jetbrains.kotlin

import groovy.lang.Closure
import org.gradle.api.Project
import org.gradle.api.Task
import org.gradle.api.tasks.TaskState
import org.gradle.api.execution.TaskExecutionListener
import org.gradle.api.tasks.AbstractExecTask
import org.jetbrains.kotlin.gradle.plugin.KotlinTargetPreset
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget
import org.jetbrains.report.*
Expand All @@ -27,16 +30,6 @@ import java.util.Base64
* This file includes short-cuts that may potentially be implemented in Kotlin MPP Gradle plugin in the future.
*/

// Short-cuts for detecting the host OS.
@get:JvmName("isMacos")
val isMacos by lazy { hostOs == "Mac OS X" }

@get:JvmName("isWindows")
val isWindows by lazy { hostOs.startsWith("Windows") }

@get:JvmName("isLinux")
val isLinux by lazy { hostOs == "Linux" }

// Short-cuts for mostly used paths.
@get:JvmName("mingwPath")
val mingwPath by lazy { System.getenv("MINGW64_DIR") ?: "c:/msys64/mingw64" }
Expand All @@ -57,9 +50,9 @@ fun defaultHostPreset(
throw Exception("Preset whitelist must not be empty in Kotlin/Native ${subproject.displayName}.")

val presetCandidate = when {
isMacos -> subproject.kotlin.presets.macosX64
isLinux -> subproject.kotlin.presets.linuxX64
isWindows -> subproject.kotlin.presets.mingwX64
PlatformInfo.isMac() -> subproject.kotlin.presets.macosX64
PlatformInfo.isLinux() -> subproject.kotlin.presets.linuxX64
PlatformInfo.isWindows() -> subproject.kotlin.presets.mingwX64
else -> null
}

Expand All @@ -70,9 +63,9 @@ fun defaultHostPreset(
}

fun getNativeProgramExtension(): String = when {
isMacos -> ".kexe"
isLinux -> ".kexe"
isWindows -> ".exe"
PlatformInfo.isMac() -> ".kexe"
PlatformInfo.isLinux() -> ".kexe"
PlatformInfo.isWindows() -> ".exe"
else -> error("Unknown host")
}

Expand Down Expand Up @@ -161,10 +154,21 @@ fun sendUploadRequest(url: String, fileName: String, username: String? = null, p
fun createRunTask(
subproject: Project,
name: String,
target: KotlinNativeTarget,
runTask: AbstractExecTask<*>,
configureClosure: Closure<Any>? = null
): Task {
val task = subproject.tasks.create(name, RunKotlinNativeTask::class.java, runTask)
task.configure(configureClosure ?: task.emptyConfigureClosure())
return task
}

@JvmOverloads
fun createBenchmarksRunTask(
subproject: Project,
name: String,
configureClosure: Closure<Any>? = null
): Task {
val task = subproject.tasks.create(name, RunKotlinNativeTask::class.java, target)
val task = subproject.tasks.create(name, RunBenchmarksExecutableTask::class.java)
task.configure(configureClosure ?: task.emptyConfigureClosure())
return task
}
Expand All @@ -174,7 +178,7 @@ fun getJvmCompileTime(programName: String): BenchmarkResult =

@JvmOverloads
fun getNativeCompileTime(programName: String,
tasks: List<String> = listOf("compileKotlinNative", "linkBenchmarkReleaseExecutableNative")): BenchmarkResult =
tasks: List<String> = listOf("linkBenchmarkReleaseExecutableNative")): BenchmarkResult =
TaskTimerListener.getBenchmarkResult(programName, tasks)

fun getCompileBenchmarkTime(programName: String, tasksNames: Iterable<String>, repeats: Int, exitCodes: Map<String, Int>) =
Expand Down Expand Up @@ -207,7 +211,7 @@ class TaskTimerListener: TaskExecutionListener {
fun getTime(taskName: String) = tasksTimes[taskName] ?: 0.0
}

private var startTime = System.currentTimeMillis()
private var startTime = System.nanoTime()

override fun beforeExecute(task: Task) {
startTime = System.nanoTime()
Expand Down
Loading

0 comments on commit 69fd556

Please sign in to comment.