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 HIVIEW_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 INVALID_VALUE_INT (-1) 45 46 #define DOC_STORE_SUCCESS 0 47 #define DOC_STORE_NEW_FILE 1 48 #define DOC_STORE_READ_EMPTY 2 49 #define DOC_STORE_ERROR_NULL (-1) 50 #define DOC_STORE_ERROR_IO (-2) 51 #define DOC_STORE_ERROR_MEMORY (-3) 52 #define DOC_STORE_ERROR_INVALID (-4) 53 54 #define MAX_VERSION_LENG 1000 55 56 enum EVENT_DATA_FORMATE_VERSION { 57 INVALID = 0x0, 58 VERSION1 = 0x1, 59 VERSION2 = 0x2, // add log label into event header 60 VERSION3 = 0x3, // remove crc and append system version into file header 61 VERSION4 = 0x4, // append patch version into file header 62 CURRENT = VERSION4, 63 }; 64 65 #pragma pack(1) 66 /* File header of the binary storage file */ 67 struct DocHeader { 68 /* Magic number */ 69 uint64_t magicNum = 0; 70 71 /* Block size */ 72 uint32_t blockSize = 0; 73 74 /* Page size */ 75 uint8_t pageSize = 0; 76 77 /* Version number */ 78 uint8_t version = 0; 79 80 /* Event tag */ 81 char tag[MAX_TAG_LEN] = {0}; 82 }; 83 84 struct ContentHeader { 85 /* event seqno */ 86 uint64_t seq; 87 88 /* Event timestamp */ 89 uint64_t timestamp; 90 91 /* Time zone */ 92 uint8_t timeZone; 93 94 /* User id */ 95 uint32_t uid; 96 97 /* Process id */ 98 uint32_t pid; 99 100 /* Thread id */ 101 uint32_t tid; 102 103 /* Event hash code*/ 104 uint64_t id; 105 106 /* Event type */ 107 uint8_t type : 2; 108 109 /* Trace info flag*/ 110 uint8_t isTraceOpened : 1; 111 112 /* Log packing flag */ 113 uint8_t log; 114 }; 115 using DocHeader = struct DocHeader; 116 117 #pragma pack() 118 119 } // EventStore 120 } // HiviewDFX 121 } // OHOS 122 #endif // HIVIEW_BASE_EVENT_STORE_INCLUDE_BASE_DEF_H 123