From e57839ece698748b1664fd9e61269e636872339c Mon Sep 17 00:00:00 2001 From: LepilkinaElena Date: Thu, 29 Oct 2020 17:05:06 +0300 Subject: [PATCH] Separate performance project (#4473) --- kotlin-native/HACKING.md | 24 ++++++++++++------- .../kotlin/benchmark/BenchmarkingPlugin.kt | 6 +++++ kotlin-native/build.gradle | 6 ----- .../performance/KotlinVsSwift/build.gradle | 2 +- .../KotlinVsSwift/ring/build.gradle.kts | 1 - kotlin-native/performance/build.gradle | 19 +++++++++++---- .../performance/cinterop/build.gradle.kts | 1 - .../performance/framework/build.gradle | 6 ++--- .../performance/numerical/build.gradle.kts | 22 +++-------------- .../numerical/src/nativeInterop/cinterop/pi.c | 1 + .../numerical/src/nativeInterop/cinterop/pi.h | 6 +++++ .../performance/objcinterop/build.gradle.kts | 19 ++------------- .../performance/ring/build.gradle.kts | 2 -- kotlin-native/performance/settings.gradle | 23 ++++++++++++++++++ .../performance/startup/build.gradle.kts | 2 -- .../performance/swiftinterop/build.gradle.kts | 7 +++--- kotlin-native/settings.gradle | 17 ------------- 17 files changed, 79 insertions(+), 85 deletions(-) create mode 100644 kotlin-native/performance/settings.gradle diff --git a/kotlin-native/HACKING.md b/kotlin-native/HACKING.md index 68a466eb72c..53509c3d0cd 100644 --- a/kotlin-native/HACKING.md +++ b/kotlin-native/HACKING.md @@ -134,7 +134,8 @@ To use a local GTest copy instead of the downloaded one, add the following line To measure performance of Kotlin/Native compiler on existing benchmarks: - ./gradlew :performance:konanRun + cd performance + ../gradlew :konanRun **NOTE**: **konanRun** task needs built compiler and libs. To test against working tree make sure to run @@ -144,19 +145,23 @@ To use a local GTest copy instead of the downloaded one, add the following line **konanRun** task can be run separately for one/several benchmark applications: - ./gradlew :performance:cinterop:konanRun + cd performance + ../gradlew :cinterop:konanRun **konanRun** task has parameter `filter` which allows to run only some subset of benchmarks: - ./gradlew :performance:cinterop:konanRun --filter=struct,macros + cd performance + ../gradlew :cinterop:konanRun --filter=struct,macros Or you can use `filterRegex` if you want to specify the filter as regexes: - ./gradlew :performance:ring:konanRun --filterRegex=String.*,Loop.* + cd performance + ../gradlew :ring:konanRun --filterRegex=String.*,Loop.* There us also verbose mode to follow progress of running benchmarks - ./gradlew :performance:cinterop:konanRun --verbose + cd performance + ../gradlew :cinterop:konanRun --verbose > Task :performance:cinterop:konanRun [DEBUG] Warm up iterations for benchmark macros @@ -165,16 +170,19 @@ To use a local GTest copy instead of the downloaded one, add the following line There are also tasks for running benchmarks on JVM (pay attention, some benchmarks e.g. cinterop benchmarks can't be run on JVM) - ./gradlew :performance:jvmRun + cd performance + ../gradlew :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 :performance:ring:konanRun --filter=String.*,Loop.* -PnativeJson=stringsAndLoops.json + cd performance + ../gradlew :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 :performance:konanRun -PcompilerArgs="--time -g" + cd performance + ../gradlew :konanRun -PcompilerArgs="--time -g" To compare different results run benchmarksAnalyzer tool: diff --git a/kotlin-native/build-tools/src/main/kotlin/org/jetbrains/kotlin/benchmark/BenchmarkingPlugin.kt b/kotlin-native/build-tools/src/main/kotlin/org/jetbrains/kotlin/benchmark/BenchmarkingPlugin.kt index 49012e52e60..77d59d93dbe 100644 --- a/kotlin-native/build-tools/src/main/kotlin/org/jetbrains/kotlin/benchmark/BenchmarkingPlugin.kt +++ b/kotlin-native/build-tools/src/main/kotlin/org/jetbrains/kotlin/benchmark/BenchmarkingPlugin.kt @@ -71,6 +71,7 @@ open class BenchmarkExtension @Inject constructor(val project: Project) { var compilerOpts: List = emptyList() var buildType: NativeBuildType = NativeBuildType.RELEASE var repeatingType: BenchmarkRepeatingType = BenchmarkRepeatingType.INTERNAL + var cleanBeforeRunTask: String? = "konanRun" val dependencies: BenchmarkDependencies = BenchmarkDependencies() @@ -256,6 +257,11 @@ abstract class BenchmarkingPlugin: Plugin { // JVM report task. configureJvmJsonTask(jvmRun) + + project.afterEvaluate { + // Need to rebuild benchmark to collect compile time. + project.benchmark.cleanBeforeRunTask?.let { tasks.getByName(it).dependsOn("clean") } + } } override fun apply(target: Project) = with(target) { diff --git a/kotlin-native/build.gradle b/kotlin-native/build.gradle index 254fab291df..4dfb940a352 100644 --- a/kotlin-native/build.gradle +++ b/kotlin-native/build.gradle @@ -668,12 +668,6 @@ 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' diff --git a/kotlin-native/performance/KotlinVsSwift/build.gradle b/kotlin-native/performance/KotlinVsSwift/build.gradle index 712a7278933..504eabda699 100644 --- a/kotlin-native/performance/KotlinVsSwift/build.gradle +++ b/kotlin-native/performance/KotlinVsSwift/build.gradle @@ -1,5 +1,5 @@ buildscript { - apply from: "$rootProject.projectDir/gradle/kotlinGradlePlugin.gradle" + apply from: "$rootProject.projectDir/../gradle/kotlinGradlePlugin.gradle" repositories { maven { url 'https://cache-redirector.jetbrains.com/jcenter' diff --git a/kotlin-native/performance/KotlinVsSwift/ring/build.gradle.kts b/kotlin-native/performance/KotlinVsSwift/ring/build.gradle.kts index bb82af8837a..ce32c193cf5 100644 --- a/kotlin-native/performance/KotlinVsSwift/ring/build.gradle.kts +++ b/kotlin-native/performance/KotlinVsSwift/ring/build.gradle.kts @@ -18,5 +18,4 @@ swiftBenchmark { swiftSources = File("$projectDir/src").list().map { "$projectDir/src/$it" }.toList() compileTasks = listOf("buildSwift") useCodeSize = CodeSizeEntity.EXECUTABLE - dependencies.common(project(":endorsedLibraries:kotlinx.cli")) } \ No newline at end of file diff --git a/kotlin-native/performance/build.gradle b/kotlin-native/performance/build.gradle index f60a564661a..50c8a897b2e 100644 --- a/kotlin-native/performance/build.gradle +++ b/kotlin-native/performance/build.gradle @@ -4,12 +4,23 @@ import org.jetbrains.kotlin.BuildRegister import org.jetbrains.kotlin.MPPTools buildscript { - apply from: "$rootProject.projectDir/gradle/kotlinGradlePlugin.gradle" + ext.rootBuildDirectory = file('..') + + apply from: "$rootBuildDirectory/gradle/loadRootProperties.gradle" + apply from: "$rootBuildDirectory/gradle/kotlinGradlePlugin.gradle" repositories { - maven { - url 'https://cache-redirector.jetbrains.com/jcenter' - } + maven { url 'https://cache-redirector.jetbrains.com/jcenter'} + maven { url 'https://cache-redirector.jetbrains.com/maven-central' } + mavenCentral() + maven { url buildKotlinCompilerRepo } + maven { url kotlinCompilerRepo } jcenter() + maven { url "https://kotlin.bintray.com/kotlinx" } + maven { url "https://dl.bintray.com/kotlin/kotlin-dev" } + } + + dependencies { + classpath "org.jetbrains.kotlin:kotlin-native-build-tools:$konanVersion" } } diff --git a/kotlin-native/performance/cinterop/build.gradle.kts b/kotlin-native/performance/cinterop/build.gradle.kts index f885f4325ba..446dc4b5ce0 100644 --- a/kotlin-native/performance/cinterop/build.gradle.kts +++ b/kotlin-native/performance/cinterop/build.gradle.kts @@ -20,7 +20,6 @@ benchmark { mingwSrcDirs = listOf("src/main/kotlin-native", "../shared/src/main/kotlin-native/mingw") posixSrcDirs = listOf("src/main/kotlin-native", "../shared/src/main/kotlin-native/posix") buildType = (findProperty("nativeBuildType") as String?)?.let { NativeBuildType.valueOf(it) } ?: defaultBuildType - dependencies.common(project(":endorsedLibraries:kotlinx.cli")) } val native = kotlin.targets.getByName("native") as KotlinNativeTarget diff --git a/kotlin-native/performance/framework/build.gradle b/kotlin-native/performance/framework/build.gradle index 75433d7c607..1c985d73866 100644 --- a/kotlin-native/performance/framework/build.gradle +++ b/kotlin-native/performance/framework/build.gradle @@ -4,7 +4,7 @@ import org.jetbrains.kotlin.RunJvmTask import org.jetbrains.kotlin.gradle.plugin.mpp.NativeBuildType buildscript { - apply from: "$rootProject.projectDir/gradle/kotlinGradlePlugin.gradle" + apply from: "$rootProject.projectDir/../gradle/kotlinGradlePlugin.gradle" repositories { maven { @@ -42,8 +42,8 @@ kotlin { } kotlin.srcDir "$toolsPath/benchmarks/shared/src" kotlin.srcDir "$toolsPath/benchmarksAnalyzer/src/main/kotlin" - kotlin.srcDir "$rootProject.projectDir/endorsedLibraries/kotlinx.cli/src/main/kotlin" - kotlin.srcDir "$rootProject.projectDir/endorsedLibraries/kotlinx.cli/src/main/kotlin-native" + kotlin.srcDir "$rootProject.projectDir/../endorsedLibraries/kotlinx.cli/src/main/kotlin" + kotlin.srcDir "$rootProject.projectDir/../endorsedLibraries/kotlinx.cli/src/main/kotlin-native" kotlin.srcDir "$toolsPath/benchmarksAnalyzer/src/main/kotlin-native" } } diff --git a/kotlin-native/performance/numerical/build.gradle.kts b/kotlin-native/performance/numerical/build.gradle.kts index ede81d6f69c..d56ffc5a8af 100644 --- a/kotlin-native/performance/numerical/build.gradle.kts +++ b/kotlin-native/performance/numerical/build.gradle.kts @@ -7,7 +7,7 @@ import org.jetbrains.kotlin.benchmark.BenchmarkingPlugin import org.jetbrains.kotlin.ExecClang import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget import org.jetbrains.kotlin.gradle.plugin.mpp.NativeBuildType -import org.jetbrains.kotlin.konan.target.HostManager +import org.jetbrains.kotlin.konan.target.* plugins { id("benchmarking") @@ -22,24 +22,7 @@ benchmark { nativeSrcDirs = listOf("src/main/kotlin-native", "../shared/src/main/kotlin-native/common") mingwSrcDirs = listOf("../shared/src/main/kotlin-native/mingw") posixSrcDirs = listOf("../shared/src/main/kotlin-native/posix") - linkerOpts = listOf("$buildDir/pi.o") buildType = (findProperty("nativeBuildType") as String?)?.let { NativeBuildType.valueOf(it) } ?: defaultBuildType - - dependencies.common(project(":endorsedLibraries:kotlinx.cli")) -} - -val compileLibary by tasks.creating { - doFirst { - mkdir(buildDir) - - project.withConvention(ExecClang::class) { - execKonanClang(HostManager.host) { - args("-O3") - args("-c", "$projectDir/src/nativeInterop/cinterop/pi.c") - args("-o", "$buildDir/pi.o") - } - } - } } val native = kotlin.targets.getByName("native") as KotlinNativeTarget @@ -47,7 +30,8 @@ native.apply { compilations["main"].cinterops { create("cinterop") { headers("$projectDir/src/nativeInterop/cinterop/pi.h") + extraOpts("-Xcompile-source", "$projectDir/src/nativeInterop/cinterop/pi.c") + extraOpts("-Xsource-compiler-option", "-O3") } } - binaries.getExecutable(BenchmarkingPlugin.NATIVE_EXECUTABLE_NAME, "RELEASE").linkTask.dependsOn(compileLibary) } diff --git a/kotlin-native/performance/numerical/src/nativeInterop/cinterop/pi.c b/kotlin-native/performance/numerical/src/nativeInterop/cinterop/pi.c index 129e8a976aa..d22f3994ecd 100644 --- a/kotlin-native/performance/numerical/src/nativeInterop/cinterop/pi.c +++ b/kotlin-native/performance/numerical/src/nativeInterop/cinterop/pi.c @@ -15,6 +15,7 @@ */ #include +#include "pi.h" /* uncomment the following line to use 'long long' integers */ #define HAS_LONG_LONG diff --git a/kotlin-native/performance/numerical/src/nativeInterop/cinterop/pi.h b/kotlin-native/performance/numerical/src/nativeInterop/cinterop/pi.h index 5703de71b38..5528a38c176 100644 --- a/kotlin-native/performance/numerical/src/nativeInterop/cinterop/pi.h +++ b/kotlin-native/performance/numerical/src/nativeInterop/cinterop/pi.h @@ -11,6 +11,12 @@ #ifndef _BELLARD_PI_H #define _BELLARD_PI_H +#ifdef __cplusplus +extern "C" { +#endif int pi_nth_digit(int n); +#ifdef __cplusplus +} +#endif #endif /*_BELLARD_PI_H*/ diff --git a/kotlin-native/performance/objcinterop/build.gradle.kts b/kotlin-native/performance/objcinterop/build.gradle.kts index 71c4c7322f1..b106bb8c1f2 100644 --- a/kotlin-native/performance/objcinterop/build.gradle.kts +++ b/kotlin-native/performance/objcinterop/build.gradle.kts @@ -22,32 +22,17 @@ benchmark { nativeSrcDirs = listOf("src/main/kotlin-native", "../shared/src/main/kotlin-native/common") mingwSrcDirs = listOf("src/main/kotlin-native", "../shared/src/main/kotlin-native/mingw") posixSrcDirs = listOf("src/main/kotlin-native", "../shared/src/main/kotlin-native/posix") - linkerOpts = listOf("-L$buildDir", "-lcomplexnumbers") buildType = (findProperty("nativeBuildType") as String?)?.let { NativeBuildType.valueOf(it) } ?: defaultBuildType - - dependencies.common(project(":endorsedLibraries:kotlinx.cli")) } -val compileLibary by tasks.creating { - doFirst { - mkdir(buildDir) - - project.withConvention(ExecClang::class) { - execKonanClang(HostManager.host) { - args("$projectDir/src/nativeInterop/cinterop/complexNumbers.m") - args("-lobjc", "-fobjc-arc") - args("-fPIC", "-shared", "-o", "$buildDir/libcomplexnumbers.dylib") - } - } - } -} val native = kotlin.targets.getByName("native") as KotlinNativeTarget native.apply { compilations["main"].cinterops { create("classes") { headers("$projectDir/src/nativeInterop/cinterop/complexNumbers.h") + extraOpts("-Xcompile-source", "$projectDir/src/nativeInterop/cinterop/complexNumbers.m") + extraOpts("-Xsource-compiler-option", "-lobjc", "-Xsource-compiler-option", "-fobjc-arc") } } - binaries.getExecutable(BenchmarkingPlugin.NATIVE_EXECUTABLE_NAME, "RELEASE").linkTask.dependsOn(compileLibary) } \ No newline at end of file diff --git a/kotlin-native/performance/ring/build.gradle.kts b/kotlin-native/performance/ring/build.gradle.kts index 2eda534e016..600c4631d94 100644 --- a/kotlin-native/performance/ring/build.gradle.kts +++ b/kotlin-native/performance/ring/build.gradle.kts @@ -19,6 +19,4 @@ benchmark { mingwSrcDirs = listOf("src/main/kotlin-native", "../shared/src/main/kotlin-native/mingw") posixSrcDirs = listOf("src/main/kotlin-native", "../shared/src/main/kotlin-native/posix") buildType = (findProperty("nativeBuildType") as String?)?.let { NativeBuildType.valueOf(it) } ?: defaultBuildType - - dependencies.common(project(":endorsedLibraries:kotlinx.cli")) } diff --git a/kotlin-native/performance/settings.gradle b/kotlin-native/performance/settings.gradle new file mode 100644 index 00000000000..cfe05270f35 --- /dev/null +++ b/kotlin-native/performance/settings.gradle @@ -0,0 +1,23 @@ +/* + * Copyright 2010-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license + * that can be found in the LICENSE file. + */ + +include ':ring' +include ':cinterop' +include ':helloworld' +include ':numerical' +include ':videoplayer' +include ':framework' +include ':startup' +if (System.getProperty("os.name") == "Mac OS X") { + include ':objcinterop' + include ':swiftinterop' + if (hasProperty("runExcludedBenchmarks")) { + include ':KotlinVsSwift' + include ':KotlinVsSwift:ring' + } +} + +includeBuild '../build-tools' + diff --git a/kotlin-native/performance/startup/build.gradle.kts b/kotlin-native/performance/startup/build.gradle.kts index df66b9598f2..90ab3df90c7 100644 --- a/kotlin-native/performance/startup/build.gradle.kts +++ b/kotlin-native/performance/startup/build.gradle.kts @@ -22,6 +22,4 @@ benchmark { posixSrcDirs = listOf("../shared/src/main/kotlin-native/posix") buildType = (findProperty("nativeBuildType") as String?)?.let { NativeBuildType.valueOf(it) } ?: defaultBuildType repeatingType = BenchmarkRepeatingType.EXTERNAL - - dependencies.common(project(":endorsedLibraries:kotlinx.cli")) } diff --git a/kotlin-native/performance/swiftinterop/build.gradle.kts b/kotlin-native/performance/swiftinterop/build.gradle.kts index e5149a22829..a028d76868c 100644 --- a/kotlin-native/performance/swiftinterop/build.gradle.kts +++ b/kotlin-native/performance/swiftinterop/build.gradle.kts @@ -1,5 +1,5 @@ import org.jetbrains.kotlin.gradle.plugin.mpp.NativeBuildType - +import org.jetbrains.kotlin.konan.target.* /* * Copyright 2010-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license * that can be found in the LICENSE file. @@ -12,7 +12,7 @@ plugins { val toolsPath = "../../tools" val targetExtension = "Macos" val defaultBuildType = NativeBuildType.RELEASE - +project.extra["platformManager"] = PlatformManager(projectDir.parentFile.parentFile.absolutePath, false) swiftBenchmark { applicationName = "swiftInterop" commonSrcDirs = listOf("$toolsPath/benchmarks/shared/src/main/kotlin/report", "src", "../shared/src/main/kotlin") @@ -20,6 +20,5 @@ swiftBenchmark { swiftSources = listOf("$projectDir/swiftSrc/benchmarks.swift", "$projectDir/swiftSrc/main.swift") compileTasks = listOf("compileKotlinNative", "linkBenchmarkReleaseFrameworkNative") buildType = (findProperty("nativeBuildType") as String?)?.let { NativeBuildType.valueOf(it) } ?: defaultBuildType - - dependencies.common(project(":endorsedLibraries:kotlinx.cli")) + cleanBeforeRunTask = "compileKotlinNative" } \ No newline at end of file diff --git a/kotlin-native/settings.gradle b/kotlin-native/settings.gradle index adcc72637d6..607d407711a 100644 --- a/kotlin-native/settings.gradle +++ b/kotlin-native/settings.gradle @@ -33,23 +33,6 @@ include ':utilities:basic-utils' include ':utilities:cli-runner' include ':dependencyPacker' -include ':performance' -include ':performance:ring' -include ':performance:cinterop' -include ':performance:helloworld' -include ':performance:numerical' -include ':performance:videoplayer' -include ':performance:framework' -include ':performance:startup' -if (System.getProperty("os.name") == "Mac OS X") { - include ':performance:objcinterop' - include ':performance:swiftinterop' - if (hasProperty("runExcludedBenchmarks")) { - include ':performance:KotlinVsSwift' - include ':performance:KotlinVsSwift:ring' - } -} - include ':platformLibs' include ':endorsedLibraries' include ':endorsedLibraries:kotlinx.cli'