[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
@@ -320,7 +320,8 @@ private class KaptExecution @Inject constructor(
detectMemoryLeaksMode, detectMemoryLeaksMode,
processingClassLoader, processingClassLoader,
disableClassloaderCacheForProcessors disableClassloaderCacheForProcessors,
/*processorsPerfReportFile=*/null
) )
} }
@@ -42,7 +42,8 @@ class KaptOptions(
//if defined use it to run processors instead of creating new one //if defined use it to run processors instead of creating new one
val processingClassLoader: ClassLoader?, val processingClassLoader: ClassLoader?,
//construct new classloader for these processors instead of using one defined in processingClassLoader //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 { ) : KaptFlags {
override fun get(flag: KaptFlag) = flags[flag] override fun get(flag: KaptFlag) = flags[flag]
@@ -72,6 +73,7 @@ class KaptOptions(
var mode: AptMode = AptMode.WITH_COMPILATION var mode: AptMode = AptMode.WITH_COMPILATION
var detectMemoryLeaks: DetectMemoryLeaksMode = DetectMemoryLeaksMode.DEFAULT var detectMemoryLeaks: DetectMemoryLeaksMode = DetectMemoryLeaksMode.DEFAULT
var processorsPerfReportFile: File? = null
fun build(): KaptOptions { fun build(): KaptOptions {
val sourcesOutputDir = this.sourcesOutputDir ?: error("'sourcesOutputDir' must be set") val sourcesOutputDir = this.sourcesOutputDir ?: error("'sourcesOutputDir' must be set")
@@ -85,7 +87,8 @@ class KaptOptions(
processingClasspath, processors, processingOptions, javacOptions, KaptFlags.fromSet(flags), processingClasspath, processors, processingOptions, javacOptions, KaptFlags.fromSet(flags),
mode, detectMemoryLeaks, mode, detectMemoryLeaks,
processingClassLoader = null, processingClassLoader = null,
separateClassloaderForProcessors = emptySet() separateClassloaderForProcessors = emptySet(),
processorsPerfReportFile = processorsPerfReportFile
) )
} }
} }
@@ -122,6 +122,8 @@ fun KaptContext.doAnnotationProcessing(
showProcessorTimings(wrappedProcessors, loggerFun) showProcessorTimings(wrappedProcessors, loggerFun)
} }
options.processorsPerfReportFile?.let { dumpProcessorTiming(wrappedProcessors, options.processorsPerfReportFile, logger::info) }
if (logger.isVerbose) { if (logger.isVerbose) {
filer.displayState() 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( private fun reportIfRunningNonIncrementally(
listener: MentionedTypesTaskListener?, listener: MentionedTypesTaskListener?,
cacheManager: JavaClassCacheManager?, cacheManager: JavaClassCacheManager?,
@@ -181,6 +181,13 @@ enum class KaptCliOption(
cliToolOption = CliToolOption("-Kapt-show-processor-timings", FLAG) cliToolOption = CliToolOption("-Kapt-show-processor-timings", FLAG)
), ),
DUMP_PROCESSOR_TIMINGS(
"dumpProcessorTimings",
"<path>",
"Dump processor performance statistics to the specified file",
cliToolOption = CliToolOption("-Kapt-dump-processor-timings", VALUE)
),
STRICT_MODE_OPTION( STRICT_MODE_OPTION(
"strict", "strict",
"true | false", "true | false",
@@ -119,6 +119,7 @@ class Kapt3CommandLineProcessor : CommandLineProcessor {
STRIP_METADATA_OPTION -> setFlag(KaptFlag.STRIP_METADATA, value) STRIP_METADATA_OPTION -> setFlag(KaptFlag.STRIP_METADATA, value)
KEEP_KDOC_COMMENTS_IN_STUBS -> setFlag(KaptFlag.KEEP_KDOC_COMMENTS_IN_STUBS, value) KEEP_KDOC_COMMENTS_IN_STUBS -> setFlag(KaptFlag.KEEP_KDOC_COMMENTS_IN_STUBS, value)
SHOW_PROCESSOR_TIMINGS -> setFlag(KaptFlag.SHOW_PROCESSOR_TIMINGS, value) SHOW_PROCESSOR_TIMINGS -> setFlag(KaptFlag.SHOW_PROCESSOR_TIMINGS, value)
DUMP_PROCESSOR_TIMINGS -> processorsPerfReportFile = File(value)
INCLUDE_COMPILE_CLASSPATH -> setFlag(KaptFlag.INCLUDE_COMPILE_CLASSPATH, value) INCLUDE_COMPILE_CLASSPATH -> setFlag(KaptFlag.INCLUDE_COMPILE_CLASSPATH, value)
DETECT_MEMORY_LEAKS_OPTION -> setSelector(enumValues<DetectMemoryLeaksMode>(), value) { detectMemoryLeaks = it } DETECT_MEMORY_LEAKS_OPTION -> setSelector(enumValues<DetectMemoryLeaksMode>(), value) { detectMemoryLeaks = it }