Skip to content

Commit 5bf27f0

Browse files
ivandev0Space Team
authored and
Space Team
committed
[CLI] Notify JS IR perf manager when analysis is started and finished
#KT-67473
1 parent 18c7da5 commit 5bf27f0

File tree

1 file changed

+28
-10
lines changed

1 file changed

+28
-10
lines changed

compiler/cli/cli-js/src/org/jetbrains/kotlin/cli/js/K2JsIrCompiler.kt

+28-10
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity.*
3030
import org.jetbrains.kotlin.cli.common.messages.MessageCollector
3131
import org.jetbrains.kotlin.cli.common.messages.MessageUtil
3232
import org.jetbrains.kotlin.cli.js.klib.*
33-
import org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.K2JVMCompilerPerformanceManager
3433
import org.jetbrains.kotlin.cli.jvm.compiler.EnvironmentConfigFiles
3534
import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment
3635
import org.jetbrains.kotlin.cli.jvm.plugins.PluginCliParser
@@ -316,15 +315,10 @@ class K2JsIrCompiler : CLICompiler<K2JSCompilerArguments>() {
316315
val outputKlibPath =
317316
if (arguments.irProduceKlibFile) outputDir.resolve("$outputName.klib").normalize().absolutePath
318317
else outputDirPath
319-
if (configuration.get(CommonConfigurationKeys.USE_FIR) == true) {
320-
sourceModule = processSourceModuleWithK2(environmentForJS, libraries, friendLibraries, arguments, outputKlibPath)
321-
} else {
322-
sourceModule = processSourceModule(environmentForJS, libraries, friendLibraries, arguments, outputKlibPath)
323-
324-
if (!sourceModule.jsFrontEndResult.jsAnalysisResult.shouldGenerateCode)
325-
return OK
326-
}
318+
sourceModule = produceSourceModule(configuration, environmentForJS, libraries, friendLibraries, arguments, outputKlibPath)
327319

320+
if (configuration.get(CommonConfigurationKeys.USE_FIR) != true && !sourceModule.jsFrontEndResult.jsAnalysisResult.shouldGenerateCode)
321+
return OK
328322
}
329323

330324
if (!arguments.irProduceJs) return OK
@@ -461,13 +455,34 @@ class K2JsIrCompiler : CLICompiler<K2JSCompilerArguments>() {
461455
return OK
462456
}
463457

464-
private fun processSourceModule(
458+
private fun produceSourceModule(
459+
configuration: CompilerConfiguration,
460+
environmentForJS: KotlinCoreEnvironment,
461+
libraries: List<String>,
462+
friendLibraries: List<String>,
463+
arguments: K2JSCompilerArguments,
464+
outputKlibPath: String,
465+
): ModulesStructure {
466+
val performanceManager = configuration.get(CLIConfigurationKeys.PERF_MANAGER)
467+
performanceManager?.notifyAnalysisStarted()
468+
469+
val sourceModule = if (configuration.get(CommonConfigurationKeys.USE_FIR) == true) {
470+
processSourceModuleWithK2(environmentForJS, libraries, friendLibraries, arguments, outputKlibPath)
471+
} else {
472+
processSourceModuleWithK1(environmentForJS, libraries, friendLibraries, arguments, outputKlibPath)
473+
}
474+
475+
return sourceModule
476+
}
477+
478+
private fun processSourceModuleWithK1(
465479
environmentForJS: KotlinCoreEnvironment,
466480
libraries: List<String>,
467481
friendLibraries: List<String>,
468482
arguments: K2JSCompilerArguments,
469483
outputKlibPath: String
470484
): ModulesStructure {
485+
val performanceManager = environmentForJS.configuration.get(CLIConfigurationKeys.PERF_MANAGER)
471486
lateinit var sourceModule: ModulesStructure
472487
do {
473488
val analyzerFacade = when (arguments.wasm) {
@@ -488,6 +503,7 @@ class K2JsIrCompiler : CLICompiler<K2JSCompilerArguments>() {
488503
environmentForJS.addKotlinSourceRoots(result.additionalKotlinRoots)
489504
}
490505
} while (result is JsAnalysisResult.RetryWithAdditionalRoots)
506+
performanceManager?.notifyAnalysisFinished()
491507

492508
if (sourceModule.jsFrontEndResult.jsAnalysisResult.shouldGenerateCode && (arguments.irProduceKlibDir || arguments.irProduceKlibFile)) {
493509
val moduleSourceFiles = (sourceModule.mainModule as MainModule.SourceFiles).files
@@ -536,6 +552,7 @@ class K2JsIrCompiler : CLICompiler<K2JSCompilerArguments>() {
536552
outputKlibPath: String
537553
): ModulesStructure {
538554
val configuration = environmentForJS.configuration
555+
val performanceManager = configuration.get(CLIConfigurationKeys.PERF_MANAGER)
539556
val messageCollector = configuration.getNotNull(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY)
540557
val diagnosticsReporter = DiagnosticReporterFactory.createPendingReporter()
541558

@@ -576,6 +593,7 @@ class K2JsIrCompiler : CLICompiler<K2JSCompilerArguments>() {
576593
)
577594
}
578595

596+
performanceManager?.notifyAnalysisFinished()
579597
if (analyzedOutput.reportCompilationErrors(moduleStructure, diagnosticsReporter, messageCollector)) {
580598
throw CompilationErrorException()
581599
}

0 commit comments

Comments
 (0)