From 6e3f17356715c6415962ea12f90361c517181973 Mon Sep 17 00:00:00 2001 From: Simon Ogorodnik Date: Wed, 10 Apr 2019 21:32:15 +0300 Subject: [PATCH] Implement old FE perf test similar to FIR modularized --- .../compiler/KotlinToJVMBytecodeCompiler.kt | 2 +- ...NonFirResolveModularizedTotalKotlinTest.kt | 164 ++++++++++++++++++ 2 files changed, 165 insertions(+), 1 deletion(-) create mode 100644 compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/NonFirResolveModularizedTotalKotlinTest.kt diff --git a/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/compiler/KotlinToJVMBytecodeCompiler.kt b/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/compiler/KotlinToJVMBytecodeCompiler.kt index d1979f35aca..e64101b5162 100644 --- a/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/compiler/KotlinToJVMBytecodeCompiler.kt +++ b/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/compiler/KotlinToJVMBytecodeCompiler.kt @@ -374,7 +374,7 @@ object KotlinToJVMBytecodeCompiler { return generate(environment, environment.configuration, result, environment.getSourceFiles(), null) } - private fun analyze(environment: KotlinCoreEnvironment, targetDescription: String?): AnalysisResult? { + fun analyze(environment: KotlinCoreEnvironment, targetDescription: String?): AnalysisResult? { val sourceFiles = environment.getSourceFiles() val collector = environment.messageCollector diff --git a/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/NonFirResolveModularizedTotalKotlinTest.kt b/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/NonFirResolveModularizedTotalKotlinTest.kt new file mode 100644 index 00000000000..aa06de8d0a7 --- /dev/null +++ b/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/NonFirResolveModularizedTotalKotlinTest.kt @@ -0,0 +1,164 @@ +/* + * Copyright 2010-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license + * that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.fir + +import com.intellij.openapi.util.Disposer +import org.jetbrains.kotlin.cli.common.CLIConfigurationKeys.CONTENT_ROOTS +import org.jetbrains.kotlin.cli.common.CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY +import org.jetbrains.kotlin.cli.common.config.KotlinSourceRoot +import org.jetbrains.kotlin.cli.common.messages.CompilerMessageLocation +import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity +import org.jetbrains.kotlin.cli.common.messages.MessageCollector +import org.jetbrains.kotlin.cli.jvm.compiler.EnvironmentConfigFiles +import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment +import org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler +import org.jetbrains.kotlin.test.ConfigurationKind +import org.jetbrains.kotlin.test.KotlinTestUtils +import org.jetbrains.kotlin.test.TestJdkKind +import org.jetbrains.kotlin.test.testFramework.KtUsefulTestCase +import org.w3c.dom.Node +import org.w3c.dom.NodeList +import java.io.File +import javax.xml.parsers.DocumentBuilderFactory +import kotlin.system.measureNanoTime + + +private fun NodeList.toList(): List { + val list = mutableListOf() + for (index in 0 until this.length) { + list += item(index) + } + return list +} + +private val Node.childNodesList get() = childNodes.toList() + + +private data class XModuleData(val name: String, val classpath: List, val sources: List, val javaSourceRoots: List) + +class NonFirResolveModularizedTotalKotlinTest : KtUsefulTestCase() { + + + private var totalTime = 0L + private var files = 0 + + private fun runAnalysis(moduleData: XModuleData, environment: KotlinCoreEnvironment) { + val project = environment.project + + val time = measureNanoTime { + KotlinToJVMBytecodeCompiler.analyze(environment, null) + } + + files += environment.getSourceFiles().size + totalTime += time + println("Time is ${time * 1e-6} ms") + + } + + private fun processModule(moduleData: XModuleData) { + val configurationKind = ConfigurationKind.ALL + val testJdkKind = TestJdkKind.FULL_JDK + + + val disposable = Disposer.newDisposable() + + + val configuration = + KotlinTestUtils.newConfiguration(configurationKind, testJdkKind, moduleData.classpath, moduleData.javaSourceRoots) + configuration.addAll( + CONTENT_ROOTS, + moduleData.sources.filter { it.extension == "kt" }.map { KotlinSourceRoot(it.absolutePath, false) }) + configuration.put(MESSAGE_COLLECTOR_KEY, object : MessageCollector { + override fun clear() { + + } + + override fun report(severity: CompilerMessageSeverity, message: String, location: CompilerMessageLocation?) { + if (location != null) + print(location.toString()) + print(":") + print(severity) + print(":") + println(message) + } + + override fun hasErrors(): Boolean { + return false + } + + }) + val environment = KotlinCoreEnvironment.createForTests(disposable, configuration, EnvironmentConfigFiles.JVM_CONFIG_FILES) + +// Extensions.getArea(environment.project) +// .getExtensionPoint(PsiElementFinder.EP_NAME) +// .unregisterExtension(JavaElementFinder::class.java) + + println("Processing module: ${moduleData.name}") + runAnalysis(moduleData, environment) + + Disposer.dispose(disposable) + } + + private fun loadModule(file: File): XModuleData { + + val factory = DocumentBuilderFactory.newInstance() + factory.isIgnoringComments = true + factory.isIgnoringElementContentWhitespace = true + val builder = factory.newDocumentBuilder() + val document = builder.parse(file) + val moduleElement = document.childNodes.item(0).childNodesList.first { it.nodeType == Node.ELEMENT_NODE } + val moduleName = moduleElement.attributes.getNamedItem("name").nodeValue + val javaSourceRoots = mutableListOf() + val classpath = mutableListOf() + val sources = mutableListOf() + + for (index in 0 until moduleElement.childNodes.length) { + val item = moduleElement.childNodes.item(index) + + if (item.nodeName == "classpath") { + classpath += File(item.attributes.getNamedItem("path").nodeValue) + } + if (item.nodeName == "javaSourceRoots") { + javaSourceRoots += File(item.attributes.getNamedItem("path").nodeValue) + } + if (item.nodeName == "sources") { + sources += File(item.attributes.getNamedItem("path").nodeValue) + } + } + + return XModuleData(moduleName, classpath, sources, javaSourceRoots) + } + + + private fun runTestLocal() { + val testDataPath = "/Users/jetbrains/jps" + val root = File(testDataPath) + + println("BASE PATH: ${root.absolutePath}") + + val modules = + root.listFiles().sortedBy { it.lastModified() }.map { loadModule(it) } + + // .sortedBy { !it.sources.any { it.nameWithoutExtension == "KotlinSearchEverywhereClassifier" } } + + + for (module in modules.progress { "Analyzing ${it.name}" }) { + processModule(module) + } + + println("Total time: ${totalTime * 1e-6} ms, ${(totalTime * 1e-6) / files} ms per file") + totalTime = 0 + files = 0 + } + + fun testTotalKotlin() { + //Thread.sleep(5000) + for (i in 0..2) { + println("Pass $i") + runTestLocal() + } + } +} \ No newline at end of file