Repository: JetBrains/compose-multiplatform
File: benchmarks/multiplatform/benchmarks/build.gradle.kts (Kotlin)

Code before:
    from(rootProject.layout.buildDirectory.file("js/packages/compose-benchmarks-benchmarks-wasm-js/kotlin"))
    archiveFileName.set("d8-distribution.zip")
    destinationDirectory.set(rootProject.layout.buildDirectory.dir("distributions"))
}

tasks.register("runBrowserAndSaveStats") {
    fun printProcessOutput(inputStream: java.io.InputStream) {
        Thread {
            inputStream.bufferedReader().use { reader ->
                reader.lines().forEach { line ->
                    println(line)
                }
            }
        }.start()
    }

    doFirst {
        var serverProcess: Process? = null
        var clientProcess: Process? = null
        try {
            serverProcess = ProcessBuilder("./gradlew", "benchmarks:run", "-PrunArguments=runServer=true saveStatsToJSON=true")
                .start()
            printProcessOutput(serverProcess.inputStream)
            printProcessOutput(serverProcess.errorStream)

            clientProcess = ProcessBuilder("./gradlew", "benchmarks:wasmJsBrowserProductionRun")
                .start()
            printProcessOutput(clientProcess.inputStream)
            printProcessOutput(clientProcess.errorStream)

            serverProcess.waitFor()
        } catch (e: Throwable) {
            e.printStackTrace()
        } finally {
            serverProcess?.destroy()
            clientProcess?.destroy()
        }
    }
}

tasks.withType<org.jetbrains.kotlin.gradle.targets.js.binaryen.BinaryenExec>().configureEach {
    binaryenArgs.add("-g") // keep the readable names
}

@OptIn(ExperimentalWasmDsl::class)
rootProject.the<BinaryenRootEnvSpec>().apply {
    // version = "122" // change only if needed
}

val jsOrWasmRegex = Regex("js|wasm")


Review comment (suggestion):
looks like `saveStatsToJSON=true` is not passed here, the browser doesn't make `/benchmark` requests

Code after:
    from(rootProject.layout.buildDirectory.file("js/packages/compose-benchmarks-benchmarks-wasm-js/kotlin"))
    archiveFileName.set("d8-distribution.zip")
    destinationDirectory.set(rootProject.layout.buildDirectory.dir("distributions"))
}

tasks.register("runBrowserAndSaveStats") {
    fun printProcessOutput(inputStream: java.io.InputStream) {
        Thread {
            inputStream.bufferedReader().use { reader ->
                reader.lines().forEach { line ->
                    println(line)
                }
            }
        }.start()
    }

    fun runCommand(vararg command: String): Process {
        return ProcessBuilder(*command).start().also {
            printProcessOutput(it.inputStream)
            printProcessOutput(it.errorStream)
        }
    }

    doFirst {
        var serverProcess: Process? = null
        var clientProcess: Process? = null
        try {
            serverProcess = runCommand("./gradlew", "benchmarks:run",
                "-PrunArguments=runServer=true saveStatsToJSON=true")

            clientProcess = runCommand("./gradlew", "benchmarks:wasmJsBrowserProductionRun",
                "-PrunArguments=$runArguments saveStatsToJSON=true")

            serverProcess.waitFor()
        } catch (e: Throwable) {
            e.printStackTrace()
        } finally {
            serverProcess?.destroy()
            clientProcess?.destroy()
        }
    }
}

tasks.withType<org.jetbrains.kotlin.gradle.targets.js.binaryen.BinaryenExec>().configureEach {
    binaryenArgs.add("-g") // keep the readable names
}

@OptIn(ExperimentalWasmDsl::class)
rootProject.the<BinaryenRootEnvSpec>().apply {
    // version = "122" // change only if needed
}