Repository: JetBrains/kotlin
File: libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/targets/native/performance/KotlinPerformancePlugin.kt (Kotlin)

Code before:
        return "${if (status) "PASSED" else "FAILED"}\nCOMPILE_TIME $time"
    }


    // Get compile task and associated with it other compile tasks.
    private fun getAllExecutedTasks(compilation: KotlinCompilation<*>): List<Task> {
        val tasks = mutableListOf(compilation.compileKotlinTask as Task)
        compilation.associateWith.forEach {
            tasks += getAllExecutedTasks(it)
        }
        return tasks
    }

    private fun configureTasks(project: Project, performanceExtension: PerformanceExtension) {
        // Add time listener.
        project.gradle.addListener(TaskTimerListener())
        performanceExtension.trackedBinaries.forEach { binary ->
            project.tasks.create(
                "perf${binary.buildType.toString().toLowerCase().capitalize()}" +
                        "Report${binary.konanTarget.name.capitalize()}"
            ) {
                it.group = TASK_GROUP
                it.description = "Report results of performance measurement for Kotlin/Native targets."
                it.doLast {
                    val compileTasks = getAllExecutedTasks(binary.linkTask.compilation)
                    val successStatus = compileTasks.map { it.state.failure == null }.reduce { acc, it -> acc && it }
                    // Get code size metric.
                    var codeSize: String? = null
                    if (TrackableMetric.CODE_SIZE in performanceExtension.metrics) {
                        codeSize = binary.outputFile.let {
                            if (it.exists()) "CODE_SIZE ${it.length()}" else null
                        }
                    }
                    // Get compile time.
                    var compileTime: String? = null
                    if (TrackableMetric.COMPILE_TIME in performanceExtension.metrics) {
                        compileTime = getCompilationResults(
                            listOf(binary.linkTaskName) + compileTasks.map { it.name },
                            successStatus
                        )
                    }

                    // Create report.
                    val reportFile = File(project.buildDir, "${it.name}.txt")
                    val name = performanceExtension.binaryNamesForReport.getOrDefault(binary, binary.name)
                    reportFile.writeText(name)
                    if (compileTime != null) {
                        reportFile.appendText("\n$compileTime")
                    }
                    if (codeSize != null) {
                        reportFile.appendText("\n$codeSize")

Review comment (bug):
`val successStatus = compileTasks.all {  it.state.failure == null }`?

Code after:
        // Find binaries with trackable performance.
        if (performanceExtension.trackedBinaries.isEmpty()) {
            project.logger.warn("There is no tracked binaries. Please, provide binaries in settings of $EXTENSION_NAME plugin.")
            result = false
        }
        return result
    }

    private fun configureTasks(project: Project, performanceExtension: PerformanceExtension) {
        // Add time listener.
        val timeListener = TaskTimerListener(project)
        project.gradle.addListener(timeListener)
        performanceExtension.trackedBinaries.forEach { binary ->
            project.tasks.create(
                binary.target.disambiguateName(lowerCamelCaseName("perfReport", binary.name)),
                NativePerformanceReport::class.java
            ) {
                it.binary = binary
                it.settings = performanceExtension
                it.timeListener = timeListener
                it.group = TASK_GROUP
                it.description = "Report performance measurement results for binary '${binary.name}' of target '${binary.target.name}'."
                binary.linkTask.finalizedBy(it)
            }
        }
    }

    override fun apply(project: Project): Unit = with(project) {
        pluginManager.withPlugin("kotlin-multiplatform") {
            val kotlinExtension = project.multiplatformExtension
            val performanceExtension = PerformanceExtension(this)

            kotlinExtension.addExtension(EXTENSION_NAME, performanceExtension)
            afterEvaluate {
                if (checkSettings(project, performanceExtension)) {
                    configureTasks(project, performanceExtension)
                }
            }
        }
    }

    companion object {
        const val EXTENSION_NAME = "performance"
        const val TASK_GROUP = "Kotlin/Native Performance"
    }
}