Kapt: Add option for showing annotation processor timings (KT-28024)

This commit is contained in:
Yan Zhulanow
2018-11-06 16:40:33 +09:00
parent 9feb834d97
commit 5fd070a9b9
6 changed files with 27 additions and 4 deletions
@@ -343,6 +343,7 @@ class Kapt3KotlinGradleSubplugin : KotlinGradleSubplugin<KotlinCompile> {
pluginOptions += SubpluginOption("correctErrorTypes", "${kaptExtension.correctErrorTypes}") pluginOptions += SubpluginOption("correctErrorTypes", "${kaptExtension.correctErrorTypes}")
pluginOptions += SubpluginOption("mapDiagnosticLocations", "${kaptExtension.mapDiagnosticLocations}") pluginOptions += SubpluginOption("mapDiagnosticLocations", "${kaptExtension.mapDiagnosticLocations}")
pluginOptions += SubpluginOption("strictMode", "${kaptExtension.strictMode}") pluginOptions += SubpluginOption("strictMode", "${kaptExtension.strictMode}")
pluginOptions += SubpluginOption("showProcessorTimings", "${kaptExtension.showProcessorTimings}")
pluginOptions += SubpluginOption("detectMemoryLeaks", kaptExtension.detectMemoryLeaks) pluginOptions += SubpluginOption("detectMemoryLeaks", kaptExtension.detectMemoryLeaks)
pluginOptions += SubpluginOption("infoAsWarnings", "${project.isInfoAsWarnings()}") pluginOptions += SubpluginOption("infoAsWarnings", "${project.isInfoAsWarnings()}")
pluginOptions += FilesSubpluginOption("stubs", listOf(getKaptStubsDir())) pluginOptions += FilesSubpluginOption("stubs", listOf(getKaptStubsDir()))
@@ -33,6 +33,8 @@ open class KaptExtension {
open var strictMode: Boolean = false open var strictMode: Boolean = false
open var showProcessorTimings: Boolean = false
open var detectMemoryLeaks: String = "default" open var detectMemoryLeaks: String = "default"
@Deprecated("Use `annotationProcessor()` and `annotationProcessors()` instead") @Deprecated("Use `annotationProcessor()` and `annotationProcessors()` instead")
@@ -82,6 +82,7 @@ interface KaptFlags {
} }
enum class KaptFlag(val description: String) { enum class KaptFlag(val description: String) {
SHOW_PROCESSOR_TIMINGS("Show processor time"),
VERBOSE("Verbose mode"), VERBOSE("Verbose mode"),
INFO_AS_WARNINGS("Info as warnings"), INFO_AS_WARNINGS("Info as warnings"),
USE_LIGHT_ANALYSIS("Use light analysis"), USE_LIGHT_ANALYSIS("Use light analysis"),
@@ -11,6 +11,7 @@ import com.sun.tools.javac.processing.AnnotationProcessingError
import com.sun.tools.javac.processing.JavacFiler import com.sun.tools.javac.processing.JavacFiler
import com.sun.tools.javac.processing.JavacProcessingEnvironment import com.sun.tools.javac.processing.JavacProcessingEnvironment
import com.sun.tools.javac.tree.JCTree import com.sun.tools.javac.tree.JCTree
import org.jetbrains.kotlin.base.kapt3.KaptFlag
import org.jetbrains.kotlin.kapt3.base.util.KaptBaseError import org.jetbrains.kotlin.kapt3.base.util.KaptBaseError
import org.jetbrains.kotlin.kapt3.base.util.isJava9OrLater import org.jetbrains.kotlin.kapt3.base.util.isJava9OrLater
import org.jetbrains.kotlin.kapt3.base.util.measureTimeMillisWithResult import org.jetbrains.kotlin.kapt3.base.util.measureTimeMillisWithResult
@@ -68,12 +69,15 @@ fun KaptContext.doAnnotationProcessing(
if (logger.isVerbose) { if (logger.isVerbose) {
logger.info("Annotation processing complete, errors: $errorCount, warnings: $warningCount") logger.info("Annotation processing complete, errors: $errorCount, warnings: $warningCount")
}
logger.info("Annotation processor stats:") val showProcessorTimings = options[KaptFlag.SHOW_PROCESSOR_TIMINGS]
wrappedProcessors.forEach { processor -> if (logger.isVerbose || showProcessorTimings) {
logger.info(processor.renderSpentTime()) val loggerFun = if (showProcessorTimings) logger::warn else logger::info
} showProcessorTimings(wrappedProcessors, loggerFun)
}
if (logger.isVerbose) {
filer.displayState() filer.displayState()
} }
@@ -86,6 +90,13 @@ fun KaptContext.doAnnotationProcessing(
} }
} }
private fun showProcessorTimings(wrappedProcessors: List<ProcessorWrapper>, logger: (String) -> Unit) {
logger("Annotation processor stats:")
wrappedProcessors.forEach { processor ->
logger(processor.renderSpentTime())
}
}
private class ProcessorWrapper(private val delegate: Processor) : Processor by delegate { private class ProcessorWrapper(private val delegate: Processor) : Processor by delegate {
private var initTime: Long = 0 private var initTime: Long = 0
private val roundTime = mutableListOf<Long>() private val roundTime = mutableListOf<Long>()
@@ -134,6 +134,13 @@ enum class KaptCliOption(
cliToolOption = CliToolOption("-Kapt-verbose", FLAG) cliToolOption = CliToolOption("-Kapt-verbose", FLAG)
), ),
SHOW_PROCESSOR_TIMINGS(
"showProcessorTimings",
"true | false",
"Show processor timings",
cliToolOption = CliToolOption("-Kapt-show-processor-timings", FLAG)
),
STRICT_MODE_OPTION( STRICT_MODE_OPTION(
"strict", "strict",
"true | false", "true | false",
@@ -108,6 +108,7 @@ class Kapt3CommandLineProcessor : CommandLineProcessor {
MAP_DIAGNOSTIC_LOCATIONS_OPTION -> setFlag(KaptFlag.MAP_DIAGNOSTIC_LOCATIONS, value) MAP_DIAGNOSTIC_LOCATIONS_OPTION -> setFlag(KaptFlag.MAP_DIAGNOSTIC_LOCATIONS, value)
INFO_AS_WARNINGS_OPTION -> setFlag(KaptFlag.INFO_AS_WARNINGS, value) INFO_AS_WARNINGS_OPTION -> setFlag(KaptFlag.INFO_AS_WARNINGS, value)
STRICT_MODE_OPTION -> setFlag(KaptFlag.STRICT, value) STRICT_MODE_OPTION -> setFlag(KaptFlag.STRICT, value)
SHOW_PROCESSOR_TIMINGS -> setFlag(KaptFlag.SHOW_PROCESSOR_TIMINGS, value)
DETECT_MEMORY_LEAKS_OPTION -> setSelector(enumValues<DetectMemoryLeaksMode>(), value) { detectMemoryLeaks = it } DETECT_MEMORY_LEAKS_OPTION -> setSelector(enumValues<DetectMemoryLeaksMode>(), value) { detectMemoryLeaks = it }
APT_MODE_OPTION -> setSelector(enumValues<AptMode>(), value) { mode = it } APT_MODE_OPTION -> setSelector(enumValues<AptMode>(), value) { mode = it }