1/*
2 * Copyright (c) 2024 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16#include "ecmascript/compiler/aot_compiler_stats.h"
17
18#ifdef ENABLE_HISYSEVENT
19#include "hisysevent.h"
20#endif
21
22namespace panda::ecmascript {
23
24void AotCompilerStats::PrintCompilerStatsLog()
25{
26    EndCompiler();
27    LOG_GC(ERROR) << "AotComiler LOG\n "
28        << "bundleName: " << GetBundleName() << "\n"
29        << "pgoFilePath: " << GetPgoPath() << "\n"
30        << "aotFilePath: " << GetAotFilePath() << "\n"
31        << "totalTile: " << GetTotalTime() << "\n"
32        << "isLiteCg: " << IsLiteCg() << "\n"
33        << "compilerMethodCount: " <<  GetCompilerMethodCount() << "\n"
34        << "pgoFileLegal: " << GetPgoFileLegal() << "\n";
35    if (!GetPgoFileLegal() || IsLongTimeCompiler()) {
36        SendSysEvent();
37    }
38}
39
40void AotCompilerStats::SendSysEvent() const
41{
42#ifdef ENABLE_HISYSEVENT
43    LOG_GC(ERROR) << "send sys event";
44    int32_t ret = HiSysEventWrite(OHOS::HiviewDFX::HiSysEvent::Domain::ARKTS_RUNTIME,
45        "ARK_COMPILER_LOG",
46        OHOS::HiviewDFX::HiSysEvent::EventType::STATISTIC,
47        "BUNDLE_NAME", GetBundleName(),
48        "PGO_FILE_PATH", GetPgoPath(),
49        "AOT_FILE_PATH", GetAotFilePath(),
50        "COMPILER_TIME", GetTotalTime(),
51        "IS_LITECG", IsLiteCg(),
52        "COMPILER_METHOD_COUNT", GetCompilerMethodCount(),
53        "PGO_FILE_LEGAL", GetPgoFileLegal());
54    if (ret != 0) {
55        LOG_GC(ERROR) << "AotCompilerStats HiSysEventWrite Failed! ret = " << ret;
56    }
57#endif
58}
59
60} // namespace panda::ecmascript