From cd3e5e1bf51cae9a2177b42af61a4de4f65c1701 Mon Sep 17 00:00:00 2001 From: huyunhui Date: Fri, 11 Jul 2025 11:45:27 +0800 Subject: [PATCH] Add perf-dump for project building Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/ICLMTE Signed-off-by: huyunhui --- ets2panda/driver/build_system/src/build/base_mode.ts | 4 ++++ ets2panda/public/es2panda_lib.cpp | 9 +++++++++ 2 files changed, 13 insertions(+) diff --git a/ets2panda/driver/build_system/src/build/base_mode.ts b/ets2panda/driver/build_system/src/build/base_mode.ts index c208585be1..64c08e2b3f 100644 --- a/ets2panda/driver/build_system/src/build/base_mode.ts +++ b/ets2panda/driver/build_system/src/build/base_mode.ts @@ -112,6 +112,7 @@ export abstract class BaseMode { public byteCodeHar: boolean; public es2pandaMode: number; public skipDeclCheck: boolean; + public dumpPerf: boolean = false; constructor(buildConfig: BuildConfig) { this.buildConfig = buildConfig; @@ -326,6 +327,9 @@ export abstract class BaseMode { if (this.isDebug) { ets2pandaCmd.push('--debug-info'); } + if (this.dumpPerf) { + ets2pandaCmd.push('--dump-perf-metrics'); + } ets2pandaCmd.push(this.buildConfig.compileFiles[0]); this.logger.printInfo('ets2pandaCmd: ' + ets2pandaCmd.join(' ')); diff --git a/ets2panda/public/es2panda_lib.cpp b/ets2panda/public/es2panda_lib.cpp index dbefcc58ab..8dd7c9a0fa 100644 --- a/ets2panda/public/es2panda_lib.cpp +++ b/ets2panda/public/es2panda_lib.cpp @@ -19,6 +19,7 @@ #include #include "util/diagnostic.h" +#include "util/perfMetrics.h" #include "varbinder/varbinder.h" #include "varbinder/scope.h" #include "public/public.h" @@ -253,6 +254,9 @@ extern "C" void DestroyConfig(es2panda_Config *config) return; } + if (cfg->options->IsDumpPerfMetrics()) { + util::DumpPerfMetrics(); + } delete cfg->options; cfg->diagnosticEngine->FlushDiagnostic(); delete cfg->diagnosticEngine; @@ -531,6 +535,7 @@ __attribute__((unused)) static Context *Parse(Context *ctx) } ctx->phaseManager->Reset(); + ES2PANDA_PERF_SCOPE("@Parser"); if (ctx->isExternal && ctx->allocator != ctx->globalContext->stdLibAllocator) { ctx->sourceFileNames.emplace_back(ctx->sourceFileName); @@ -599,6 +604,7 @@ __attribute__((unused)) static Context *Check(Context *ctx) if (phase->Name() == "plugins-after-check") { break; } + ES2PANDA_PERF_EVENT_SCOPE("@phases/" + std::string(phase->Name())); phase->Apply(ctx, ctx->parserProgram); } ctx->phaseManager->SetCurrentPhaseIdToAfterCheck(); @@ -639,6 +645,7 @@ __attribute__((unused)) static Context *Lower(Context *ctx) ES2PANDA_ASSERT(ctx->state == ES2PANDA_STATE_CHECKED); while (auto phase = ctx->phaseManager->NextPhase()) { + ES2PANDA_PERF_EVENT_SCOPE("@phases/" + std::string(phase->Name())); phase->Apply(ctx, ctx->parserProgram); } ctx->state = !ctx->diagnosticEngine->IsAnyError() ? ES2PANDA_STATE_LOWERED : ES2PANDA_STATE_ERROR; @@ -669,6 +676,7 @@ __attribute__((unused)) static Context *GenerateAsm(Context *ctx) ES2PANDA_ASSERT(ctx->state == ES2PANDA_STATE_LOWERED); + ES2PANDA_PERF_SCOPE("@EmitProgram"); auto *emitter = ctx->emitter; emitter->GenAnnotation(); @@ -1071,6 +1079,7 @@ extern "C" es2panda_Scope *AstNodeRebind(es2panda_Context *ctx, es2panda_AstNode extern "C" void AstNodeRecheck(es2panda_Context *ctx, es2panda_AstNode *node) { + ES2PANDA_PERF_SCOPE("@Recheck"); auto E2pNode = reinterpret_cast(node); auto context = reinterpret_cast(ctx); auto varbinder = context->parserProgram->VarBinder()->AsETSBinder(); -- Gitee