Compare commits

...

5 Commits

Author SHA1 Message Date
Ivan Kylchik
f7a3079841 Change java source and target version for javac 2020-08-05 22:31:43 +03:00
Ivan Kylchik
16635c8891 Add java filter for sources in JavacModularizedTest 2020-08-05 22:31:43 +03:00
Ivan Kylchik
930f6008ed Implement update method in FirResolveBench.Measure class 2020-07-31 13:15:19 +03:00
Ivan Kylchik
84a4de3bcc Extract util functions from processModule method 2020-07-31 13:06:31 +03:00
Ivan Kylchik
e777349f1f Implement javac performance test 2020-07-31 12:58:12 +03:00
2 changed files with 96 additions and 9 deletions

View File

@@ -0,0 +1,75 @@
/*
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
* 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 org.jetbrains.kotlin.fir.scopes.ProcessorAction
import java.io.*
import java.nio.charset.StandardCharsets
import javax.tools.ToolProvider
class JavacModularizedTest : AbstractModularizedTest() {
private val measure = FirResolveBench.Measure()
private var totalLines = 0
override fun beforePass() {
measure.clear()
totalLines = 0
}
override fun afterPass(pass: Int) {
val statistics = FirResolveBench.TotalStatistics(0, 0, 0, 0, 0, 0, measure.files, totalLines, emptyMap(), mapOf("Javac" to measure))
statistics.report(System.out, "Pass $pass")
}
override fun processModule(moduleData: ModuleData): ProcessorAction {
val classpath = moduleData.classpath.joinToString(separator = ":")
val sources = moduleData.sources.map { it.absolutePath }
.map { File(it) }
.flatMap { if (it.isDirectory) it.walk().toList() else listOf(it) }
.filter { !it.isDirectory }
.map { it.absolutePath }
.filter { it.endsWith(".java") }
.toTypedArray()
if (sources.isEmpty() || sources.any { !File(it).exists() }) return ProcessorAction.NEXT
val outputDir = moduleData.outputDir.absolutePath
val additionalOptions = "-source 11 -target 11 -proc:none -XDcompilePolicy=check -verbose".split(" ").toTypedArray()
ByteArrayOutputStream().use { byteArrayStream ->
PrintStream(byteArrayStream, true, StandardCharsets.UTF_8.name()).use { printStream ->
val diff = withVmSnapshot {
val javac = ToolProvider.getSystemJavaCompiler()
val result = javac.run(null, printStream, printStream, *additionalOptions, "-d", outputDir, "-cp", classpath, *sources)
if (result != 0) return ProcessorAction.STOP
}
val output = byteArrayStream.toString(StandardCharsets.UTF_8.name())
val timeLime = output.split("\n").single { it.startsWith("[total") }
val timeResult = timeLime.removePrefix("[total ").removeSuffix("ms]")
measure.update(timeResult.toLong() * 1_000_000L, sources.size, diff)
}
}
totalLines += sources.map { File(it).readLines().size }.sum()
return ProcessorAction.NEXT
}
private inline fun withVmSnapshot(block: () -> Unit): VMCounters {
val before = vmStateSnapshot()
block()
val after = vmStateSnapshot()
return after - before
}
fun testJavac() {
for (i in 0 until PASSES) {
println("Pass $i")
runTestOnce(i)
}
afterAllPasses()
}
}

View File

@@ -82,7 +82,26 @@ class FirResolveBench(val withProgress: Boolean) {
var gcTime: Long = 0,
var gcCollections: Int = 0,
var files: Int = 0
)
) {
fun update(time: Long, files: Int, diff: VMCounters) {
this.time += time
this.files += files
this.user += diff.userTime
this.cpu += diff.cpuTime
this.gcCollections += diff.gcInfo.values.sumBy { it.collections.toInt() }
this.gcTime += diff.gcInfo.values.sumByLong { it.gcTime }
}
fun clear() {
time = 0L
user = 0L
cpu = 0L
gcTime = 0L
gcCollections = 0
files = 0
}
}
val timePerTransformer = mutableMapOf<KClass<*>, Measure>()
var resolvedTypes = 0
@@ -146,14 +165,7 @@ class FirResolveBench(val withProgress: Boolean) {
}
private fun recordTime(stageClass: KClass<*>, diff: VMCounters, time: Long) {
timePerTransformer.computeIfAbsent(stageClass) { Measure() }.apply {
this.time += time
this.files += 1
this.user += diff.userTime
this.cpu += diff.cpuTime
this.gcCollections += diff.gcInfo.values.sumBy { it.collections.toInt() }
this.gcTime += diff.gcInfo.values.sumByLong { it.gcTime }
}
timePerTransformer.computeIfAbsent(stageClass) { Measure() }.apply { update(time, 1, diff) }
}
private fun runStage(processor: FirResolveProcessor, firFileSequence: Sequence<FirFile>) {