mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[gradle] [IDEA-334242] remove Gradle performance meter collector
GitOrigin-RevId: 36f1a9ebe4f043907c935111ee8adb3f6db6913b
This commit is contained in:
committed by
intellij-monorepo-bot
parent
b2b800e977
commit
609391377b
@@ -2,8 +2,6 @@
|
||||
package org.jetbrains.plugins.gradle.execution
|
||||
|
||||
import com.intellij.execution.executors.DefaultRunExecutor
|
||||
import com.intellij.internal.statistic.FUCollectorTestCase
|
||||
import com.intellij.internal.statistic.eventLog.ExternalEventLogSettings
|
||||
import com.intellij.openapi.application.ApplicationManager
|
||||
import com.intellij.openapi.externalSystem.action.ExternalSystemActionUtil
|
||||
import com.intellij.openapi.externalSystem.model.execution.ExternalSystemTaskExecutionSettings
|
||||
@@ -16,66 +14,17 @@ import com.intellij.openapi.externalSystem.task.TaskCallback
|
||||
import com.intellij.openapi.externalSystem.util.ExternalSystemApiUtil
|
||||
import com.intellij.openapi.externalSystem.util.ExternalSystemUtil
|
||||
import com.intellij.openapi.externalSystem.util.ExternalSystemUtil.runTask
|
||||
import com.intellij.openapi.util.registry.Registry
|
||||
import com.intellij.testFramework.ExtensionTestUtil
|
||||
import com.jetbrains.fus.reporting.model.lion3.LogEvent
|
||||
import junit.framework.AssertionFailedError
|
||||
import junit.framework.TestCase
|
||||
import org.assertj.core.api.Assertions.assertThat
|
||||
import org.jetbrains.plugins.gradle.importing.GradleImportingTestCase
|
||||
import org.jetbrains.plugins.gradle.importing.TestGradleBuildScriptBuilder
|
||||
import org.jetbrains.plugins.gradle.statistics.GradleExecutionPerformanceCollector
|
||||
import org.jetbrains.plugins.gradle.util.GradleConstants
|
||||
import org.junit.Test
|
||||
import org.junit.runners.Parameterized
|
||||
import java.util.concurrent.CompletableFuture
|
||||
import java.util.concurrent.TimeUnit
|
||||
import java.util.function.Consumer
|
||||
|
||||
class GradleTasksExecutionTest : GradleImportingTestCase() {
|
||||
|
||||
@Test
|
||||
fun `test fus contains only well known task metrics`() {
|
||||
Registry.get("gradle.import.performance.statistics").setValue("true", testRootDisposable)
|
||||
ExtensionTestUtil.maskExtensions(ExternalEventLogSettings.EP_NAME, listOf(object : ExternalEventLogSettings {
|
||||
override fun forceLoggingAlwaysEnabled(): Boolean = true
|
||||
override fun getExtraLogUploadHeaders(): Map<String, String> = emptyMap()
|
||||
}), testRootDisposable)
|
||||
val buildScript = createBuildScriptBuilder()
|
||||
.withTask("userDefinedTask") {
|
||||
code("dependsOn { subprojects.collect { \"\$it.name:clean\"} }\n dependsOn { subprojects.collect { \"\$it.name:build\"} }")
|
||||
}
|
||||
.allprojects { withJavaPlugin() }
|
||||
.project(":projectA", Consumer<TestGradleBuildScriptBuilder> { it: TestGradleBuildScriptBuilder -> it.withIdeaPlugin() })
|
||||
.project(":projectB", Consumer<TestGradleBuildScriptBuilder> { it: TestGradleBuildScriptBuilder ->
|
||||
it.withTask("customTaskFromProjectB")
|
||||
it.withPostfix { code("tasks.findByName('build').dependsOn('customTaskFromProjectB')") }
|
||||
})
|
||||
.project(":projectC", Consumer<TestGradleBuildScriptBuilder> { it: TestGradleBuildScriptBuilder ->
|
||||
it.withTask("customTaskFromProjectC")
|
||||
it.withPostfix { code("tasks.findByName('clean').dependsOn('customTaskFromProjectC')") }
|
||||
})
|
||||
.generate()
|
||||
createProjectSubFile("build.gradle", buildScript)
|
||||
createSettingsFile("include 'projectA', 'projectB', 'projectC'")
|
||||
val events: List<LogEvent> = collectGradlePerformanceEvents {
|
||||
assertThat(runTaskAndGetErrorOutput(projectPath, "userDefinedTask")).isEmpty()
|
||||
}
|
||||
val executedGradleTasks = events.filter { it.event.id == "task.executed" }.map { it.event.data["name"].toString() }
|
||||
val expectedGradleTasks = listOf("compileJava", "processResources", "classes", "jar", "assemble", "compileTestJava",
|
||||
"processTestResources", "testClasses", "test", "check", "build", "clean", "other")
|
||||
assertCollection(executedGradleTasks, expectedGradleTasks)
|
||||
val executedStages = events.groupingBy { it.event.id }.eachCount()
|
||||
val expectedStages = setOf("execution.completed", "build.loaded", "settings.evaluated", "project.loaded",
|
||||
"task.graph.calculated", "container.callback.executed", "task.executed", "task.graph.executed")
|
||||
assertCollection(executedStages.keys, expectedStages)
|
||||
executedStages.forEach { (name, count) ->
|
||||
if (name != "task.executed") {
|
||||
TestCase.assertEquals(1, count)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `run task with specified build file test`() {
|
||||
createProjectSubFile("build.gradle", """
|
||||
@@ -222,10 +171,6 @@ tasks.register("hello-module") {
|
||||
}
|
||||
}
|
||||
|
||||
private fun collectGradlePerformanceEvents(runnable: () -> Unit): List<LogEvent> = FUCollectorTestCase
|
||||
.collectLogEvents(getTestRootDisposable(), runnable)
|
||||
.filter { it.group.id == GradleExecutionPerformanceCollector.GROUP.id }
|
||||
|
||||
companion object {
|
||||
/**
|
||||
* It's sufficient to run the test against one gradle version
|
||||
|
||||
@@ -60,7 +60,6 @@
|
||||
<issueChecker implementation="org.jetbrains.plugins.gradle.issue.GradleDaemonStartupIssueChecker"/>
|
||||
<issueChecker implementation="org.jetbrains.plugins.gradle.issue.GradleBuildCancelledIssueChecker"/>
|
||||
<issueChecker implementation="org.jetbrains.plugins.gradle.issue.GradleOutOfMemoryIssueChecker"/>
|
||||
<operationHelperExtension implementation="org.jetbrains.plugins.gradle.service.execution.GradleExecutionMeasuringExtension"/>
|
||||
|
||||
<autoReloadSettingsCollector
|
||||
implementation="org.jetbrains.plugins.gradle.service.project.GradleAutoImportAware$GradlePropertiesCollector"/>
|
||||
@@ -163,9 +162,6 @@
|
||||
<statistics.projectUsagesCollector implementation="org.jetbrains.plugins.gradle.statistics.GradleSettingsCollector"/>
|
||||
<statistics.counterUsagesCollector implementationClass="org.jetbrains.plugins.gradle.statistics.GradleModelBuilderMessageCollector"/>
|
||||
<statistics.counterUsagesCollector implementationClass="org.jetbrains.plugins.gradle.statistics.GradleActionsUsagesCollector"/>
|
||||
<statistics.counterUsagesCollector implementationClass="org.jetbrains.plugins.gradle.statistics.GradleExecutionPerformanceCollector"/>
|
||||
<statistics.validation.customValidationRule implementation="org.jetbrains.plugins.gradle.statistics.GradleExecutionPerformanceCollector$TaskNameValidator"/>
|
||||
<statistics.validation.customValidationRule implementation="org.jetbrains.plugins.gradle.statistics.GradleExecutionPerformanceCollector$TaskPluginValidator"/>
|
||||
|
||||
<externalSystem.runConfigurationEx implementation="org.jetbrains.plugins.gradle.service.execution.GradleRunConfigurationExtension"/>
|
||||
<externalSystem.runConfigurationImporter
|
||||
@@ -202,8 +198,6 @@
|
||||
description="Enable experimental support of version catalogs based on after-sync gradle models"/>
|
||||
<registryKey key="gradle.download.sources" defaultValue="false"
|
||||
description="Download sources of project dependencies during import"/>
|
||||
<registryKey key="gradle.import.performance.statistics" defaultValue="false"
|
||||
description="Collect performance-related statistics of Gradle import"/>
|
||||
<commandLineInspectionProjectConfigurator implementation="org.jetbrains.plugins.gradle.GradleCommandLineProjectConfigurator"/>
|
||||
<warmupConfigurator implementation="org.jetbrains.plugins.gradle.GradleWarmupConfigurator"/>
|
||||
<notificationGroup id="Gradle Notification Group" displayType="STICKY_BALLOON" bundle="messages.GradleBundle" key="notification.group.gradle"/>
|
||||
|
||||
-55
@@ -1,55 +0,0 @@
|
||||
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package org.jetbrains.plugins.gradle.service.execution
|
||||
|
||||
import com.intellij.internal.statistic.utils.StatisticsUploadAssistant
|
||||
import com.intellij.openapi.externalSystem.model.task.ExternalSystemTaskId
|
||||
import com.intellij.openapi.util.registry.Registry
|
||||
import org.gradle.tooling.LongRunningOperation
|
||||
import org.gradle.tooling.events.OperationType
|
||||
import org.gradle.tooling.events.ProgressListener
|
||||
import org.gradle.tooling.model.build.BuildEnvironment
|
||||
import org.gradle.util.GradleVersion
|
||||
import org.jetbrains.annotations.ApiStatus
|
||||
import org.jetbrains.plugins.gradle.frameworkSupport.buildscript.isGradleOlderThan
|
||||
import org.jetbrains.plugins.gradle.service.execution.statistics.GradleExecutionStageFusHandler
|
||||
import org.jetbrains.plugins.gradle.service.project.GradleOperationHelperExtension
|
||||
import org.jetbrains.plugins.gradle.service.project.ProjectResolverContext
|
||||
import org.jetbrains.plugins.gradle.settings.GradleExecutionSettings
|
||||
import java.lang.ref.WeakReference
|
||||
|
||||
@Deprecated(message = "Obsolete")
|
||||
@ApiStatus.ScheduledForRemoval
|
||||
class GradleExecutionMeasuringExtension : GradleOperationHelperExtension {
|
||||
|
||||
override fun prepareForExecution(id: ExternalSystemTaskId,
|
||||
operation: LongRunningOperation,
|
||||
gradleExecutionSettings: GradleExecutionSettings,
|
||||
buildEnvironment: BuildEnvironment?) {
|
||||
if (isSkipExecution(buildEnvironment)) {
|
||||
return
|
||||
}
|
||||
val handler = GradleExecutionStageFusHandler(id.id, WeakReference(id.findProject()))
|
||||
val router = TaskExecutionAggregatedRouter(handler)
|
||||
operation.addProgressListener(
|
||||
ProgressListener {
|
||||
router.route(it)
|
||||
},
|
||||
OperationType.TASK, OperationType.GENERIC
|
||||
)
|
||||
}
|
||||
|
||||
override fun prepareForSync(operation: LongRunningOperation, resolverCtx: ProjectResolverContext) = Unit
|
||||
|
||||
private fun BuildEnvironment.gradleVersion(): GradleVersion? = gradle?.gradleVersion?.let { GradleVersion.version(it) }
|
||||
|
||||
private fun isSkipExecution(buildEnvironment: BuildEnvironment?): Boolean {
|
||||
if (!StatisticsUploadAssistant.isCollectAllowedOrForced()) {
|
||||
return true
|
||||
}
|
||||
if (!Registry.`is`("gradle.import.performance.statistics", false)) {
|
||||
return true
|
||||
}
|
||||
val gradleVersion = buildEnvironment?.gradleVersion()
|
||||
return gradleVersion == null || gradleVersion.isGradleOlderThan("5.1")
|
||||
}
|
||||
}
|
||||
-158
@@ -1,158 +0,0 @@
|
||||
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package org.jetbrains.plugins.gradle.service.execution
|
||||
|
||||
import org.gradle.tooling.events.ProgressEvent
|
||||
import org.gradle.tooling.events.internal.DefaultFinishEvent
|
||||
import org.gradle.tooling.events.lifecycle.internal.DefaultBuildPhaseFinishEvent
|
||||
import org.gradle.tooling.events.task.internal.DefaultTaskFailureResult
|
||||
import org.gradle.tooling.events.task.internal.DefaultTaskFinishEvent
|
||||
import org.jetbrains.annotations.ApiStatus
|
||||
import org.jetbrains.plugins.gradle.service.execution.statistics.AggregatedTaskReport
|
||||
import org.jetbrains.plugins.gradle.service.execution.statistics.GradleExecutionStageHandler
|
||||
import org.jetbrains.plugins.gradle.service.execution.statistics.TaskGraphExecutionReport
|
||||
import org.jetbrains.plugins.gradle.util.GradleTaskClassifier
|
||||
|
||||
@Deprecated(message = "Obsolete")
|
||||
@ApiStatus.ScheduledForRemoval
|
||||
class TaskExecutionAggregatedRouter(val handler: GradleExecutionStageHandler) {
|
||||
|
||||
private companion object {
|
||||
private const val USER_DEFINED_TASK_NAME_REPLACEMENT = "other"
|
||||
private const val UNKNOWN = "unknown"
|
||||
|
||||
private const val ORG_JETBRAINS_PACKAGE = "org.jetbrains."
|
||||
private const val ORG_GRADLE_PACKAGE = "org.gradle."
|
||||
|
||||
private const val UP_TO_DATE = "UP-TO-DATE"
|
||||
private const val FROM_CACHE = "FROM-CACHE"
|
||||
private const val LOAD_BUILD_DESCRIPTOR_NAME = "Load build"
|
||||
private const val LOAD_PROJECTS_DESCRIPTOR_NAME = "Load projects"
|
||||
private const val RUN_BUILD_DESCRIPTOR_NAME = "Run build"
|
||||
private const val EVALUATE_SETTINGS_DESCRIPTOR_NAME = "Evaluate settings"
|
||||
private const val CONTAINER_CALLBACK_ACTION_DESCRIPTOR_NAME = "Execute container callback action"
|
||||
private const val CALCULATE_TASK_GRAPH_DESCRIPTOR_NAME = "Calculate task graph"
|
||||
private const val RUN_TASKS = "Run tasks"
|
||||
}
|
||||
|
||||
private val inflightTasks: MutableMap<String, AggregatedTaskReport> = HashMap()
|
||||
private var inflightContainerCallbackDuration: Long = 0
|
||||
private var inflightTaskGraphDuration: Long = 0
|
||||
private var taskGraphEventEmitted: Boolean = false
|
||||
private var flushed: Boolean = false
|
||||
|
||||
fun route(event: ProgressEvent) {
|
||||
if (flushed) {
|
||||
return
|
||||
}
|
||||
if (event is DefaultFinishEvent<*, *>) {
|
||||
onFinishEvent(event)
|
||||
}
|
||||
}
|
||||
|
||||
fun flush() {
|
||||
if (flushed) {
|
||||
return
|
||||
}
|
||||
handler.onContainerCallbackExecuted(inflightContainerCallbackDuration)
|
||||
handler.onTaskGraphCalculated(inflightTaskGraphDuration)
|
||||
inflightTasks.values.forEach(handler::onTaskExecuted)
|
||||
inflightTasks.clear()
|
||||
flushed = true
|
||||
}
|
||||
|
||||
private fun onFinishEvent(event: DefaultFinishEvent<*, *>) {
|
||||
val stage: String = event.getStage()
|
||||
val duration = event.duration()
|
||||
when (stage) {
|
||||
LOAD_BUILD_DESCRIPTOR_NAME -> handler.onGradleBuildLoaded(duration)
|
||||
RUN_BUILD_DESCRIPTOR_NAME -> {
|
||||
handler.onGradleExecutionCompleted(duration)
|
||||
flush()
|
||||
}
|
||||
EVALUATE_SETTINGS_DESCRIPTOR_NAME -> handler.onGradleSettingsEvaluated(duration)
|
||||
LOAD_PROJECTS_DESCRIPTOR_NAME -> handler.onGradleProjectLoaded(duration)
|
||||
CONTAINER_CALLBACK_ACTION_DESCRIPTOR_NAME -> inflightContainerCallbackDuration += duration
|
||||
CALCULATE_TASK_GRAPH_DESCRIPTOR_NAME -> inflightTaskGraphDuration += duration
|
||||
}
|
||||
if (stage == RUN_TASKS) {
|
||||
onTaskGraphFinish(event)
|
||||
}
|
||||
if (event is DefaultTaskFinishEvent) {
|
||||
addTaskFinish(event)
|
||||
}
|
||||
}
|
||||
|
||||
private fun onTaskGraphFinish(event: DefaultFinishEvent<*, *>) {
|
||||
if (taskGraphEventEmitted) {
|
||||
return
|
||||
}
|
||||
var fromCache = 0
|
||||
var upToDate = 0
|
||||
var executed = 0
|
||||
inflightTasks.values.forEach {
|
||||
fromCache += it.fromCacheCount
|
||||
upToDate += it.upToDateCount
|
||||
executed += it.count
|
||||
}
|
||||
val count = if (event is DefaultBuildPhaseFinishEvent) {
|
||||
event.descriptor.buildItemsCount
|
||||
}
|
||||
else {
|
||||
executed
|
||||
}
|
||||
val report = TaskGraphExecutionReport(
|
||||
durationMs = event.duration(),
|
||||
count = count,
|
||||
fromCacheCount = fromCache,
|
||||
upToDateCount = upToDate,
|
||||
executed = executed
|
||||
)
|
||||
handler.onTaskGraphExecuted(report)
|
||||
taskGraphEventEmitted = true
|
||||
}
|
||||
|
||||
private fun addTaskFinish(event: DefaultTaskFinishEvent) {
|
||||
val source = event.getTaskSource()
|
||||
var taskName: String = USER_DEFINED_TASK_NAME_REPLACEMENT
|
||||
var taskSource: String = UNKNOWN
|
||||
if (isKnownTaskSource(source)) {
|
||||
taskName = event.getClassifiedTaskName()
|
||||
taskSource = source
|
||||
}
|
||||
val accumulatorKey = taskName + taskSource
|
||||
inflightTasks
|
||||
.computeIfAbsent(accumulatorKey) { AggregatedTaskReport(name = taskName, plugin = taskSource) }
|
||||
.apply {
|
||||
val eventName = event.displayName
|
||||
val taskDuration = event.duration()
|
||||
if (eventName.contains(UP_TO_DATE)) {
|
||||
upToDateCount += 1
|
||||
upToDateDuration += taskDuration
|
||||
}
|
||||
if (eventName.contains(FROM_CACHE)) {
|
||||
fromCacheCount += 1
|
||||
fromCacheDuration += taskDuration
|
||||
}
|
||||
if (event.result is DefaultTaskFailureResult) {
|
||||
failed += 1
|
||||
}
|
||||
sumDurationMs += taskDuration
|
||||
count += 1
|
||||
}
|
||||
}
|
||||
|
||||
private fun DefaultTaskFinishEvent.getClassifiedTaskName(): String = descriptor.taskPath
|
||||
.split(":")
|
||||
.last()
|
||||
.trim()
|
||||
.let { GradleTaskClassifier.classifyTaskName(it) }
|
||||
|
||||
private fun DefaultTaskFinishEvent.getTaskSource(): String = descriptor.originPlugin?.displayName ?: UNKNOWN
|
||||
|
||||
private fun ProgressEvent.getStage() = descriptor.name
|
||||
|
||||
private fun DefaultFinishEvent<*, *>.duration(): Long = result.run { endTime - startTime }
|
||||
|
||||
private fun isKnownTaskSource(name: String?): Boolean = name != null && (name.startsWith(ORG_GRADLE_PACKAGE) || name.startsWith(
|
||||
ORG_JETBRAINS_PACKAGE))
|
||||
}
|
||||
-18
@@ -1,18 +0,0 @@
|
||||
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package org.jetbrains.plugins.gradle.service.execution.statistics
|
||||
|
||||
import org.jetbrains.annotations.ApiStatus
|
||||
|
||||
@Deprecated(message = "Obsolete")
|
||||
@ApiStatus.ScheduledForRemoval
|
||||
data class AggregatedTaskReport(
|
||||
val name: String,
|
||||
val plugin: String,
|
||||
var count: Int = 0,
|
||||
var sumDurationMs: Long = 0,
|
||||
var upToDateCount: Int = 0,
|
||||
var fromCacheCount: Int = 0,
|
||||
var upToDateDuration: Long = 0,
|
||||
var fromCacheDuration: Long = 0,
|
||||
var failed: Int = 0
|
||||
)
|
||||
-61
@@ -1,61 +0,0 @@
|
||||
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package org.jetbrains.plugins.gradle.service.execution.statistics
|
||||
|
||||
import com.intellij.internal.statistic.eventLog.events.EventFields
|
||||
import com.intellij.internal.statistic.eventLog.events.EventId2
|
||||
import com.intellij.internal.statistic.eventLog.events.VarargEventId
|
||||
import com.intellij.openapi.project.Project
|
||||
import org.jetbrains.annotations.ApiStatus
|
||||
import org.jetbrains.plugins.gradle.statistics.GradleExecutionPerformanceCollector
|
||||
import java.lang.ref.WeakReference
|
||||
|
||||
@Deprecated(message = "Obsolete")
|
||||
@ApiStatus.ScheduledForRemoval
|
||||
class GradleExecutionStageFusHandler(val taskId: Long, val project: WeakReference<Project>) : GradleExecutionStageHandler {
|
||||
|
||||
override fun onGradleExecutionCompleted(duration: Long) = duration.emit(GradleExecutionPerformanceCollector.EXECUTION_COMPLETED)
|
||||
|
||||
override fun onGradleBuildLoaded(duration: Long) = duration.emit(GradleExecutionPerformanceCollector.BUILD_LOADED)
|
||||
|
||||
override fun onGradleSettingsEvaluated(duration: Long) = duration.emit(GradleExecutionPerformanceCollector.SETTINGS_EVALUATED)
|
||||
|
||||
override fun onGradleProjectLoaded(duration: Long) = duration.emit(GradleExecutionPerformanceCollector.PROJECT_LOADED)
|
||||
|
||||
override fun onContainerCallbackExecuted(duration: Long) = duration.emit(GradleExecutionPerformanceCollector.CONTAINER_CALLBACK_EXECUTED)
|
||||
|
||||
override fun onTaskGraphCalculated(duration: Long) = duration.emit(GradleExecutionPerformanceCollector.TASK_GRAPH_CALCULATED)
|
||||
|
||||
override fun onTaskGraphExecuted(report: TaskGraphExecutionReport) = report.emit(GradleExecutionPerformanceCollector.TASK_GRAPH_EXECUTED)
|
||||
|
||||
override fun onTaskExecuted(task: AggregatedTaskReport) = task.emit(GradleExecutionPerformanceCollector.TASK_EXECUTED)
|
||||
|
||||
private fun Long.emit(target: EventId2<Long, Long>) = target.log(project.get(), taskId, this)
|
||||
|
||||
private fun TaskGraphExecutionReport.emit(target: VarargEventId) {
|
||||
val events = listOf(
|
||||
GradleExecutionPerformanceCollector.EXTERNAL_TASK_ID.with(taskId),
|
||||
EventFields.DurationMs.with(durationMs),
|
||||
EventFields.Count.with(count),
|
||||
GradleExecutionPerformanceCollector.UP_TO_DATE_COUNT.with(upToDateCount),
|
||||
GradleExecutionPerformanceCollector.FROM_CACHE_COUNT.with(fromCacheCount),
|
||||
GradleExecutionPerformanceCollector.EXECUTED.with(executed),
|
||||
)
|
||||
target.log(project.get(), events)
|
||||
}
|
||||
|
||||
private fun AggregatedTaskReport.emit(target: VarargEventId) {
|
||||
val events = listOf(
|
||||
GradleExecutionPerformanceCollector.EXTERNAL_TASK_ID.with(taskId),
|
||||
GradleExecutionPerformanceCollector.SUM_DURATION_MS.with(sumDurationMs),
|
||||
GradleExecutionPerformanceCollector.NAME.with(name),
|
||||
GradleExecutionPerformanceCollector.GRADLE_PLUGIN.with(plugin),
|
||||
GradleExecutionPerformanceCollector.UP_TO_DATE_COUNT.with(upToDateCount),
|
||||
GradleExecutionPerformanceCollector.FROM_CACHE_COUNT.with(fromCacheCount),
|
||||
EventFields.Count.with(count),
|
||||
GradleExecutionPerformanceCollector.UP_TO_DATE_DURATION_MS.with(upToDateDuration),
|
||||
GradleExecutionPerformanceCollector.FROM_CACHE_DURATION_MS.with(fromCacheDuration),
|
||||
GradleExecutionPerformanceCollector.FAILED_COUNT.with(failed),
|
||||
)
|
||||
target.log(project.get(), events)
|
||||
}
|
||||
}
|
||||
-26
@@ -1,26 +0,0 @@
|
||||
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package org.jetbrains.plugins.gradle.service.execution.statistics
|
||||
|
||||
import org.jetbrains.annotations.ApiStatus
|
||||
|
||||
@Deprecated(message = "Obsolete")
|
||||
@ApiStatus.ScheduledForRemoval
|
||||
interface GradleExecutionStageHandler {
|
||||
|
||||
fun onGradleExecutionCompleted(duration: Long)
|
||||
|
||||
fun onGradleBuildLoaded(duration: Long)
|
||||
|
||||
fun onGradleSettingsEvaluated(duration: Long)
|
||||
|
||||
fun onGradleProjectLoaded(duration: Long)
|
||||
|
||||
fun onContainerCallbackExecuted(duration: Long)
|
||||
|
||||
fun onTaskGraphCalculated(duration: Long)
|
||||
|
||||
fun onTaskExecuted(task: AggregatedTaskReport)
|
||||
|
||||
fun onTaskGraphExecuted(report: TaskGraphExecutionReport)
|
||||
|
||||
}
|
||||
-14
@@ -1,14 +0,0 @@
|
||||
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package org.jetbrains.plugins.gradle.service.execution.statistics
|
||||
|
||||
import org.jetbrains.annotations.ApiStatus
|
||||
|
||||
@Deprecated(message = "Obsolete")
|
||||
@ApiStatus.ScheduledForRemoval
|
||||
data class TaskGraphExecutionReport(
|
||||
val durationMs: Long,
|
||||
val executed: Int,
|
||||
val count: Int,
|
||||
val upToDateCount: Int,
|
||||
val fromCacheCount: Int
|
||||
)
|
||||
-73
@@ -1,73 +0,0 @@
|
||||
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package org.jetbrains.plugins.gradle.statistics
|
||||
|
||||
import com.intellij.internal.statistic.eventLog.EventLogGroup
|
||||
import com.intellij.internal.statistic.eventLog.events.*
|
||||
import com.intellij.internal.statistic.eventLog.validator.ValidationResultType
|
||||
import com.intellij.internal.statistic.eventLog.validator.rules.EventContext
|
||||
import com.intellij.internal.statistic.eventLog.validator.rules.impl.CustomValidationRule
|
||||
import com.intellij.internal.statistic.service.fus.collectors.CounterUsagesCollector
|
||||
import org.jetbrains.annotations.ApiStatus
|
||||
import org.jetbrains.plugins.gradle.util.GradleTaskClassifier
|
||||
|
||||
@Deprecated(message = "Obsolete")
|
||||
@ApiStatus.ScheduledForRemoval
|
||||
class GradleExecutionPerformanceCollector : CounterUsagesCollector() {
|
||||
|
||||
override fun getGroup(): EventLogGroup = GROUP
|
||||
|
||||
companion object {
|
||||
val EXTERNAL_TASK_ID: EventField<Long> = EventFields.Long("task_id")
|
||||
val GRADLE_PLUGIN: StringEventField = EventFields.StringValidatedByCustomRule<TaskPluginValidator>("gradle_plugin")
|
||||
val NAME: StringEventField = EventFields.StringValidatedByCustomRule<TaskNameValidator>("name")
|
||||
val UP_TO_DATE_COUNT: EventField<Int> = EventFields.Int("up_to_date_count")
|
||||
val FROM_CACHE_COUNT: EventField<Int> = EventFields.Int("from_cache_count")
|
||||
val EXECUTED: EventField<Int> = EventFields.Int("executed")
|
||||
val SUM_DURATION_MS: EventField<Long> = EventFields.Long("sum_duration_ms")
|
||||
val UP_TO_DATE_DURATION_MS: EventField<Long> = EventFields.Long("sum_duration_up_to_date_ms")
|
||||
val FROM_CACHE_DURATION_MS: EventField<Long> = EventFields.Long("sum_duration_from_cache_ms")
|
||||
val FAILED_COUNT: EventField<Int> = EventFields.Int("failed_count")
|
||||
|
||||
val GROUP: EventLogGroup = EventLogGroup("build.gradle.performance", 1)
|
||||
val EXECUTION_COMPLETED: EventId2<Long, Long> = registerEvent("execution.completed")
|
||||
val BUILD_LOADED: EventId2<Long, Long> = registerEvent("build.loaded")
|
||||
val SETTINGS_EVALUATED: EventId2<Long, Long> = registerEvent("settings.evaluated")
|
||||
val PROJECT_LOADED: EventId2<Long, Long> = registerEvent("project.loaded")
|
||||
val TASK_GRAPH_CALCULATED: EventId2<Long, Long> = registerEvent("task.graph.calculated")
|
||||
val CONTAINER_CALLBACK_EXECUTED: EventId2<Long, Long> = registerEvent("container.callback.executed")
|
||||
val TASK_EXECUTED: VarargEventId = GROUP.registerVarargEvent(
|
||||
"task.executed", EXTERNAL_TASK_ID, SUM_DURATION_MS, NAME, GRADLE_PLUGIN, UP_TO_DATE_COUNT, FROM_CACHE_COUNT, EventFields.Count,
|
||||
UP_TO_DATE_DURATION_MS, FROM_CACHE_DURATION_MS, FAILED_COUNT
|
||||
)
|
||||
val TASK_GRAPH_EXECUTED: VarargEventId = GROUP.registerVarargEvent(
|
||||
"task.graph.executed", EXTERNAL_TASK_ID, EventFields.DurationMs, EventFields.Count, UP_TO_DATE_COUNT, FROM_CACHE_COUNT, EXECUTED
|
||||
)
|
||||
|
||||
@JvmStatic
|
||||
private fun registerEvent(name: String): EventId2<Long, Long> = GROUP.registerEvent(name, EXTERNAL_TASK_ID, EventFields.DurationMs)
|
||||
}
|
||||
|
||||
internal class TaskNameValidator : CustomValidationRule() {
|
||||
|
||||
override fun getRuleId(): String = "build_gradle_performance_task_name"
|
||||
|
||||
override fun doValidate(data: String, context: EventContext): ValidationResultType {
|
||||
if (GradleTaskClassifier.isClassified(data)) {
|
||||
return ValidationResultType.ACCEPTED
|
||||
}
|
||||
return ValidationResultType.THIRD_PARTY
|
||||
}
|
||||
}
|
||||
|
||||
internal class TaskPluginValidator : CustomValidationRule() {
|
||||
|
||||
override fun getRuleId(): String = "build_gradle_performance_task_plugin"
|
||||
|
||||
override fun doValidate(data: String, context: EventContext): ValidationResultType {
|
||||
if (data.startsWith("org.jetbrains.") || data.startsWith("org.gradle.")) {
|
||||
return ValidationResultType.ACCEPTED
|
||||
}
|
||||
return ValidationResultType.THIRD_PARTY
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,68 +0,0 @@
|
||||
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package org.jetbrains.plugins.gradle.util
|
||||
|
||||
import org.jetbrains.annotations.ApiStatus
|
||||
import java.util.*
|
||||
import java.util.regex.Pattern
|
||||
|
||||
@Deprecated(message = "Obsolete")
|
||||
@ApiStatus.ScheduledForRemoval
|
||||
object GradleTaskClassifier {
|
||||
|
||||
private const val OTHER: String = "other"
|
||||
private val PATTERN: Pattern = Pattern.compile("(?=\\p{Upper})")
|
||||
private val KNOWN_TASK_WORDS: Set<String> = setOf(
|
||||
"assemble",
|
||||
"build",
|
||||
"check",
|
||||
"checkstyle",
|
||||
"classes",
|
||||
"clean",
|
||||
"compile",
|
||||
"groovy",
|
||||
"init",
|
||||
"lint",
|
||||
"pmd",
|
||||
"jar",
|
||||
"java",
|
||||
"javadoc",
|
||||
"jmh",
|
||||
"kotlin",
|
||||
"process",
|
||||
"resources",
|
||||
"scala",
|
||||
"test",
|
||||
"war",
|
||||
"wrapper"
|
||||
)
|
||||
|
||||
@JvmStatic
|
||||
fun classifyTaskName(name: String?): String {
|
||||
if (name == null) {
|
||||
return OTHER
|
||||
}
|
||||
val particles = name.split(PATTERN)
|
||||
.map { it.lowercase() }
|
||||
.filter { KNOWN_TASK_WORDS.contains(it) }
|
||||
if (particles.isEmpty()) {
|
||||
return OTHER
|
||||
}
|
||||
return particles.joinToConventionalNaming()
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun isClassified(name: String): Boolean = OTHER.equals(name, ignoreCase = true)
|
||||
|| name.split(PATTERN).all { KNOWN_TASK_WORDS.contains(it.lowercase()) }
|
||||
|
||||
private fun List<String>.joinToConventionalNaming(): String {
|
||||
if (size == 1) {
|
||||
return first()
|
||||
}
|
||||
val result = StringBuilder(first())
|
||||
for (index in 1 until size) {
|
||||
val word = get(index).replaceFirstChar { it.titlecase(Locale.getDefault()) }
|
||||
result.append(word)
|
||||
}
|
||||
return result.toString()
|
||||
}
|
||||
}
|
||||
-56
@@ -1,56 +0,0 @@
|
||||
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package org.jetbrains.plugins.gradle.service.execution
|
||||
|
||||
import com.intellij.internal.statistic.FUCollectorTestCase
|
||||
import com.intellij.internal.statistic.eventLog.ExternalEventLogSettings
|
||||
import com.intellij.openapi.util.registry.Registry
|
||||
import com.intellij.testFramework.ExtensionTestUtil
|
||||
import com.jetbrains.fus.reporting.model.lion3.LogEvent
|
||||
import org.assertj.core.api.Assertions.assertThat
|
||||
import org.jetbrains.plugins.gradle.importing.GradleImportingTestCase
|
||||
import org.jetbrains.plugins.gradle.importing.TestGradleBuildScriptBuilder
|
||||
import org.jetbrains.plugins.gradle.statistics.GradleExecutionPerformanceCollector
|
||||
import org.jetbrains.plugins.gradle.tooling.annotation.TargetVersions
|
||||
import org.junit.Test
|
||||
|
||||
class GradleImportPerformanceFusTest : GradleImportingTestCase() {
|
||||
|
||||
@Test
|
||||
@TargetVersions("5.1+")
|
||||
fun `test gradle import performance events not collected by default`() {
|
||||
toggleFus(true)
|
||||
assertThat(collectGradleImportPerformanceEvents()).isEmpty()
|
||||
}
|
||||
|
||||
@Test
|
||||
@TargetVersions("5.1+")
|
||||
fun `test gradle import performance events not collected if fus disabled by registry key`() {
|
||||
toggleFus(true)
|
||||
toggleRegistry(false)
|
||||
assertThat(collectGradleImportPerformanceEvents()).isEmpty()
|
||||
}
|
||||
|
||||
@Test
|
||||
@TargetVersions("5.1+")
|
||||
fun `test gradle import performance events not collected if fus is off`() {
|
||||
toggleFus(false)
|
||||
toggleRegistry(true)
|
||||
assertThat(collectGradleImportPerformanceEvents()).isEmpty()
|
||||
}
|
||||
|
||||
private fun toggleRegistry(enabled: Boolean) = Registry.get("gradle.import.performance.statistics").setValue(enabled, testRootDisposable)
|
||||
|
||||
private fun toggleFus(enabled: Boolean) {
|
||||
val settings = object : ExternalEventLogSettings {
|
||||
override fun forceLoggingAlwaysEnabled(): Boolean = enabled
|
||||
override fun getExtraLogUploadHeaders(): Map<String, String> = emptyMap()
|
||||
}
|
||||
ExtensionTestUtil.maskExtensions(ExternalEventLogSettings.EP_NAME, listOf(settings), testRootDisposable)
|
||||
}
|
||||
|
||||
private fun collectGradleImportPerformanceEvents(): List<LogEvent> = FUCollectorTestCase
|
||||
.collectLogEvents(getTestRootDisposable()) {
|
||||
importProject(script { it: TestGradleBuildScriptBuilder -> it.withJavaPlugin() })
|
||||
}
|
||||
.filter { it.group.id == GradleExecutionPerformanceCollector.GROUP.id }
|
||||
}
|
||||
-47
@@ -1,47 +0,0 @@
|
||||
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package org.jetbrains.plugins.gradle.util
|
||||
|
||||
import org.junit.jupiter.api.Assertions.*
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.junit.jupiter.params.ParameterizedTest
|
||||
import org.junit.jupiter.params.provider.Arguments
|
||||
import org.junit.jupiter.params.provider.MethodSource
|
||||
|
||||
class GradleTaskClassifierTest {
|
||||
|
||||
@MethodSource("argumentToValidateTaskClassification")
|
||||
@ParameterizedTest
|
||||
fun testClassifyTask(expected: String, toClassify: String?) {
|
||||
assertEquals(expected, GradleTaskClassifier.classifyTaskName(toClassify))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testClassifiedVerifier() {
|
||||
assertTrue(GradleTaskClassifier.isClassified("other"))
|
||||
assertTrue(GradleTaskClassifier.isClassified("test"))
|
||||
assertTrue(GradleTaskClassifier.isClassified("lint"))
|
||||
assertTrue(GradleTaskClassifier.isClassified("compileJava"))
|
||||
assertTrue(GradleTaskClassifier.isClassified("compileTestKotlin"))
|
||||
assertFalse(GradleTaskClassifier.isClassified("compileIntegrationTestKotlin"))
|
||||
assertFalse(GradleTaskClassifier.isClassified("Abcd"))
|
||||
assertFalse(GradleTaskClassifier.isClassified("publishAbcToRepository"))
|
||||
assertFalse(GradleTaskClassifier.isClassified("publish"))
|
||||
}
|
||||
|
||||
|
||||
private companion object {
|
||||
@JvmStatic
|
||||
fun argumentToValidateTaskClassification(): List<Arguments> = listOf(
|
||||
Arguments.of("compileKotlin", "compileKotlinLibrarySources"),
|
||||
Arguments.of("compileJava", "compileUnknownJava"),
|
||||
Arguments.of("lint", "lint"),
|
||||
Arguments.of("lintTest", "lintUnitTestSources"),
|
||||
Arguments.of("compileTestKotlin", "compileJava11TestKotlin"),
|
||||
Arguments.of("other", "publish"),
|
||||
Arguments.of("compileTestKotlin", "compileMyIntegrationTestKotlin"),
|
||||
Arguments.of("other", null),
|
||||
Arguments.of("other", ""),
|
||||
Arguments.of("compileJava", "userCompileJava"),
|
||||
)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user