1 /*
2  * Copyright (c) 2023 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/pgo_profiler/pgo_utils.h"
17 #include <cstdint>
18 
19 namespace panda::ecmascript::pgo {
20 
21 const std::string DumpUtils::ELEMENT_SEPARATOR = "/";
22 const std::string DumpUtils::BLOCK_SEPARATOR = ",";
23 const std::string DumpUtils::TYPE_SEPARATOR = "|";
24 const std::string DumpUtils::BLOCK_START = ":";
25 const std::string DumpUtils::ARRAY_START = "[";
26 const std::string DumpUtils::ARRAY_END = "]";
27 const std::string DumpUtils::NEW_LINE = "\n";
28 const std::string DumpUtils::SPACE = " ";
29 const std::string DumpUtils::BLOCK_AND_ARRAY_START = BLOCK_START + SPACE + ARRAY_START + SPACE;
30 const std::string DumpUtils::VERSION_HEADER = "Profiler Version" + BLOCK_START + SPACE;
31 const std::string DumpUtils::PANDA_FILE_INFO_HEADER = "Panda file sumcheck list" + BLOCK_AND_ARRAY_START;
32 const uint32_t DumpUtils::HEX_FORMAT_WIDTH_FOR_32BITS = 10;  // for example, 0xffffffff is 10 characters
33 
34 const std::string ApNameUtils::AP_SUFFIX = ".ap";
35 const std::string ApNameUtils::RUNTIME_AP_PREFIX = "rt_";
36 const std::string ApNameUtils::MERGED_AP_PREFIX = "merged_";
37 const std::string ApNameUtils::DEFAULT_AP_NAME = "modules" + AP_SUFFIX;
38 
GetRuntimeApName(const std::string &ohosModuleName)39 std::string ApNameUtils::GetRuntimeApName(const std::string &ohosModuleName)
40 {
41     return RUNTIME_AP_PREFIX + GetBriefApName(ohosModuleName);
42 }
43 
GetMergedApName(const std::string &ohosModuleName)44 std::string ApNameUtils::GetMergedApName(const std::string &ohosModuleName)
45 {
46     return MERGED_AP_PREFIX + GetBriefApName(ohosModuleName);
47 }
48 
GetOhosPkgApName(const std::string &ohosModuleName)49 std::string ApNameUtils::GetOhosPkgApName(const std::string &ohosModuleName)
50 {
51     return GetBriefApName(ohosModuleName);
52 }
53 
GetBriefApName(const std::string &ohosModuleName)54 std::string ApNameUtils::GetBriefApName(const std::string &ohosModuleName)
55 {
56     return ohosModuleName + AP_SUFFIX;
57 }
58 } // namespace panda::ecmascript::pgo