Support dumping stats for number of generated sources by annotation processors
^KT-51132 In Progress
This commit is contained in:
@@ -152,6 +152,10 @@ private fun dumpProcessorTiming(wrappedProcessors: List<ProcessorWrapper>, apRep
|
|||||||
wrappedProcessors.forEach { processor ->
|
wrappedProcessors.forEach { processor ->
|
||||||
appendLine(processor.renderSpentTime())
|
appendLine(processor.renderSpentTime())
|
||||||
}
|
}
|
||||||
|
appendLine("Generated files report:")
|
||||||
|
wrappedProcessors.forEach { processor ->
|
||||||
|
appendLine(processor.renderGenerations())
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -182,12 +186,14 @@ private fun reportIfRunningNonIncrementally(
|
|||||||
private class ProcessorWrapper(private val delegate: IncrementalProcessor) : Processor by delegate {
|
private class ProcessorWrapper(private val delegate: IncrementalProcessor) : Processor by delegate {
|
||||||
private var initTime: Long = 0
|
private var initTime: Long = 0
|
||||||
private val roundTime = mutableListOf<Long>()
|
private val roundTime = mutableListOf<Long>()
|
||||||
|
private val sourcesGenerated = mutableListOf<Int>()
|
||||||
|
|
||||||
override fun process(annotations: MutableSet<out TypeElement>, roundEnv: RoundEnvironment): Boolean {
|
override fun process(annotations: MutableSet<out TypeElement>, roundEnv: RoundEnvironment): Boolean {
|
||||||
val (time, result) = measureTimeMillisWithResult {
|
val (time, result) = measureTimeMillisWithResult {
|
||||||
delegate.process(annotations, roundEnv)
|
delegate.process(annotations, roundEnv)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
updateGenerationStats(roundEnv)
|
||||||
roundTime += time
|
roundTime += time
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
@@ -225,6 +231,38 @@ private class ProcessorWrapper(private val delegate: IncrementalProcessor) : Pro
|
|||||||
"init: $initTime ms, " +
|
"init: $initTime ms, " +
|
||||||
"${roundTime.size} round(s): ${roundTime.joinToString { "$it ms" }}"
|
"${roundTime.size} round(s): ${roundTime.joinToString { "$it ms" }}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun renderGenerations(): String {
|
||||||
|
val processorName = delegate.processorName
|
||||||
|
|
||||||
|
return "$processorName: " +
|
||||||
|
"total sources: ${sourcesGenerated.sum()}, " +
|
||||||
|
"sources per round: ${sourcesGenerated.joinToString()}"
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun updateGenerationStats(roundEnv: RoundEnvironment) {
|
||||||
|
var numSourcesGenerated = -1
|
||||||
|
try {
|
||||||
|
val procEnv = roundEnv::class.java.getDeclaredField("processingEnv")
|
||||||
|
procEnv.isAccessible = true
|
||||||
|
val proEnvObj = procEnv.get(roundEnv) as ProcessingEnvironment
|
||||||
|
|
||||||
|
val filerField = JavacProcessingEnvironment::class.java.getDeclaredField("filer")
|
||||||
|
filerField.isAccessible = true
|
||||||
|
val filerObj = filerField.get(proEnvObj)
|
||||||
|
|
||||||
|
val genSourceNameField = JavacFiler::class.java.getDeclaredField("generatedSourceNames")
|
||||||
|
genSourceNameField.isAccessible = true
|
||||||
|
val genSourceNameObj = genSourceNameField.get(filerObj)
|
||||||
|
|
||||||
|
@Suppress("UNCHECKED_CAST")
|
||||||
|
val sources: Set<String>? = genSourceNameObj as? Set<String>
|
||||||
|
numSourcesGenerated = sources?.size ?: -1
|
||||||
|
} catch (e: Exception) {
|
||||||
|
// Not much we can do
|
||||||
|
}
|
||||||
|
sourcesGenerated.add(numSourcesGenerated)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun KaptContext.parseJavaFiles(javaSourceFiles: List<File>): JavacList<JCTree.JCCompilationUnit> {
|
fun KaptContext.parseJavaFiles(javaSourceFiles: List<File>): JavacList<JCTree.JCCompilationUnit> {
|
||||||
|
|||||||
Reference in New Issue
Block a user