[FIR] Isolate benchmark thread, add jit log format events for passes

Add special output for pass events to match with LogCompilation
This commit is contained in:
Simon Ogorodnik
2020-09-09 14:59:18 +03:00
parent 618de5fa32
commit b6fb3c9799
5 changed files with 174 additions and 27 deletions
@@ -44,7 +44,12 @@ fun checkFirProvidersConsistency(firFiles: List<FirFile>) {
private data class FailureInfo(val transformer: KClass<*>, val throwable: Throwable, val file: String)
data class ErrorTypeReport(val report: String, var count: Int = 0)
class FirResolveBench(val withProgress: Boolean) {
abstract class BenchListener {
abstract fun before()
abstract fun after(stageClass: KClass<*>)
}
class FirResolveBench(val withProgress: Boolean, val listener: BenchListener? = null) {
data class TotalStatistics(
val unresolvedTypes: Int,
val resolvedTypes: Int,
@@ -81,7 +86,8 @@ class FirResolveBench(val withProgress: Boolean) {
var cpu: Long = 0,
var gcTime: Long = 0,
var gcCollections: Int = 0,
var files: Int = 0
var files: Int = 0,
var vmCounters: VMCounters = VMCounters()
)
val timePerTransformer = mutableMapOf<KClass<*>, Measure>()
@@ -105,6 +111,7 @@ class FirResolveBench(val withProgress: Boolean) {
builder: RawFirBuilder,
ktFiles: List<KtFile>
): List<FirFile> {
listener?.before()
return ktFiles.map { file ->
val before = vmStateSnapshot()
val firFile: FirFile
@@ -118,6 +125,7 @@ class FirResolveBench(val withProgress: Boolean) {
totalLines += StringUtil.countNewLines(file.text)
firFile
}.also {
listener?.after(builder::class)
totalTime = timePerTransformer.values.sumByLong { it.time }
}
}
@@ -126,6 +134,7 @@ class FirResolveBench(val withProgress: Boolean) {
builder: LightTree2Fir,
files: List<File>
): List<FirFile> {
listener?.before()
return files.map { file ->
val before = vmStateSnapshot()
val firFile: FirFile
@@ -141,6 +150,7 @@ class FirResolveBench(val withProgress: Boolean) {
totalLines += StringUtil.countNewLines(code)
firFile
}.also {
listener?.after(builder::class)
totalTime = timePerTransformer.values.sumByLong { it.time }
}
}
@@ -165,6 +175,7 @@ class FirResolveBench(val withProgress: Boolean) {
private fun runStage(processor: FirTransformerBasedResolveProcessor, firFileSequence: Sequence<FirFile>) {
val transformer = processor.transformer
listener?.before()
for (firFile in firFileSequence) {
processWithTimeMeasure(
transformer::class,
@@ -180,6 +191,7 @@ class FirResolveBench(val withProgress: Boolean) {
}
}
}
listener?.after(transformer::class)
}
private fun runStage(processor: FirGlobalResolveProcessor, firFiles: List<FirFile>) {
@@ -403,6 +415,24 @@ fun FirResolveBench.TotalStatistics.reportErrors(stream: PrintStream) {
}
}
fun FirResolveBench.TotalStatistics.reportTimings(stream: PrintStream) {
printTable(stream) {
row {
cell("Stage", LEFT)
cells("Time", "Time per file", "Files: OK/E/T", "CPU", "User", "GC", "GC count", "L/S")
}
separator()
timePerTransformer.forEach { (transformer, measure) ->
printMeasureAsTable(measure, this@reportTimings, transformer)
}
if (timePerTransformer.keys.isNotEmpty()) {
separator()
printMeasureAsTable(totalMeasure, this@reportTimings, "Total time")
}
}
}
fun FirResolveBench.TotalStatistics.report(stream: PrintStream, header: String) {
with(stream) {
infix fun Int.percentOf(other: Int): String {
@@ -419,21 +449,7 @@ fun FirResolveBench.TotalStatistics.report(stream: PrintStream, header: String)
println("Erroneously resolved implicit types: $implicitTypes (${implicitTypes percentOf resolvedTypes} of resolved)")
println("Unique error types: $uniqueErrorTypes")
printTable(stream) {
row {
cell("Stage", LEFT)
cells("Time", "Time per file", "Files: OK/E/T", "CPU", "User", "GC", "GC count", "L/S")
}
separator()
timePerTransformer.forEach { (transformer, measure) ->
printMeasureAsTable(measure, this@report, transformer)
}
if (timePerTransformer.keys.isNotEmpty()) {
separator()
printMeasureAsTable(totalMeasure, this@report, "Total time")
}
}
this@report.reportTimings(stream)
}
}
@@ -17,19 +17,48 @@ data class GCInfo(val name: String, val gcTime: Long, val collections: Long) {
collections = collections - other.collections
)
}
operator fun plus(other: GCInfo): GCInfo {
return this.copy(
gcTime = gcTime + other.gcTime,
collections = collections + other.collections
)
}
}
data class VMCounters(val userTime: Long, val cpuTime: Long, val gcInfo: Map<String, GCInfo>) {
data class VMCounters(
val userTime: Long = 0,
val cpuTime: Long = 0,
val gcInfo: Map<String, GCInfo> = emptyMap(),
val safePointTotalTime: Long = 0,
val safePointSyncTime: Long = 0,
val safePointCount: Long = 0,
) {
operator fun minus(other: VMCounters): VMCounters {
return VMCounters(
userTime - other.userTime,
cpuTime - other.cpuTime,
merge(gcInfo, other.gcInfo) { a, b -> a - b }
merge(gcInfo, other.gcInfo) { a, b -> a - b },
safePointTotalTime - other.safePointTotalTime,
safePointSyncTime - other.safePointSyncTime,
safePointCount - other.safePointCount
)
}
operator fun plus(other: VMCounters): VMCounters {
return VMCounters(
userTime + other.userTime,
cpuTime + other.cpuTime,
merge(gcInfo, other.gcInfo) { a, b -> a + b },
safePointTotalTime + other.safePointTotalTime,
safePointSyncTime + other.safePointSyncTime,
safePointCount + other.safePointCount
)
}
}
@@ -50,9 +79,13 @@ object Init {
fun vmStateSnapshot(): VMCounters {
Init
val threadMXBean = ManagementFactoryHelper.getThreadMXBean()
val hotspotRuntimeMBean = ManagementFactoryHelper.getHotspotRuntimeMBean()
return VMCounters(
threadMXBean.threadUserTime(), threadMXBean.threadCpuTime(),
ManagementFactoryHelper.getGarbageCollectorMXBeans().associate { it.name to GCInfo(it.name, it.collectionTime, it.collectionCount) }
ManagementFactoryHelper.getGarbageCollectorMXBeans().associate { it.name to GCInfo(it.name, it.collectionTime, it.collectionCount) },
hotspotRuntimeMBean.totalSafepointTime,
hotspotRuntimeMBean.safepointSyncTime,
hotspotRuntimeMBean.safepointCount
)
}
}