From fd6a6513e54c4579703463dc0f45069d1ccaf608 Mon Sep 17 00:00:00 2001 From: Tatiana Titova Date: Wed, 20 Aug 2025 17:08:00 +0300 Subject: [PATCH] Add init measurements Signed-off-by: Tatiana Titova --- ets2panda/compiler/core/compileJob.cpp | 4 +++- ets2panda/compiler/lowering/phase.cpp | 2 ++ ets2panda/driver/build_system/src/build/base_mode.ts | 4 ++++ ets2panda/driver/build_system/src/build/build_mode.ts | 3 +++ ets2panda/driver/build_system/src/utils/record_time_mem.ts | 2 +- ets2panda/parser/parserImpl.cpp | 2 ++ ets2panda/public/es2panda_lib.cpp | 3 +++ ets2panda/util/perfMetrics.cpp | 2 +- 8 files changed, 19 insertions(+), 3 deletions(-) diff --git a/ets2panda/compiler/core/compileJob.cpp b/ets2panda/compiler/core/compileJob.cpp index 1c1bbcea20..bc28669544 100644 --- a/ets2panda/compiler/core/compileJob.cpp +++ b/ets2panda/compiler/core/compileJob.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 - 2024 Huawei Device Co., Ltd. + * Copyright (c) 2021 - 2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -20,6 +20,8 @@ namespace ark::es2panda::compiler { void CompileJob::Run() { + ES2PANDA_PERF_FN_SCOPE(); + std::unique_lock lock(m_); cond_.wait(lock, [this] { return dependencies_ == 0; }); diff --git a/ets2panda/compiler/lowering/phase.cpp b/ets2panda/compiler/lowering/phase.cpp index 35d0a0f540..d8411bc96b 100644 --- a/ets2panda/compiler/lowering/phase.cpp +++ b/ets2panda/compiler/lowering/phase.cpp @@ -232,6 +232,8 @@ bool Phase::Apply(public_lib::Context *ctx, parser::Program *program) SetPhaseManager(ctx->phaseManager); GetPhaseManager()->SetCurrentPhaseId(id_); + ES2PANDA_PERF_EVENT_SCOPE("@lowering-phase/" + std::string(Name())); + #ifndef NDEBUG if (!Precondition(ctx, program)) { ctx->GetChecker()->LogError(diagnostic::PRECOND_FAILED, {Name()}, lexer::SourcePosition {}); diff --git a/ets2panda/driver/build_system/src/build/base_mode.ts b/ets2panda/driver/build_system/src/build/base_mode.ts index 231eaa7349..e24b323240 100644 --- a/ets2panda/driver/build_system/src/build/base_mode.ts +++ b/ets2panda/driver/build_system/src/build/base_mode.ts @@ -205,6 +205,7 @@ export abstract class BaseMode { '_', '--extension', 'ets', + '--dump-perf-metrics', '--arktsconfig', fileInfo.arktsConfigFile, fileInfo.filePath @@ -260,6 +261,7 @@ export abstract class BaseMode { '_', '--extension', 'ets', + '--dump-perf-metrics', '--arktsconfig', fileInfo.arktsConfigFile, '--output', @@ -356,6 +358,7 @@ export abstract class BaseMode { '_', '--extension', 'ets', + '--dump-perf-metrics', '--arktsconfig', moduleInfo.arktsConfigFile, '--output', @@ -1369,6 +1372,7 @@ export abstract class BaseMode { '_', '--extension', 'ets', + '--dump-perf-metrics', '--arktsconfig', fileInfo.arktsConfigFile, '--output', diff --git a/ets2panda/driver/build_system/src/build/build_mode.ts b/ets2panda/driver/build_system/src/build/build_mode.ts index ceb492b3e0..5228675b60 100644 --- a/ets2panda/driver/build_system/src/build/build_mode.ts +++ b/ets2panda/driver/build_system/src/build/build_mode.ts @@ -31,12 +31,15 @@ export class BuildMode extends BaseMode { public async run(): Promise { if (this.es2pandaMode === ES2PANDA_MODE.RUN_PARALLEL) { // RUN_PARALLEL: Executes tasks using multiple processes + console.log(' run parallel '); await super.runParallel(); } else if (this.es2pandaMode === ES2PANDA_MODE.RUN_CONCURRENT) { // RUN_CONCURRENT: Executes tasks using multiple threads with astcache + console.log(' run concurrently '); await super.runConcurrent(); } else if (this.es2pandaMode === ES2PANDA_MODE.RUN) { // RUN: Executes tasks sequentially in a single process and single thread + console.log(' run sequentially '); await super.run(); } else { // Default fallback: Uses parallel execution (same as RUN_PARALLEL) diff --git a/ets2panda/driver/build_system/src/utils/record_time_mem.ts b/ets2panda/driver/build_system/src/utils/record_time_mem.ts index 3998068a44..f0ba60c29f 100644 --- a/ets2panda/driver/build_system/src/utils/record_time_mem.ts +++ b/ets2panda/driver/build_system/src/utils/record_time_mem.ts @@ -59,7 +59,7 @@ export class CompileSingleData { this.file = file; this.timeMemMap = new Map(); // close by default - this.recordType = recordType ?? RECORD_TYPE.DEFAULT_TYPE; + this.recordType = recordType ?? RECORD_TYPE.ON_TYPE; } public record(startKey: string, lastEndKey: string = '') { diff --git a/ets2panda/parser/parserImpl.cpp b/ets2panda/parser/parserImpl.cpp index 1496bd4dbd..c014c06080 100644 --- a/ets2panda/parser/parserImpl.cpp +++ b/ets2panda/parser/parserImpl.cpp @@ -74,6 +74,8 @@ void ParserImpl::ParseScript(const SourceFile &sourceFile, bool genStdLib) void ParserImpl::ParseProgram(ScriptKind kind) { + ES2PANDA_PERF_FN_SCOPE(); + lexer::SourcePosition startLoc = lexer_->GetToken().Start(); lexer_->NextToken(); program_->SetKind(kind); diff --git a/ets2panda/public/es2panda_lib.cpp b/ets2panda/public/es2panda_lib.cpp index ea052d5e3d..911a1ac0b2 100644 --- a/ets2panda/public/es2panda_lib.cpp +++ b/ets2panda/public/es2panda_lib.cpp @@ -741,6 +741,9 @@ extern "C" __attribute__((unused)) es2panda_Context *ProceedToState(es2panda_Con ctx->state = ES2PANDA_STATE_ERROR; break; } + if (ctx->config != nullptr && ctx->config->options != nullptr && ctx->config->options->IsDumpPerfMetrics()) { + util::DumpPerfMetrics(); + } return reinterpret_cast(ctx); } diff --git a/ets2panda/util/perfMetrics.cpp b/ets2panda/util/perfMetrics.cpp index 981ec934c4..311ff32df9 100644 --- a/ets2panda/util/perfMetrics.cpp +++ b/ets2panda/util/perfMetrics.cpp @@ -272,7 +272,7 @@ static void DumpPerfMetricsImpl(std::optional prefix) } } - std::cout << ss.str(); + std::cout << ss.str() << std::flush; } void DumpPerfMetrics() -- Gitee