From a53d78b317e89dc2d0798a51542217b710af822f Mon Sep 17 00:00:00 2001 From: Ilya Goncharov Date: Tue, 24 Sep 2024 18:57:05 +0000 Subject: [PATCH] [Wasm] Add statistic collection for Wasm IC ^KT-71506 fixed --- .../kotlin/gradle/FusStatisticsIT.kt | 26 +++++++++++++++++++ .../gradle/plugin/statistics/FusMetrics.kt | 10 +++++++ .../gradle/targets/js/ir/KotlinJsIrLink.kt | 6 ++++- .../statistics/metrics/BooleanMetrics.kt | 4 ++- .../statistics/ModuleChangesCatchingTest.kt | 2 +- 5 files changed, 45 insertions(+), 3 deletions(-) diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/FusStatisticsIT.kt b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/FusStatisticsIT.kt index d4db94d3793b7..ab6f4a4e6614e 100644 --- a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/FusStatisticsIT.kt +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/FusStatisticsIT.kt @@ -10,11 +10,13 @@ import org.jetbrains.kotlin.gradle.report.BuildReportType import org.jetbrains.kotlin.gradle.testbase.* import org.jetbrains.kotlin.gradle.testbase.BuildOptions.IsolatedProjectsMode import org.jetbrains.kotlin.gradle.util.replaceText +import org.jetbrains.kotlin.test.TestMetadata import org.junit.jupiter.api.DisplayName import org.junit.jupiter.api.condition.OS import java.nio.file.Files import java.nio.file.Path import kotlin.io.path.deleteIfExists +import kotlin.io.path.writeText import kotlin.streams.toList import kotlin.test.assertTrue @@ -370,6 +372,30 @@ class FusStatisticsIT : KGPBaseTest() { } } + @MppGradlePluginTests + @GradleTest + fun testWasmIncrementalStatisticCollection(gradleVersion: GradleVersion) { + project( + "new-mpp-wasm-test", gradleVersion + ) { + gradleProperties.writeText("kotlin.incremental.wasm=true") + + buildGradleKts.modify { + it + .replace("wasmJs {", "wasmJs {\nbinaries.executable()") + .replace("", "nodejs") + } + + build("compileDevelopmentExecutableKotlinWasmJs", "-Pkotlin.session.logger.root.path=$projectPath") { + assertTasksExecuted(":compileDevelopmentExecutableKotlinWasmJs") + assertFileContains( + fusStatisticsPath, + "WASM_IR_INCREMENTAL=true", + ) + } + } + } + private fun TestProject.applyDokka() { buildGradle.replaceText( "plugins {", diff --git a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/plugin/statistics/FusMetrics.kt b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/plugin/statistics/FusMetrics.kt index 5e896cb80d7f0..b31bdbaae18b4 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/plugin/statistics/FusMetrics.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/plugin/statistics/FusMetrics.kt @@ -226,6 +226,16 @@ internal object CompileKotlinJsIrLinkMetrics : FusMetrics { } } +internal object CompileKotlinWasmIrLinkMetrics : FusMetrics { + internal fun collectMetrics( + incrementalWasm: Boolean, + metricsConsumer: StatisticsValuesConsumer, + ) { + metricsConsumer.report(BooleanMetrics.WASM_IR_INCREMENTAL, incrementalWasm) + } +} + + internal object KotlinMetadataConfigurationMetrics : FusMetrics { internal fun collectMetrics(metricContainer: MetricContainer) { metricContainer.put(BooleanMetrics.ENABLED_HMPP, true) diff --git a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/js/ir/KotlinJsIrLink.kt b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/js/ir/KotlinJsIrLink.kt index 80bf6960d0126..51c0293bac223 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/js/ir/KotlinJsIrLink.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/js/ir/KotlinJsIrLink.kt @@ -15,11 +15,11 @@ import org.gradle.work.NormalizeLineEndings import org.gradle.workers.WorkerExecutor import org.jetbrains.kotlin.cli.common.arguments.K2JSCompilerArguments import org.jetbrains.kotlin.gradle.InternalKotlinGradlePluginApi -import org.jetbrains.kotlin.gradle.dsl.KotlinJsCompilerOptionsDefault import org.jetbrains.kotlin.gradle.plugin.KotlinCompilerArgumentsProducer.ContributeCompilerArgumentsContext import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType import org.jetbrains.kotlin.gradle.plugin.PropertiesProvider import org.jetbrains.kotlin.gradle.plugin.statistics.CompileKotlinJsIrLinkMetrics +import org.jetbrains.kotlin.gradle.plugin.statistics.CompileKotlinWasmIrLinkMetrics import org.jetbrains.kotlin.gradle.plugin.statistics.UsesBuildFusService import org.jetbrains.kotlin.gradle.targets.js.dsl.KotlinJsBinaryMode import org.jetbrains.kotlin.gradle.targets.js.dsl.KotlinJsBinaryMode.DEVELOPMENT @@ -135,6 +135,10 @@ abstract class KotlinJsIrLink @Inject constructor( buildFusService.orNull?.reportFusMetrics { CompileKotlinJsIrLinkMetrics.collectMetrics(args, incrementalJsIr, it) } + } else { + buildFusService.orNull?.reportFusMetrics { + CompileKotlinWasmIrLinkMetrics.collectMetrics(incrementalWasm, it) + } } } diff --git a/libraries/tools/kotlin-gradle-statistics/src/main/kotlin/org/jetbrains/kotlin/statistics/metrics/BooleanMetrics.kt b/libraries/tools/kotlin-gradle-statistics/src/main/kotlin/org/jetbrains/kotlin/statistics/metrics/BooleanMetrics.kt index eb26bd003b1d8..6227fac0dd6ad 100644 --- a/libraries/tools/kotlin-gradle-statistics/src/main/kotlin/org/jetbrains/kotlin/statistics/metrics/BooleanMetrics.kt +++ b/libraries/tools/kotlin-gradle-statistics/src/main/kotlin/org/jetbrains/kotlin/statistics/metrics/BooleanMetrics.kt @@ -54,6 +54,8 @@ enum class BooleanMetrics(val type: BooleanOverridePolicy, val anonymization: Bo JS_IR_INCREMENTAL(OR, SAFE), + WASM_IR_INCREMENTAL(OR, SAFE), + //Build reports FILE_BUILD_REPORT(OR, SAFE), BUILD_SCAN_BUILD_REPORT(OR, SAFE), @@ -93,6 +95,6 @@ enum class BooleanMetrics(val type: BooleanOverridePolicy, val anonymization: Bo ; companion object { - const val VERSION = 10 + const val VERSION = 11 } } diff --git a/libraries/tools/kotlin-gradle-statistics/src/test/kotlin/org/jetbrains/kotlin/statistics/ModuleChangesCatchingTest.kt b/libraries/tools/kotlin-gradle-statistics/src/test/kotlin/org/jetbrains/kotlin/statistics/ModuleChangesCatchingTest.kt index c17cfd1f5dfcc..63eb34145be23 100644 --- a/libraries/tools/kotlin-gradle-statistics/src/test/kotlin/org/jetbrains/kotlin/statistics/ModuleChangesCatchingTest.kt +++ b/libraries/tools/kotlin-gradle-statistics/src/test/kotlin/org/jetbrains/kotlin/statistics/ModuleChangesCatchingTest.kt @@ -23,7 +23,7 @@ private const val STRING_METRICS_RELATIVE_PATH = "$SOURCE_CODE_RELATIVE_PATH/Str private const val NUMERICAL_METRICS_RELATIVE_PATH = "$SOURCE_CODE_RELATIVE_PATH/NumericalMetrics.kt" private val STRING_METRICS_EXPECTED_VERSION_AND_HASH = Pair(2, "636529439256b809cd4fb99e20310505") -private val BOOLEAN_METRICS_EXPECTED_VERSION_AND_HASH = Pair(10, "2fc50dacfafd4f4b796ac76f2ce7cc16") +private val BOOLEAN_METRICS_EXPECTED_VERSION_AND_HASH = Pair(11, "90b586ea9ab1f5bf387c185248166cfd") private val NUMERICAL_METRICS_EXPECTED_VERSION_AND_HASH = Pair(2, "d8c1a1f4fb7227fbe8247320bf3370ca") private val SOURCE_FOLDER_EXPECTED_VERSION_AND_HASH = Pair(