diff --git a/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/internal/kapt/KaptWithoutKotlincTask.kt b/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/internal/kapt/KaptWithoutKotlincTask.kt index e2415988dc3..8cd5495ff15 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/internal/kapt/KaptWithoutKotlincTask.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/internal/kapt/KaptWithoutKotlincTask.kt @@ -320,7 +320,8 @@ private class KaptExecution @Inject constructor( detectMemoryLeaksMode, processingClassLoader, - disableClassloaderCacheForProcessors + disableClassloaderCacheForProcessors, + /*processorsPerfReportFile=*/null ) } diff --git a/plugins/kapt3/kapt3-base/src/org/jetbrains/kotlin/kapt3/base/KaptOptions.kt b/plugins/kapt3/kapt3-base/src/org/jetbrains/kotlin/kapt3/base/KaptOptions.kt index d58541ad76d..94c42e4da48 100644 --- a/plugins/kapt3/kapt3-base/src/org/jetbrains/kotlin/kapt3/base/KaptOptions.kt +++ b/plugins/kapt3/kapt3-base/src/org/jetbrains/kotlin/kapt3/base/KaptOptions.kt @@ -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 + val separateClassloaderForProcessors: Set, + 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 ) } } diff --git a/plugins/kapt3/kapt3-base/src/org/jetbrains/kotlin/kapt3/base/annotationProcessing.kt b/plugins/kapt3/kapt3-base/src/org/jetbrains/kotlin/kapt3/base/annotationProcessing.kt index b00181be0b5..ebd890ff47b 100644 --- a/plugins/kapt3/kapt3-base/src/org/jetbrains/kotlin/kapt3/base/annotationProcessing.kt +++ b/plugins/kapt3/kapt3-base/src/org/jetbrains/kotlin/kapt3/base/annotationProcessing.kt @@ -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, logg } } +private fun dumpProcessorTiming(wrappedProcessors: List, 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?, diff --git a/plugins/kapt3/kapt3-cli/src/KaptCliOption.kt b/plugins/kapt3/kapt3-cli/src/KaptCliOption.kt index 078989a315e..535b2911a6a 100644 --- a/plugins/kapt3/kapt3-cli/src/KaptCliOption.kt +++ b/plugins/kapt3/kapt3-cli/src/KaptCliOption.kt @@ -181,6 +181,13 @@ enum class KaptCliOption( cliToolOption = CliToolOption("-Kapt-show-processor-timings", FLAG) ), + DUMP_PROCESSOR_TIMINGS( + "dumpProcessorTimings", + "", + "Dump processor performance statistics to the specified file", + cliToolOption = CliToolOption("-Kapt-dump-processor-timings", VALUE) + ), + STRICT_MODE_OPTION( "strict", "true | false", diff --git a/plugins/kapt3/kapt3-compiler/src/org/jetbrains/kotlin/kapt3/Kapt3Plugin.kt b/plugins/kapt3/kapt3-compiler/src/org/jetbrains/kotlin/kapt3/Kapt3Plugin.kt index 36cb58f3d49..927aa1fd4f1 100644 --- a/plugins/kapt3/kapt3-compiler/src/org/jetbrains/kotlin/kapt3/Kapt3Plugin.kt +++ b/plugins/kapt3/kapt3-compiler/src/org/jetbrains/kotlin/kapt3/Kapt3Plugin.kt @@ -119,6 +119,7 @@ class Kapt3CommandLineProcessor : CommandLineProcessor { STRIP_METADATA_OPTION -> setFlag(KaptFlag.STRIP_METADATA, value) KEEP_KDOC_COMMENTS_IN_STUBS -> setFlag(KaptFlag.KEEP_KDOC_COMMENTS_IN_STUBS, 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) DETECT_MEMORY_LEAKS_OPTION -> setSelector(enumValues(), value) { detectMemoryLeaks = it }