Added FUS statistics for applied plugins: kotlin-js, cocoapod plugin
#KT-59324 In Progress Merge-request: KT-MR-11360 Merged-by: Dmitrii Krasnov <Dmitrii.Krasnov@jetbrains.com>
This commit is contained in:
committed by
Space Team
parent
3ff21db77f
commit
e7c589a573
+41
-26
@@ -6,10 +6,9 @@
|
||||
package org.jetbrains.kotlin.gradle
|
||||
|
||||
import org.gradle.util.GradleVersion
|
||||
import org.jetbrains.kotlin.gradle.testbase.GradleTest
|
||||
import org.junit.jupiter.api.DisplayName
|
||||
import org.jetbrains.kotlin.gradle.testbase.*
|
||||
import org.jetbrains.kotlin.gradle.util.replaceText
|
||||
import org.junit.jupiter.api.DisplayName
|
||||
import java.nio.file.Path
|
||||
|
||||
@DisplayName("FUS statistic")
|
||||
@@ -25,6 +24,9 @@ class FusStatisticsIT : KGPDaemonsBaseTest() {
|
||||
"KOTLIN_COMPILER_VERSION",
|
||||
)
|
||||
|
||||
private val GradleProject.fusStatisticsPath: Path
|
||||
get() = projectPath.getSingleFileInDir("kotlin-profile")
|
||||
|
||||
@DisplayName("for dokka")
|
||||
@GradleTest
|
||||
@GradleTestVersions(
|
||||
@@ -46,30 +48,32 @@ class FusStatisticsIT : KGPDaemonsBaseTest() {
|
||||
}
|
||||
}
|
||||
|
||||
private fun TestProject.applyDokka() {
|
||||
buildGradle.replaceText(
|
||||
"plugins {",
|
||||
"""
|
||||
plugins {
|
||||
id("org.jetbrains.dokka") version "1.8.10"
|
||||
""".trimIndent()
|
||||
)
|
||||
@DisplayName("Verify that the metric for applying the Cocoapods plugin is being collected")
|
||||
@GradleTest
|
||||
fun testMetricCollectingOfApplyingCocoapodsPlugin(gradleVersion: GradleVersion) {
|
||||
project("native-cocoapods-template", gradleVersion) {
|
||||
build("assemble", "-Pkotlin.session.logger.root.path=$projectPath") {
|
||||
assertFileContains(fusStatisticsPath, "COCOAPODS_PLUGIN_ENABLED=true")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private val GradleProject.fusStatisticsPath: Path
|
||||
get() = projectPath.getSingleFileInDir("kotlin-profile")
|
||||
|
||||
@DisplayName("general fields")
|
||||
@DisplayName("Verify that the metric for applying the Kotlin JS plugin is being collected")
|
||||
@GradleTest
|
||||
@GradleTestVersions(
|
||||
additionalVersions = [TestVersions.Gradle.G_7_6, TestVersions.Gradle.G_8_0],
|
||||
)
|
||||
fun testFusStatistics(gradleVersion: GradleVersion) {
|
||||
project(
|
||||
"simpleProject",
|
||||
gradleVersion,
|
||||
) {
|
||||
build("compileKotlin", "-Pkotlin.session.logger.root.path=$projectPath") {
|
||||
fun testMetricCollectingOfApplyingKotlinJsPlugin(gradleVersion: GradleVersion) {
|
||||
project("simple-js-library", gradleVersion) {
|
||||
build("assemble", "-Pkotlin.session.logger.root.path=$projectPath") {
|
||||
assertFileContains(fusStatisticsPath, "KOTLIN_JS_PLUGIN_ENABLED=true")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@DisplayName("Ensure that the metric are not collected if plugins were not applied to simple project")
|
||||
@GradleTest
|
||||
fun testAppliedPluginsMetricsAreNotCollectedInSimpleProject(gradleVersion: GradleVersion) {
|
||||
project("simpleProject", gradleVersion) {
|
||||
build("assemble", "-Pkotlin.session.logger.root.path=$projectPath") {
|
||||
val fusStatisticsPath = fusStatisticsPath
|
||||
assertFileContains(
|
||||
fusStatisticsPath,
|
||||
@@ -77,9 +81,9 @@ class FusStatisticsIT : KGPDaemonsBaseTest() {
|
||||
)
|
||||
assertFileDoesNotContain(
|
||||
fusStatisticsPath,
|
||||
"ENABLED_DOKKA",
|
||||
"ENABLED_DOKKA_HTML",
|
||||
"ENABLED_DOKKA_HTML"
|
||||
) // asserts that we do not put DOKKA metrics everywhere just in case
|
||||
assertFileDoesNotContain(fusStatisticsPath, "KOTLIN_JS_PLUGIN_ENABLED")
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -166,7 +170,7 @@ class FusStatisticsIT : KGPDaemonsBaseTest() {
|
||||
@GradleTest
|
||||
@GradleTestVersions(
|
||||
additionalVersions = [TestVersions.Gradle.G_7_6, TestVersions.Gradle.G_8_0],
|
||||
)
|
||||
)
|
||||
fun testFusStatisticsWithConfigurationCache(gradleVersion: GradleVersion) {
|
||||
project(
|
||||
"simpleProject",
|
||||
@@ -188,4 +192,15 @@ class FusStatisticsIT : KGPDaemonsBaseTest() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun TestProject.applyDokka() {
|
||||
buildGradle.replaceText(
|
||||
"plugins {",
|
||||
"""
|
||||
plugins {
|
||||
id("org.jetbrains.dokka") version "1.8.10"
|
||||
""".trimIndent()
|
||||
)
|
||||
}
|
||||
|
||||
}
|
||||
+14
-5
@@ -8,7 +8,7 @@ package org.jetbrains.kotlin.gradle.plugin.statistics
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.api.artifacts.DependencySet
|
||||
import org.gradle.api.logging.Logging
|
||||
import org.jetbrains.kotlin.gradle.plugin.internal.isProjectIsolationEnabled
|
||||
import org.jetbrains.kotlin.gradle.plugin.statistics.plugins.ObservablePlugins
|
||||
import org.jetbrains.kotlin.gradle.utils.*
|
||||
import org.jetbrains.kotlin.statistics.BuildSessionLogger
|
||||
import org.jetbrains.kotlin.statistics.metrics.BooleanMetrics
|
||||
@@ -23,7 +23,6 @@ import kotlin.system.measureTimeMillis
|
||||
|
||||
class KotlinBuildStatHandler {
|
||||
companion object {
|
||||
const val DOKKA_PLUGIN = "org.jetbrains.dokka"
|
||||
|
||||
@JvmStatic
|
||||
internal fun getLogger() = Logging.getLogger(KotlinBuildStatHandler::class.java)
|
||||
@@ -104,9 +103,8 @@ class KotlinBuildStatHandler {
|
||||
|
||||
val statisticOverhead = measureTimeMillis {
|
||||
gradle.allprojects { project ->
|
||||
project.plugins.findPlugin(DOKKA_PLUGIN)?.also {
|
||||
configurationTimeMetrics.put(BooleanMetrics.ENABLED_DOKKA, true)
|
||||
}
|
||||
collectAppliedPluginsStatistics(project, configurationTimeMetrics)
|
||||
|
||||
for (configuration in project.configurations) {
|
||||
try {
|
||||
val configurationName = configuration.name
|
||||
@@ -176,6 +174,17 @@ class KotlinBuildStatHandler {
|
||||
return configurationTimeMetrics
|
||||
}
|
||||
|
||||
private fun collectAppliedPluginsStatistics(
|
||||
project: Project,
|
||||
configurationTimeMetrics: MetricContainer,
|
||||
) {
|
||||
for (plugin in ObservablePlugins.values()) {
|
||||
project.plugins.withId(plugin.title) {
|
||||
configurationTimeMetrics.put(plugin.metric, true)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun reportLibrariesVersions(configurationTimeMetrics: MetricContainer, dependencies: DependencySet?) {
|
||||
dependencies?.forEach { dependency ->
|
||||
when {
|
||||
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.gradle.plugin.statistics.plugins
|
||||
|
||||
import org.jetbrains.kotlin.statistics.metrics.BooleanMetrics
|
||||
|
||||
/**
|
||||
* Represents an enumeration of plugins that can be observed during statistics collecting.
|
||||
*
|
||||
* Each plugin is associated with a title and a boolean statistic metric.
|
||||
*
|
||||
* @property title The title of the plugin.
|
||||
* @property metric The boolean statistic metric associated with the plugin.
|
||||
*/
|
||||
enum class ObservablePlugins(
|
||||
val title: String,
|
||||
val metric: BooleanMetrics,
|
||||
) {
|
||||
DOKKA_PLUGIN("org.jetbrains.dokka", BooleanMetrics.ENABLED_DOKKA),
|
||||
KOTLIN_JS_PLUGIN("org.jetbrains.kotlin.js", BooleanMetrics.KOTLIN_JS_PLUGIN_ENABLED),
|
||||
COCOAPODS_PLUGIN("org.jetbrains.kotlin.native.cocoapods", BooleanMetrics.COCOAPODS_PLUGIN_ENABLED)
|
||||
}
|
||||
+6
-2
@@ -68,9 +68,13 @@ enum class BooleanMetrics(val type: BooleanOverridePolicy, val anonymization: Bo
|
||||
TESTS_EXECUTED(OVERRIDE, SAFE),
|
||||
MAVEN_PUBLISH_EXECUTED(OVERRIDE, SAFE),
|
||||
BUILD_FAILED(OVERRIDE, SAFE),
|
||||
KOTLIN_COMPILATION_FAILED(OR, SAFE);
|
||||
KOTLIN_COMPILATION_FAILED(OR, SAFE),
|
||||
|
||||
// Other plugins enabled
|
||||
KOTLIN_JS_PLUGIN_ENABLED(OR, SAFE),
|
||||
COCOAPODS_PLUGIN_ENABLED(OR, SAFE);
|
||||
|
||||
companion object {
|
||||
const val VERSION = 1
|
||||
const val VERSION = 2
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -23,7 +23,7 @@ private const val STRING_METRICS_RELATIVE_PATH = "$SOURCE_CODE_RELATIVE_PATH/met
|
||||
private const val NUMERICAL_METRICS_RELATIVE_PATH = "$SOURCE_CODE_RELATIVE_PATH/metrics/NumericalMetrics.kt"
|
||||
|
||||
private val STRING_METRICS_EXPECTED_VERSION_AND_HASH = Pair(1, "90347332db2ce54b51e7daa64595371e")
|
||||
private val BOOLEAN_METRICS_EXPECTED_VERSION_AND_HASH = Pair(1, "b1d0eb433e0df5544a33d4c944e66e45")
|
||||
private val BOOLEAN_METRICS_EXPECTED_VERSION_AND_HASH = Pair(2, "c558be5bebec6dc07469cad384ac74d1")
|
||||
private val NUMERICAL_METRICS_EXPECTED_VERSION_AND_HASH = Pair(1, "8fda0e0845f12f40346a9e4c5cae5989")
|
||||
private val SOURCE_FOLDER_EXPECTED_VERSION_AND_HASH =
|
||||
Pair(
|
||||
|
||||
Reference in New Issue
Block a user