Kapt3: Minor: Measure stub generation time
This commit is contained in:
committed by
Yan Zhulanow
parent
6b1fc6fc39
commit
03244123c9
+30
-6
@@ -47,6 +47,7 @@ class Kapt3AnalysisCompletedHandlerExtension(
|
||||
val stubsOutputDir: File?,
|
||||
val options: Map<String, String>, //TODO
|
||||
val aptOnly: Boolean,
|
||||
val pluginInitializedTime: Long,
|
||||
val logger: Logger
|
||||
) : AnalysisCompletedHandlerExtension {
|
||||
private var annotationProcessingComplete = false
|
||||
@@ -61,6 +62,8 @@ class Kapt3AnalysisCompletedHandlerExtension(
|
||||
return null
|
||||
}
|
||||
|
||||
annotationProcessingComplete = true
|
||||
|
||||
fun doNotGenerateCode() = AnalysisResult.Companion.success(BindingContext.EMPTY, module, shouldGenerateCode = false)
|
||||
|
||||
if (files.isEmpty()) {
|
||||
@@ -68,6 +71,7 @@ class Kapt3AnalysisCompletedHandlerExtension(
|
||||
return if (aptOnly) doNotGenerateCode() else null
|
||||
}
|
||||
|
||||
logger.info { "Initial analysis took ${System.currentTimeMillis() - pluginInitializedTime} ms" }
|
||||
logger.info { "Kotlin files: " + files.map { it.virtualFile?.name ?: "<in memory ${it.hashCode()}>" } }
|
||||
|
||||
val processors = loadProcessors(annotationProcessingClasspath)
|
||||
@@ -90,7 +94,10 @@ class Kapt3AnalysisCompletedHandlerExtension(
|
||||
disableParamAssertions = false)
|
||||
|
||||
try {
|
||||
KotlinCodegenFacade.compileCorrectFiles(generationState, CompilationErrorHandler.THROW_EXCEPTION)
|
||||
val (stubCompilationTime) = measureTimeMillis {
|
||||
KotlinCodegenFacade.compileCorrectFiles(generationState, CompilationErrorHandler.THROW_EXCEPTION)
|
||||
}
|
||||
|
||||
val compiledClasses = builderFactory.compiledClasses
|
||||
val origins = builderFactory.origins
|
||||
logger.info { "Compiled classes: " + compiledClasses.joinToString { it.name } }
|
||||
@@ -101,17 +108,28 @@ class Kapt3AnalysisCompletedHandlerExtension(
|
||||
logger.info { "Java source files: " + javaFilesFromJavaSourceRoots.joinToString { it.canonicalPath } }
|
||||
|
||||
val kaptRunner = KaptRunner(logger)
|
||||
val treeConverter = JCTreeConverter(kaptRunner.context, generationState.typeMapper, compiledClasses, origins)
|
||||
val jcCompilationUnitsForKotlinClasses = treeConverter.convert()
|
||||
|
||||
val (jcStubGenerationTime, jcCompilationUnitsForKotlinClasses) = measureTimeMillis {
|
||||
val treeConverter = JCTreeConverter(kaptRunner.context, generationState.typeMapper, compiledClasses, origins)
|
||||
treeConverter.convert()
|
||||
}
|
||||
|
||||
logger.info { "Stubs for Kotlin classes: " + jcCompilationUnitsForKotlinClasses.joinToString { it.sourcefile.name } }
|
||||
|
||||
logger.info { "Stubs compilation took $stubCompilationTime ms" }
|
||||
logger.info { "Java stub generation took $jcStubGenerationTime ms" }
|
||||
|
||||
if (stubsOutputDir != null) {
|
||||
saveStubs(stubsOutputDir, jcCompilationUnitsForKotlinClasses)
|
||||
}
|
||||
|
||||
kaptRunner.doAnnotationProcessing(
|
||||
javaFilesFromJavaSourceRoots, processors,
|
||||
annotationProcessingClasspath, sourcesOutputDir, classFilesOutputDir, jcCompilationUnitsForKotlinClasses)
|
||||
val (annotationProcessingTime) = measureTimeMillis {
|
||||
kaptRunner.doAnnotationProcessing(
|
||||
javaFilesFromJavaSourceRoots, processors,
|
||||
annotationProcessingClasspath, sourcesOutputDir, classFilesOutputDir, jcCompilationUnitsForKotlinClasses)
|
||||
}
|
||||
|
||||
logger.info { "Annotation processing took $annotationProcessingTime ms" }
|
||||
} catch (thr: Throwable) {
|
||||
if (thr !is KaptError || thr.kind != KaptError.Kind.ERROR_RAISED) {
|
||||
logger.exception(thr)
|
||||
@@ -133,6 +151,12 @@ class Kapt3AnalysisCompletedHandlerExtension(
|
||||
}
|
||||
}
|
||||
|
||||
private inline fun <T> measureTimeMillis(block: () -> T) : Pair<Long, T> {
|
||||
val start = System.currentTimeMillis()
|
||||
val result = block()
|
||||
return Pair(System.currentTimeMillis() - start, result)
|
||||
}
|
||||
|
||||
private fun saveStubs(outputDir: File, stubs: JavacList<JCTree.JCCompilationUnit>) {
|
||||
for (stub in stubs) {
|
||||
val className = (stub.defs.first { it is JCTree.JCClassDecl } as JCTree.JCClassDecl).simpleName.toString()
|
||||
|
||||
@@ -152,7 +152,8 @@ class Kapt3ComponentRegistrar : ComponentRegistrar {
|
||||
}
|
||||
|
||||
val kapt3AnalysisCompletedHandlerExtension = Kapt3AnalysisCompletedHandlerExtension(
|
||||
classpath, javaSourceRoots, sourcesOutputDir, classFilesOutputDir, stubsOutputDir, apOptions, isAptOnly, logger)
|
||||
classpath, javaSourceRoots, sourcesOutputDir, classFilesOutputDir, stubsOutputDir, apOptions,
|
||||
isAptOnly, System.currentTimeMillis(), logger)
|
||||
AnalysisCompletedHandlerExtension.registerExtension(project, kapt3AnalysisCompletedHandlerExtension)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user