diff --git a/build-tools/src/main/kotlin/org/jetbrains/kotlin/MPPTools.kt b/build-tools/src/main/kotlin/org/jetbrains/kotlin/MPPTools.kt index bfde23554f9..a0c8e191eb1 100644 --- a/build-tools/src/main/kotlin/org/jetbrains/kotlin/MPPTools.kt +++ b/build-tools/src/main/kotlin/org/jetbrains/kotlin/MPPTools.kt @@ -194,20 +194,23 @@ fun createRunTask( return subproject.tasks.create(name, RunKotlinNativeTask::class.java, linkTask, executable, outputFileName) } -fun getJvmCompileTime(programName: String): BenchmarkResult = - TaskTimerListener.getBenchmarkResult(programName, listOf("compileKotlinMetadata", "jvmJar")) +fun getJvmCompileTime(subproject: Project,programName: String): BenchmarkResult = + TaskTimerListener.getTimerListenerOfSubproject(subproject) + .getBenchmarkResult(programName, listOf("compileKotlinMetadata", "jvmJar")) @JvmOverloads -fun getNativeCompileTime(programName: String, +fun getNativeCompileTime(subproject: Project, programName: String, tasks: List = listOf("linkBenchmarkReleaseExecutableNative")): BenchmarkResult = - TaskTimerListener.getBenchmarkResult(programName, tasks) + TaskTimerListener.getTimerListenerOfSubproject(subproject).getBenchmarkResult(programName, tasks) -fun getCompileBenchmarkTime(programName: String, tasksNames: Iterable, repeats: Int, exitCodes: Map) = +fun getCompileBenchmarkTime(subproject: Project, + programName: String, tasksNames: Iterable, + repeats: Int, exitCodes: Map) = (1..repeats).map { number -> var time = 0.0 var status = BenchmarkResult.Status.PASSED tasksNames.forEach { - time += TaskTimerListener.getTime("$it$number") + time += TaskTimerListener.getTimerListenerOfSubproject(subproject).getTime("$it$number") status = if (exitCodes["$it$number"] != 0) BenchmarkResult.Status.FAILED else status } @@ -227,20 +230,25 @@ fun toCompileBenchmark(metricDescription: String, status: String, programName: S // Class time tracker for all tasks. class TaskTimerListener: TaskExecutionListener { companion object { - val tasksTimes = mutableMapOf() + internal val timerListeners = mutableMapOf() - fun getBenchmarkResult(programName: String, tasksNames: List): BenchmarkResult { - val time = tasksNames.map { tasksTimes[it] ?: 0.0 }.sum() - // TODO get this info from gradle plugin with exit code end stacktrace. - val status = tasksNames.map { tasksTimes.containsKey(it) }.reduce { a, b -> a && b } - return BenchmarkResult(programName, - if (status) BenchmarkResult.Status.PASSED else BenchmarkResult.Status.FAILED, - time, BenchmarkResult.Metric.COMPILE_TIME, time, 1, 0) - } - - fun getTime(taskName: String) = tasksTimes[taskName] ?: 0.0 + internal fun getTimerListenerOfSubproject(subproject: Project) = + timerListeners[subproject.name] ?: error("TimeListener for project ${subproject.name} wasn't set") } + val tasksTimes = mutableMapOf() + + fun getBenchmarkResult(programName: String, tasksNames: List): BenchmarkResult { + val time = tasksNames.map { tasksTimes[it] ?: 0.0 }.sum() + // TODO get this info from gradle plugin with exit code end stacktrace. + val status = tasksNames.map { tasksTimes.containsKey(it) }.reduce { a, b -> a && b } + return BenchmarkResult(programName, + if (status) BenchmarkResult.Status.PASSED else BenchmarkResult.Status.FAILED, + time, BenchmarkResult.Metric.COMPILE_TIME, time, 1, 0) + } + + fun getTime(taskName: String) = tasksTimes[taskName] ?: 0.0 + private var startTime = System.nanoTime() override fun beforeExecute(task: Task) { @@ -253,5 +261,7 @@ class TaskTimerListener: TaskExecutionListener { } fun addTimeListener(subproject: Project) { - subproject.gradle.addListener(TaskTimerListener()) + val listener = TaskTimerListener() + TaskTimerListener.timerListeners.put(subproject.name, listener) + subproject.gradle.addListener(listener) } diff --git a/build-tools/src/main/kotlin/org/jetbrains/kotlin/benchmark/BenchmarkingPlugin.kt b/build-tools/src/main/kotlin/org/jetbrains/kotlin/benchmark/BenchmarkingPlugin.kt index 5aede9220c1..49012e52e60 100644 --- a/build-tools/src/main/kotlin/org/jetbrains/kotlin/benchmark/BenchmarkingPlugin.kt +++ b/build-tools/src/main/kotlin/org/jetbrains/kotlin/benchmark/BenchmarkingPlugin.kt @@ -220,8 +220,8 @@ abstract class BenchmarkingPlugin: Plugin { it.doLast { val applicationName = benchmark.applicationName val benchContents = buildDir.resolve(nativeBenchResults).readText() - val nativeCompileTime = if (benchmark.compileTasks.isEmpty()) getNativeCompileTime(applicationName) - else getNativeCompileTime(applicationName, benchmark.compileTasks) + val nativeCompileTime = if (benchmark.compileTasks.isEmpty()) getNativeCompileTime(project, applicationName) + else getNativeCompileTime(project, applicationName, benchmark.compileTasks) val properties = commonBenchmarkProperties + mapOf( "type" to "native", diff --git a/build-tools/src/main/kotlin/org/jetbrains/kotlin/benchmark/CompileBenchmarkingPlugin.kt b/build-tools/src/main/kotlin/org/jetbrains/kotlin/benchmark/CompileBenchmarkingPlugin.kt index 3df6e444b7a..2b43af565e5 100644 --- a/build-tools/src/main/kotlin/org/jetbrains/kotlin/benchmark/CompileBenchmarkingPlugin.kt +++ b/build-tools/src/main/kotlin/org/jetbrains/kotlin/benchmark/CompileBenchmarkingPlugin.kt @@ -85,6 +85,7 @@ open class CompileBenchmarkingPlugin : Plugin { doLast { val nativeCompileTime = getCompileBenchmarkTime( + project, applicationName, buildSteps.names, repeatNumber, diff --git a/build-tools/src/main/kotlin/org/jetbrains/kotlin/benchmark/KotlinNativeBenchmarkingPlugin.kt b/build-tools/src/main/kotlin/org/jetbrains/kotlin/benchmark/KotlinNativeBenchmarkingPlugin.kt index b639a309b94..5dc4c5c4e02 100644 --- a/build-tools/src/main/kotlin/org/jetbrains/kotlin/benchmark/KotlinNativeBenchmarkingPlugin.kt +++ b/build-tools/src/main/kotlin/org/jetbrains/kotlin/benchmark/KotlinNativeBenchmarkingPlugin.kt @@ -43,7 +43,7 @@ open class KotlinNativeBenchmarkingPlugin: BenchmarkingPlugin() { it.doLast { val applicationName = benchmark.applicationName val jarPath = (tasks.getByName("jvmJar") as Jar).archiveFile.get().asFile - val jvmCompileTime = getJvmCompileTime(applicationName) + val jvmCompileTime = getJvmCompileTime(project, applicationName) val benchContents = buildDir.resolve(jvmBenchResults).readText() val properties: Map = commonBenchmarkProperties + mapOf( diff --git a/performance/framework/build.gradle b/performance/framework/build.gradle index c9a71d5318e..54d7b3815ad 100644 --- a/performance/framework/build.gradle +++ b/performance/framework/build.gradle @@ -91,7 +91,7 @@ task konanJsonReport { def frameworkPath = kotlin.macosX64("macos").binaries. getFramework(frameworkName, kotlin.macosX64("macos").binaries.DEBUG).outputFile.absolutePath def nativeExecutable = new File("$frameworkPath/$frameworkName").canonicalPath - def nativeCompileTime = MPPTools.getNativeCompileTime(applicationName, ['compileKotlinMacos', + def nativeCompileTime = MPPTools.getNativeCompileTime(project, applicationName, ['compileKotlinMacos', 'linkBenchmarksAnalyzerDebugFrameworkMacos', 'cinteropLibcurlMacos']) def properties = getCommonProperties() + ['type' : 'native',