Remove KotlinBuildStatsService.getInstance() calls
#KT-58768 In Progress
This commit is contained in:
committed by
Space Team
parent
94b35570ed
commit
3fd9e22f37
+2
-2
@@ -25,6 +25,7 @@ class FusStatisticsIT : KGPDaemonsBaseTest() {
|
||||
"GRADLE_VERSION",
|
||||
"KOTLIN_STDLIB_VERSION",
|
||||
"KOTLIN_COMPILER_VERSION",
|
||||
"USE_CLASSPATH_SNAPSHOT=true"
|
||||
)
|
||||
|
||||
private val GradleProject.fusStatisticsPath: Path
|
||||
@@ -56,7 +57,7 @@ class FusStatisticsIT : KGPDaemonsBaseTest() {
|
||||
fun testMetricCollectingOfApplyingCocoapodsPlugin(gradleVersion: GradleVersion) {
|
||||
project("native-cocoapods-template", gradleVersion) {
|
||||
build("assemble", "-Pkotlin.session.logger.root.path=$projectPath") {
|
||||
assertFileContains(fusStatisticsPath, "COCOAPODS_PLUGIN_ENABLED=true")
|
||||
assertFileContains(fusStatisticsPath, "COCOAPODS_PLUGIN_ENABLED=true", "ENABLED_HMPP=true", "MPP_PLATFORMS")
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -122,7 +123,6 @@ class FusStatisticsIT : KGPDaemonsBaseTest() {
|
||||
gradleVersion,
|
||||
) {
|
||||
build("compileKotlin", "-Pkotlin.session.logger.root.path=$projectPath") {
|
||||
val fusStatisticsPath = fusStatisticsPath
|
||||
assertFileContains(
|
||||
fusStatisticsPath,
|
||||
*expectedMetrics,
|
||||
|
||||
+1
-14
@@ -50,7 +50,6 @@ import org.jetbrains.kotlin.gradle.plugin.PropertiesProvider.PropertyNames.KOTLI
|
||||
import org.jetbrains.kotlin.gradle.plugin.PropertiesProvider.PropertyNames.MPP_13X_FLAGS_SET_BY_PLUGIN
|
||||
import org.jetbrains.kotlin.gradle.plugin.diagnostics.KotlinToolingDiagnostics
|
||||
import org.jetbrains.kotlin.gradle.plugin.diagnostics.reportDiagnosticOncePerBuild
|
||||
import org.jetbrains.kotlin.gradle.plugin.statistics.KotlinBuildStatsService
|
||||
import org.jetbrains.kotlin.gradle.targets.js.ir.KotlinIrJsGeneratedTSValidationStrategy
|
||||
import org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsIrOutputGranularity
|
||||
import org.jetbrains.kotlin.gradle.tasks.KotlinCompilerExecutionStrategy
|
||||
@@ -58,7 +57,6 @@ import org.jetbrains.kotlin.gradle.utils.NativeCompilerDownloader
|
||||
import org.jetbrains.kotlin.gradle.utils.localProperties
|
||||
import org.jetbrains.kotlin.konan.target.KonanTarget
|
||||
import org.jetbrains.kotlin.konan.target.presetName
|
||||
import org.jetbrains.kotlin.statistics.metrics.StringMetrics
|
||||
import org.jetbrains.kotlin.util.capitalizeDecapitalize.toLowerCaseAsciiOnly
|
||||
import org.jetbrains.kotlin.util.capitalizeDecapitalize.toUpperCaseAsciiOnly
|
||||
import org.jetbrains.kotlin.util.prefixIfNot
|
||||
@@ -158,18 +156,7 @@ internal class PropertiesProvider private constructor(private val project: Proje
|
||||
get() = booleanProperty("kotlin.incremental.usePreciseJavaTracking")
|
||||
|
||||
val useClasspathSnapshot: Boolean
|
||||
get() {
|
||||
val reporter = KotlinBuildStatsService.getInstance()
|
||||
|
||||
val gradleProperty = booleanProperty(KOTLIN_INCREMENTAL_USE_CLASSPATH_SNAPSHOT)
|
||||
if (gradleProperty != null) {
|
||||
reporter?.report(StringMetrics.USE_CLASSPATH_SNAPSHOT, gradleProperty.toString())
|
||||
return gradleProperty
|
||||
} else {
|
||||
reporter?.report(StringMetrics.USE_CLASSPATH_SNAPSHOT, "default-true")
|
||||
return true
|
||||
}
|
||||
}
|
||||
get() = booleanProperty(KOTLIN_INCREMENTAL_USE_CLASSPATH_SNAPSHOT) ?: true
|
||||
|
||||
val useKotlinAbiSnapshot: Boolean
|
||||
get() = booleanProperty(KOTLIN_ABI_SNAPSHOT) ?: false
|
||||
|
||||
+16
-9
@@ -23,6 +23,7 @@ import org.gradle.util.GradleVersion
|
||||
import org.jetbrains.kotlin.build.report.metrics.GradleBuildPerformanceMetric
|
||||
import org.jetbrains.kotlin.gradle.logging.kotlinDebug
|
||||
import org.jetbrains.kotlin.gradle.plugin.BuildEventsListenerRegistryHolder
|
||||
import org.jetbrains.kotlin.gradle.plugin.PropertiesProvider
|
||||
import org.jetbrains.kotlin.gradle.plugin.StatisticsBuildFlowManager
|
||||
import org.jetbrains.kotlin.gradle.plugin.internal.isConfigurationCacheRequested
|
||||
import org.jetbrains.kotlin.gradle.plugin.internal.isProjectIsolationEnabled
|
||||
@@ -65,10 +66,11 @@ abstract class BuildFusService : BuildService<BuildFusService.Parameters>, AutoC
|
||||
internal fun reportFusMetrics(reportAction: (StatisticsValuesConsumer) -> Unit) {
|
||||
reportAction(fusMetricsConsumer)
|
||||
}
|
||||
|
||||
private val buildId = randomUUID().toString()
|
||||
|
||||
companion object {
|
||||
private val serviceName = "${BuildFusService::class.simpleName}_${BuildFusService::class.java.classLoader.hashCode()}"
|
||||
internal val serviceName = "${BuildFusService::class.simpleName}_${BuildFusService::class.java.classLoader.hashCode()}"
|
||||
|
||||
fun registerIfAbsent(project: Project, pluginVersion: String) =
|
||||
registerIfAbsentImpl(project, pluginVersion).also { serviceProvider ->
|
||||
@@ -89,10 +91,12 @@ abstract class BuildFusService : BuildService<BuildFusService.Parameters>, AutoC
|
||||
|
||||
project.gradle.sharedServices.registrations.findByName(serviceName)?.let {
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
return (it.service as Provider<BuildFusService>).also {
|
||||
it.get().parameters.configurationMetrics.add(project.provider {
|
||||
KotlinBuildStatHandler.collectProjectConfigurationTimeMetrics(project)
|
||||
})
|
||||
return (it.service as Provider<BuildFusService>).also { buildServiceProvider ->
|
||||
project.afterEvaluate {
|
||||
buildServiceProvider.get().parameters.configurationMetrics.add(
|
||||
project.provider { KotlinBuildStatHandler.collectProjectConfigurationTimeMetrics(project) }
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -102,6 +106,7 @@ abstract class BuildFusService : BuildService<BuildFusService.Parameters>, AutoC
|
||||
}
|
||||
|
||||
val buildReportOutputs = reportingSettings(project).buildReportOutputs
|
||||
val useClasspathSnapshot = PropertiesProvider(project).useClasspathSnapshot
|
||||
val gradle = project.gradle
|
||||
|
||||
//Workaround for known issues for Gradle 8+: https://github.com/gradle/gradle/issues/24887:
|
||||
@@ -113,14 +118,11 @@ abstract class BuildFusService : BuildService<BuildFusService.Parameters>, AutoC
|
||||
KotlinBuildStatHandler.collectGeneralConfigurationTimeMetrics(
|
||||
gradle,
|
||||
buildReportOutputs,
|
||||
useClasspathSnapshot,
|
||||
pluginVersion,
|
||||
isProjectIsolationEnabled
|
||||
)
|
||||
})
|
||||
|
||||
spec.parameters.configurationMetrics.add(project.provider {
|
||||
KotlinBuildStatHandler.collectProjectConfigurationTimeMetrics(project)
|
||||
})
|
||||
spec.parameters.useBuildFinishFlowAction.set(GradleVersion.current().baseVersion >= GradleVersion.version("8.1"))
|
||||
}.also { buildService ->
|
||||
@Suppress("DEPRECATION")
|
||||
@@ -133,6 +135,11 @@ abstract class BuildFusService : BuildService<BuildFusService.Parameters>, AutoC
|
||||
if (GradleVersion.current().baseVersion >= GradleVersion.version("8.1")) {
|
||||
StatisticsBuildFlowManager.getInstance(project).subscribeForBuildResult()
|
||||
}
|
||||
project.afterEvaluate {
|
||||
buildService.get().parameters.configurationMetrics.add(project.provider {
|
||||
KotlinBuildStatHandler.collectProjectConfigurationTimeMetrics(project)
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
+4
-3
@@ -53,14 +53,15 @@ class KotlinBuildStatHandler {
|
||||
internal fun collectGeneralConfigurationTimeMetrics(
|
||||
gradle: Gradle,
|
||||
buildReportOutputs: List<BuildReportType>,
|
||||
useClasspathSnapshot: Boolean,
|
||||
pluginVersion: String,
|
||||
isProjectIsolationEnabled: Boolean,
|
||||
): MetricContainer {
|
||||
val configurationTimeMetrics = MetricContainer()
|
||||
|
||||
configurationTimeMetrics.put(StringMetrics.KOTLIN_COMPILER_VERSION, pluginVersion)
|
||||
|
||||
val statisticOverhead = measureTimeMillis {
|
||||
configurationTimeMetrics.put(StringMetrics.KOTLIN_COMPILER_VERSION, pluginVersion)
|
||||
configurationTimeMetrics.put(StringMetrics.USE_CLASSPATH_SNAPSHOT, useClasspathSnapshot.toString())
|
||||
buildReportOutputs.forEach {
|
||||
when (it) {
|
||||
BuildReportType.BUILD_SCAN -> configurationTimeMetrics.put(BooleanMetrics.BUILD_SCAN_BUILD_REPORT, true)
|
||||
@@ -89,7 +90,7 @@ class KotlinBuildStatHandler {
|
||||
}
|
||||
|
||||
/**
|
||||
* Collect project's configuration metrics
|
||||
* Collect project's configuration metrics including applied plugins. It should be called inside afterEvaluate block.
|
||||
*/
|
||||
internal fun collectProjectConfigurationTimeMetrics(
|
||||
project: Project,
|
||||
|
||||
+1
-1
@@ -66,7 +66,7 @@ internal abstract class KotlinBuildStatsService internal constructor() : Statist
|
||||
*/
|
||||
@JvmStatic
|
||||
@Synchronized
|
||||
fun getInstance(): KotlinBuildStatsService? {
|
||||
private fun getInstance(): KotlinBuildStatsService? {
|
||||
if (statisticsIsEnabled != true) {
|
||||
return null
|
||||
}
|
||||
|
||||
+4
-1
@@ -8,6 +8,7 @@ package org.jetbrains.kotlin.gradle.plugin.statistics
|
||||
import org.jetbrains.kotlin.gradle.dsl.multiplatformExtension
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinProjectSetupAction
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget
|
||||
import org.jetbrains.kotlin.gradle.utils.addConfigurationMetrics
|
||||
import org.jetbrains.kotlin.statistics.metrics.StringMetrics
|
||||
|
||||
internal val MultiplatformBuildStatsReportSetupAction = KotlinProjectSetupAction {
|
||||
@@ -15,6 +16,8 @@ internal val MultiplatformBuildStatsReportSetupAction = KotlinProjectSetupAction
|
||||
/* Report the platform to tbe build stats service */
|
||||
val targetName = if (target is KotlinNativeTarget) target.konanTarget.name
|
||||
else target.platformType.name
|
||||
KotlinBuildStatsService.getInstance()?.report(StringMetrics.MPP_PLATFORMS, targetName)
|
||||
project.addConfigurationMetrics {
|
||||
it.put(StringMetrics.MPP_PLATFORMS, targetName)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+3
-9
@@ -28,23 +28,17 @@ class NonSynchronizedMetricsContainer : StatisticsValuesConsumer, Serializable {
|
||||
private val stringMetrics = HashMap<MetricDescriptor<StringMetrics>, IMetricContainer<String>>()
|
||||
|
||||
override fun report(metric: BooleanMetrics, value: Boolean, subprojectName: String?, weight: Long?): Boolean {
|
||||
booleanMetrics.getOrPut(MetricDescriptor(metric, subprojectName)) { metric.type.newMetricContainer() }.let { metricContainer ->
|
||||
metricContainer.addValue(value, weight)
|
||||
}
|
||||
booleanMetrics.getOrPut(MetricDescriptor(metric, subprojectName)) { metric.type.newMetricContainer() }.addValue(value, weight)
|
||||
return true
|
||||
}
|
||||
|
||||
override fun report(metric: NumericalMetrics, value: Long, subprojectName: String?, weight: Long?): Boolean {
|
||||
numericalMetrics.getOrPut(MetricDescriptor(metric, subprojectName)) { metric.type.newMetricContainer() }.let { metricContainer ->
|
||||
metricContainer.addValue(value, weight)
|
||||
}
|
||||
numericalMetrics.getOrPut(MetricDescriptor(metric, subprojectName)) { metric.type.newMetricContainer() }.addValue(value, weight)
|
||||
return true
|
||||
}
|
||||
|
||||
override fun report(metric: StringMetrics, value: String, subprojectName: String?, weight: Long?): Boolean {
|
||||
stringMetrics.getOrPut(MetricDescriptor(metric, subprojectName)) { metric.type.newMetricContainer() }.let { metricContainer ->
|
||||
metricContainer.addValue(value, weight)
|
||||
}
|
||||
stringMetrics.getOrPut(MetricDescriptor(metric, subprojectName)) { metric.type.newMetricContainer() }.addValue(value, weight)
|
||||
return true
|
||||
}
|
||||
|
||||
|
||||
+8
-8
@@ -13,7 +13,7 @@ import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinCompilationFactory
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinOnlyTarget
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinOnlyTargetPreset
|
||||
import org.jetbrains.kotlin.gradle.plugin.statistics.KotlinBuildStatsService
|
||||
import org.jetbrains.kotlin.gradle.utils.addConfigurationMetrics
|
||||
import org.jetbrains.kotlin.gradle.utils.runProjectConfigurationHealthCheckWhenEvaluated
|
||||
import org.jetbrains.kotlin.statistics.metrics.StringMetrics
|
||||
|
||||
@@ -33,14 +33,14 @@ open class KotlinJsIrTargetPreset(
|
||||
this.isMpp = this@KotlinJsIrTargetPreset.isMpp
|
||||
project.runProjectConfigurationHealthCheckWhenEvaluated {
|
||||
|
||||
val buildStatsService = KotlinBuildStatsService.getInstance()
|
||||
when {
|
||||
isBrowserConfigured && isNodejsConfigured -> buildStatsService?.report(StringMetrics.JS_TARGET_MODE, "both")
|
||||
isBrowserConfigured -> buildStatsService?.report(StringMetrics.JS_TARGET_MODE, "browser")
|
||||
isNodejsConfigured -> buildStatsService?.report(StringMetrics.JS_TARGET_MODE, "nodejs")
|
||||
!isBrowserConfigured && !isNodejsConfigured -> buildStatsService?.report(StringMetrics.JS_TARGET_MODE, "none")
|
||||
project.addConfigurationMetrics {
|
||||
when {
|
||||
isBrowserConfigured && isNodejsConfigured -> it.put(StringMetrics.JS_TARGET_MODE, "both")
|
||||
isBrowserConfigured -> it.put(StringMetrics.JS_TARGET_MODE, "browser")
|
||||
isNodejsConfigured -> it.put(StringMetrics.JS_TARGET_MODE, "nodejs")
|
||||
!isBrowserConfigured && !isNodejsConfigured -> it.put(StringMetrics.JS_TARGET_MODE, "none")
|
||||
}
|
||||
}
|
||||
Unit
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+3
-8
@@ -8,12 +8,8 @@ package org.jetbrains.kotlin.gradle.targets.metadata
|
||||
import org.gradle.api.NamedDomainObjectContainer
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.api.artifacts.result.ResolvedArtifactResult
|
||||
import org.gradle.api.attributes.Category
|
||||
import org.gradle.api.attributes.Category.CATEGORY_ATTRIBUTE
|
||||
import org.gradle.api.attributes.Usage.USAGE_ATTRIBUTE
|
||||
import org.gradle.api.file.FileCollection
|
||||
import org.gradle.api.tasks.TaskProvider
|
||||
import org.gradle.api.tasks.bundling.Jar
|
||||
import org.jetbrains.kotlin.commonizer.SharedCommonizerTarget
|
||||
import org.jetbrains.kotlin.gradle.dsl.kotlinExtension
|
||||
import org.jetbrains.kotlin.gradle.dsl.metadataTarget
|
||||
@@ -21,9 +17,7 @@ import org.jetbrains.kotlin.gradle.dsl.multiplatformExtension
|
||||
import org.jetbrains.kotlin.gradle.plugin.*
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.*
|
||||
import org.jetbrains.kotlin.gradle.plugin.sources.*
|
||||
import org.jetbrains.kotlin.gradle.plugin.statistics.KotlinBuildStatsService
|
||||
import org.jetbrains.kotlin.gradle.targets.native.internal.createCInteropMetadataDependencyClasspath
|
||||
import org.jetbrains.kotlin.gradle.targets.native.internal.includeCommonizedCInteropMetadata
|
||||
import org.jetbrains.kotlin.gradle.targets.native.internal.sharedCommonizerTarget
|
||||
import org.jetbrains.kotlin.gradle.tasks.registerTask
|
||||
import org.jetbrains.kotlin.gradle.utils.*
|
||||
@@ -60,7 +54,9 @@ class KotlinMetadataTargetConfigurator :
|
||||
super.configureTarget(target)
|
||||
|
||||
if (target.project.isKotlinGranularMetadataEnabled) {
|
||||
KotlinBuildStatsService.getInstance()?.report(BooleanMetrics.ENABLED_HMPP, true)
|
||||
target.project.addConfigurationMetrics {
|
||||
it.put(BooleanMetrics.ENABLED_HMPP, true)
|
||||
}
|
||||
|
||||
target.compilations.withType(KotlinCommonCompilation::class.java).getByName(KotlinCompilation.MAIN_COMPILATION_NAME).run {
|
||||
// Force the default 'main' compilation to produce *.kotlin_metadata regardless of the klib feature flag.
|
||||
@@ -262,7 +258,6 @@ class KotlinMetadataTargetConfigurator :
|
||||
private val ResolvedArtifactResult.isMpp: Boolean get() = variant.attributes.containsMultiplatformAttributes
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
+1
-2
@@ -13,8 +13,6 @@ import org.gradle.api.artifacts.transform.TransformSpec
|
||||
import org.gradle.api.attributes.Attribute
|
||||
import org.gradle.api.provider.Provider
|
||||
import org.jetbrains.kotlin.compilerRunner.GradleCompilerRunner
|
||||
import org.jetbrains.kotlin.gradle.dsl.KotlinAndroidProjectExtension
|
||||
import org.jetbrains.kotlin.gradle.dsl.KotlinJvmProjectExtension
|
||||
import org.jetbrains.kotlin.gradle.dsl.KotlinTopLevelExtension
|
||||
import org.jetbrains.kotlin.gradle.incremental.IncrementalModuleInfoBuildService
|
||||
import org.jetbrains.kotlin.gradle.internal.ClassLoadersCachingBuildService
|
||||
@@ -42,6 +40,7 @@ internal open class BaseKotlinCompileConfig<TASK : KotlinCompile> : AbstractKotl
|
||||
init {
|
||||
configureTaskProvider { taskProvider ->
|
||||
val useClasspathSnapshot = propertiesProvider.useClasspathSnapshot
|
||||
|
||||
val classpathConfiguration = if (useClasspathSnapshot) {
|
||||
val jvmToolchain = taskProvider.flatMap { it.defaultKotlinJavaToolchain }
|
||||
val runKotlinCompilerViaBuildToolsApi = propertiesProvider.runKotlinCompilerViaBuildToolsApi
|
||||
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* 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.utils
|
||||
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.api.provider.Provider
|
||||
import org.jetbrains.kotlin.gradle.plugin.statistics.BuildFusService
|
||||
import org.jetbrains.kotlin.gradle.plugin.statistics.MetricContainer
|
||||
|
||||
|
||||
/**
|
||||
* Invokes build FUS service if the reporting service is initialised and add configuration time metrics.
|
||||
*
|
||||
* BuildFusService.reportFusMetrics should be called for execution time metrics
|
||||
*/
|
||||
internal fun Project.addConfigurationMetrics(reportAction: (MetricContainer) -> Unit) {
|
||||
project.gradle.sharedServices.registrations.findByName(BuildFusService.serviceName)?.also {
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
(it.service as Provider<BuildFusService>).also {
|
||||
it.get().parameters.configurationMetrics.add(project.provider {
|
||||
val configurationTimeMetrics = MetricContainer()
|
||||
reportAction(configurationTimeMetrics)
|
||||
configurationTimeMetrics
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user