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 VERSION4 = 0x4, // append patch version into file header 68 CURRENT = VERSION4, 69 }; 70 71 #pragma pack(1) 72 /* File header of the binary storage file */ 73 struct DocHeader { 74 /* Magic number */ 75 uint64_t magicNum = 0; 76 77 /* Block size */ 78 uint32_t blockSize = 0; 79 80 /* Page size */ 81 uint8_t pageSize = 0; 82 83 /* Version number */ 84 uint8_t version = 0; 85 86 /* Event tag */ 87 char tag[MAX_TAG_LEN] = {0}; 88 }; 89 90 struct ContentHeader { 91 /* event seqno */ 92 uint64_t seq; 93 94 /* Event timestamp */ 95 uint64_t timestamp; 96 97 /* Time zone */ 98 uint8_t timeZone; 99 100 /* User id */ 101 uint32_t uid; 102 103 /* Process id */ 104 uint32_t pid; 105 106 /* Thread id */ 107 uint32_t tid; 108 109 /* Event hash code*/ 110 uint64_t id; 111 112 /* Event type */ 113 uint8_t type : 2; 114 115 /* Trace info flag*/ 116 uint8_t isTraceOpened : 1; 117 118 /* Log packing flag */ 119 uint8_t log; 120 }; 121 using DocHeader = struct DocHeader; 122 123 #pragma pack() 124 125 } // EventStore 126 } // HiviewDFX 127 } // OHOS 128 #endif // HIVIEW_BASE_EVENT_STORE_INCLUDE_BASE_DEF_H 129