From cc379a8386dcad36b2629b7ad9840aa3e878bc67 Mon Sep 17 00:00:00 2001 From: Ivan Kylchik Date: Fri, 19 Apr 2024 16:48:52 +0200 Subject: [PATCH] [CLI] Notify JS IR perf manager when generation is started and finished #KT-67473 (cherry picked from commit f3cd3b14414b7d02c84de46cbeef964ae479d3e9) --- .../org/jetbrains/kotlin/cli/js/K2JsIrCompiler.kt | 13 +++++++++++-- compiler/ir/backend.js/build.gradle.kts | 1 + .../org/jetbrains/kotlin/ir/backend/js/compiler.kt | 8 ++++++++ 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/compiler/cli/cli-js/src/org/jetbrains/kotlin/cli/js/K2JsIrCompiler.kt b/compiler/cli/cli-js/src/org/jetbrains/kotlin/cli/js/K2JsIrCompiler.kt index 8b60099512075..81beddc11bf1b 100644 --- a/compiler/cli/cli-js/src/org/jetbrains/kotlin/cli/js/K2JsIrCompiler.kt +++ b/compiler/cli/cli-js/src/org/jetbrains/kotlin/cli/js/K2JsIrCompiler.kt @@ -99,6 +99,8 @@ class K2JsIrCompiler : CLICompiler() { val messageCollector: MessageCollector, val mainCallArguments: List? ) { + private val performanceManager = module.compilerConfiguration[CLIConfigurationKeys.PERF_MANAGER] + private fun lowerIr(): LoweredIr { return compile( module, @@ -126,11 +128,18 @@ class K2JsIrCompiler : CLICompiler() { val transformer = IrModuleToJsTransformer(ir.context, mainCallArguments, ir.moduleFragmentToUniqueName) val mode = TranslationMode.fromFlags(arguments.irDce, arguments.granularity, arguments.irMinimizedMemberNames) - return transformer.makeJsCodeGenerator(ir.allModules, mode) + return transformer + .also { performanceManager?.notifyIRGenerationStarted() } + .makeJsCodeGenerator(ir.allModules, mode) } fun compileAndTransformIrNew(): CompilationOutputsBuilt { - return makeJsCodeGenerator().generateJsCode(relativeRequirePath = true, outJsProgram = false) + return makeJsCodeGenerator() + .generateJsCode(relativeRequirePath = true, outJsProgram = false) + .also { + performanceManager?.notifyIRGenerationFinished() + performanceManager?.notifyGenerationFinished() + } } } diff --git a/compiler/ir/backend.js/build.gradle.kts b/compiler/ir/backend.js/build.gradle.kts index 11caa4ada3da6..062a2f393241b 100644 --- a/compiler/ir/backend.js/build.gradle.kts +++ b/compiler/ir/backend.js/build.gradle.kts @@ -4,6 +4,7 @@ plugins { } dependencies { + implementation(project(":compiler:cli-base")) api(project(":compiler:util")) api(project(":compiler:frontend")) api(project(":compiler:backend-common")) diff --git a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/compiler.kt b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/compiler.kt index 7f6fa6feea78a..4a34c6d6cbdfd 100644 --- a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/compiler.kt +++ b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/compiler.kt @@ -8,6 +8,7 @@ package org.jetbrains.kotlin.ir.backend.js import org.jetbrains.kotlin.backend.common.linkage.issues.checkNoUnboundSymbols import org.jetbrains.kotlin.backend.common.phaser.PhaseConfig import org.jetbrains.kotlin.backend.common.phaser.invokeToplevel +import org.jetbrains.kotlin.cli.common.CLIConfigurationKeys import org.jetbrains.kotlin.config.CompilerConfiguration import org.jetbrains.kotlin.ir.IrBuiltIns import org.jetbrains.kotlin.ir.backend.js.lower.collectNativeImplementations @@ -49,6 +50,8 @@ fun compile( filesToLower: Set? = null, granularity: JsGenerationGranularity = JsGenerationGranularity.WHOLE_PROGRAM, ): LoweredIr { + val performanceManager = depsDescriptors.compilerConfiguration[CLIConfigurationKeys.PERF_MANAGER] + performanceManager?.notifyIRTranslationStarted() val (moduleFragment: IrModuleFragment, dependencyModules, irBuiltIns, symbolTable, deserializer, moduleToName) = loadIr(depsDescriptors, irFactory, verifySignatures, filesToLower, loadFunctionInterfacesIntoStdlib = true) @@ -92,6 +95,7 @@ fun compileIr( val moduleDescriptor = moduleFragment.descriptor val irFactory = symbolTable.irFactory val shouldGeneratePolyfills = configuration.getBoolean(JSConfigurationKeys.GENERATE_POLYFILLS) + val performanceManager = configuration[CLIConfigurationKeys.PERF_MANAGER] val allModules = when (mainModule) { is MainModule.SourceFiles -> dependencyModules + listOf(moduleFragment) @@ -130,10 +134,14 @@ fun compileIr( // TODO should be done incrementally generateJsTests(context, allModules.last()) + performanceManager?.notifyIRTranslationFinished() + performanceManager?.notifyGenerationStarted() + performanceManager?.notifyIRLoweringStarted() (irFactory.stageController as? WholeWorldStageController)?.let { lowerPreservingTags(allModules, context, phaseConfig, it) } ?: jsPhases.invokeToplevel(phaseConfig, context, allModules) + performanceManager?.notifyIRLoweringFinished() return LoweredIr(context, moduleFragment, allModules, moduleToName) }