add aot hisysevent

Issue: https://gitee.com/openharmony/arkcompiler_ets_runtime/issues/I9IDDE
Signed-off-by: linxiang8 <linxiang8@huawei.com>
Change-Id: I43f19086b571347128391acdf7c0351579dbc566
This commit is contained in:
linxiang8 2024-04-20 17:03:18 +08:00
parent 813ec57d21
commit 05dfdaf4a4
8 changed files with 243 additions and 22 deletions

View File

@ -80,6 +80,7 @@ libark_jsoptimizer_sources = [
"access_object_stub_builder.cpp",
"aot_compilation_env.cpp",
"aot_compiler_preprocessor.cpp",
"aot_compiler_stats.cpp",
"argument_accessor.cpp",
"array_bounds_check_elimination.cpp",
"assembler/aarch64/assembler_aarch64.cpp",

View File

@ -32,17 +32,19 @@
#include "ecmascript/platform/file.h"
#include "ecmascript/platform/os.h"
#include "ecmascript/compiler/aot_compiler_stats.h"
namespace panda::ecmascript::kungfu {
namespace {
void CompileValidFiles(PassManager &passManager, AOTFileGenerator &generator, bool &ret,
const CVector<AbcFileInfo> &fileInfos)
const CVector<AbcFileInfo> &fileInfos, AotCompilerStats &compilerStats)
{
for (const AbcFileInfo &fileInfo : fileInfos) {
JSPandaFile *jsPandaFile = fileInfo.jsPandaFile_.get();
const std::string &extendedFilePath = fileInfo.extendedFilePath_;
LOG_COMPILER(INFO) << "AOT compile: " << extendedFilePath;
generator.SetCurrentCompileFileName(jsPandaFile->GetNormalizedFileDesc());
if (passManager.Compile(jsPandaFile, extendedFilePath, generator) == false) {
if (passManager.Compile(jsPandaFile, extendedFilePath, generator, compilerStats) == false) {
ret = false;
continue;
}
@ -68,14 +70,6 @@ std::pair<bool, int> CheckVersion(JSRuntimeOptions &runtimeOptions, bool result)
int Main(const int argc, const char **argv)
{
auto startTime =
std::chrono::duration_cast<std::chrono::nanoseconds>(std::chrono::system_clock::now().time_since_epoch())
.count();
LOG_ECMA(DEBUG) << "Print ark_aot_compiler received args:";
for (int i = 0; i < argc; i++) {
LOG_ECMA(DEBUG) << argv[i];
}
if (argc < 2) { // 2: at least have two arguments
LOG_COMPILER(ERROR) << AotCompilerPreprocessor::GetHelper();
return -1;
@ -95,10 +89,6 @@ int Main(const int argc, const char **argv)
}
}
if (runtimeOptions.IsStartupTime()) {
LOG_COMPILER(DEBUG) << "Startup start time: " << startTime;
}
bool ret = true;
// ark_aot_compiler running need disable asm interpreter to disable the loading of AOT files.
runtimeOptions.SetEnableAsmInterpreter(false);
@ -131,6 +121,16 @@ int Main(const int argc, const char **argv)
// no need to compile in partial mode without any ap files.
return 0;
}
AotCompilerStats compilerStats;
std::string bundleName = "";
if (cPreprocessor.GetMainPkgArgs()) {
bundleName = cPreprocessor.GetMainPkgArgs()->GetBundleName();
}
compilerStats.SetBundleName(bundleName);
compilerStats.SetAotFilePath(cOptions.outputFileName_);
compilerStats.SetPgoPath(cOptions.profilerIn_);
compilerStats.StartCompiler();
profilerDecoder.SetHotnessThreshold(cOptions.hotnessThreshold_);
profilerDecoder.SetInPath(cOptions.profilerIn_);
cPreprocessor.AOTInitialize();
@ -140,6 +140,12 @@ int Main(const int argc, const char **argv)
// need support muilt abc
auto result = CheckVersion(runtimeOptions, cPreprocessor.HandleMergedPgoFile(checksum));
if (result.first) {
if (result.second != 0) {
compilerStats.SetPgoFileLegal(false);
}
if (runtimeOptions.IsTargetCompilerMode()) {
compilerStats.PrintCompilerStatsLog();
}
return result.second;
}
cPreprocessor.GeneratePGOTypes(cOptions);
@ -187,21 +193,22 @@ int Main(const int argc, const char **argv)
cOptions.optBCRange_);
bool isEnableLiteCG = runtimeOptions.IsCompilerEnableLiteCG();
if (cPreprocessor.GetMainPkgArgs()) {
std::string bundleName = cPreprocessor.GetMainPkgArgs()->GetBundleName();
if (ohos::EnableAotListHelper::GetInstance()->IsEnableList(bundleName)) {
isEnableLiteCG = true;
}
if (ohos::EnableAotListHelper::GetInstance()->IsEnableList(bundleName)) {
isEnableLiteCG = true;
}
vm->GetJSOptions().SetCompilerEnableLiteCG(isEnableLiteCG);
compilerStats.SetIsLiteCg(isEnableLiteCG);
AOTFileGenerator generator(&log, &logList, &aotCompilationEnv, cOptions.triple_, isEnableLiteCG);
CompileValidFiles(passManager, generator, ret, fileInfos);
CompileValidFiles(passManager, generator, ret, fileInfos, compilerStats);
std::string appSignature = cPreprocessor.GetMainPkgArgsAppSignature();
generator.SaveAOTFile(cOptions.outputFileName_ + AOTFileManager::FILE_EXTENSION_AN, appSignature);
generator.SaveSnapshotFile();
log.Print();
if (runtimeOptions.IsTargetCompilerMode()) {
compilerStats.PrintCompilerStatsLog();
}
}
LOG_COMPILER(INFO) << (ret ? "ts aot compile success" : "ts aot compile failed");

View File

@ -0,0 +1,60 @@
/*
* Copyright (c) 2024 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "ecmascript/compiler/aot_compiler_stats.h"
#ifdef ENABLE_HISYSEVENT
#include "hisysevent.h"
#endif
namespace panda::ecmascript {
void AotCompilerStats::PrintCompilerStatsLog()
{
EndCompiler();
LOG_GC(ERROR) << "AotComiler LOG\n "
<< "bundleName: " << GetBundleName() << "\n"
<< "pgoFilePath: " << GetPgoPath() << "\n"
<< "aotFilePath: " << GetAotFilePath() << "\n"
<< "totalTile: " << GetTotalTime() << "\n"
<< "isLiteCg: " << IsLiteCg() << "\n"
<< "compilerMethodCount: " << GetCompilerMethodCount() << "\n"
<< "pgoFileLegal: " << GetPgoFileLegal() << "\n";
if (!GetPgoFileLegal() || IsLongTimeCompiler()) {
SendSysEvent();
}
}
void AotCompilerStats::SendSysEvent() const
{
#ifdef ENABLE_HISYSEVENT
LOG_GC(ERROR) << "send sys event";
int32_t ret = HiSysEventWrite(OHOS::HiviewDFX::HiSysEvent::Domain::ARKTS_RUNTIME,
"ARK_COMPILER_LOG",
OHOS::HiviewDFX::HiSysEvent::EventType::STATISTIC,
"BUNDLE_NAME", GetBundleName(),
"PGO_FILE_PATH", GetPgoPath(),
"AOT_FILE_PATH", GetAotFilePath(),
"COMPILER_TIME", GetTotalTime(),
"IS_LITECG", IsLiteCg(),
"COMPILER_METHOD_COUNT", GetCompilerMethodCount(),
"PGO_FILE_LEGAL", GetPgoFileLegal());
if (ret != 0) {
LOG_GC(ERROR) << "AotCompilerStats HiSysEventWrite Failed! ret = " << ret;
}
#endif
}
} // namespace panda::ecmascript

View File

@ -0,0 +1,133 @@
/*
* Copyright (c) 2024 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef ECMASCRIPT_AOT_COMPILER_STATS_H
#define ECMASCRIPT_AOT_COMPILER_STATS_H
#include "ecmascript/log.h"
#include "ecmascript/log_wrapper.h"
#include <ctime>
#include <chrono>
#include <string>
namespace panda::ecmascript {
using Clock = std::chrono::high_resolution_clock;
using Duration = std::chrono::duration<uint64_t, std::nano>;
class AotCompilerStats {
public:
AotCompilerStats() {};
~AotCompilerStats() = default;
void SetBundleName(std::string bundleName)
{
bundleName_ = bundleName;
}
std::string GetBundleName() const
{
return bundleName_;
}
void SetPgoPath(std::string pgoFilePath)
{
pgoFilePath_ = pgoFilePath;
}
std::string GetPgoPath() const
{
return pgoFilePath_;
}
void SetAotFilePath(std::string aotFilePath)
{
aotFilePath_ = aotFilePath;
}
std::string GetAotFilePath() const
{
return aotFilePath_;
}
void StartCompiler()
{
start_ = Clock::now();
}
void EndCompiler()
{
end_ = Clock::now();
}
float GetTotalTime() const
{
auto duration = std::chrono::duration_cast<std::chrono::microseconds>(end_ - start_);
return (float) duration.count() / SECOND_TIME;
}
void SetIsLiteCg(bool litecg)
{
isLiteCg_ = litecg;
}
bool IsLiteCg() const
{
return isLiteCg_;
}
void SetCompilerMethodCount(uint32_t count)
{
compilerMethodCount_ += count;
}
uint32_t GetCompilerMethodCount() const
{
return compilerMethodCount_;
}
void SetPgoFileLegal(bool legal)
{
pgoFileLegal_ = legal;
}
bool GetPgoFileLegal() const
{
return pgoFileLegal_;
}
void PrintCompilerStatsLog();
private:
void SendSysEvent() const;
bool IsLongTimeCompiler() const
{
return GetTotalTime() > longTime_;
}
std::string bundleName_ = "";
std::string pgoFilePath_ = "";
std::string aotFilePath_ = "";
Clock::time_point start_;
Clock::time_point end_;
bool isLiteCg_ = false;
uint32_t compilerMethodCount_ = 0;
bool pgoFileLegal_ = true;
float longTime_ = 120;
static constexpr uint32_t SECOND_TIME = 1000000;
};
}
#endif // ECMASCRIPT_AOT_COMPILER_STATS_H

View File

@ -155,6 +155,11 @@ public:
panda_file::File::EntityId resolvedMethodId(resolvedMethod);
UpdateCompileQueue(recordName, resolvedMethodId);
}
uint32_t GetCompilerMethodCount() const
{
return compiledMethodCnt_;
}
protected:
// add maxMethodsInModule_ functions in a module and when a module is
// full(maxMethodsInModule_ functions have been put into) or the module is the last module,

View File

@ -213,7 +213,8 @@ JitPassManager::~JitPassManager()
}
}
bool PassManager::Compile(JSPandaFile *jsPandaFile, const std::string &fileName, AOTFileGenerator &gen)
bool PassManager::Compile(JSPandaFile *jsPandaFile, const std::string &fileName, AOTFileGenerator &gen,
AotCompilerStats &compilerStats)
{
[[maybe_unused]] EcmaHandleScope handleScope(compilationEnv_->GetJSThread());
@ -323,6 +324,7 @@ bool PassManager::Compile(JSPandaFile *jsPandaFile, const std::string &fileName,
pipeline.RunPass<CGIRGenPass>();
});
compilerStats.SetCompilerMethodCount(cmpDriver.GetCompilerMethodCount());
LOG_COMPILER(INFO) << collector.GetBytecodeInfo().GetSkippedMethodSize()
<< " methods have been skipped";
return true;

View File

@ -29,6 +29,8 @@
#include "ecmascript/jspandafile/method_literal.h"
#include "ecmascript/ts_types/ts_manager.h"
#include "ecmascript/compiler/aot_compiler_stats.h"
namespace panda::ecmascript::kungfu {
class Bytecodes;
class LexEnvManager;
@ -155,7 +157,8 @@ public:
};
virtual ~PassManager() = default;
bool Compile(JSPandaFile *jsPandaFile, const std::string &fileName, AOTFileGenerator &generator);
bool Compile(JSPandaFile *jsPandaFile, const std::string &fileName, AOTFileGenerator &generator,
AotCompilerStats &compilerStats);
protected:
bool IsReleasedPandaFile(const JSPandaFile *jsPandaFile) const;

View File

@ -31,3 +31,13 @@ ARK_STATS_GC:
GC_OLD_MEM_COMMITTED: {type: INT32, desc: Total memory committed by the old generation after GC in the statistical period}
GC_HUGE_MEM_USED: {type: INT32, desc: Total memory used by the Huge segment after GC in this measurement period}
GC_HUGE_MEM_COMMITTED: {type: INT32, desc: Total committed memory of the Huge segment after GC in this measurement period}
ARK_COMPILER_LOG:
__BASE: {type: STATISTIC, level: MINOR, desc: ARKTSRUNTIME AOT COMPILER KEY STATS, preserve: true}
BUNDLE_NAME: {type: STRING, desc: application bundle name}
PGO_FILE_PATH: {type: STRING, desc: application pgo file path}
AOT_FILE_PATH: {type: STRING, desc: application aot file path}
COMPILER_TIME: {type: FLOAT, desc: compiler total time}
IS_LITECG: {type: BOOL, desc: codegen type is litecg}
COMPILER_METHOD_COUNT: {type: UINT32, desc: compiler method count}
PGO_FILE_LEGAL: {type: BOOL, desc: pgo file is legal}