Kapt: Add option for showing annotation processor timings (KT-28024)
This commit is contained in:
+1
@@ -343,6 +343,7 @@ class Kapt3KotlinGradleSubplugin : KotlinGradleSubplugin<KotlinCompile> {
|
||||
pluginOptions += SubpluginOption("correctErrorTypes", "${kaptExtension.correctErrorTypes}")
|
||||
pluginOptions += SubpluginOption("mapDiagnosticLocations", "${kaptExtension.mapDiagnosticLocations}")
|
||||
pluginOptions += SubpluginOption("strictMode", "${kaptExtension.strictMode}")
|
||||
pluginOptions += SubpluginOption("showProcessorTimings", "${kaptExtension.showProcessorTimings}")
|
||||
pluginOptions += SubpluginOption("detectMemoryLeaks", kaptExtension.detectMemoryLeaks)
|
||||
pluginOptions += SubpluginOption("infoAsWarnings", "${project.isInfoAsWarnings()}")
|
||||
pluginOptions += FilesSubpluginOption("stubs", listOf(getKaptStubsDir()))
|
||||
|
||||
+2
@@ -32,6 +32,8 @@ open class KaptExtension {
|
||||
open var mapDiagnosticLocations: Boolean = false
|
||||
|
||||
open var strictMode: Boolean = false
|
||||
|
||||
open var showProcessorTimings: Boolean = false
|
||||
|
||||
open var detectMemoryLeaks: String = "default"
|
||||
|
||||
|
||||
@@ -82,6 +82,7 @@ interface KaptFlags {
|
||||
}
|
||||
|
||||
enum class KaptFlag(val description: String) {
|
||||
SHOW_PROCESSOR_TIMINGS("Show processor time"),
|
||||
VERBOSE("Verbose mode"),
|
||||
INFO_AS_WARNINGS("Info as warnings"),
|
||||
USE_LIGHT_ANALYSIS("Use light analysis"),
|
||||
|
||||
+15
-4
@@ -11,6 +11,7 @@ import com.sun.tools.javac.processing.AnnotationProcessingError
|
||||
import com.sun.tools.javac.processing.JavacFiler
|
||||
import com.sun.tools.javac.processing.JavacProcessingEnvironment
|
||||
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.isJava9OrLater
|
||||
import org.jetbrains.kotlin.kapt3.base.util.measureTimeMillisWithResult
|
||||
@@ -68,12 +69,15 @@ fun KaptContext.doAnnotationProcessing(
|
||||
|
||||
if (logger.isVerbose) {
|
||||
logger.info("Annotation processing complete, errors: $errorCount, warnings: $warningCount")
|
||||
}
|
||||
|
||||
logger.info("Annotation processor stats:")
|
||||
wrappedProcessors.forEach { processor ->
|
||||
logger.info(processor.renderSpentTime())
|
||||
}
|
||||
val showProcessorTimings = options[KaptFlag.SHOW_PROCESSOR_TIMINGS]
|
||||
if (logger.isVerbose || showProcessorTimings) {
|
||||
val loggerFun = if (showProcessorTimings) logger::warn else logger::info
|
||||
showProcessorTimings(wrappedProcessors, loggerFun)
|
||||
}
|
||||
|
||||
if (logger.isVerbose) {
|
||||
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 var initTime: Long = 0
|
||||
private val roundTime = mutableListOf<Long>()
|
||||
|
||||
@@ -134,6 +134,13 @@ enum class KaptCliOption(
|
||||
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",
|
||||
"true | false",
|
||||
|
||||
@@ -108,6 +108,7 @@ class Kapt3CommandLineProcessor : CommandLineProcessor {
|
||||
MAP_DIAGNOSTIC_LOCATIONS_OPTION -> setFlag(KaptFlag.MAP_DIAGNOSTIC_LOCATIONS, value)
|
||||
INFO_AS_WARNINGS_OPTION -> setFlag(KaptFlag.INFO_AS_WARNINGS, 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 }
|
||||
APT_MODE_OPTION -> setSelector(enumValues<AptMode>(), value) { mode = it }
|
||||
|
||||
Reference in New Issue
Block a user