[IC] Measure time metrics in CompilationTransaction

#KT-49785 In Progress
This commit is contained in:
Alexander Likhachev
2022-11-17 19:52:12 +01:00
committed by Space Team
parent 742e240bdc
commit 5461667421
2 changed files with 27 additions and 15 deletions
@@ -18,7 +18,9 @@ enum class BuildTime(val parent: BuildTime? = null, val readableString: String)
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"),
@@ -6,6 +6,8 @@
package org.jetbrains.kotlin.incremental
import org.jetbrains.kotlin.build.report.BuildReporter
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.compilerRunner.OutputItemsCollector
import org.jetbrains.kotlin.konan.file.use
@@ -54,11 +56,13 @@ class RecoverableCompilationTransaction(
override fun registerAddedOrChangedFile(outputFile: Path) {
if (fileRelocationIsAlreadyRegisteredFor(outputFile)) return
if (Files.exists(outputFile)) {
stashFile(outputFile)
} else {
reporter.warn { "Marking the $outputFile file as newly added" }
fileRelocationRegistry[outputFile] = null
reporter.measure(BuildTime.PRECISE_BACKUP_OUTPUT) {
if (Files.exists(outputFile)) {
stashFile(outputFile)
} else {
reporter.warn { "Marking the $outputFile file as newly added" }
fileRelocationRegistry[outputFile] = null
}
}
}
@@ -70,7 +74,9 @@ class RecoverableCompilationTransaction(
}
return
}
stashFile(outputFile)
reporter.measure(BuildTime.PRECISE_BACKUP_OUTPUT) {
stashFile(outputFile)
}
}
private fun stashFile(outputFile: Path) {
@@ -86,22 +92,26 @@ class RecoverableCompilationTransaction(
private fun revertChanges() {
reporter.warn { "Reverting changes" }
for ((originPath, relocatedPath) in fileRelocationRegistry) {
if (relocatedPath == null) {
if (Files.exists(originPath)) {
Files.delete(originPath)
reporter.measure(BuildTime.RESTORE_OUTPUT_FROM_BACKUP) {
for ((originPath, relocatedPath) in fileRelocationRegistry) {
if (relocatedPath == null) {
if (Files.exists(originPath)) {
Files.delete(originPath)
}
continue
}
continue
Files.move(relocatedPath, originPath, StandardCopyOption.REPLACE_EXISTING)
}
Files.move(relocatedPath, originPath, StandardCopyOption.REPLACE_EXISTING)
}
}
private fun cleanupStash() {
reporter.warn { "Cleaning up stash" }
Files.walk(stashDir).use {
it.sorted(Comparator.reverseOrder())
.forEach(Files::delete)
reporter.measure(BuildTime.CLEAN_BACKUP_STASH) {
Files.walk(stashDir).use {
it.sorted(Comparator.reverseOrder())
.forEach(Files::delete)
}
}
}