From 4eccbd75c384920930bad2f0136a5883e9ed506c Mon Sep 17 00:00:00 2001 From: "Alexander.Likhachev" Date: Mon, 30 Oct 2023 23:06:36 +0100 Subject: [PATCH] [IC] Measure IC size metrics after the caches are closed Before this fix, the size metrics were measured after the compilation is finished, but before the caches are closed. In many cases it might lead to incorrect measurements. After flipping the default value of the `keepIncrementalCompilationCachesInMemory` flag for Gradle builds, it started to cause always incorrect results. ^KT-63010 In Progress --- .../kotlin/incremental/IncrementalCompilerRunner.kt | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/compiler/incremental-compilation-impl/src/org/jetbrains/kotlin/incremental/IncrementalCompilerRunner.kt b/compiler/incremental-compilation-impl/src/org/jetbrains/kotlin/incremental/IncrementalCompilerRunner.kt index a913def51ac..6c20d236849 100644 --- a/compiler/incremental-compilation-impl/src/org/jetbrains/kotlin/incremental/IncrementalCompilerRunner.kt +++ b/compiler/incremental-compilation-impl/src/org/jetbrains/kotlin/incremental/IncrementalCompilerRunner.kt @@ -113,7 +113,7 @@ abstract class IncrementalCompilerRunner< changedFiles: ChangedFiles?, // When not-null, changes are provided by the build system; otherwise, the IC will need to track them fileLocations: FileLocations? = null, // Must be not-null if the build system needs to support build cache relocatability ): ExitCode = reporter.measure(GradleBuildTime.INCREMENTAL_COMPILATION_DAEMON) { - return when (val result = tryCompileIncrementally(allSourceFiles, changedFiles, args, fileLocations, messageCollector)) { + val result = when (val result = tryCompileIncrementally(allSourceFiles, changedFiles, args, fileLocations, messageCollector)) { is ICResult.Completed -> { reporter.debug { "Incremental compilation completed" } result.exitCode @@ -146,6 +146,8 @@ abstract class IncrementalCompilerRunner< ) } } + collectSizeMetrics() + return result } /** The result when attempting to compile incrementally ([tryCompileIncrementally]). */ @@ -411,11 +413,9 @@ abstract class IncrementalCompilerRunner< protected open fun performWorkBeforeCompilation(compilationMode: CompilationMode, args: Args) {} - protected open fun performWorkAfterCompilation(compilationMode: CompilationMode, exitCode: ExitCode, caches: CacheManager) { - collectMetrics() - } + protected open fun performWorkAfterCompilation(compilationMode: CompilationMode, exitCode: ExitCode, caches: CacheManager) {} - private fun collectMetrics() { + private fun collectSizeMetrics() { reporter.measure(GradleBuildTime.CALCULATE_OUTPUT_SIZE) { reporter.addMetric( GradleBuildPerformanceMetric.SNAPSHOT_SIZE,