• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "ecmascript/log_wrapper.h"
19 #include "ecmascript/platform/directory.h"
20 #include "ecmascript/platform/os.h"
21 #ifdef ENABLE_HISYSEVENT
22 #include "hisysevent.h"
23 #endif
24 
25 namespace panda::ecmascript {
26 
27 const std::string DOMAIN_FOR_DATA_PARTITION = "FILEMANAGEMENT";
28 const std::string EVENT_FOR_DATA_PARTITION = "USER_DATA_SIZE";
29 const std::string PARTITION_NAME = "/data";
30 const std::string COMPONENT_NAME = "ets_runtime";
31 
PrintCompilerStatsLog()32 void AotCompilerStats::PrintCompilerStatsLog()
33 {
34     EndCompiler();
35     LOG_GC(ERROR) << "AotComiler LOG\n "
36         << "bundleName: " << GetBundleName() << "\n"
37         << "pgoFilePath: " << GetPgoPath() << "\n"
38         << "aotFilePath: " << GetAotFilePath() << "\n"
39         << "totalTile: " << GetTotalTime() << "\n"
40         << "isLiteCg: " << IsLiteCg() << "\n"
41         << "compilerMethodCount: " <<  GetCompilerMethodCount() << "\n"
42         << "pgoFileLegal: " << GetPgoFileLegal() << "\n";
43     if (!GetPgoFileLegal() || IsLongTimeCompiler()) {
44         SendSysEvent();
45     }
46 }
47 
SendSysEvent() const48 void AotCompilerStats::SendSysEvent() const
49 {
50 #ifdef ENABLE_HISYSEVENT
51     LOG_GC(ERROR) << "send sys event";
52     int32_t ret = HiSysEventWrite(OHOS::HiviewDFX::HiSysEvent::Domain::ARKTS_RUNTIME,
53         "ARK_COMPILER_LOG",
54         OHOS::HiviewDFX::HiSysEvent::EventType::STATISTIC,
55         "BUNDLE_NAME", GetBundleName(),
56         "PGO_FILE_PATH", GetPgoPath(),
57         "AOT_FILE_PATH", GetAotFilePath(),
58         "COMPILER_TIME", GetTotalTime(),
59         "IS_LITECG", IsLiteCg(),
60         "COMPILER_METHOD_COUNT", GetCompilerMethodCount(),
61         "PGO_FILE_LEGAL", GetPgoFileLegal());
62     if (ret != 0) {
63         LOG_GC(ERROR) << "AotCompilerStats HiSysEventWrite Failed! ret = " << ret;
64     }
65 #endif
66 }
67 
SendDataPartitionSysEvent(const std::string & path) const68 int32_t AotCompilerStats::SendDataPartitionSysEvent(const std::string &path) const
69 {
70 #ifdef ENABLE_HISYSEVENT
71     if (path.empty()) {
72         return -1;
73     }
74     LOG_ECMA(INFO) << "send data partition sys";
75     int32_t ret = HiSysEventWrite(OHOS::HiviewDFX::HiSysEvent::Domain::FILEMANAGEMENT,
76         "USER_DATA_SIZE",
77         OHOS::HiviewDFX::HiSysEvent::EventType::STATISTIC,
78         "COMPONENT_NAME", COMPONENT_NAME,
79         "PARTITION_NAME", PARTITION_NAME,
80         "REMAIN_PARTITION_SIZE", panda::ecmascript::GetDeviceValidSize(PARTITION_NAME),
81         "FILE_OR_FOLDER_PATH", path,
82         "FILE_OR_FOLDER_SIZE", panda::ecmascript::GetFolderSize(path));
83     if (ret != 0) {
84         LOG_ECMA(ERROR) << "AotCompilerStats SendDataPartitionSysEvent Failed! ret = " << ret;
85     }
86     return ret;
87 #endif
88     return 0;
89 }
90 
91 } // namespace panda::ecmascript