Split Gradle and JPS metrics

#KT-58026 In progress
This commit is contained in:
Nataliya.Valtman
2023-07-19 12:57:06 +02:00
committed by Space Team
parent 524df83265
commit ed2dd4b2ae
55 changed files with 918 additions and 546 deletions
@@ -21,11 +21,8 @@ import org.jetbrains.kotlin.build.GeneratedFile
import org.jetbrains.kotlin.build.report.BuildReporter
import org.jetbrains.kotlin.build.report.debug
import org.jetbrains.kotlin.build.report.info
import org.jetbrains.kotlin.build.report.metrics.BuildAttribute
import org.jetbrains.kotlin.build.report.metrics.*
import org.jetbrains.kotlin.build.report.metrics.BuildAttribute.*
import org.jetbrains.kotlin.build.report.metrics.BuildPerformanceMetric
import org.jetbrains.kotlin.build.report.metrics.BuildTime
import org.jetbrains.kotlin.build.report.metrics.measure
import org.jetbrains.kotlin.build.report.warn
import org.jetbrains.kotlin.cli.common.*
import org.jetbrains.kotlin.cli.common.arguments.CommonCompilerArguments
@@ -48,6 +45,7 @@ import org.jetbrains.kotlin.util.removeSuffixIfPresent
import org.jetbrains.kotlin.utils.toMetadataVersion
import java.io.File
import java.nio.file.Files
import java.util.*
abstract class IncrementalCompilerRunner<
Args : CommonCompilerArguments,
@@ -55,7 +53,7 @@ abstract class IncrementalCompilerRunner<
>(
private val workingDir: File,
cacheDirName: String,
protected val reporter: BuildReporter,
protected val reporter: BuildReporter<GradleBuildTime, GradleBuildPerformanceMetric>,
protected val buildHistoryFile: File,
/**
@@ -111,7 +109,7 @@ abstract class IncrementalCompilerRunner<
// otherwise we track source files changes ourselves.
changedFiles: ChangedFiles?,
projectDir: File? = null
): ExitCode = reporter.measure(BuildTime.INCREMENTAL_COMPILATION_DAEMON) {
): ExitCode = reporter.measure(GradleBuildTime.INCREMENTAL_COMPILATION_DAEMON) {
return when (val result = tryCompileIncrementally(allSourceFiles, changedFiles, args, projectDir, messageCollector)) {
is ICResult.Completed -> {
reporter.debug { "Incremental compilation completed" }
@@ -202,7 +200,7 @@ abstract class IncrementalCompilerRunner<
// Step 2: Compute files to recompile
val compilationMode = try {
reporter.measure(BuildTime.IC_CALCULATE_INITIAL_DIRTY_SET) {
reporter.measure(GradleBuildTime.IC_CALCULATE_INITIAL_DIRTY_SET) {
calculateSourcesToCompile(caches, knownChangedFiles, args, messageCollector, classpathAbiSnapshot ?: emptyMap())
}
} catch (e: Throwable) {
@@ -259,7 +257,7 @@ abstract class IncrementalCompilerRunner<
trackChangedFiles: Boolean, // Whether we need to track changes to the source files or the build system already handles it
messageCollector: MessageCollector,
): ExitCode {
reporter.measure(BuildTime.CLEAR_OUTPUT_ON_REBUILD) {
reporter.measure(GradleBuildTime.CLEAR_OUTPUT_ON_REBUILD) {
val mainOutputDirs = setOf(destinationDir(args), workingDir)
val outputDirsToClean = outputDirs?.also {
check(it.containsAll(mainOutputDirs)) { "outputDirs is missing classesDir and workingDir: $it" }
@@ -284,7 +282,7 @@ abstract class IncrementalCompilerRunner<
private class AbiSnapshotData(val snapshot: AbiSnapshot, val classpathAbiSnapshot: Map<String, AbiSnapshot>)
private fun getClasspathAbiSnapshot(args: Args): Map<String, AbiSnapshot> {
return reporter.measure(BuildTime.SET_UP_ABI_SNAPSHOTS) {
return reporter.measure(GradleBuildTime.SET_UP_ABI_SNAPSHOTS) {
setupJarDependencies(args, reporter)
}
}
@@ -330,7 +328,7 @@ abstract class IncrementalCompilerRunner<
classpathAbiSnapshots: Map<String, AbiSnapshot>
): CompilationMode
protected open fun setupJarDependencies(args: Args, reporter: BuildReporter): Map<String, AbiSnapshot> = emptyMap()
protected open fun setupJarDependencies(args: Args, reporter: BuildReporter<GradleBuildTime, GradleBuildPerformanceMetric>): Map<String, AbiSnapshot> = emptyMap()
protected fun initDirtyFiles(dirtyFiles: DirtyFilesContainer, changedFiles: ChangedFiles.Known) {
dirtyFiles.add(changedFiles.modified, "was modified since last time")
@@ -415,12 +413,12 @@ abstract class IncrementalCompilerRunner<
}
private fun collectMetrics() {
reporter.measure(BuildTime.CALCULATE_OUTPUT_SIZE) {
reporter.measure(GradleBuildTime.CALCULATE_OUTPUT_SIZE) {
reporter.addMetric(
BuildPerformanceMetric.SNAPSHOT_SIZE,
GradleBuildPerformanceMetric.SNAPSHOT_SIZE,
buildHistoryFile.length() + lastBuildInfoFile.length() + abiSnapshotFile.length()
)
reporter.addMetric(BuildPerformanceMetric.CACHE_DIRECTORY_SIZE, cacheDirectory.walk().sumOf { it.length() })
reporter.addMetric(GradleBuildPerformanceMetric.CACHE_DIRECTORY_SIZE, cacheDirectory.walk().sumOf { it.length() })
}
}
@@ -472,7 +470,7 @@ abstract class IncrementalCompilerRunner<
val bufferingMessageCollector = BufferingMessageCollector()
val messageCollectorAdapter = MessageCollectorToOutputItemsCollectorAdapter(bufferingMessageCollector, transactionOutputsRegistrar)
val compiledSources = reporter.measure(BuildTime.COMPILATION_ROUND) {
val compiledSources = reporter.measure(GradleBuildTime.COMPILATION_ROUND) {
runCompiler(
sourcesToCompile, args, caches, services, messageCollectorAdapter,
allKotlinSources, compilationMode is CompilationMode.Incremental
@@ -509,7 +507,7 @@ abstract class IncrementalCompilerRunner<
transaction.deleteFile(dirtySourcesSinceLastTimeFile.toPath())
val changesCollector = ChangesCollector()
reporter.measure(BuildTime.IC_UPDATE_CACHES) {
reporter.measure(GradleBuildTime.IC_UPDATE_CACHES) {
caches.platformCache.updateComplementaryFiles(dirtySources, expectActualTracker)
caches.inputsCache.registerOutputForSourceFiles(generatedFiles)
caches.lookupCache.update(lookupTracker, sourcesToCompile, removedKotlinSources)
@@ -557,7 +555,7 @@ abstract class IncrementalCompilerRunner<
}
if (exitCode == ExitCode.OK) {
reporter.measure(BuildTime.STORE_BUILD_INFO) {
reporter.measure(GradleBuildTime.STORE_BUILD_INFO) {
BuildInfo.write(icContext, currentBuildInfo, lastBuildInfoFile)
//write abi snapshot
@@ -610,7 +608,7 @@ abstract class IncrementalCompilerRunner<
compilationMode: CompilationMode,
currentBuildInfo: BuildInfo,
dirtyData: DirtyData,
) = reporter.measure(BuildTime.IC_WRITE_HISTORY_FILE) {
) = reporter.measure(GradleBuildTime.IC_WRITE_HISTORY_FILE) {
val prevDiffs = BuildDiffsStorage.readFromFile(buildHistoryFile, reporter)?.buildDiffs ?: emptyList()
val newDiff = if (compilationMode is CompilationMode.Incremental) {
BuildDifference(currentBuildInfo.startTS, true, dirtyData)
@@ -636,22 +634,22 @@ abstract class IncrementalCompilerRunner<
protected fun reportPerformanceData(defaultPerformanceManager: CommonCompilerPerformanceManager) {
defaultPerformanceManager.getMeasurementResults().forEach {
when (it) {
is CompilerInitializationMeasurement -> reporter.addTimeMetricMs(BuildTime.COMPILER_INITIALIZATION, it.milliseconds)
is CompilerInitializationMeasurement -> reporter.addTimeMetricMs(GradleBuildTime.COMPILER_INITIALIZATION, it.milliseconds)
is CodeAnalysisMeasurement -> {
reporter.addTimeMetricMs(BuildTime.CODE_ANALYSIS, it.milliseconds)
reporter.addTimeMetricMs(GradleBuildTime.CODE_ANALYSIS, it.milliseconds)
it.lines?.apply {
reporter.addMetric(BuildPerformanceMetric.ANALYZED_LINES_NUMBER, this.toLong())
reporter.addMetric(GradleBuildPerformanceMetric.ANALYZED_LINES_NUMBER, this.toLong())
if (it.milliseconds > 0) {
reporter.addMetric(BuildPerformanceMetric.ANALYSIS_LPS, this * 1000 / it.milliseconds)
reporter.addMetric(GradleBuildPerformanceMetric.ANALYSIS_LPS, this * 1000 / it.milliseconds)
}
}
}
is CodeGenerationMeasurement -> {
reporter.addTimeMetricMs(BuildTime.CODE_GENERATION, it.milliseconds)
reporter.addTimeMetricMs(GradleBuildTime.CODE_GENERATION, it.milliseconds)
it.lines?.apply {
reporter.addMetric(BuildPerformanceMetric.CODE_GENERATED_LINES_NUMBER, this.toLong())
reporter.addMetric(GradleBuildPerformanceMetric.CODE_GENERATED_LINES_NUMBER, this.toLong())
if (it.milliseconds > 0) {
reporter.addMetric(BuildPerformanceMetric.CODE_GENERATION_LPS, this * 1000 / it.milliseconds)
reporter.addMetric(GradleBuildPerformanceMetric.CODE_GENERATION_LPS, this * 1000 / it.milliseconds)
}
}
}
@@ -15,6 +15,8 @@ import org.jetbrains.kotlin.backend.common.extensions.IrGenerationExtension
import org.jetbrains.kotlin.backend.jvm.JvmIrDeserializerImpl
import org.jetbrains.kotlin.build.DEFAULT_KOTLIN_SOURCE_FILES_EXTENSIONS
import org.jetbrains.kotlin.build.report.BuildReporter
import org.jetbrains.kotlin.build.report.metrics.GradleBuildPerformanceMetric
import org.jetbrains.kotlin.build.report.metrics.GradleBuildTime
import org.jetbrains.kotlin.cli.common.*
import org.jetbrains.kotlin.cli.common.arguments.K2JVMCompilerArguments
import org.jetbrains.kotlin.cli.common.config.addKotlinSourceRoot
@@ -61,7 +63,7 @@ import java.io.File
open class IncrementalFirJvmCompilerRunner(
workingDir: File,
reporter: BuildReporter,
reporter: BuildReporter<GradleBuildTime, GradleBuildPerformanceMetric>,
buildHistoryFile: File,
outputDirs: Collection<File>?,
modulesApiHistory: ModulesApiHistory,
@@ -23,6 +23,8 @@ import org.jetbrains.kotlin.build.report.ICReporter
import org.jetbrains.kotlin.build.report.info
import org.jetbrains.kotlin.build.report.metrics.BuildAttribute
import org.jetbrains.kotlin.build.report.metrics.DoNothingBuildMetricsReporter
import org.jetbrains.kotlin.build.report.metrics.GradleBuildPerformanceMetric
import org.jetbrains.kotlin.build.report.metrics.GradleBuildTime
import org.jetbrains.kotlin.cli.common.ExitCode
import org.jetbrains.kotlin.cli.common.arguments.CommonCompilerArguments
import org.jetbrains.kotlin.cli.common.arguments.K2JSCompilerArguments
@@ -83,7 +85,7 @@ inline fun <R> withJsIC(args: CommonCompilerArguments, enabled: Boolean = true,
class IncrementalJsCompilerRunner(
workingDir: File,
reporter: BuildReporter,
reporter: BuildReporter<GradleBuildTime, GradleBuildPerformanceMetric>,
buildHistoryFile: File,
private val modulesApiHistory: ModulesApiHistory,
private val scopeExpansion: CompileScopeExpansionMode = CompileScopeExpansionMode.NEVER,
@@ -61,7 +61,7 @@ import java.io.File
open class IncrementalJvmCompilerRunner(
workingDir: File,
reporter: BuildReporter,
reporter: BuildReporter<GradleBuildTime, GradleBuildPerformanceMetric>,
private val usePreciseJavaTracking: Boolean,
buildHistoryFile: File,
outputDirs: Collection<File>?,
@@ -142,7 +142,7 @@ open class IncrementalJvmCompilerRunner(
//TODO can't use the same way as for build-history files because abi-snapshot for all dependencies should be stored into last-build
// and not only changed one
// (but possibly we dont need to read it all and may be it is possible to update only those who was changed)
override fun setupJarDependencies(args: K2JVMCompilerArguments, reporter: BuildReporter): Map<String, AbiSnapshot> {
override fun setupJarDependencies(args: K2JVMCompilerArguments, reporter: BuildReporter<GradleBuildTime, GradleBuildPerformanceMetric>): Map<String, AbiSnapshot> {
//fill abiSnapshots
val abiSnapshots = HashMap<String, AbiSnapshot>()
args.classpathAsList
@@ -186,8 +186,8 @@ open class IncrementalJvmCompilerRunner(
val changedAndImpactedSymbols = when (classpathChanges) {
// Note: classpathChanges is deserialized, so they are no longer singleton objects and need to be compared using `is` (not `==`)
is NoChanges -> ChangesEither.Known(emptySet(), emptySet())
is ToBeComputedByIncrementalCompiler -> reporter.measure(BuildTime.COMPUTE_CLASSPATH_CHANGES) {
reporter.addMetric(BuildPerformanceMetric.COMPUTE_CLASSPATH_CHANGES_EXECUTION_COUNT, 1)
is ToBeComputedByIncrementalCompiler -> reporter.measure(GradleBuildTime.COMPUTE_CLASSPATH_CHANGES) {
reporter.addMetric(GradleBuildPerformanceMetric.COMPUTE_CLASSPATH_CHANGES_EXECUTION_COUNT, 1)
val storeCurrentClasspathSnapshotForReuse =
{ currentClasspathSnapshotArg: List<AccessibleClassSnapshot>,
shrunkCurrentClasspathAgainstPreviousLookupsArg: List<AccessibleClassSnapshot> ->
@@ -206,7 +206,7 @@ open class IncrementalJvmCompilerRunner(
}
is NotAvailableDueToMissingClasspathSnapshot -> ChangesEither.Unknown(BuildAttribute.CLASSPATH_SNAPSHOT_NOT_FOUND)
is NotAvailableForNonIncrementalRun -> ChangesEither.Unknown(BuildAttribute.UNKNOWN_CHANGES_IN_GRADLE_INPUTS)
is ClasspathSnapshotDisabled -> reporter.measure(BuildTime.IC_ANALYZE_CHANGES_IN_DEPENDENCIES) {
is ClasspathSnapshotDisabled -> reporter.measure(GradleBuildTime.IC_ANALYZE_CHANGES_IN_DEPENDENCIES) {
if (!withAbiSnapshot && !buildHistoryFile.isFile) {
// If the previous build was a Gradle cache hit, the build history file must have been deleted as it is marked as
// @LocalState in the Gradle task. Therefore, this compilation will need to run non-incrementally.
@@ -242,7 +242,7 @@ open class IncrementalJvmCompilerRunner(
dirtyFiles.addByDirtySymbols(changedAndImpactedSymbols.lookupSymbols)
dirtyFiles.addByDirtyClasses(changedAndImpactedSymbols.fqNames)
reporter.measure(BuildTime.IC_ANALYZE_CHANGES_IN_JAVA_SOURCES) {
reporter.measure(GradleBuildTime.IC_ANALYZE_CHANGES_IN_JAVA_SOURCES) {
if (!usePreciseJavaTracking) {
val javaFilesChanges = javaFilesProcessor!!.process(changedFiles)
val affectedJavaSymbols = when (javaFilesChanges) {
@@ -256,10 +256,10 @@ open class IncrementalJvmCompilerRunner(
}
}
val androidLayoutChanges = reporter.measure(BuildTime.IC_ANALYZE_CHANGES_IN_ANDROID_LAYOUTS) {
val androidLayoutChanges = reporter.measure(GradleBuildTime.IC_ANALYZE_CHANGES_IN_ANDROID_LAYOUTS) {
processLookupSymbolsForAndroidLayouts(changedFiles)
}
val removedClassesChanges = reporter.measure(BuildTime.IC_DETECT_REMOVED_CLASSES) {
val removedClassesChanges = reporter.measure(GradleBuildTime.IC_DETECT_REMOVED_CLASSES) {
getRemovedClassesChanges(caches, changedFiles)
}
@@ -468,7 +468,7 @@ open class IncrementalJvmCompilerRunner(
// No need to shrink and save classpath snapshot if exitCode != ExitCode.OK as the task will fail anyway
if (classpathChanges is ClasspathChanges.ClasspathSnapshotEnabled && exitCode == ExitCode.OK) {
reporter.measure(BuildTime.SHRINK_AND_SAVE_CURRENT_CLASSPATH_SNAPSHOT_AFTER_COMPILATION) {
reporter.measure(GradleBuildTime.SHRINK_AND_SAVE_CURRENT_CLASSPATH_SNAPSHOT_AFTER_COMPILATION) {
shrinkAndSaveClasspathSnapshot(
compilationWasIncremental = compilationMode is CompilationMode.Incremental, classpathChanges, caches.lookupCache,
currentClasspathSnapshot, shrunkCurrentClasspathAgainstPreviousLookups, ClasspathSnapshotBuildReporter(reporter)
@@ -7,9 +7,7 @@ package org.jetbrains.kotlin.incremental
import org.jetbrains.kotlin.build.report.BuildReporter
import org.jetbrains.kotlin.build.report.info
import org.jetbrains.kotlin.build.report.metrics.BuildTime
import org.jetbrains.kotlin.build.report.metrics.BuildAttribute
import org.jetbrains.kotlin.build.report.metrics.measure
import org.jetbrains.kotlin.build.report.metrics.*
import org.jetbrains.kotlin.incremental.multiproject.ModulesApiHistory
import org.jetbrains.kotlin.incremental.util.Either
import org.jetbrains.kotlin.name.FqName
@@ -20,7 +18,7 @@ internal fun getClasspathChanges(
changedFiles: ChangedFiles.Known,
lastBuildInfo: BuildInfo,
modulesApiHistory: ModulesApiHistory,
reporter: BuildReporter,
reporter: BuildReporter<GradleBuildTime, GradleBuildPerformanceMetric>,
abiSnapshots: Map<String, AbiSnapshot>,
withSnapshot: Boolean,
caches: IncrementalCacheCommon,
@@ -64,7 +62,7 @@ internal fun getClasspathChanges(
}
return ChangesEither.Known(symbols, fqNames)
}
return reporter.measure(BuildTime.IC_ANALYZE_JAR_FILES) {
return reporter.measure(GradleBuildTime.IC_ANALYZE_JAR_FILES) {
analyzeJarFiles()
}
} else {
@@ -74,7 +72,7 @@ internal fun getClasspathChanges(
val fqNames = HashSet<FqName>()
val historyFilesEither =
reporter.measure(BuildTime.IC_FIND_HISTORY_FILES) {
reporter.measure(GradleBuildTime.IC_FIND_HISTORY_FILES) {
modulesApiHistory.historyFilesForChangedFiles(modifiedClasspath)
}
@@ -116,7 +114,7 @@ internal fun getClasspathChanges(
return ChangesEither.Known(symbols, fqNames)
}
return reporter.measure(BuildTime.IC_ANALYZE_HISTORY_FILES) {
return reporter.measure(GradleBuildTime.IC_ANALYZE_HISTORY_FILES) {
analyzeHistoryFiles()
}
}
@@ -8,9 +8,7 @@ package org.jetbrains.kotlin.incremental.classpathDiff
import com.intellij.openapi.util.io.FileUtil
import org.jetbrains.kotlin.build.report.DoNothingICReporter
import org.jetbrains.kotlin.build.report.debug
import org.jetbrains.kotlin.build.report.metrics.BuildMetricsReporter
import org.jetbrains.kotlin.build.report.metrics.BuildTime
import org.jetbrains.kotlin.build.report.metrics.measure
import org.jetbrains.kotlin.build.report.metrics.*
import org.jetbrains.kotlin.incremental.*
import org.jetbrains.kotlin.incremental.classpathDiff.BreadthFirstSearch.findReachableNodes
import org.jetbrains.kotlin.incremental.classpathDiff.ClasspathSnapshotShrinker.shrinkClasspath
@@ -39,19 +37,19 @@ object ClasspathChangesComputer {
storeCurrentClasspathSnapshotForReuse: (currentClasspathSnapshot: List<AccessibleClassSnapshot>, shrunkCurrentClasspathAgainstPreviousLookups: List<AccessibleClassSnapshot>) -> Unit,
reporter: ClasspathSnapshotBuildReporter
): ProgramSymbolSet {
val currentClasspathSnapshot = reporter.measure(BuildTime.LOAD_CURRENT_CLASSPATH_SNAPSHOT) {
val currentClasspathSnapshot = reporter.measure(GradleBuildTime.LOAD_CURRENT_CLASSPATH_SNAPSHOT) {
val classpathSnapshot =
CachedClasspathSnapshotSerializer.load(classpathSnapshotFiles.currentClasspathEntrySnapshotFiles, reporter)
reporter.measure(BuildTime.REMOVE_DUPLICATE_CLASSES) {
reporter.measure(GradleBuildTime.REMOVE_DUPLICATE_CLASSES) {
classpathSnapshot.removeDuplicateAndInaccessibleClasses()
}
}
val shrunkCurrentClasspathAgainstPreviousLookups = reporter.measure(BuildTime.SHRINK_CURRENT_CLASSPATH_SNAPSHOT) {
val shrunkCurrentClasspathAgainstPreviousLookups = reporter.measure(GradleBuildTime.SHRINK_CURRENT_CLASSPATH_SNAPSHOT) {
shrinkClasspath(
currentClasspathSnapshot, lookupStorage,
ClasspathSnapshotShrinker.MetricsReporter(
reporter,
BuildTime.GET_LOOKUP_SYMBOLS, BuildTime.FIND_REFERENCED_CLASSES, BuildTime.FIND_TRANSITIVELY_REFERENCED_CLASSES
GradleBuildTime.GET_LOOKUP_SYMBOLS, GradleBuildTime.FIND_REFERENCED_CLASSES, GradleBuildTime.FIND_TRANSITIVELY_REFERENCED_CLASSES
)
)
}
@@ -61,14 +59,14 @@ object ClasspathChangesComputer {
}
storeCurrentClasspathSnapshotForReuse(currentClasspathSnapshot, shrunkCurrentClasspathAgainstPreviousLookups)
val shrunkPreviousClasspathSnapshot = reporter.measure(BuildTime.LOAD_SHRUNK_PREVIOUS_CLASSPATH_SNAPSHOT) {
val shrunkPreviousClasspathSnapshot = reporter.measure(GradleBuildTime.LOAD_SHRUNK_PREVIOUS_CLASSPATH_SNAPSHOT) {
ListExternalizer(AccessibleClassSnapshotExternalizer).loadFromFile(classpathSnapshotFiles.shrunkPreviousClasspathSnapshotFile)
}
reporter.debug {
"Loaded shrunk previous classpath snapshot for diffing, found ${shrunkPreviousClasspathSnapshot.size} classes"
}
return reporter.measure(BuildTime.COMPUTE_CHANGED_AND_IMPACTED_SET) {
return reporter.measure(GradleBuildTime.COMPUTE_CHANGED_AND_IMPACTED_SET) {
computeChangedAndImpactedSet(shrunkCurrentClasspathAgainstPreviousLookups, shrunkPreviousClasspathSnapshot, reporter)
}
}
@@ -100,7 +98,7 @@ object ClasspathChangesComputer {
} else null
}
val changedSet = reporter.measure(BuildTime.COMPUTE_CLASS_CHANGES) {
val changedSet = reporter.measure(GradleBuildTime.COMPUTE_CLASS_CHANGES) {
computeClassChanges(changedCurrentClasses, changedPreviousClasses, reporter)
}
reporter.reportVerboseWithLimit { "Changed set = ${changedSet.toDebugString()}" }
@@ -109,7 +107,7 @@ object ClasspathChangesComputer {
return changedSet
}
val changedAndImpactedSet = reporter.measure(BuildTime.COMPUTE_IMPACTED_SET) {
val changedAndImpactedSet = reporter.measure(GradleBuildTime.COMPUTE_IMPACTED_SET) {
// Note that changes may contain added symbols (they can also impact recompilation -- see examples in JavaClassChangesComputer).
// So ideally, the result should be:
// computeImpactedSymbols(changes = changesOnPreviousClasspath, allClasses = classesOnPreviousClasspath) +
@@ -144,13 +142,13 @@ object ClasspathChangesComputer {
private fun computeClassChanges(
currentClassSnapshots: List<AccessibleClassSnapshot>,
previousClassSnapshots: List<AccessibleClassSnapshot>,
metrics: BuildMetricsReporter
metrics: BuildMetricsReporter<GradleBuildTime, GradleBuildPerformanceMetric>
): ProgramSymbolSet {
val (currentKotlinClassSnapshots, currentJavaClassSnapshots) = currentClassSnapshots.partition { it is KotlinClassSnapshot }
val (previousKotlinClassSnapshots, previousJavaClassSnapshots) = previousClassSnapshots.partition { it is KotlinClassSnapshot }
@Suppress("UNCHECKED_CAST")
val kotlinClassChanges = metrics.measure(BuildTime.COMPUTE_KOTLIN_CLASS_CHANGES) {
val kotlinClassChanges = metrics.measure(GradleBuildTime.COMPUTE_KOTLIN_CLASS_CHANGES) {
computeKotlinClassChanges(
currentKotlinClassSnapshots as List<KotlinClassSnapshot>,
previousKotlinClassSnapshots as List<KotlinClassSnapshot>
@@ -158,7 +156,7 @@ object ClasspathChangesComputer {
}
@Suppress("UNCHECKED_CAST")
val javaClassChanges = metrics.measure(BuildTime.COMPUTE_JAVA_CLASS_CHANGES) {
val javaClassChanges = metrics.measure(GradleBuildTime.COMPUTE_JAVA_CLASS_CHANGES) {
JavaClassChangesComputer.compute(
currentJavaClassSnapshots as List<JavaClassSnapshot>,
previousJavaClassSnapshots as List<JavaClassSnapshot>
@@ -9,9 +9,11 @@ import org.jetbrains.kotlin.build.report.BuildReporter
import org.jetbrains.kotlin.build.report.ICReporter
import org.jetbrains.kotlin.build.report.debug
import org.jetbrains.kotlin.build.report.metrics.BuildMetricsReporter
import org.jetbrains.kotlin.build.report.metrics.GradleBuildPerformanceMetric
import org.jetbrains.kotlin.build.report.metrics.GradleBuildTime
class ClasspathSnapshotBuildReporter(private val buildReporter: BuildReporter) :
ICReporter by buildReporter, BuildMetricsReporter by buildReporter {
class ClasspathSnapshotBuildReporter(private val buildReporter: BuildReporter<GradleBuildTime, GradleBuildPerformanceMetric>) :
ICReporter by buildReporter, BuildMetricsReporter<GradleBuildTime, GradleBuildPerformanceMetric> by buildReporter {
override fun report(message: () -> String, severity: ICReporter.ReportSeverity) {
buildReporter.report({ "[ClasspathSnapshot] ${message()}" }, severity)
@@ -8,6 +8,7 @@ package org.jetbrains.kotlin.incremental.classpathDiff
import com.intellij.util.containers.Interner
import com.intellij.util.io.DataExternalizer
import org.jetbrains.kotlin.build.report.metrics.BuildPerformanceMetric
import org.jetbrains.kotlin.build.report.metrics.GradleBuildPerformanceMetric
import org.jetbrains.kotlin.incremental.KotlinClassInfo
import org.jetbrains.kotlin.incremental.storage.*
import org.jetbrains.kotlin.load.kotlin.header.KotlinClassHeader
@@ -45,9 +46,9 @@ object CachedClasspathSnapshotSerializer {
})
cache.evictEntries()
reporter.addMetric(BuildPerformanceMetric.LOAD_CLASSPATH_SNAPSHOT_EXECUTION_COUNT, 1)
reporter.addMetric(BuildPerformanceMetric.LOAD_CLASSPATH_ENTRY_SNAPSHOT_CACHE_HITS, classpathEntrySnapshotFiles.size - cacheMisses)
reporter.addMetric(BuildPerformanceMetric.LOAD_CLASSPATH_ENTRY_SNAPSHOT_CACHE_MISSES, cacheMisses)
reporter.addMetric(GradleBuildPerformanceMetric.LOAD_CLASSPATH_SNAPSHOT_EXECUTION_COUNT, 1)
reporter.addMetric(GradleBuildPerformanceMetric.LOAD_CLASSPATH_ENTRY_SNAPSHOT_CACHE_HITS, classpathEntrySnapshotFiles.size - cacheMisses)
reporter.addMetric(GradleBuildPerformanceMetric.LOAD_CLASSPATH_ENTRY_SNAPSHOT_CACHE_MISSES, cacheMisses)
return classpathSnapshot
}
@@ -6,10 +6,7 @@
package org.jetbrains.kotlin.incremental.classpathDiff
import org.jetbrains.kotlin.build.report.debug
import org.jetbrains.kotlin.build.report.metrics.BuildMetricsReporter
import org.jetbrains.kotlin.build.report.metrics.BuildPerformanceMetric
import org.jetbrains.kotlin.build.report.metrics.BuildTime
import org.jetbrains.kotlin.build.report.metrics.measure
import org.jetbrains.kotlin.build.report.metrics.*
import org.jetbrains.kotlin.incremental.ClasspathChanges
import org.jetbrains.kotlin.incremental.ClasspathChanges.ClasspathSnapshotEnabled.IncrementalRun.NoChanges
import org.jetbrains.kotlin.incremental.ClasspathChanges.ClasspathSnapshotEnabled.IncrementalRun.ToBeComputedByIncrementalCompiler
@@ -117,10 +114,10 @@ object ClasspathSnapshotShrinker {
* record different [BuildTime]s (because the [BuildTime.parent]s are different).
*/
class MetricsReporter(
private val metrics: BuildMetricsReporter? = null,
private val getLookupSymbols: BuildTime? = null,
private val findReferencedClasses: BuildTime? = null,
private val findTransitivelyReferencedClasses: BuildTime? = null
private val metrics: BuildMetricsReporter<GradleBuildTime, GradleBuildPerformanceMetric>? = null,
private val getLookupSymbols: GradleBuildTime? = null,
private val findReferencedClasses: GradleBuildTime? = null,
private val findTransitivelyReferencedClasses: GradleBuildTime? = null
) {
fun <T> getLookupSymbols(fn: () -> T) = metrics?.measure(getLookupSymbols!!, fn) ?: fn()
fun <T> findReferencedClasses(fn: () -> T) = metrics?.measure(findReferencedClasses!!, fn) ?: fn()
@@ -246,9 +243,9 @@ internal fun shrinkAndSaveClasspathSnapshot(
// shrunkCurrentClasspathAgainst[*Current*]Lookups == shrunkCurrentClasspathAgainst[*Previous*]Lookups
shrinkMode.currentClasspathSnapshot to shrinkMode.shrunkCurrentClasspathAgainstPreviousLookups
}
is ShrinkMode.ChangedLookups -> reporter.measure(BuildTime.INCREMENTAL_SHRINK_CURRENT_CLASSPATH_SNAPSHOT) {
is ShrinkMode.ChangedLookups -> reporter.measure(GradleBuildTime.INCREMENTAL_SHRINK_CURRENT_CLASSPATH_SNAPSHOT) {
// There are changes in the lookups, so we will shrink incrementally.
val currentClasspath = reporter.measure(BuildTime.INCREMENTAL_LOAD_CURRENT_CLASSPATH_SNAPSHOT) {
val currentClasspath = reporter.measure(GradleBuildTime.INCREMENTAL_LOAD_CURRENT_CLASSPATH_SNAPSHOT) {
when (shrinkMode) {
is ShrinkMode.ChangedLookupsUnchangedClasspath ->
CachedClasspathSnapshotSerializer
@@ -258,7 +255,7 @@ internal fun shrinkAndSaveClasspathSnapshot(
}
}
val shrunkCurrentClasspathAgainstPrevLookups =
reporter.measure(BuildTime.INCREMENTAL_LOAD_SHRUNK_CURRENT_CLASSPATH_SNAPSHOT_AGAINST_PREVIOUS_LOOKUPS) {
reporter.measure(GradleBuildTime.INCREMENTAL_LOAD_SHRUNK_CURRENT_CLASSPATH_SNAPSHOT_AGAINST_PREVIOUS_LOOKUPS) {
when (shrinkMode) {
is ShrinkMode.ChangedLookupsUnchangedClasspath -> {
// There are no changes in the classpath, so
@@ -279,8 +276,8 @@ internal fun shrinkAndSaveClasspathSnapshot(
}
is ShrinkMode.NonIncremental -> {
// Changes in the lookups and classpath are not available, so we will shrink non-incrementally.
reporter.measure(BuildTime.NON_INCREMENTAL_SHRINK_CURRENT_CLASSPATH_SNAPSHOT) {
val currentClasspath = reporter.measure(BuildTime.NON_INCREMENTAL_LOAD_CURRENT_CLASSPATH_SNAPSHOT) {
reporter.measure(GradleBuildTime.NON_INCREMENTAL_SHRINK_CURRENT_CLASSPATH_SNAPSHOT) {
val currentClasspath = reporter.measure(GradleBuildTime.NON_INCREMENTAL_LOAD_CURRENT_CLASSPATH_SNAPSHOT) {
CachedClasspathSnapshotSerializer
.load(classpathChanges.classpathSnapshotFiles.currentClasspathEntrySnapshotFiles, reporter)
.removeDuplicateAndInaccessibleClasses()
@@ -298,7 +295,7 @@ internal fun shrinkAndSaveClasspathSnapshot(
"File '${classpathChanges.classpathSnapshotFiles.shrunkPreviousClasspathSnapshotFile.path}' does not exist"
}
} else {
reporter.measure(BuildTime.SAVE_SHRUNK_CURRENT_CLASSPATH_SNAPSHOT) {
reporter.measure(GradleBuildTime.SAVE_SHRUNK_CURRENT_CLASSPATH_SNAPSHOT) {
ListExternalizer(AccessibleClassSnapshotExternalizer).saveToFile(
classpathChanges.classpathSnapshotFiles.shrunkPreviousClasspathSnapshotFile,
shrunkCurrentClasspath!!
@@ -313,17 +310,17 @@ internal fun shrinkAndSaveClasspathSnapshot(
}
}
reporter.addMetric(BuildPerformanceMetric.SHRINK_AND_SAVE_CLASSPATH_SNAPSHOT_EXECUTION_COUNT, 1)
reporter.addMetric(GradleBuildPerformanceMetric.SHRINK_AND_SAVE_CLASSPATH_SNAPSHOT_EXECUTION_COUNT, 1)
reporter.addMetric(
BuildPerformanceMetric.CLASSPATH_ENTRY_COUNT,
GradleBuildPerformanceMetric.CLASSPATH_ENTRY_COUNT,
classpathChanges.classpathSnapshotFiles.currentClasspathEntrySnapshotFiles.size.toLong()
)
reporter.addMetric(
BuildPerformanceMetric.CLASSPATH_SNAPSHOT_SIZE,
GradleBuildPerformanceMetric.CLASSPATH_SNAPSHOT_SIZE,
classpathChanges.classpathSnapshotFiles.currentClasspathEntrySnapshotFiles.sumOf { it.length() }
)
reporter.addMetric(
BuildPerformanceMetric.SHRUNK_CLASSPATH_SNAPSHOT_SIZE,
GradleBuildPerformanceMetric.SHRUNK_CLASSPATH_SNAPSHOT_SIZE,
classpathChanges.classpathSnapshotFiles.shrunkPreviousClasspathSnapshotFile.length()
)
}
@@ -5,10 +5,7 @@
package org.jetbrains.kotlin.incremental.classpathDiff
import org.jetbrains.kotlin.build.report.metrics.BuildMetricsReporter
import org.jetbrains.kotlin.build.report.metrics.BuildTime
import org.jetbrains.kotlin.build.report.metrics.DoNothingBuildMetricsReporter
import org.jetbrains.kotlin.build.report.metrics.measure
import org.jetbrains.kotlin.build.report.metrics.*
import org.jetbrains.kotlin.incremental.ClassNodeSnapshotter.snapshotClass
import org.jetbrains.kotlin.incremental.ClassNodeSnapshotter.snapshotClassExcludingMembers
import org.jetbrains.kotlin.incremental.ClassNodeSnapshotter.snapshotField
@@ -44,10 +41,10 @@ object ClasspathEntrySnapshotter {
fun snapshot(
classpathEntry: File,
granularity: ClassSnapshotGranularity,
metrics: BuildMetricsReporter = DoNothingBuildMetricsReporter
metrics: BuildMetricsReporter<GradleBuildTime, GradleBuildPerformanceMetric> = DoNothingBuildMetricsReporter
): ClasspathEntrySnapshot {
DirectoryOrJarReader.create(classpathEntry).use { directoryOrJarReader ->
val classes = metrics.measure(BuildTime.LOAD_CLASSES_PATHS_ONLY) {
val classes = metrics.measure(GradleBuildTime.LOAD_CLASSES_PATHS_ONLY) {
directoryOrJarReader.getUnixStyleRelativePaths(DEFAULT_CLASS_FILTER).map { unixStyleRelativePath ->
ClassFileWithContentsProvider(
classFile = ClassFile(classpathEntry, unixStyleRelativePath),
@@ -55,7 +52,7 @@ object ClasspathEntrySnapshotter {
)
}
}
val snapshots = metrics.measure(BuildTime.SNAPSHOT_CLASSES) {
val snapshots = metrics.measure(GradleBuildTime.SNAPSHOT_CLASSES) {
ClassSnapshotter.snapshot(classes, granularity, metrics)
}
return ClasspathEntrySnapshot(
@@ -71,7 +68,7 @@ object ClassSnapshotter {
fun snapshot(
classes: List<ClassFileWithContentsProvider>,
granularity: ClassSnapshotGranularity,
metrics: BuildMetricsReporter = DoNothingBuildMetricsReporter
metrics: BuildMetricsReporter<GradleBuildTime, GradleBuildPerformanceMetric> = DoNothingBuildMetricsReporter
): List<ClassSnapshot> {
fun ClassFile.getClassName(): JvmClassName {
check(unixStyleRelativePath.endsWith(".class", ignoreCase = true))
@@ -83,7 +80,7 @@ object ClassSnapshotter {
fun snapshotClass(classFile: ClassFileWithContentsProvider): ClassSnapshot {
return classFileToSnapshotMap.getOrPut(classFile) {
val clazz = metrics.measure(BuildTime.LOAD_CONTENTS_OF_CLASSES) {
val clazz = metrics.measure(GradleBuildTime.LOAD_CONTENTS_OF_CLASSES) {
classFile.loadContents()
}
// Snapshot outer class first as we need this info to determine whether a class is transitively inaccessible (see below)
@@ -98,10 +95,10 @@ object ClassSnapshotter {
clazz.classInfo.isInaccessible() || outerClassSnapshot is InaccessibleClassSnapshot -> {
InaccessibleClassSnapshot
}
clazz.classInfo.isKotlinClass -> metrics.measure(BuildTime.SNAPSHOT_KOTLIN_CLASSES) {
clazz.classInfo.isKotlinClass -> metrics.measure(GradleBuildTime.SNAPSHOT_KOTLIN_CLASSES) {
snapshotKotlinClass(clazz, granularity)
}
else -> metrics.measure(BuildTime.SNAPSHOT_JAVA_CLASSES) {
else -> metrics.measure(GradleBuildTime.SNAPSHOT_JAVA_CLASSES) {
snapshotJavaClass(clazz, granularity)
}
}
@@ -7,11 +7,13 @@ package org.jetbrains.kotlin.incremental.utils
import org.jetbrains.kotlin.build.report.BuildReporter
import org.jetbrains.kotlin.build.report.metrics.BuildMetricsReporter
import org.jetbrains.kotlin.build.report.metrics.GradleBuildPerformanceMetric
import org.jetbrains.kotlin.build.report.metrics.GradleBuildTime
class TestBuildReporter(
val testICReporter: TestICReporter,
buildMetricsReporter: BuildMetricsReporter
) : BuildReporter(testICReporter, buildMetricsReporter) {
buildMetricsReporter: BuildMetricsReporter<GradleBuildTime, GradleBuildPerformanceMetric>
) : BuildReporter<GradleBuildTime, GradleBuildPerformanceMetric>(testICReporter, buildMetricsReporter) {
fun reportCachesDump(cachesDump: String) {
testICReporter.cachesDump = cachesDump
}