• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023-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 #ifndef HIVIEW_BASE_EVENT_STORE_INCLUDE_BASE_DEF_H
17 #define HIVIEW_BASE_EVENT_STORE_INCLUDE_BASE_DEF_H
18 
19 #include <string>
20 
21 namespace OHOS {
22 namespace HiviewDFX {
23 namespace EventStore {
24 #if __BYTE_ORDER == __LITTLE_ENDIAN
25 #define MAGIC_NUM (0x894556454E541a0a & ~1) // set the first low bit to 0
26 #elif __BYTE_ORDER == __BIG_ENDIAN
27 #define MAGIC_NUM (0x894556454E541a0a | 1)  // set the first low bit to 1
28 #else
29 #error "ERROR: No BIG_LITTLE_ENDIAN defines."
30 #endif
31 
32 #define NUM_OF_BYTES_IN_KB 1024
33 #define NUM_OF_BYTES_IN_MB (1024 * 1024)
34 #define CRC_SIZE sizeof(uint32_t)
35 #define BLOCK_SIZE sizeof(uint32_t)
36 #define SEQ_SIZE sizeof(int64_t)
37 
38 #define MAX_DOMAIN_LEN 17
39 #define MAX_EVENT_NAME_LEN 33
40 #define MAX_TAG_LEN 17
41 
42 #define MAX_NEW_SIZE (386 * 1024)
43 
44 #define EVENT_NAME_INDEX 0
45 #define EVENT_TYPE_INDEX 1
46 #define EVENT_LEVEL_INDEX 2
47 #define EVENT_SEQ_INDEX 3
48 #define FILE_NAME_SPLIT_SIZE 4
49 
50 #define INVALID_VALUE_INT (-1)
51 
52 #define DOC_STORE_SUCCESS 0
53 #define DOC_STORE_NEW_FILE 1
54 #define DOC_STORE_READ_EMPTY 2
55 #define DOC_STORE_ERROR_NULL (-1)
56 #define DOC_STORE_ERROR_IO (-2)
57 #define DOC_STORE_ERROR_MEMORY (-3)
58 #define DOC_STORE_ERROR_INVALID (-4)
59 
60 #define MAX_VERSION_LENG 1000
61 
62 enum EVENT_DATA_FORMATE_VERSION {
63     INVALID = 0x0,
64     VERSION1 = 0x1,
65     VERSION2 = 0x2,    // add log label into event header
66     VERSION3 = 0x3,    // remove crc and append system version into file header
67     CURRENT = VERSION3,
68 };
69 
70 #pragma pack(1)
71 /* File header of the binary storage file */
72 struct DocHeader {
73     /* Magic number */
74     uint64_t magicNum = 0;
75 
76     /* Block size */
77     uint32_t blockSize = 0;
78 
79     /* Page size */
80     uint8_t pageSize = 0;
81 
82     /* Version number */
83     uint8_t version = 0;
84 
85     /* Event tag */
86     char tag[MAX_TAG_LEN] = {0};
87 };
88 
89 struct ContentHeader {
90     /* event seqno */
91     uint64_t seq;
92 
93     /* Event timestamp */
94     uint64_t timestamp;
95 
96     /* Time zone */
97     uint8_t timeZone;
98 
99     /* User id */
100     uint32_t uid;
101 
102     /* Process id */
103     uint32_t pid;
104 
105     /* Thread id */
106     uint32_t tid;
107 
108     /* Event hash code*/
109     uint64_t id;
110 
111     /* Event type */
112     uint8_t type : 2;
113 
114     /* Trace info flag*/
115     uint8_t isTraceOpened : 1;
116 
117     /* Log packing flag */
118     uint8_t log;
119 };
120 using DocHeader = struct DocHeader;
121 
122 #pragma pack()
123 
124 } // EventStore
125 } // HiviewDFX
126 } // OHOS
127 #endif // HIVIEW_BASE_EVENT_STORE_INCLUDE_BASE_DEF_H
128