diff --git a/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/CommonCompilerArguments.kt b/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/CommonCompilerArguments.kt index 1696e6c1600..791be09d7b9 100644 --- a/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/CommonCompilerArguments.kt +++ b/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/CommonCompilerArguments.kt @@ -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 = "", + description = "Dump detailed performance statistics to the specified file" + ) + var dumpPerf: String? by FreezableVar(null) + open fun configureAnalysisFlags(collector: MessageCollector): MutableMap, Any> { return HashMap, Any>().apply { put(AnalysisFlag.skipMetadataVersionCheck, skipMetadataVersionCheck) diff --git a/compiler/cli/src/org/jetbrains/kotlin/cli/common/CLICompiler.java b/compiler/cli/src/org/jetbrains/kotlin/cli/common/CLICompiler.java index 10c3d5fa961..064a9d8d69c 100644 --- a/compiler/cli/src/org/jetbrains/kotlin/cli/common/CLICompiler.java +++ b/compiler/cli/src/org/jetbrains/kotlin/cli/common/CLICompiler.java @@ -69,7 +69,7 @@ public abstract class CLICompiler 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 extends CLI ); } + if (arguments.getDumpPerf() != null) { + performanceManager.dumpPerformanceReport(new File(arguments.getDumpPerf())); + } + return groupingCollector.hasErrors() ? COMPILATION_ERROR : code; } catch (CompilationCanceledException e) { diff --git a/compiler/cli/src/org/jetbrains/kotlin/cli/common/CommonCompilerPerformanceManager.kt b/compiler/cli/src/org/jetbrains/kotlin/cli/common/CommonCompilerPerformanceManager.kt index e4818a629cf..d6e1448be70 100644 --- a/compiler/cli/src/org/jetbrains/kotlin/cli/common/CommonCompilerPerformanceManager.kt +++ b/compiler/cli/src/org/jetbrains/kotlin/cli/common/CommonCompilerPerformanceManager.kt @@ -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() } \ No newline at end of file diff --git a/compiler/testData/cli/js/jsExtraHelp.out b/compiler/testData/cli/js/jsExtraHelp.out index 12fb8f20c07..54f547aa718 100644 --- a/compiler/testData/cli/js/jsExtraHelp.out +++ b/compiler/testData/cli/js/jsExtraHelp.out @@ -6,6 +6,7 @@ where advanced options include: -Xallow-kotlin-package Allow compiling code in package 'kotlin' and allow not requiring kotlin.stdlib in module-info -Xcoroutines={enable|warn|error} Enable coroutines or report warnings or errors on declarations and use sites of 'suspend' modifier + -Xdump-perf= Dump detailed performance statistics to the specified file -Xeffect-system Enable experimental language feature: effect system -Xexperimental= Enable and propagate usages of experimental API for marker annotation with the given fully qualified name -Xintellij-plugin-root= Path to the kotlin-compiler.jar or directory where IntelliJ configuration files can be found diff --git a/compiler/testData/cli/jvm/extraHelp.out b/compiler/testData/cli/jvm/extraHelp.out index 030915177f3..af680395050 100644 --- a/compiler/testData/cli/jvm/extraHelp.out +++ b/compiler/testData/cli/jvm/extraHelp.out @@ -47,6 +47,7 @@ where advanced options include: -Xallow-kotlin-package Allow compiling code in package 'kotlin' and allow not requiring kotlin.stdlib in module-info -Xcoroutines={enable|warn|error} Enable coroutines or report warnings or errors on declarations and use sites of 'suspend' modifier + -Xdump-perf= Dump detailed performance statistics to the specified file -Xeffect-system Enable experimental language feature: effect system -Xexperimental= Enable and propagate usages of experimental API for marker annotation with the given fully qualified name -Xintellij-plugin-root= Path to the kotlin-compiler.jar or directory where IntelliJ configuration files can be found