Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class KaptOptions(

val mode: AptMode,
val detectMemoryLeaks: DetectMemoryLeaksMode,
val processorsPerfReportFile: File?

//these two config can be replaced with single function-like interface (ProcessorName -> ClassLoader),
// but it is hard to pass function between different classloaders
Expand Down Expand Up @@ -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")
Expand All @@ -83,7 +85,7 @@ class KaptOptions(
changedFiles, compiledSources, incrementalCache, classpathChanges,
sourcesOutputDir, classesOutputDir, stubsOutputDir, incrementalDataOutputDir,
processingClasspath, processors, processingOptions, javacOptions, KaptFlags.fromSet(flags),
mode, detectMemoryLeaks,
mode, detectMemoryLeaks, processorsPerfReportFile,
processingClassLoader = null,
separateClassloaderForProcessors = emptySet()
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ fun KaptContext.doAnnotationProcessing(
showProcessorTimings(wrappedProcessors, loggerFun)
}

options.processorsPerfReportFile?.let { dumpProcessorTiming(wrappedProcessors, options.processorsPerfReportFile, logger::info) }

if (logger.isVerbose) {
filer.displayState()
}
Expand All @@ -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?,
Expand Down
7 changes: 7 additions & 0 deletions plugins/kapt3/kapt3-cli/src/KaptCliOption.kt
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,13 @@ enum class KaptCliOption(
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",
"true | false",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<DetectMemoryLeaksMode>(), value) { detectMemoryLeaks = it }
Expand Down