• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 HISYSEVENT_INTERFACE_ENCODE_INCLUDE_RAW_BASE_DEF_H
17 #define HISYSEVENT_INTERFACE_ENCODE_INCLUDE_RAW_BASE_DEF_H
18 
19 #include <cstdarg>
20 #include <cstddef>
21 #include <cstdint>
22 #include <string>
23 
24 #include "def.h"
25 
26 namespace OHOS {
27 namespace HiviewDFX {
28 namespace Encoded {
29 constexpr char BASE_INFO_KEY_DOMAIN[] = "domain_";
30 constexpr char BASE_INFO_KEY_NAME[] = "name_";
31 constexpr char BASE_INFO_KEY_TYPE[] = "type_";
32 constexpr char BASE_INFO_KEY_TIME_STAMP[] = "time_";
33 constexpr char BASE_INFO_KEY_TIME_ZONE[] = "tz_";
34 constexpr char BASE_INFO_KEY_ID[] = "id_";
35 constexpr char BASE_INFO_KEY_PID[] = "pid_";
36 constexpr char BASE_INFO_KEY_TID[] = "tid_";
37 constexpr char BASE_INFO_KEY_UID[] = "uid_";
38 constexpr char BASE_INFO_KEY_TRACE_ID[] = "traceid_";
39 constexpr char BASE_INFO_KEY_SPAN_ID[] = "spanid_";
40 constexpr char BASE_INFO_KEY_PARENT_SPAN_ID[] = "pspanid_";
41 constexpr char BASE_INFO_KEY_TRACE_FLAG[] = "trace_flag_";
42 
43 #pragma pack(1)
44 struct HiSysEventHeader {
45     /* Event domain */
46     char domain[MAX_DOMAIN_LENGTH + 1];
47 
48     /* Event name */
49     char name[MAX_EVENT_NAME_LENGTH + 1];
50 
51     /* Event timestamp */
52     uint64_t timestamp;
53 
54     /* Time zone */
55     uint8_t timeZone;
56 
57     /* User id */
58     uint32_t uid;
59 
60     /* Process id */
61     uint32_t pid;
62 
63     /* Thread id */
64     uint32_t tid;
65 
66     /* Event hash code*/
67     uint64_t id;
68 
69     /* Event type */
70     uint8_t type : 2;
71 
72     /* Trace info flag */
73     uint8_t isTraceOpened : 1;
74 };
75 
76 struct TraceInfo {
77     /* Hitrace flag */
78     uint8_t traceFlag;
79 
80     /* Hitrace id */
81     uint64_t traceId;
82 
83     /* Hitrace span id */
84     uint32_t spanId;
85 
86     /* Hitrace parent span id */
87     uint32_t pSpanId;
88 };
89 
90 struct ParamValueType {
91     /* Array flag */
92     uint8_t isArray : 1;
93 
94     /* Type of parameter value */
95     uint8_t valueType : 4;
96 
97     /* Byte count of parameter value */
98     uint8_t valueByteCnt : 3;
99 };
100 #pragma pack()
101 
102 enum ValueType: uint8_t {
103     // Unknown value
104     UNKNOWN = 0,
105 
106     // Bool value
107     BOOL,
108 
109     // Int8_t value
110     INT8,
111 
112     // Uint8_t value
113     UINT8,
114 
115     // Int16_t value
116     INT16,
117 
118     // Uint16_t value
119     UINT16,
120 
121     // Int32_t value
122     INT32,
123 
124     // Uint32_t value
125     UINT32,
126 
127     // Int64_t value
128     INT64,
129 
130     // Uint64_t value
131     UINT64,
132 
133     // Float value
134     FLOAT,
135 
136     // Double value
137     DOUBLE,
138 
139     // String value
140     STRING,
141 };
142 
143 enum EncodeType: int8_t {
144     // Varint encoding
145     VARINT = 0,
146 
147     // Length delimited encoding
148     LENGTH_DELIMITED = 1,
149 
150     // Reserved
151     INVALID = 4,
152 };
153 
154 int ParseTimeZone(long tzVal);
155 } // namespace Encoded
156 } // namespace HiviewDFX
157 } // namespace OHOS
158 
159 #endif // HISYSEVENT_INTERFACE_ENCODE_RAW_INCLUDE_RAW_BASE_DEF_H