• 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 #ifndef HIVIEW_BASE_EVENT_STORE_INCLUDE_BASE_DEF_H
16 #define HIVIEW_BASE_EVENT_STORE_INCLUDE_BASE_DEF_H
17 
18 #include <string>
19 
20 namespace OHOS {
21 namespace HiviewDFX {
22 namespace EventStore {
23 #define MAGIC_NUM 0x894556454E541a0a
24 #define NUM_OF_BYTES_IN_KB 1024
25 #define NUM_OF_BYTES_IN_MB (1024 * 1024)
26 #define BLOCK_SIZE sizeof(uint32_t)
27 #define HEADER_SIZE sizeof(DocHeader)
28 #define DOC_EVENT_HEADER_SIZE sizeof(DocEventHeader)
29 
30 #define MAX_TAG_LEN 17
31 
32 #define MAX_NEW_SIZE (386 * 1024)
33 
34 #define EVENT_NAME_INDEX 0
35 #define EVENT_TYPE_INDEX 1
36 #define EVENT_LEVEL_INDEX 2
37 #define EVENT_SEQ_INDEX 3
38 #define FILE_NAME_SPLIT_SIZE 4
39 
40 #define INVALID_VALUE_INT (-1)
41 
42 #define DOC_STORE_SUCCESS 0
43 #define DOC_STORE_NEW_FILE 1
44 #define DOC_STORE_READ_EMPTY 2
45 #define DOC_STORE_ERROR_NULL (-1)
46 #define DOC_STORE_ERROR_IO (-2)
47 #define DOC_STORE_ERROR_MEMORY (-3)
48 #define DOC_STORE_ERROR_INVALID (-4)
49 
50 const char FILE_NAME_SEPARATOR[] = "-";
51 const char FILE_SEPARATOR[] = "/";
52 const char FILE_EXT[] = ".db";
53 
54 /* Object returned by the event query */
55 struct Entry {
56     /* Event sequence */
57     int64_t id = 0;
58 
59     /* Event timestamp */
60     int64_t ts = 0;
61 
62     /* Event json string */
63     std::string value;
64 };
65 using Entry = struct Entry;
66 
67 /* File header of the binary storage file */
68 struct DocHeader {
69     /* Magic number */
70     uint64_t magicNum = 0;
71 
72     /* Page size */
73     uint8_t pageSize = 0;
74 
75     /* Version number */
76     uint8_t version = 0;
77 
78     /* Event tag */
79     char tag[MAX_TAG_LEN] = {0};
80 };
81 using DocHeader = struct DocHeader;
82 
83 /* Event content header for each event in the binary storage file */
84 struct DocEventHeader {
85     int64_t seq = 0;
86     uint64_t timestamp = 0;
87     uint8_t timeZone = 0;
88     uint32_t uid = 0;
89     uint32_t pid = 0;
90     uint32_t tid = 0;
91     uint64_t id = 0;
92     uint8_t isTraceOpened : 1;
93 };
94 using DocEventHeader = struct DocEventHeader;
95 
96 /* Common event information read from the binary storage file */
97 struct CommonEventInfo {
98     std::string domain;
99     std::string name;
100     std::string level;
101     std::string tag;
102     uint8_t type = 0;
103 };
104 using CommonEventInfo = struct CommonEventInfo;
105 } // EventStore
106 } // HiviewDFX
107 } // OHOS
108 #endif // HIVIEW_BASE_EVENT_STORE_INCLUDE_BASE_DEF_H
109