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 #ifndef OHOS_HIVIEWDFX_HITRACE_COMMON_UTILS_H
17 #define OHOS_HIVIEWDFX_HITRACE_COMMON_UTILS_H
18 
19 #include <string>
20 #include <map>
21 #include <vector>
22 #include "hilog/log.h"
23 
24 using OHOS::HiviewDFX::HiLog;
25 
26 namespace OHOS {
27 namespace HiviewDFX {
28 namespace Hitrace {
29 
30 struct TagCategory {
31     std::string description;
32     uint64_t tag;
33     int type;
34     std::vector<std::string> sysFiles;
35 };
36 
37 #undef LOG_DOMAIN
38 #define LOG_DOMAIN 0xD002D33
39 
40 #undef LOG_TAG
41 #define LOG_TAG "HitraceInfo"
42 
43 /**
44  * Canonicalization and verification of file paths.
45 */
46 std::string CanonicalizeSpecPath(const char* src);
47 
48 /**
49  * Clock sync: Use trace to mark the real-time and monotonic at this moment
50  * Example of trace output:
51  *  ...... 88.767049: tracing_mark_write: trace_event_clock_sync: realtime_ts=1501929219561
52  *  ...... 88.767072: tracing_mark_write: trace_event_clock_sync: parent_ts=88.767036
53 */
54 bool MarkClockSync(const std::string& traceRootPath);
55 
56 /**
57  * Parse trace tags info from /system/etc/hiview/hitrace_utils.json
58 */
59 bool ParseTagInfo(std::map<std::string, TagCategory> &allTags,
60                   std::map<std::string, std::vector<std::string>> &tagGroupTable);
61 
62 bool IsNumber(const std::string &str);
63 
64 } // Hitrace
65 } // HiviewDFX
66 } // OHOS
67 
68 #endif // OHOS_HIVIEWDFX_HITRACE_COMMON_UTILS_H