Kapt: Log annotation processor initialization time

This commit is contained in:
Yan Zhulanow
2018-10-16 22:37:01 +03:00
parent 6d017f07ad
commit 0ae5d1c08f
@@ -15,10 +15,13 @@ import org.jetbrains.kotlin.kapt3.base.util.KaptBaseError
import org.jetbrains.kotlin.kapt3.base.util.isJava9OrLater
import org.jetbrains.kotlin.kapt3.base.util.measureTimeMillisWithResult
import java.io.File
import javax.annotation.processing.ProcessingEnvironment
import javax.annotation.processing.Processor
import javax.annotation.processing.RoundEnvironment
import javax.lang.model.SourceVersion
import javax.lang.model.element.TypeElement
import javax.tools.JavaFileObject
import kotlin.system.measureTimeMillis
import com.sun.tools.javac.util.List as JavacList
fun KaptContext.doAnnotationProcessing(
@@ -69,11 +72,7 @@ fun KaptContext.doAnnotationProcessing(
logger.info("Annotation processor stats:")
wrappedProcessors.forEach { processor ->
val rounds = processor.rounds
val roundMs = rounds.joinToString { "$it ms" }
val totalMs = rounds.sum()
logger.info("${processor.name}: ${rounds.size} rounds ($roundMs), $totalMs ms in total")
logger.info(processor.renderSpentTime())
}
filer.displayState()
@@ -89,19 +88,51 @@ fun KaptContext.doAnnotationProcessing(
}
private class ProcessorWrapper(private val delegate: Processor) : Processor by delegate {
val rounds = mutableListOf<Long>()
val name: String
get() = delegate.javaClass.simpleName
private var initTime: Long = 0
private val roundTime = mutableListOf<Long>()
override fun process(annotations: MutableSet<out TypeElement>?, roundEnv: RoundEnvironment?): Boolean {
val (time, result) = measureTimeMillisWithResult {
delegate.process(annotations, roundEnv)
}
rounds += time
roundTime += time
return result
}
override fun init(processingEnv: ProcessingEnvironment?) {
initTime += measureTimeMillis {
delegate.init(processingEnv)
}
}
override fun getSupportedOptions(): MutableSet<String> {
val (time, result) = measureTimeMillisWithResult { delegate.supportedOptions }
initTime += time
return result
}
override fun getSupportedSourceVersion(): SourceVersion {
val (time, result) = measureTimeMillisWithResult { delegate.supportedSourceVersion }
initTime += time
return result
}
override fun getSupportedAnnotationTypes(): MutableSet<String> {
val (time, result) = measureTimeMillisWithResult { delegate.supportedAnnotationTypes }
initTime += time
return result
}
fun renderSpentTime(): String {
val processorName = delegate.javaClass.simpleName
val totalTime = initTime + roundTime.sum()
return "$processorName: " +
"total: $totalTime ms, " +
"init: $initTime ms, " +
"${roundTime.size} round(s): ${roundTime.joinToString { "$it ms" }}"
}
}
fun KaptContext.parseJavaFiles(javaSourceFiles: List<File>): JavacList<JCTree.JCCompilationUnit> {