[Kapt] Support dumping processors stats to a file

Using the option -Kapt-dump-processor-timings
This commit is contained in:
Udi Cohen
2021-04-02 14:17:43 -04:00
committed by Andrey Zinovyev
parent beba85a848
commit b8002cb54f
5 changed files with 28 additions and 3 deletions
@@ -42,7 +42,8 @@ class KaptOptions(
//if defined use it to run processors instead of creating new one
val processingClassLoader: ClassLoader?,
//construct new classloader for these processors instead of using one defined in processingClassLoader
val separateClassloaderForProcessors: Set<String>
val separateClassloaderForProcessors: Set<String>,
val processorsPerfReportFile: File?
) : KaptFlags {
override fun get(flag: KaptFlag) = flags[flag]
@@ -72,6 +73,7 @@ class KaptOptions(
var mode: AptMode = AptMode.WITH_COMPILATION
var detectMemoryLeaks: DetectMemoryLeaksMode = DetectMemoryLeaksMode.DEFAULT
var processorsPerfReportFile: File? = null
fun build(): KaptOptions {
val sourcesOutputDir = this.sourcesOutputDir ?: error("'sourcesOutputDir' must be set")
@@ -85,7 +87,8 @@ class KaptOptions(
processingClasspath, processors, processingOptions, javacOptions, KaptFlags.fromSet(flags),
mode, detectMemoryLeaks,
processingClassLoader = null,
separateClassloaderForProcessors = emptySet()
separateClassloaderForProcessors = emptySet(),
processorsPerfReportFile = processorsPerfReportFile
)
}
}
@@ -122,6 +122,8 @@ fun KaptContext.doAnnotationProcessing(
showProcessorTimings(wrappedProcessors, loggerFun)
}
options.processorsPerfReportFile?.let { dumpProcessorTiming(wrappedProcessors, options.processorsPerfReportFile, logger::info) }
if (logger.isVerbose) {
filer.displayState()
}
@@ -142,6 +144,17 @@ private fun showProcessorTimings(wrappedProcessors: List<ProcessorWrapper>, logg
}
}
private fun dumpProcessorTiming(wrappedProcessors: List<ProcessorWrapper>, apReportFile: File, logger: (String) -> Unit) {
logger("Dumping Kapt Annotation Processing performance report to ${apReportFile.absolutePath}")
apReportFile.writeText(buildString {
appendLine("Kapt Annotation Processing performance report:")
wrappedProcessors.forEach { processor ->
appendLine(processor.renderSpentTime())
}
})
}
private fun reportIfRunningNonIncrementally(
listener: MentionedTypesTaskListener?,
cacheManager: JavaClassCacheManager?,