Split Gradle and JPS metrics
#KT-58026 In progress
This commit is contained in:
committed by
Space Team
parent
524df83265
commit
ed2dd4b2ae
+4
-4
@@ -7,13 +7,13 @@ package org.jetbrains.kotlin.build.report.metrics
|
||||
|
||||
import java.io.Serializable
|
||||
|
||||
data class BuildMetrics(
|
||||
val buildTimes: BuildTimes = BuildTimes(),
|
||||
val buildPerformanceMetrics: BuildPerformanceMetrics = BuildPerformanceMetrics(),
|
||||
data class BuildMetrics<B : BuildTime, P : BuildPerformanceMetric>(
|
||||
val buildTimes: BuildTimes<B> = BuildTimes(),
|
||||
val buildPerformanceMetrics: BuildPerformanceMetrics<P> = BuildPerformanceMetrics(),
|
||||
val buildAttributes: BuildAttributes = BuildAttributes(),
|
||||
val gcMetrics: GcMetrics = GcMetrics()
|
||||
) : Serializable {
|
||||
fun addAll(other: BuildMetrics) {
|
||||
fun addAll(other: BuildMetrics<B, P>) {
|
||||
buildTimes.addAll(other.buildTimes)
|
||||
buildPerformanceMetrics.addAll(other.buildPerformanceMetrics)
|
||||
buildAttributes.addAll(other.buildAttributes)
|
||||
|
||||
+12
-12
@@ -7,14 +7,14 @@ package org.jetbrains.kotlin.build.report.metrics
|
||||
|
||||
import java.lang.management.ManagementFactory
|
||||
|
||||
interface BuildMetricsReporter {
|
||||
fun startMeasure(time: BuildTime)
|
||||
fun endMeasure(time: BuildTime)
|
||||
fun addTimeMetricNs(time: BuildTime, durationNs: Long)
|
||||
fun addTimeMetricMs(time: BuildTime, durationMs: Long) = addTimeMetricNs(time, durationMs * 1_000_000)
|
||||
interface BuildMetricsReporter<B : BuildTime, P : BuildPerformanceMetric> {
|
||||
fun startMeasure(time: B)
|
||||
fun endMeasure(time: B)
|
||||
fun addTimeMetricNs(time: B, durationNs: Long)
|
||||
fun addTimeMetricMs(time: B, durationMs: Long) = addTimeMetricNs(time, durationMs * 1_000_000)
|
||||
|
||||
fun addMetric(metric: BuildPerformanceMetric, value: Long)
|
||||
fun addTimeMetric(metric: BuildPerformanceMetric)
|
||||
fun addMetric(metric: P, value: Long)
|
||||
fun addTimeMetric(metric: P)
|
||||
|
||||
//Change metric to enum if possible
|
||||
fun addGcMetric(metric: String, value: GcMetric)
|
||||
@@ -23,11 +23,11 @@ interface BuildMetricsReporter {
|
||||
|
||||
fun addAttribute(attribute: BuildAttribute)
|
||||
|
||||
fun getMetrics(): BuildMetrics
|
||||
fun addMetrics(metrics: BuildMetrics)
|
||||
fun getMetrics(): BuildMetrics<B, P>
|
||||
fun addMetrics(metrics: BuildMetrics<B, P>)
|
||||
}
|
||||
|
||||
inline fun <T> BuildMetricsReporter.measure(time: BuildTime, fn: () -> T): T {
|
||||
inline fun <B : BuildTime, P : BuildPerformanceMetric, T> BuildMetricsReporter<B, P>.measure(time: B, fn: () -> T): T {
|
||||
startMeasure(time)
|
||||
try {
|
||||
return fn()
|
||||
@@ -37,13 +37,13 @@ inline fun <T> BuildMetricsReporter.measure(time: BuildTime, fn: () -> T): T {
|
||||
}
|
||||
|
||||
|
||||
fun BuildMetricsReporter.startMeasureGc() {
|
||||
fun <B : BuildTime, P : BuildPerformanceMetric> BuildMetricsReporter<B, P>.startMeasureGc() {
|
||||
ManagementFactory.getGarbageCollectorMXBeans().forEach {
|
||||
startGcMetric(it.name, GcMetric(it.collectionTime, it.collectionCount))
|
||||
}
|
||||
}
|
||||
|
||||
fun BuildMetricsReporter.endMeasureGc() {
|
||||
fun <B : BuildTime, P : BuildPerformanceMetric> BuildMetricsReporter<B, P>.endMeasureGc() {
|
||||
ManagementFactory.getGarbageCollectorMXBeans().forEach {
|
||||
endGcMetric(it.name, GcMetric(it.collectionTime, it.collectionCount))
|
||||
}
|
||||
|
||||
+14
-17
@@ -6,27 +6,24 @@
|
||||
package org.jetbrains.kotlin.build.report.metrics
|
||||
|
||||
import java.io.Serializable
|
||||
import java.util.*
|
||||
import kotlin.collections.HashMap
|
||||
|
||||
class BuildMetricsReporterImpl : BuildMetricsReporter, Serializable {
|
||||
private val myBuildTimeStartNs: EnumMap<BuildTime, Long> =
|
||||
EnumMap(
|
||||
BuildTime::class.java
|
||||
)
|
||||
open class BuildMetricsReporterImpl<B : BuildTime, P : BuildPerformanceMetric> : BuildMetricsReporter<B, P>, Serializable {
|
||||
private val myBuildTimeStartNs = HashMap<BuildTime, Long>()
|
||||
private val myGcPerformance = HashMap<String, GcMetric>()
|
||||
private val myBuildTimes = BuildTimes()
|
||||
private val myBuildMetrics = BuildPerformanceMetrics()
|
||||
private val myBuildTimes = BuildTimes<B>()
|
||||
private val myBuildMetrics = BuildPerformanceMetrics<P>()
|
||||
private val myBuildAttributes = BuildAttributes()
|
||||
private val myGcMetrics = GcMetrics()
|
||||
|
||||
override fun startMeasure(time: BuildTime) {
|
||||
override fun startMeasure(time: B) {
|
||||
if (time in myBuildTimeStartNs) {
|
||||
error("$time was restarted before it finished")
|
||||
}
|
||||
myBuildTimeStartNs[time] = System.nanoTime()
|
||||
}
|
||||
|
||||
override fun endMeasure(time: BuildTime) {
|
||||
override fun endMeasure(time: B) {
|
||||
val startNs = myBuildTimeStartNs.remove(time) ?: error("$time finished before it started")
|
||||
val durationNs = System.nanoTime() - startNs
|
||||
myBuildTimes.addTimeNs(time, durationNs)
|
||||
@@ -45,20 +42,20 @@ class BuildMetricsReporterImpl : BuildMetricsReporter, Serializable {
|
||||
myGcMetrics.add(name, diff)
|
||||
}
|
||||
|
||||
override fun addTimeMetricNs(time: BuildTime, durationNs: Long) {
|
||||
override fun addTimeMetricNs(time: B, durationNs: Long) {
|
||||
myBuildTimes.addTimeNs(time, durationNs)
|
||||
}
|
||||
|
||||
override fun addMetric(metric: BuildPerformanceMetric, value: Long) {
|
||||
override fun addMetric(metric: P, value: Long) {
|
||||
myBuildMetrics.add(metric, value)
|
||||
}
|
||||
|
||||
override fun addTimeMetric(metric: BuildPerformanceMetric) {
|
||||
when (metric.type) {
|
||||
override fun addTimeMetric(metric: P) {
|
||||
when (metric.getType()) {
|
||||
ValueType.NANOSECONDS -> myBuildMetrics.add(metric, System.nanoTime())
|
||||
ValueType.MILLISECONDS -> myBuildMetrics.add(metric, System.currentTimeMillis())
|
||||
ValueType.TIME -> myBuildMetrics.add(metric, System.currentTimeMillis())
|
||||
else -> error("Unable to add time metric for '${metric.type}' type")
|
||||
else -> error("Unable to add time metric for '${metric.getType()}' type")
|
||||
}
|
||||
|
||||
}
|
||||
@@ -71,7 +68,7 @@ class BuildMetricsReporterImpl : BuildMetricsReporter, Serializable {
|
||||
myBuildAttributes.add(attribute)
|
||||
}
|
||||
|
||||
override fun getMetrics(): BuildMetrics =
|
||||
override fun getMetrics(): BuildMetrics<B, P> =
|
||||
BuildMetrics(
|
||||
buildTimes = myBuildTimes,
|
||||
buildPerformanceMetrics = myBuildMetrics,
|
||||
@@ -79,7 +76,7 @@ class BuildMetricsReporterImpl : BuildMetricsReporter, Serializable {
|
||||
gcMetrics = myGcMetrics
|
||||
)
|
||||
|
||||
override fun addMetrics(metrics: BuildMetrics) {
|
||||
override fun addMetrics(metrics: BuildMetrics<B, P>) {
|
||||
myBuildAttributes.addAll(metrics.buildAttributes)
|
||||
myBuildTimes.addAll(metrics.buildTimes)
|
||||
myBuildMetrics.addAll(metrics.buildPerformanceMetrics)
|
||||
|
||||
+129
-19
@@ -7,11 +7,65 @@ package org.jetbrains.kotlin.build.report.metrics
|
||||
|
||||
import java.io.Serializable
|
||||
|
||||
interface BuildPerformanceMetric : BuildTime, Serializable {
|
||||
override fun getParent(): BuildPerformanceMetric?
|
||||
|
||||
override fun getAllMetrics(): List<BuildPerformanceMetric>
|
||||
|
||||
override fun children(): List<BuildPerformanceMetric>?
|
||||
|
||||
fun getType(): ValueType
|
||||
}
|
||||
|
||||
enum class JpsBuildPerformanceMetric(
|
||||
private val parent: JpsBuildPerformanceMetric? = null,
|
||||
private val readableString: String,
|
||||
private val type: ValueType,
|
||||
) : BuildPerformanceMetric {
|
||||
DAEMON_GC_TIME(readableString = "Time spent in GC", type = ValueType.NANOSECONDS),
|
||||
DAEMON_GC_COUNT(readableString = "Count of GC", type = ValueType.NUMBER),
|
||||
|
||||
COMPILE_ITERATION(parent = null, "Total compiler iteration", type = ValueType.NUMBER),
|
||||
ANALYZED_LINES_NUMBER(parent = COMPILE_ITERATION, "Number of lines analyzed", type = ValueType.NUMBER),
|
||||
CODE_GENERATED_LINES_NUMBER(parent = COMPILE_ITERATION, "Number of lines for code generation", type = ValueType.NUMBER),
|
||||
ANALYSIS_LPS(parent = COMPILE_ITERATION, "Analysis lines per second", type = ValueType.NUMBER),
|
||||
CODE_GENERATION_LPS(parent = COMPILE_ITERATION, "Code generation lines per second", type = ValueType.NUMBER),
|
||||
;
|
||||
|
||||
override fun getReadableString(): String = readableString
|
||||
override fun getType(): ValueType = type
|
||||
|
||||
override fun getParent(): BuildPerformanceMetric? = parent
|
||||
|
||||
override fun children(): List<BuildPerformanceMetric>? {
|
||||
return children[this]
|
||||
}
|
||||
|
||||
override fun getName(): String = this.name
|
||||
|
||||
override fun getAllMetrics(): List<BuildPerformanceMetric> {
|
||||
return entries
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val serialVersionUID = 1L
|
||||
|
||||
val children by lazy {
|
||||
entries.filter { it.parent != null }.groupBy { it.parent }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Suppress("Reformat")
|
||||
enum class BuildPerformanceMetric(val parent: BuildPerformanceMetric? = null, val readableString: String, val type: ValueType) : Serializable {
|
||||
enum class GradleBuildPerformanceMetric(
|
||||
private val parent: GradleBuildPerformanceMetric? = null,
|
||||
private val readableString: String,
|
||||
private val type: ValueType,
|
||||
) :
|
||||
BuildPerformanceMetric {
|
||||
CACHE_DIRECTORY_SIZE(readableString = "Total size of the cache directory", type = ValueType.BYTES),
|
||||
LOOKUP_SIZE(CACHE_DIRECTORY_SIZE, "Lookups size", type = ValueType.BYTES),
|
||||
SNAPSHOT_SIZE(CACHE_DIRECTORY_SIZE, "ABI snapshot size", type = ValueType.BYTES),
|
||||
LOOKUP_SIZE(CACHE_DIRECTORY_SIZE, "Lookups size", type = ValueType.BYTES),
|
||||
SNAPSHOT_SIZE(CACHE_DIRECTORY_SIZE, "ABI snapshot size", type = ValueType.BYTES),
|
||||
|
||||
BUNDLE_SIZE(readableString = "Total size of the final bundle", type = ValueType.BYTES),
|
||||
|
||||
@@ -22,24 +76,64 @@ enum class BuildPerformanceMetric(val parent: BuildPerformanceMetric? = null, va
|
||||
DAEMON_GC_COUNT(readableString = "Count of GC", type = ValueType.NUMBER),
|
||||
|
||||
COMPILE_ITERATION(parent = null, "Total compiler iteration", type = ValueType.NUMBER),
|
||||
ANALYZED_LINES_NUMBER(parent = COMPILE_ITERATION, "Number of lines analyzed", type = ValueType.NUMBER),
|
||||
CODE_GENERATED_LINES_NUMBER(parent = COMPILE_ITERATION, "Number of lines for code generation", type = ValueType.NUMBER),
|
||||
ANALYSIS_LPS(parent = COMPILE_ITERATION, "Analysis lines per second", type = ValueType.NUMBER),
|
||||
CODE_GENERATION_LPS(parent = COMPILE_ITERATION, "Code generation lines per second", type = ValueType.NUMBER),
|
||||
ANALYZED_LINES_NUMBER(parent = COMPILE_ITERATION, "Number of lines analyzed", type = ValueType.NUMBER),
|
||||
CODE_GENERATED_LINES_NUMBER(parent = COMPILE_ITERATION, "Number of lines for code generation", type = ValueType.NUMBER),
|
||||
ANALYSIS_LPS(parent = COMPILE_ITERATION, "Analysis lines per second", type = ValueType.NUMBER),
|
||||
CODE_GENERATION_LPS(parent = COMPILE_ITERATION, "Code generation lines per second", type = ValueType.NUMBER),
|
||||
|
||||
// Metrics for the `kotlin.incremental.useClasspathSnapshot` feature
|
||||
CLASSPATH_ENTRY_SNAPSHOT_TRANSFORM_EXECUTION_COUNT(parent = null, "Number of times 'ClasspathEntrySnapshotTransform' ran", type = ValueType.NUMBER),
|
||||
JAR_CLASSPATH_ENTRY_SIZE(parent = CLASSPATH_ENTRY_SNAPSHOT_TRANSFORM_EXECUTION_COUNT, "Size of jar classpath entry", type = ValueType.BYTES),
|
||||
JAR_CLASSPATH_ENTRY_SNAPSHOT_SIZE(parent = CLASSPATH_ENTRY_SNAPSHOT_TRANSFORM_EXECUTION_COUNT, "Size of jar classpath entry's snapshot", type = ValueType.BYTES),
|
||||
DIRECTORY_CLASSPATH_ENTRY_SNAPSHOT_SIZE(parent = CLASSPATH_ENTRY_SNAPSHOT_TRANSFORM_EXECUTION_COUNT, "Size of directory classpath entry's snapshot", type = ValueType.BYTES),
|
||||
CLASSPATH_ENTRY_SNAPSHOT_TRANSFORM_EXECUTION_COUNT(
|
||||
parent = null,
|
||||
"Number of times 'ClasspathEntrySnapshotTransform' ran",
|
||||
type = ValueType.NUMBER
|
||||
),
|
||||
JAR_CLASSPATH_ENTRY_SIZE(
|
||||
parent = CLASSPATH_ENTRY_SNAPSHOT_TRANSFORM_EXECUTION_COUNT,
|
||||
"Size of jar classpath entry",
|
||||
type = ValueType.BYTES
|
||||
),
|
||||
JAR_CLASSPATH_ENTRY_SNAPSHOT_SIZE(
|
||||
parent = CLASSPATH_ENTRY_SNAPSHOT_TRANSFORM_EXECUTION_COUNT,
|
||||
"Size of jar classpath entry's snapshot",
|
||||
type = ValueType.BYTES
|
||||
),
|
||||
DIRECTORY_CLASSPATH_ENTRY_SNAPSHOT_SIZE(
|
||||
parent = CLASSPATH_ENTRY_SNAPSHOT_TRANSFORM_EXECUTION_COUNT,
|
||||
"Size of directory classpath entry's snapshot",
|
||||
type = ValueType.BYTES
|
||||
),
|
||||
COMPUTE_CLASSPATH_CHANGES_EXECUTION_COUNT(parent = null, "Number of times classpath changes are computed", type = ValueType.NUMBER),
|
||||
SHRINK_AND_SAVE_CLASSPATH_SNAPSHOT_EXECUTION_COUNT(parent = null, "Number of times classpath snapshot is shrunk and saved after compilation", type = ValueType.NUMBER),
|
||||
CLASSPATH_ENTRY_COUNT(parent = SHRINK_AND_SAVE_CLASSPATH_SNAPSHOT_EXECUTION_COUNT, "Number of classpath entries", type = ValueType.NUMBER),
|
||||
CLASSPATH_SNAPSHOT_SIZE(parent = SHRINK_AND_SAVE_CLASSPATH_SNAPSHOT_EXECUTION_COUNT, "Size of classpath snapshot", type = ValueType.BYTES),
|
||||
SHRUNK_CLASSPATH_SNAPSHOT_SIZE(parent = SHRINK_AND_SAVE_CLASSPATH_SNAPSHOT_EXECUTION_COUNT, "Size of shrunk classpath snapshot", type = ValueType.BYTES),
|
||||
SHRINK_AND_SAVE_CLASSPATH_SNAPSHOT_EXECUTION_COUNT(
|
||||
parent = null,
|
||||
"Number of times classpath snapshot is shrunk and saved after compilation",
|
||||
type = ValueType.NUMBER
|
||||
),
|
||||
CLASSPATH_ENTRY_COUNT(
|
||||
parent = SHRINK_AND_SAVE_CLASSPATH_SNAPSHOT_EXECUTION_COUNT,
|
||||
"Number of classpath entries",
|
||||
type = ValueType.NUMBER
|
||||
),
|
||||
CLASSPATH_SNAPSHOT_SIZE(
|
||||
parent = SHRINK_AND_SAVE_CLASSPATH_SNAPSHOT_EXECUTION_COUNT,
|
||||
"Size of classpath snapshot",
|
||||
type = ValueType.BYTES
|
||||
),
|
||||
SHRUNK_CLASSPATH_SNAPSHOT_SIZE(
|
||||
parent = SHRINK_AND_SAVE_CLASSPATH_SNAPSHOT_EXECUTION_COUNT,
|
||||
"Size of shrunk classpath snapshot",
|
||||
type = ValueType.BYTES
|
||||
),
|
||||
LOAD_CLASSPATH_SNAPSHOT_EXECUTION_COUNT(parent = null, "Number of times classpath snapshot is loaded", type = ValueType.NUMBER),
|
||||
LOAD_CLASSPATH_ENTRY_SNAPSHOT_CACHE_HITS(parent = LOAD_CLASSPATH_SNAPSHOT_EXECUTION_COUNT, "Number of cache hits when loading classpath entry snapshots", type = ValueType.NUMBER),
|
||||
LOAD_CLASSPATH_ENTRY_SNAPSHOT_CACHE_MISSES(parent = LOAD_CLASSPATH_SNAPSHOT_EXECUTION_COUNT, "Number of cache misses when loading classpath entry snapshots", type = ValueType.NUMBER),
|
||||
LOAD_CLASSPATH_ENTRY_SNAPSHOT_CACHE_HITS(
|
||||
parent = LOAD_CLASSPATH_SNAPSHOT_EXECUTION_COUNT,
|
||||
"Number of cache hits when loading classpath entry snapshots",
|
||||
type = ValueType.NUMBER
|
||||
),
|
||||
LOAD_CLASSPATH_ENTRY_SNAPSHOT_CACHE_MISSES(
|
||||
parent = LOAD_CLASSPATH_SNAPSHOT_EXECUTION_COUNT,
|
||||
"Number of cache misses when loading classpath entry snapshots",
|
||||
type = ValueType.NUMBER
|
||||
),
|
||||
|
||||
//time metrics
|
||||
START_TASK_ACTION_EXECUTION(readableString = "Start time of task action", type = ValueType.TIME),
|
||||
@@ -50,11 +144,27 @@ enum class BuildPerformanceMetric(val parent: BuildPerformanceMetric? = null, va
|
||||
START_WORKER_EXECUTION(readableString = "Start time of worker execution", type = ValueType.NANOSECONDS),
|
||||
START_KOTLIN_DAEMON_EXECUTION(readableString = "Start time of kotlin daemon task execution", type = ValueType.NANOSECONDS),
|
||||
;
|
||||
|
||||
override fun getReadableString(): String = readableString
|
||||
|
||||
override fun getParent(): BuildPerformanceMetric? = parent
|
||||
override fun getType(): ValueType = type
|
||||
|
||||
override fun getName(): String = this.name
|
||||
|
||||
override fun children(): List<BuildPerformanceMetric>? {
|
||||
return children[this]
|
||||
}
|
||||
|
||||
override fun getAllMetrics(): List<BuildPerformanceMetric> {
|
||||
return entries
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val serialVersionUID = 0L
|
||||
const val serialVersionUID = 1L
|
||||
|
||||
val children by lazy {
|
||||
values().filter { it.parent != null }.groupBy { it.parent }
|
||||
entries.filter { it.parent != null }.groupBy { it.parent }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+6
-5
@@ -7,24 +7,25 @@ package org.jetbrains.kotlin.build.report.metrics
|
||||
|
||||
import java.io.Serializable
|
||||
import java.util.*
|
||||
import kotlin.collections.HashMap
|
||||
|
||||
class BuildPerformanceMetrics : Serializable {
|
||||
class BuildPerformanceMetrics<T: BuildPerformanceMetric> : Serializable {
|
||||
companion object {
|
||||
const val serialVersionUID = 0L
|
||||
}
|
||||
|
||||
private val myBuildMetrics = EnumMap<BuildPerformanceMetric, Long>(BuildPerformanceMetric::class.java)
|
||||
private val myBuildMetrics = HashMap<T, Long>()
|
||||
|
||||
fun addAll(other: BuildPerformanceMetrics) {
|
||||
fun addAll(other: BuildPerformanceMetrics<T>) {
|
||||
for ((bt, timeNs) in other.myBuildMetrics) {
|
||||
add(bt, timeNs)
|
||||
}
|
||||
}
|
||||
|
||||
fun add(metric: BuildPerformanceMetric, value: Long = 1) {
|
||||
fun add(metric: T, value: Long = 1) {
|
||||
myBuildMetrics[metric] = myBuildMetrics.getOrDefault(metric, 0) + value
|
||||
}
|
||||
|
||||
fun asMap(): Map<BuildPerformanceMetric, Long> = myBuildMetrics
|
||||
fun asMap(): Map<T, Long> = myBuildMetrics
|
||||
|
||||
}
|
||||
+133
-64
@@ -7,82 +7,151 @@ package org.jetbrains.kotlin.build.report.metrics
|
||||
|
||||
import java.io.Serializable
|
||||
|
||||
interface BuildTime : Serializable {
|
||||
fun getReadableString(): String
|
||||
|
||||
fun getParent(): BuildTime?
|
||||
|
||||
fun getAllMetrics(): List<BuildTime>
|
||||
|
||||
fun children(): List<BuildTime>?
|
||||
|
||||
fun getName(): String
|
||||
}
|
||||
|
||||
|
||||
enum class JpsBuildTime(private val parent: JpsBuildTime? = null, private val readableString: String) : BuildTime {
|
||||
|
||||
JPS_ITERATION(readableString = "Jps iteration")
|
||||
;
|
||||
|
||||
override fun getReadableString(): String = readableString
|
||||
override fun getParent(): BuildTime? = parent
|
||||
|
||||
override fun getAllMetrics(): List<BuildTime> {
|
||||
return entries
|
||||
}
|
||||
|
||||
override fun children(): List<BuildTime>? {
|
||||
return children[this]
|
||||
}
|
||||
|
||||
override fun getName(): String = this.name
|
||||
|
||||
companion object {
|
||||
const val serialVersionUID = 1L
|
||||
|
||||
val children by lazy {
|
||||
entries.filter { it.parent != null }.groupBy { it.parent }
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Suppress("Reformat")
|
||||
enum class BuildTime(val parent: BuildTime? = null, val readableString: String) : Serializable {
|
||||
enum class GradleBuildTime(private val parent: GradleBuildTime? = null, private val readableString: String) : BuildTime {
|
||||
GRADLE_TASK(readableString = "Total Gradle task time"),
|
||||
GRADLE_TASK_PREPARATION(readableString = "Spent time before task action"),
|
||||
GRADLE_TASK_ACTION(readableString = "Task action"),
|
||||
OUT_OF_WORKER_TASK_ACTION(GRADLE_TASK_ACTION, "Task action before worker execution"),
|
||||
BACKUP_OUTPUT(OUT_OF_WORKER_TASK_ACTION, "Backup output"),
|
||||
RUN_WORKER_DELAY(readableString = "Start gradle worker"),
|
||||
RUN_COMPILATION_IN_WORKER(GRADLE_TASK_ACTION, "Run compilation in Gradle worker"),
|
||||
CLEAR_JAR_CACHE(RUN_COMPILATION_IN_WORKER, "Clear jar cache"),
|
||||
CLEAR_OUTPUT(RUN_COMPILATION_IN_WORKER, "Clear output"),
|
||||
PRECISE_BACKUP_OUTPUT(RUN_COMPILATION_IN_WORKER, "Precise backup output"),
|
||||
RESTORE_OUTPUT_FROM_BACKUP(RUN_COMPILATION_IN_WORKER, "Restore output"),
|
||||
CLEAN_BACKUP_STASH(RUN_COMPILATION_IN_WORKER, "Cleaning up the backup stash"),
|
||||
CONNECT_TO_DAEMON(RUN_COMPILATION_IN_WORKER, "Connect to Kotlin daemon"),
|
||||
CALCULATE_OUTPUT_SIZE(RUN_COMPILATION_IN_WORKER, "Calculate output size"),
|
||||
RUN_COMPILATION(RUN_COMPILATION_IN_WORKER, "Run compilation"),
|
||||
NON_INCREMENTAL_COMPILATION_IN_PROCESS(RUN_COMPILATION, "Non incremental inprocess compilation"),
|
||||
NON_INCREMENTAL_COMPILATION_OUT_OF_PROCESS(RUN_COMPILATION, "Non incremental out of process compilation"),
|
||||
NON_INCREMENTAL_COMPILATION_DAEMON(RUN_COMPILATION, "Non incremental compilation in daemon"),
|
||||
INCREMENTAL_COMPILATION_DAEMON(RUN_COMPILATION, "Incremental compilation in daemon"),
|
||||
STORE_BUILD_INFO(INCREMENTAL_COMPILATION_DAEMON, "Store build info"),
|
||||
JAR_SNAPSHOT(INCREMENTAL_COMPILATION_DAEMON, "ABI JAR Snapshot support"),
|
||||
SET_UP_ABI_SNAPSHOTS(JAR_SNAPSHOT, "Set up ABI snapshot"),
|
||||
IC_ANALYZE_JAR_FILES(JAR_SNAPSHOT, "Analyze jar files"),
|
||||
IC_CALCULATE_INITIAL_DIRTY_SET(INCREMENTAL_COMPILATION_DAEMON, "Calculate initial dirty sources set"), //TODO
|
||||
COMPUTE_CLASSPATH_CHANGES(IC_CALCULATE_INITIAL_DIRTY_SET, "Compute classpath changes"),
|
||||
LOAD_CURRENT_CLASSPATH_SNAPSHOT(COMPUTE_CLASSPATH_CHANGES, "Load current classpath snapshot"),
|
||||
REMOVE_DUPLICATE_CLASSES(LOAD_CURRENT_CLASSPATH_SNAPSHOT, "Remove duplicate classes"),
|
||||
SHRINK_CURRENT_CLASSPATH_SNAPSHOT(COMPUTE_CLASSPATH_CHANGES, "Shrink current classpath snapshot"),
|
||||
GET_LOOKUP_SYMBOLS(SHRINK_CURRENT_CLASSPATH_SNAPSHOT, "Get lookup symbols"),
|
||||
FIND_REFERENCED_CLASSES(SHRINK_CURRENT_CLASSPATH_SNAPSHOT, "Find referenced classes"),
|
||||
FIND_TRANSITIVELY_REFERENCED_CLASSES(SHRINK_CURRENT_CLASSPATH_SNAPSHOT, "Find transitively referenced classes"),
|
||||
LOAD_SHRUNK_PREVIOUS_CLASSPATH_SNAPSHOT(COMPUTE_CLASSPATH_CHANGES, "Load shrunk previous classpath snapshot"),
|
||||
COMPUTE_CHANGED_AND_IMPACTED_SET(COMPUTE_CLASSPATH_CHANGES, "Compute changed and impacted set"),
|
||||
COMPUTE_CLASS_CHANGES(COMPUTE_CHANGED_AND_IMPACTED_SET, "Compute class changes"),
|
||||
COMPUTE_KOTLIN_CLASS_CHANGES(COMPUTE_CLASS_CHANGES, "Compute Kotlin class changes"),
|
||||
COMPUTE_JAVA_CLASS_CHANGES(COMPUTE_CLASS_CHANGES, "Compute Java class changes"),
|
||||
COMPUTE_IMPACTED_SET(COMPUTE_CHANGED_AND_IMPACTED_SET, "Compute impacted set"),
|
||||
IC_ANALYZE_CHANGES_IN_DEPENDENCIES(IC_CALCULATE_INITIAL_DIRTY_SET, "Analyze dependency changes"),
|
||||
IC_FIND_HISTORY_FILES(IC_ANALYZE_CHANGES_IN_DEPENDENCIES, "Find history files"),
|
||||
IC_ANALYZE_HISTORY_FILES(IC_ANALYZE_CHANGES_IN_DEPENDENCIES, "Analyze history files"),
|
||||
IC_ANALYZE_CHANGES_IN_JAVA_SOURCES(IC_CALCULATE_INITIAL_DIRTY_SET, "Analyze Java file changes"),
|
||||
IC_ANALYZE_CHANGES_IN_ANDROID_LAYOUTS(IC_CALCULATE_INITIAL_DIRTY_SET, "Analyze Android layouts"),
|
||||
IC_DETECT_REMOVED_CLASSES(IC_CALCULATE_INITIAL_DIRTY_SET, "Detect removed classes"),
|
||||
CLEAR_OUTPUT_ON_REBUILD(INCREMENTAL_COMPILATION_DAEMON, "Clear outputs on rebuild"),
|
||||
IC_UPDATE_CACHES(INCREMENTAL_COMPILATION_DAEMON, "Update caches"),
|
||||
COMPILATION_ROUND(INCREMENTAL_COMPILATION_DAEMON, "Sources compilation round"),
|
||||
COMPILER_PERFORMANCE(COMPILATION_ROUND, readableString = "Compiler time"),
|
||||
COMPILER_INITIALIZATION(COMPILER_PERFORMANCE, "Compiler initialization time"),
|
||||
CODE_ANALYSIS(COMPILER_PERFORMANCE, "Compiler code analysis"),
|
||||
CODE_GENERATION(COMPILER_PERFORMANCE, "Compiler code generation"),
|
||||
IC_WRITE_HISTORY_FILE(INCREMENTAL_COMPILATION_DAEMON, "Write history file"),
|
||||
SHRINK_AND_SAVE_CURRENT_CLASSPATH_SNAPSHOT_AFTER_COMPILATION(INCREMENTAL_COMPILATION_DAEMON, "Shrink and save current classpath snapshot after compilation"),
|
||||
INCREMENTAL_SHRINK_CURRENT_CLASSPATH_SNAPSHOT(SHRINK_AND_SAVE_CURRENT_CLASSPATH_SNAPSHOT_AFTER_COMPILATION, "Shrink current classpath snapshot incrementally"),
|
||||
INCREMENTAL_LOAD_CURRENT_CLASSPATH_SNAPSHOT(INCREMENTAL_SHRINK_CURRENT_CLASSPATH_SNAPSHOT, "Load current classpath snapshot"),
|
||||
INCREMENTAL_LOAD_SHRUNK_CURRENT_CLASSPATH_SNAPSHOT_AGAINST_PREVIOUS_LOOKUPS(INCREMENTAL_SHRINK_CURRENT_CLASSPATH_SNAPSHOT, "Load shrunk current classpath snapshot against previous lookups"),
|
||||
NON_INCREMENTAL_SHRINK_CURRENT_CLASSPATH_SNAPSHOT(SHRINK_AND_SAVE_CURRENT_CLASSPATH_SNAPSHOT_AFTER_COMPILATION, "Shrink current classpath snapshot non-incrementally"),
|
||||
NON_INCREMENTAL_LOAD_CURRENT_CLASSPATH_SNAPSHOT(NON_INCREMENTAL_SHRINK_CURRENT_CLASSPATH_SNAPSHOT, "Load current classpath snapshot"),
|
||||
SAVE_SHRUNK_CURRENT_CLASSPATH_SNAPSHOT(SHRINK_AND_SAVE_CURRENT_CLASSPATH_SNAPSHOT_AFTER_COMPILATION, "Save shrunk current classpath snapshot"),
|
||||
OUT_OF_WORKER_TASK_ACTION(GRADLE_TASK_ACTION, "Task action before worker execution"),
|
||||
BACKUP_OUTPUT(OUT_OF_WORKER_TASK_ACTION, "Backup output"),
|
||||
RUN_WORKER_DELAY(readableString = "Start gradle worker"),
|
||||
RUN_COMPILATION_IN_WORKER(GRADLE_TASK_ACTION, "Run compilation in Gradle worker"),
|
||||
CLEAR_JAR_CACHE(RUN_COMPILATION_IN_WORKER, "Clear jar cache"),
|
||||
CLEAR_OUTPUT(RUN_COMPILATION_IN_WORKER, "Clear output"),
|
||||
PRECISE_BACKUP_OUTPUT(RUN_COMPILATION_IN_WORKER, "Precise backup output"),
|
||||
RESTORE_OUTPUT_FROM_BACKUP(RUN_COMPILATION_IN_WORKER, "Restore output"),
|
||||
CLEAN_BACKUP_STASH(RUN_COMPILATION_IN_WORKER, "Cleaning up the backup stash"),
|
||||
CONNECT_TO_DAEMON(RUN_COMPILATION_IN_WORKER, "Connect to Kotlin daemon"),
|
||||
CALCULATE_OUTPUT_SIZE(RUN_COMPILATION_IN_WORKER, "Calculate output size"),
|
||||
RUN_COMPILATION(RUN_COMPILATION_IN_WORKER, "Run compilation"),
|
||||
NON_INCREMENTAL_COMPILATION_IN_PROCESS(RUN_COMPILATION, "Non incremental inprocess compilation"),
|
||||
NON_INCREMENTAL_COMPILATION_OUT_OF_PROCESS(RUN_COMPILATION, "Non incremental out of process compilation"),
|
||||
NON_INCREMENTAL_COMPILATION_DAEMON(RUN_COMPILATION, "Non incremental compilation in daemon"),
|
||||
INCREMENTAL_COMPILATION_DAEMON(RUN_COMPILATION, "Incremental compilation in daemon"),
|
||||
STORE_BUILD_INFO(INCREMENTAL_COMPILATION_DAEMON, "Store build info"),
|
||||
JAR_SNAPSHOT(INCREMENTAL_COMPILATION_DAEMON, "ABI JAR Snapshot support"),
|
||||
SET_UP_ABI_SNAPSHOTS(JAR_SNAPSHOT, "Set up ABI snapshot"),
|
||||
IC_ANALYZE_JAR_FILES(JAR_SNAPSHOT, "Analyze jar files"),
|
||||
IC_CALCULATE_INITIAL_DIRTY_SET(INCREMENTAL_COMPILATION_DAEMON, "Calculate initial dirty sources set"), //TODO
|
||||
COMPUTE_CLASSPATH_CHANGES(IC_CALCULATE_INITIAL_DIRTY_SET, "Compute classpath changes"),
|
||||
LOAD_CURRENT_CLASSPATH_SNAPSHOT(COMPUTE_CLASSPATH_CHANGES, "Load current classpath snapshot"),
|
||||
REMOVE_DUPLICATE_CLASSES(LOAD_CURRENT_CLASSPATH_SNAPSHOT, "Remove duplicate classes"),
|
||||
SHRINK_CURRENT_CLASSPATH_SNAPSHOT(COMPUTE_CLASSPATH_CHANGES, "Shrink current classpath snapshot"),
|
||||
GET_LOOKUP_SYMBOLS(SHRINK_CURRENT_CLASSPATH_SNAPSHOT, "Get lookup symbols"),
|
||||
FIND_REFERENCED_CLASSES(SHRINK_CURRENT_CLASSPATH_SNAPSHOT, "Find referenced classes"),
|
||||
FIND_TRANSITIVELY_REFERENCED_CLASSES(SHRINK_CURRENT_CLASSPATH_SNAPSHOT, "Find transitively referenced classes"),
|
||||
LOAD_SHRUNK_PREVIOUS_CLASSPATH_SNAPSHOT(COMPUTE_CLASSPATH_CHANGES, "Load shrunk previous classpath snapshot"),
|
||||
COMPUTE_CHANGED_AND_IMPACTED_SET(COMPUTE_CLASSPATH_CHANGES, "Compute changed and impacted set"),
|
||||
COMPUTE_CLASS_CHANGES(COMPUTE_CHANGED_AND_IMPACTED_SET, "Compute class changes"),
|
||||
COMPUTE_KOTLIN_CLASS_CHANGES(COMPUTE_CLASS_CHANGES, "Compute Kotlin class changes"),
|
||||
COMPUTE_JAVA_CLASS_CHANGES(COMPUTE_CLASS_CHANGES, "Compute Java class changes"),
|
||||
COMPUTE_IMPACTED_SET(COMPUTE_CHANGED_AND_IMPACTED_SET, "Compute impacted set"),
|
||||
IC_ANALYZE_CHANGES_IN_DEPENDENCIES(IC_CALCULATE_INITIAL_DIRTY_SET, "Analyze dependency changes"),
|
||||
IC_FIND_HISTORY_FILES(IC_ANALYZE_CHANGES_IN_DEPENDENCIES, "Find history files"),
|
||||
IC_ANALYZE_HISTORY_FILES(IC_ANALYZE_CHANGES_IN_DEPENDENCIES, "Analyze history files"),
|
||||
IC_ANALYZE_CHANGES_IN_JAVA_SOURCES(IC_CALCULATE_INITIAL_DIRTY_SET, "Analyze Java file changes"),
|
||||
IC_ANALYZE_CHANGES_IN_ANDROID_LAYOUTS(IC_CALCULATE_INITIAL_DIRTY_SET, "Analyze Android layouts"),
|
||||
IC_DETECT_REMOVED_CLASSES(IC_CALCULATE_INITIAL_DIRTY_SET, "Detect removed classes"),
|
||||
CLEAR_OUTPUT_ON_REBUILD(INCREMENTAL_COMPILATION_DAEMON, "Clear outputs on rebuild"),
|
||||
IC_UPDATE_CACHES(INCREMENTAL_COMPILATION_DAEMON, "Update caches"),
|
||||
COMPILATION_ROUND(INCREMENTAL_COMPILATION_DAEMON, "Sources compilation round"),
|
||||
COMPILER_PERFORMANCE(COMPILATION_ROUND, readableString = "Compiler time"),
|
||||
COMPILER_INITIALIZATION(COMPILER_PERFORMANCE, "Compiler initialization time"),
|
||||
CODE_ANALYSIS(COMPILER_PERFORMANCE, "Compiler code analysis"),
|
||||
CODE_GENERATION(COMPILER_PERFORMANCE, "Compiler code generation"),
|
||||
IC_WRITE_HISTORY_FILE(INCREMENTAL_COMPILATION_DAEMON, "Write history file"),
|
||||
SHRINK_AND_SAVE_CURRENT_CLASSPATH_SNAPSHOT_AFTER_COMPILATION(
|
||||
INCREMENTAL_COMPILATION_DAEMON,
|
||||
"Shrink and save current classpath snapshot after compilation"
|
||||
),
|
||||
INCREMENTAL_SHRINK_CURRENT_CLASSPATH_SNAPSHOT(
|
||||
SHRINK_AND_SAVE_CURRENT_CLASSPATH_SNAPSHOT_AFTER_COMPILATION,
|
||||
"Shrink current classpath snapshot incrementally"
|
||||
),
|
||||
INCREMENTAL_LOAD_CURRENT_CLASSPATH_SNAPSHOT(INCREMENTAL_SHRINK_CURRENT_CLASSPATH_SNAPSHOT, "Load current classpath snapshot"),
|
||||
INCREMENTAL_LOAD_SHRUNK_CURRENT_CLASSPATH_SNAPSHOT_AGAINST_PREVIOUS_LOOKUPS(
|
||||
INCREMENTAL_SHRINK_CURRENT_CLASSPATH_SNAPSHOT,
|
||||
"Load shrunk current classpath snapshot against previous lookups"
|
||||
),
|
||||
NON_INCREMENTAL_SHRINK_CURRENT_CLASSPATH_SNAPSHOT(
|
||||
SHRINK_AND_SAVE_CURRENT_CLASSPATH_SNAPSHOT_AFTER_COMPILATION,
|
||||
"Shrink current classpath snapshot non-incrementally"
|
||||
),
|
||||
NON_INCREMENTAL_LOAD_CURRENT_CLASSPATH_SNAPSHOT(NON_INCREMENTAL_SHRINK_CURRENT_CLASSPATH_SNAPSHOT, "Load current classpath snapshot"),
|
||||
SAVE_SHRUNK_CURRENT_CLASSPATH_SNAPSHOT(
|
||||
SHRINK_AND_SAVE_CURRENT_CLASSPATH_SNAPSHOT_AFTER_COMPILATION,
|
||||
"Save shrunk current classpath snapshot"
|
||||
),
|
||||
TASK_FINISH_LISTENER_NOTIFICATION(readableString = "Task finish event notification"),
|
||||
CLASSPATH_ENTRY_SNAPSHOT_TRANSFORM(readableString = "Classpath entry snapshot transform"),
|
||||
LOAD_CLASSES_PATHS_ONLY(parent = CLASSPATH_ENTRY_SNAPSHOT_TRANSFORM, "Load classes (paths only)"),
|
||||
SNAPSHOT_CLASSES(parent = CLASSPATH_ENTRY_SNAPSHOT_TRANSFORM, "Snapshot classes"),
|
||||
LOAD_CONTENTS_OF_CLASSES(parent = SNAPSHOT_CLASSES, "Load contents of classes"),
|
||||
SNAPSHOT_KOTLIN_CLASSES(parent = SNAPSHOT_CLASSES, "Snapshot Kotlin classes"),
|
||||
SNAPSHOT_JAVA_CLASSES(parent = SNAPSHOT_CLASSES, "Snapshot Java classes"),
|
||||
SAVE_CLASSPATH_ENTRY_SNAPSHOT(parent = CLASSPATH_ENTRY_SNAPSHOT_TRANSFORM, "Save classpath entry snapshot"),
|
||||
LOAD_CLASSES_PATHS_ONLY(parent = CLASSPATH_ENTRY_SNAPSHOT_TRANSFORM, "Load classes (paths only)"),
|
||||
SNAPSHOT_CLASSES(parent = CLASSPATH_ENTRY_SNAPSHOT_TRANSFORM, "Snapshot classes"),
|
||||
LOAD_CONTENTS_OF_CLASSES(parent = SNAPSHOT_CLASSES, "Load contents of classes"),
|
||||
SNAPSHOT_KOTLIN_CLASSES(parent = SNAPSHOT_CLASSES, "Snapshot Kotlin classes"),
|
||||
SNAPSHOT_JAVA_CLASSES(parent = SNAPSHOT_CLASSES, "Snapshot Java classes"),
|
||||
SAVE_CLASSPATH_ENTRY_SNAPSHOT(parent = CLASSPATH_ENTRY_SNAPSHOT_TRANSFORM, "Save classpath entry snapshot"),
|
||||
|
||||
;
|
||||
|
||||
override fun getReadableString(): String = readableString
|
||||
override fun getParent(): BuildTime? = parent
|
||||
|
||||
override fun children(): List<BuildTime>? {
|
||||
return children[this]
|
||||
}
|
||||
|
||||
override fun getAllMetrics(): List<BuildTime> {
|
||||
return entries
|
||||
}
|
||||
|
||||
override fun getName(): String = this.name
|
||||
|
||||
companion object {
|
||||
const val serialVersionUID = 0L
|
||||
const val serialVersionUID = 1L
|
||||
|
||||
val children by lazy {
|
||||
values().filter { it.parent != null }.groupBy { it.parent }
|
||||
entries.filter { it.parent != null }.groupBy { it.parent }
|
||||
}
|
||||
}
|
||||
}
|
||||
+7
-6
@@ -7,23 +7,24 @@ package org.jetbrains.kotlin.build.report.metrics
|
||||
|
||||
import java.io.Serializable
|
||||
import java.util.*
|
||||
import kotlin.collections.HashMap
|
||||
|
||||
class BuildTimes : Serializable {
|
||||
private val buildTimesNs = EnumMap<BuildTime, Long>(BuildTime::class.java)
|
||||
class BuildTimes<T : BuildTime> : Serializable {
|
||||
private val buildTimesNs = HashMap<T, Long>()
|
||||
|
||||
fun addAll(other: BuildTimes) {
|
||||
fun addAll(other: BuildTimes<T>) {
|
||||
for ((buildTime, timeNs) in other.buildTimesNs) {
|
||||
addTimeNs(buildTime, timeNs)
|
||||
}
|
||||
}
|
||||
|
||||
fun addTimeNs(buildTime: BuildTime, timeNs: Long) {
|
||||
fun addTimeNs(buildTime: T, timeNs: Long) {
|
||||
buildTimesNs[buildTime] = buildTimesNs.getOrDefault(buildTime, 0) + timeNs
|
||||
}
|
||||
|
||||
fun addTimeMs(buildTime: BuildTime, timeMs: Long) = addTimeNs(buildTime, timeMs * 1_000_000)
|
||||
fun addTimeMs(buildTime: T, timeMs: Long) = addTimeNs(buildTime, timeMs * 1_000_000)
|
||||
|
||||
fun asMapMs(): Map<BuildTime, Long> = buildTimesNs.mapValues { it.value / 1_000_000 }
|
||||
fun asMapMs(): Map<T, Long> = buildTimesNs.mapValues { it.value / 1_000_000 }
|
||||
|
||||
companion object {
|
||||
const val serialVersionUID = 0L
|
||||
|
||||
+8
-8
@@ -5,20 +5,20 @@
|
||||
|
||||
package org.jetbrains.kotlin.build.report.metrics
|
||||
|
||||
object DoNothingBuildMetricsReporter : BuildMetricsReporter {
|
||||
override fun startMeasure(time: BuildTime) {
|
||||
object DoNothingBuildMetricsReporter : BuildMetricsReporter<GradleBuildTime, GradleBuildPerformanceMetric> {
|
||||
override fun startMeasure(time: GradleBuildTime) {
|
||||
}
|
||||
|
||||
override fun endMeasure(time: BuildTime) {
|
||||
override fun endMeasure(time: GradleBuildTime) {
|
||||
}
|
||||
|
||||
override fun addTimeMetricNs(time: BuildTime, durationNs: Long) {
|
||||
override fun addTimeMetricNs(time: GradleBuildTime, durationNs: Long) {
|
||||
}
|
||||
|
||||
override fun addMetric(metric: BuildPerformanceMetric, value: Long) {
|
||||
override fun addMetric(metric: GradleBuildPerformanceMetric, value: Long) {
|
||||
}
|
||||
|
||||
override fun addTimeMetric(metric: BuildPerformanceMetric) {
|
||||
override fun addTimeMetric(metric: GradleBuildPerformanceMetric) {
|
||||
}
|
||||
|
||||
override fun addAttribute(attribute: BuildAttribute) {
|
||||
@@ -33,12 +33,12 @@ object DoNothingBuildMetricsReporter : BuildMetricsReporter {
|
||||
override fun endGcMetric(name: String, value: GcMetric) {
|
||||
}
|
||||
|
||||
override fun getMetrics(): BuildMetrics =
|
||||
override fun getMetrics(): BuildMetrics<GradleBuildTime, GradleBuildPerformanceMetric> =
|
||||
BuildMetrics(
|
||||
BuildTimes(),
|
||||
BuildPerformanceMetrics(),
|
||||
BuildAttributes()
|
||||
)
|
||||
|
||||
override fun addMetrics(metrics: BuildMetrics) {}
|
||||
override fun addMetrics(metrics: BuildMetrics<GradleBuildTime, GradleBuildPerformanceMetric>) {}
|
||||
}
|
||||
+33
-34
@@ -5,44 +5,43 @@
|
||||
|
||||
package org.jetbrains.kotlin.build.report.statistics
|
||||
|
||||
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.*
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.*
|
||||
|
||||
//Sensitive data. This object is used directly for statistic via http
|
||||
private val formatter = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss").also { it.timeZone = TimeZone.getTimeZone("UTC")}
|
||||
data class CompileStatisticsData(
|
||||
val version: Int = 3,
|
||||
val projectName: String?,
|
||||
val label: String?,
|
||||
val taskName: String,
|
||||
val taskResult: String?,
|
||||
val startTimeMs: Long,
|
||||
val durationMs: Long,
|
||||
val tags: Set<StatTag>,
|
||||
val changes: List<String>,
|
||||
val buildUuid: String = "Unset",
|
||||
val kotlinVersion: String,
|
||||
val kotlinLanguageVersion: String?,
|
||||
val hostName: String? = "Unset",
|
||||
val finishTime: Long,
|
||||
val timestamp: String = formatter.format(finishTime),
|
||||
val compilerArguments: List<String>,
|
||||
val nonIncrementalAttributes: Set<BuildAttribute>,
|
||||
//TODO think about it,time in milliseconds
|
||||
val buildTimesMetrics: Map<BuildTime, Long>,
|
||||
val performanceMetrics: Map<BuildPerformanceMetric, Long>,
|
||||
val gcTimeMetrics: Map<String, Long>?,
|
||||
val gcCountMetrics: Map<String, Long>?,
|
||||
val type: String = BuildDataType.TASK_DATA.name,
|
||||
val fromKotlinPlugin: Boolean?,
|
||||
val compiledSources: List<String> = emptyList(),
|
||||
val skipMessage: String?,
|
||||
val icLogLines: List<String>,
|
||||
)
|
||||
private val formatter = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss").also { it.timeZone = TimeZone.getTimeZone("UTC") }
|
||||
|
||||
interface CompileStatisticsData<B : BuildTime, P : BuildPerformanceMetric> {
|
||||
fun getVersion(): Int = 4
|
||||
fun getProjectName(): String?
|
||||
fun getLabel(): String?
|
||||
fun getTaskName(): String
|
||||
fun getTaskResult(): String?
|
||||
fun getStartTimeMs(): Long
|
||||
fun getDurationMs(): Long
|
||||
fun getTags(): Set<StatTag>
|
||||
fun getChanges(): List<String>
|
||||
fun getBuildUuid(): String = "Unset"
|
||||
fun getKotlinVersion(): String
|
||||
fun getKotlinLanguageVersion(): String?
|
||||
fun getHostName(): String? = "Unset"
|
||||
fun getFinishTime(): Long
|
||||
fun getTimestamp(): String = formatter.format(getFinishTime())
|
||||
fun getCompilerArguments(): List<String>
|
||||
fun getNonIncrementalAttributes(): Set<BuildAttribute>
|
||||
|
||||
//TODO think about it,time in milliseconds
|
||||
fun getBuildTimesMetrics(): Map<B, Long>
|
||||
fun getPerformanceMetrics(): Map<P, Long>
|
||||
fun getGcTimeMetrics(): Map<String, Long>?
|
||||
fun getGcCountMetrics(): Map<String, Long>?
|
||||
fun getType(): String = BuildDataType.TASK_DATA.name
|
||||
fun getFromKotlinPlugin(): Boolean?
|
||||
fun getCompiledSources(): List<String> = emptyList()
|
||||
fun getSkipMessage(): String?
|
||||
fun getIcLogLines(): List<String>
|
||||
}
|
||||
|
||||
enum class StatTag(val readableString: String) {
|
||||
ABI_SNAPSHOT("ABI Snapshot"),
|
||||
@@ -86,7 +85,7 @@ data class BuildFinishStatisticsData(
|
||||
val timestamp: String = formatter.format(finishTime),
|
||||
val hostName: String? = "Unset",
|
||||
val tags: Set<StatTag>,
|
||||
val gitBranch: String = "Unset"
|
||||
val gitBranch: String = "Unset",
|
||||
)
|
||||
|
||||
|
||||
|
||||
+56
-54
@@ -15,26 +15,26 @@ import java.io.Serializable
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.*
|
||||
|
||||
class FileReportService(
|
||||
class FileReportService<B : BuildTime, P : BuildPerformanceMetric>(
|
||||
private val outputFile: File,
|
||||
private val printMetrics: Boolean,
|
||||
private val logger: KotlinLogger
|
||||
private val logger: KotlinLogger,
|
||||
) : Serializable {
|
||||
companion object {
|
||||
private val formatter = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss").also { it.timeZone = TimeZone.getTimeZone("UTC")}
|
||||
fun reportBuildStatInFile(
|
||||
private val formatter = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss").also { it.timeZone = TimeZone.getTimeZone("UTC") }
|
||||
fun <B : BuildTime, P : BuildPerformanceMetric> reportBuildStatInFile(
|
||||
buildReportDir: File,
|
||||
projectName: String,
|
||||
includeMetricsInReport: Boolean,
|
||||
buildData: List<CompileStatisticsData>,
|
||||
buildData: List<CompileStatisticsData<B, P>>,
|
||||
startParameters: BuildStartParameters,
|
||||
failureMessages: List<String>,
|
||||
logger: KotlinLogger
|
||||
logger: KotlinLogger,
|
||||
) {
|
||||
val ts = SimpleDateFormat("yyyy-MM-dd-HH-mm-ss").format(Calendar.getInstance().time)
|
||||
val reportFile = buildReportDir.resolve("$projectName-build-$ts.txt")
|
||||
|
||||
FileReportService(
|
||||
FileReportService<B, P>(
|
||||
outputFile = reportFile,
|
||||
printMetrics = includeMetricsInReport,
|
||||
logger = logger
|
||||
@@ -45,9 +45,9 @@ class FileReportService(
|
||||
private lateinit var p: Printer
|
||||
|
||||
fun process(
|
||||
statisticsData: List<CompileStatisticsData>,
|
||||
statisticsData: List<CompileStatisticsData<B, P>>,
|
||||
startParameters: BuildStartParameters,
|
||||
failureMessages: List<String> = emptyList()
|
||||
failureMessages: List<String> = emptyList(),
|
||||
) {
|
||||
val buildReportPath = outputFile.toPath().toUri().toString()
|
||||
try {
|
||||
@@ -69,9 +69,9 @@ class FileReportService(
|
||||
}
|
||||
|
||||
private fun printBuildReport(
|
||||
statisticsData: List<CompileStatisticsData>,
|
||||
statisticsData: List<CompileStatisticsData<B, P>>,
|
||||
startParameters: BuildStartParameters,
|
||||
failureMessages: List<String>
|
||||
failureMessages: List<String>,
|
||||
) {
|
||||
// NOTE: BuildExecutionData / BuildOperationRecord contains data for both tasks and transforms.
|
||||
// Where possible, we still use the term "tasks" because saying "tasks/transforms" is a bit verbose and "build operations" may sound
|
||||
@@ -80,13 +80,13 @@ class FileReportService(
|
||||
printBuildInfo(startParameters, failureMessages)
|
||||
if (printMetrics && statisticsData.isNotEmpty()) {
|
||||
printMetrics(
|
||||
statisticsData.map { it.buildTimesMetrics }.reduce { agg, value ->
|
||||
statisticsData.map { it.getBuildTimesMetrics() }.reduce { agg, value ->
|
||||
(agg.keys + value.keys).associateWith { (agg[it] ?: 0) + (value[it] ?: 0) }
|
||||
},
|
||||
statisticsData.map { it.performanceMetrics }.reduce { agg, value ->
|
||||
statisticsData.map { it.getPerformanceMetrics() }.reduce { agg, value ->
|
||||
(agg.keys + value.keys).associateWith { (agg[it] ?: 0) + (value[it] ?: 0) }
|
||||
},
|
||||
statisticsData.map { it.nonIncrementalAttributes.asSequence() }.reduce { agg, value -> agg + value }.toList(),
|
||||
statisticsData.map { it.getNonIncrementalAttributes().asSequence() }.reduce { agg, value -> agg + value }.toList(),
|
||||
aggregatedMetric = true
|
||||
)
|
||||
p.println()
|
||||
@@ -114,12 +114,12 @@ class FileReportService(
|
||||
}
|
||||
|
||||
private fun printMetrics(
|
||||
buildTimesMetrics: Map<BuildTime, Long>,
|
||||
performanceMetrics: Map<BuildPerformanceMetric, Long>,
|
||||
buildTimesMetrics: Map<out BuildTime, Long>,
|
||||
performanceMetrics: Map<out BuildPerformanceMetric, Long>,
|
||||
nonIncrementalAttributes: Collection<BuildAttribute>,
|
||||
gcTimeMetrics: Map<String, Long>? = emptyMap(),
|
||||
gcCountMetrics: Map<String, Long>? = emptyMap(),
|
||||
aggregatedMetric: Boolean = false
|
||||
aggregatedMetric: Boolean = false,
|
||||
) {
|
||||
printBuildTimes(buildTimesMetrics)
|
||||
if (aggregatedMetric) p.println()
|
||||
@@ -129,7 +129,7 @@ class FileReportService(
|
||||
|
||||
printBuildAttributes(nonIncrementalAttributes)
|
||||
|
||||
//TODO: KT-57310 Implement build GC metric in
|
||||
//TODO: KT-57310 Implement build GC metric in
|
||||
if (!aggregatedMetric) {
|
||||
printGcMetrics(gcTimeMetrics, gcCountMetrics)
|
||||
}
|
||||
@@ -137,7 +137,7 @@ class FileReportService(
|
||||
|
||||
private fun printGcMetrics(
|
||||
gcTimeMetrics: Map<String, Long>?,
|
||||
gcCountMetrics: Map<String, Long>?
|
||||
gcCountMetrics: Map<String, Long>?,
|
||||
) {
|
||||
val keys = HashSet<String>()
|
||||
gcCountMetrics?.keys?.also { keys.addAll(it) }
|
||||
@@ -155,7 +155,7 @@ class FileReportService(
|
||||
}
|
||||
}
|
||||
|
||||
private fun printBuildTimes(buildTimes: Map<BuildTime, Long>) {
|
||||
private fun printBuildTimes(buildTimes: Map<out BuildTime, Long>) {
|
||||
if (buildTimes.isEmpty()) return
|
||||
|
||||
p.println("Time metrics:")
|
||||
@@ -166,29 +166,29 @@ class FileReportService(
|
||||
|
||||
val timeMs = buildTimes[buildTime]
|
||||
if (timeMs != null) {
|
||||
p.println("${buildTime.readableString}: ${formatTime(timeMs)}")
|
||||
p.println("${buildTime.getReadableString()}: ${formatTime(timeMs)}")
|
||||
p.withIndent {
|
||||
BuildTime.children[buildTime]?.forEach { printBuildTime(it) }
|
||||
buildTime.children()?.forEach { printBuildTime(it) }
|
||||
}
|
||||
} else {
|
||||
//Skip formatting if parent metric does not set
|
||||
BuildTime.children[buildTime]?.forEach { printBuildTime(it) }
|
||||
buildTime.children()?.forEach { printBuildTime(it) }
|
||||
}
|
||||
}
|
||||
|
||||
for (buildTime in BuildTime.values()) {
|
||||
if (buildTime.parent != null) continue
|
||||
for (buildTime in buildTimes.keys.first().getAllMetrics()) {
|
||||
if (buildTime.getParent() != null) continue
|
||||
|
||||
printBuildTime(buildTime)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun printBuildPerformanceMetrics(buildMetrics: Map<BuildPerformanceMetric, Long>) {
|
||||
private fun printBuildPerformanceMetrics(buildMetrics: Map<out BuildPerformanceMetric, Long>) {
|
||||
if (buildMetrics.isEmpty()) return
|
||||
|
||||
p.withIndent("Size metrics:") {
|
||||
for (metric in BuildPerformanceMetric.values()) {
|
||||
for (metric in buildMetrics.keys.first().getAllMetrics()) {
|
||||
buildMetrics[metric]?.let { printSizeMetric(metric, it) }
|
||||
}
|
||||
}
|
||||
@@ -197,10 +197,10 @@ class FileReportService(
|
||||
private fun printSizeMetric(sizeMetric: BuildPerformanceMetric, value: Long) {
|
||||
fun BuildPerformanceMetric.numberOfAncestors(): Int {
|
||||
var count = 0
|
||||
var parent: BuildPerformanceMetric? = parent
|
||||
var parent: BuildPerformanceMetric? = getParent()
|
||||
while (parent != null) {
|
||||
count++
|
||||
parent = parent.parent
|
||||
parent = parent.getParent()
|
||||
}
|
||||
return count
|
||||
}
|
||||
@@ -208,12 +208,12 @@ class FileReportService(
|
||||
val indentLevel = sizeMetric.numberOfAncestors()
|
||||
|
||||
repeat(indentLevel) { p.pushIndent() }
|
||||
when (sizeMetric.type) {
|
||||
ValueType.BYTES -> p.println("${sizeMetric.readableString}: ${formatSize(value)}")
|
||||
ValueType.NUMBER -> p.println("${sizeMetric.readableString}: $value")
|
||||
ValueType.NANOSECONDS -> p.println("${sizeMetric.readableString}: $value")
|
||||
ValueType.MILLISECONDS -> p.println("${sizeMetric.readableString}: ${formatTime(value)}")
|
||||
ValueType.TIME -> p.println("${sizeMetric.readableString}: ${formatter.format(value)}")
|
||||
when (sizeMetric.getType()) {
|
||||
ValueType.BYTES -> p.println("${sizeMetric.getReadableString()}: ${formatSize(value)}")
|
||||
ValueType.NUMBER -> p.println("${sizeMetric.getReadableString()}: $value")
|
||||
ValueType.NANOSECONDS -> p.println("${sizeMetric.getReadableString()}: $value")
|
||||
ValueType.MILLISECONDS -> p.println("${sizeMetric.getReadableString()}: ${formatTime(value)}")
|
||||
ValueType.TIME -> p.println("${sizeMetric.getReadableString()}: ${formatter.format(value)}")
|
||||
}
|
||||
repeat(indentLevel) { p.popIndent() }
|
||||
}
|
||||
@@ -230,16 +230,16 @@ class FileReportService(
|
||||
}
|
||||
}
|
||||
|
||||
private fun printTaskOverview(statisticsData: Collection<CompileStatisticsData>) {
|
||||
private fun printTaskOverview(statisticsData: Collection<CompileStatisticsData<B, P>>) {
|
||||
var allTasksTimeMs = 0L
|
||||
var kotlinTotalTimeMs = 0L
|
||||
val kotlinTasks = ArrayList<CompileStatisticsData>()
|
||||
val kotlinTasks = ArrayList<CompileStatisticsData<B, P>>()
|
||||
|
||||
for (task in statisticsData) {
|
||||
val taskTimeMs = task.durationMs
|
||||
val taskTimeMs = task.getDurationMs()
|
||||
allTasksTimeMs += taskTimeMs
|
||||
|
||||
if (task.fromKotlinPlugin == true) {
|
||||
if (task.getFromKotlinPlugin() == true) {
|
||||
kotlinTotalTimeMs += taskTimeMs
|
||||
kotlinTasks.add(task)
|
||||
}
|
||||
@@ -254,45 +254,47 @@ class FileReportService(
|
||||
p.println("Total time for Kotlin tasks: ${formatTime(kotlinTotalTimeMs)} ($ktTaskPercent % of all tasks time)")
|
||||
|
||||
val table = TextTable("Time", "% of Kotlin time", "Task")
|
||||
for (task in kotlinTasks.sortedWith(compareBy({ -it.durationMs }, { it.startTimeMs }))) {
|
||||
val timeMs = task.durationMs
|
||||
for (task in kotlinTasks.sortedWith(compareBy({ -it.getDurationMs() }, { it.getStartTimeMs() }))) {
|
||||
val timeMs = task.getDurationMs()
|
||||
val percent = (timeMs.toDouble() / kotlinTotalTimeMs * 100).asString(1)
|
||||
table.addRow(formatTime(timeMs), "$percent %", task.taskName)
|
||||
table.addRow(formatTime(timeMs), "$percent %", task.getTaskName())
|
||||
}
|
||||
table.printTo(p)
|
||||
p.println()
|
||||
}
|
||||
|
||||
private fun printTasksLog(statisticsData: List<CompileStatisticsData>) {
|
||||
for (task in statisticsData.sortedWith(compareBy({ -it.durationMs }, { it.startTimeMs }))) {
|
||||
private fun printTasksLog(statisticsData: List<CompileStatisticsData<B, P>>) {
|
||||
for (task in statisticsData.sortedWith(compareBy({ -it.getDurationMs() }, { it.getStartTimeMs() }))) {
|
||||
printTaskLog(task)
|
||||
p.println()
|
||||
}
|
||||
}
|
||||
|
||||
private fun printTaskLog(statisticsData: CompileStatisticsData) {
|
||||
val skipMessage = statisticsData.skipMessage
|
||||
private fun <B : BuildTime, P : BuildPerformanceMetric> printTaskLog(statisticsData: CompileStatisticsData<B, P>) {
|
||||
val skipMessage = statisticsData.getSkipMessage()
|
||||
if (skipMessage != null) {
|
||||
p.println("Task '${statisticsData.taskName}' was skipped: $skipMessage")
|
||||
p.println("Task '${statisticsData.getTaskName()}' was skipped: $skipMessage")
|
||||
} else {
|
||||
p.println("Task '${statisticsData.taskName}' finished in ${formatTime(statisticsData.durationMs)}")
|
||||
p.println("Task '${statisticsData.getTaskName()}' finished in ${formatTime(statisticsData.getDurationMs())}")
|
||||
}
|
||||
|
||||
statisticsData.kotlinLanguageVersion?.also {
|
||||
statisticsData.getKotlinLanguageVersion()?.also {
|
||||
p.withIndent("Task info:") {
|
||||
p.println("Kotlin language version: $it")
|
||||
}
|
||||
}
|
||||
|
||||
if (statisticsData.icLogLines.isNotEmpty()) {
|
||||
p.withIndent("Compilation log for task '${statisticsData.taskName}':") {
|
||||
statisticsData.icLogLines.forEach { p.println(it) }
|
||||
if (statisticsData.getIcLogLines().isNotEmpty()) {
|
||||
p.withIndent("Compilation log for task '${statisticsData.getTaskName()}':") {
|
||||
statisticsData.getIcLogLines().forEach { p.println(it) }
|
||||
}
|
||||
}
|
||||
|
||||
if (printMetrics) {
|
||||
printMetrics(statisticsData.buildTimesMetrics, statisticsData.performanceMetrics, statisticsData.nonIncrementalAttributes,
|
||||
statisticsData.gcTimeMetrics, statisticsData.gcCountMetrics)
|
||||
printMetrics(
|
||||
statisticsData.getBuildTimesMetrics(), statisticsData.getPerformanceMetrics(), statisticsData.getNonIncrementalAttributes(),
|
||||
statisticsData.getGcTimeMetrics(), statisticsData.getGcCountMetrics()
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -23,6 +23,8 @@ import com.intellij.openapi.vfs.impl.jar.CoreJarFileSystem
|
||||
import org.jetbrains.kotlin.build.DEFAULT_KOTLIN_SOURCE_FILES_EXTENSIONS
|
||||
import org.jetbrains.kotlin.build.report.RemoteBuildReporter
|
||||
import org.jetbrains.kotlin.build.report.info
|
||||
import org.jetbrains.kotlin.build.report.metrics.GradleBuildPerformanceMetric
|
||||
import org.jetbrains.kotlin.build.report.metrics.GradleBuildTime
|
||||
import org.jetbrains.kotlin.build.report.metrics.endMeasureGc
|
||||
import org.jetbrains.kotlin.build.report.metrics.startMeasureGc
|
||||
import org.jetbrains.kotlin.cli.common.CLICompiler
|
||||
@@ -294,7 +296,7 @@ abstract class CompileServiceImplBase(
|
||||
createMessageCollector: (ServicesFacadeT, CompilationOptions) -> MessageCollector,
|
||||
createReporter: (ServicesFacadeT, CompilationOptions) -> DaemonMessageReporter,
|
||||
createServices: (JpsServicesFacadeT, EventManager, Profiler) -> Services,
|
||||
getICReporter: (ServicesFacadeT, CompilationResultsT?, IncrementalCompilationOptions) -> RemoteBuildReporter
|
||||
getICReporter: (ServicesFacadeT, CompilationResultsT?, IncrementalCompilationOptions) -> RemoteBuildReporter<GradleBuildTime, GradleBuildPerformanceMetric>
|
||||
) = kotlin.run {
|
||||
val messageCollector = createMessageCollector(servicesFacade, compilationOptions)
|
||||
val daemonReporter = createReporter(servicesFacade, compilationOptions)
|
||||
@@ -532,7 +534,7 @@ abstract class CompileServiceImplBase(
|
||||
args: K2JSCompilerArguments,
|
||||
incrementalCompilationOptions: IncrementalCompilationOptions,
|
||||
compilerMessageCollector: MessageCollector,
|
||||
reporter: RemoteBuildReporter
|
||||
reporter: RemoteBuildReporter<GradleBuildTime, GradleBuildPerformanceMetric>
|
||||
): ExitCode {
|
||||
reporter.startMeasureGc()
|
||||
val allKotlinFiles = arrayListOf<File>()
|
||||
@@ -577,7 +579,7 @@ abstract class CompileServiceImplBase(
|
||||
k2jvmArgs: K2JVMCompilerArguments,
|
||||
incrementalCompilationOptions: IncrementalCompilationOptions,
|
||||
compilerMessageCollector: MessageCollector,
|
||||
reporter: RemoteBuildReporter
|
||||
reporter: RemoteBuildReporter<GradleBuildTime, GradleBuildPerformanceMetric>
|
||||
): ExitCode {
|
||||
reporter.startMeasureGc()
|
||||
val allKotlinExtensions = (DEFAULT_KOTLIN_SOURCE_FILES_EXTENSIONS +
|
||||
|
||||
+5
-3
@@ -6,17 +6,19 @@
|
||||
package org.jetbrains.kotlin.daemon.report
|
||||
|
||||
import org.jetbrains.kotlin.build.report.metrics.BuildMetricsReporter
|
||||
import org.jetbrains.kotlin.build.report.metrics.GradleBuildPerformanceMetric
|
||||
import org.jetbrains.kotlin.build.report.metrics.GradleBuildTime
|
||||
import org.jetbrains.kotlin.build.report.metrics.RemoteBuildMetricsReporter
|
||||
import org.jetbrains.kotlin.daemon.common.CompilationResultCategory
|
||||
import org.jetbrains.kotlin.daemon.common.CompilationResults
|
||||
|
||||
class RemoteBuildMetricsReporterAdapter(
|
||||
private val delegate: BuildMetricsReporter,
|
||||
private val delegate: BuildMetricsReporter<GradleBuildTime, GradleBuildPerformanceMetric>,
|
||||
private val shouldReport: Boolean,
|
||||
private val compilationResults: CompilationResults
|
||||
) :
|
||||
BuildMetricsReporter by delegate,
|
||||
RemoteBuildMetricsReporter {
|
||||
BuildMetricsReporter<GradleBuildTime, GradleBuildPerformanceMetric> by delegate,
|
||||
RemoteBuildMetricsReporter<GradleBuildTime, GradleBuildPerformanceMetric> {
|
||||
|
||||
override fun flush() {
|
||||
if (shouldReport) {
|
||||
|
||||
@@ -21,13 +21,15 @@ import org.jetbrains.kotlin.build.report.RemoteBuildReporter
|
||||
import org.jetbrains.kotlin.build.report.RemoteICReporter
|
||||
import org.jetbrains.kotlin.build.report.metrics.BuildMetricsReporterImpl
|
||||
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.daemon.common.*
|
||||
|
||||
fun getBuildReporter(
|
||||
servicesFacade: CompilerServicesFacadeBase,
|
||||
compilationResults: CompilationResults,
|
||||
compilationOptions: IncrementalCompilationOptions
|
||||
): RemoteBuildReporter {
|
||||
): RemoteBuildReporter<GradleBuildTime, GradleBuildPerformanceMetric> {
|
||||
val root = compilationOptions.modulesInfo.projectRoot
|
||||
val reporters = ArrayList<RemoteICReporter>()
|
||||
|
||||
|
||||
+22
-24
@@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+3
-1
@@ -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,
|
||||
|
||||
+3
-1
@@ -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,
|
||||
|
||||
+9
-9
@@ -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)
|
||||
|
||||
+5
-7
@@ -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()
|
||||
}
|
||||
}
|
||||
|
||||
+12
-14
@@ -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>
|
||||
|
||||
+4
-2
@@ -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)
|
||||
|
||||
+4
-3
@@ -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
|
||||
}
|
||||
|
||||
+15
-18
@@ -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()
|
||||
)
|
||||
}
|
||||
|
||||
+8
-11
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
+4
-2
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user