Add -Xdump-perf
This commit is contained in:
+7
@@ -153,6 +153,13 @@ abstract class CommonCompilerArguments : CommonToolArguments() {
|
||||
@Argument(value = "-Xreport-perf", description = "Report detailed performance statistics")
|
||||
var reportPerf: Boolean by FreezableVar(false)
|
||||
|
||||
@Argument(
|
||||
value = "-Xdump-perf",
|
||||
valueDescription = "<path>",
|
||||
description = "Dump detailed performance statistics to the specified file"
|
||||
)
|
||||
var dumpPerf: String? by FreezableVar(null)
|
||||
|
||||
open fun configureAnalysisFlags(collector: MessageCollector): MutableMap<AnalysisFlag<*>, Any> {
|
||||
return HashMap<AnalysisFlag<*>, Any>().apply {
|
||||
put(AnalysisFlag.skipMetadataVersionCheck, skipMetadataVersionCheck)
|
||||
|
||||
@@ -69,7 +69,7 @@ public abstract class CLICompiler<A extends CommonCompilerArguments> extends CLI
|
||||
@Override
|
||||
public ExitCode execImpl(@NotNull MessageCollector messageCollector, @NotNull Services services, @NotNull A arguments) {
|
||||
CommonCompilerPerformanceManager performanceManager = getPerformanceManager();
|
||||
if (arguments.getReportPerf()) {
|
||||
if (arguments.getReportPerf() || arguments.getDumpPerf() != null) {
|
||||
performanceManager.enableCollectingPerformanceStatistics();
|
||||
}
|
||||
|
||||
@@ -101,6 +101,10 @@ public abstract class CLICompiler<A extends CommonCompilerArguments> extends CLI
|
||||
);
|
||||
}
|
||||
|
||||
if (arguments.getDumpPerf() != null) {
|
||||
performanceManager.dumpPerformanceReport(new File(arguments.getDumpPerf()));
|
||||
}
|
||||
|
||||
return groupingCollector.hasErrors() ? COMPILATION_ERROR : code;
|
||||
}
|
||||
catch (CompilationCanceledException e) {
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
package org.jetbrains.kotlin.cli.common
|
||||
|
||||
import org.jetbrains.kotlin.util.PerformanceCounter
|
||||
import java.io.File
|
||||
import java.lang.management.ManagementFactory
|
||||
import java.util.concurrent.TimeUnit
|
||||
|
||||
@@ -53,6 +54,10 @@ abstract class CommonCompilerPerformanceManager(private val presentableName: Str
|
||||
measurements += CodeGenerationMeasurement(lines, files, TimeUnit.NANOSECONDS.toMillis(time), additionalDescription)
|
||||
}
|
||||
|
||||
fun dumpPerformanceReport(destination: File) {
|
||||
destination.writeBytes(createPerformanceReport())
|
||||
}
|
||||
|
||||
private fun recordGcTime() {
|
||||
if (!isEnabled) return
|
||||
|
||||
@@ -76,4 +81,9 @@ abstract class CommonCompilerPerformanceManager(private val presentableName: Str
|
||||
private fun recordPerfCountersMeasurements() {
|
||||
PerformanceCounter.report { s -> measurements += PerformanceCounterMeasurement(s) }
|
||||
}
|
||||
|
||||
private fun createPerformanceReport(): ByteArray = buildString {
|
||||
appendln("$presentableName performance report")
|
||||
measurements.map { it.render() }.sorted().forEach { appendln(it) }
|
||||
}.toByteArray()
|
||||
}
|
||||
Reference in New Issue
Block a user