1 /* 2 * Copyright (c) Huawei Technologies Co., Ltd. 2023. All rights reserved. 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 BYTRACE_COMMON_TYPES_H 17 #define BYTRACE_COMMON_TYPES_H 18 19 #include <atomic> 20 #include <functional> 21 #include <memory> 22 #include <string> 23 #include <unordered_map> 24 #include "proto_reader_help.h" 25 #include "ts_common.h" 26 27 namespace SysTuning { 28 namespace TraceStreamer { 29 enum ParseResult { PARSE_ERROR = 0, PARSE_SUCCESS = 1 }; 30 enum RawType { RAW_CPU_IDLE = 1, RAW_SCHED_WAKEUP = 2, RAW_SCHED_WAKING = 3 }; 31 enum ErrorCode { ERROR_CODE_EXIT = -2, ERROR_CODE_NODATA = -1 }; 32 struct BytraceLine { 33 uint64_t ts = 0; 34 uint32_t pid = 0; 35 uint32_t cpu = 0; 36 37 std::string task; // thread name 38 uint32_t tgid = 0; 39 std::string eventName; 40 std::string argsStr; 41 }; 42 enum ParseStatus { 43 TS_PARSE_STATUS_INIT = 0, 44 TS_PARSE_STATUS_SEPRATED = 1, 45 TS_PARSE_STATUS_PARSING = 2, 46 TS_PARSE_STATUS_PARSED = 3, 47 TS_PARSE_STATUS_INVALID = 4 48 }; 49 struct DataSegment { 50 std::string seg; 51 BytraceLine bufLine; 52 std::atomic<ParseStatus> status{TS_PARSE_STATUS_INIT}; 53 }; 54 struct HilogLine { 55 uint64_t lineSeq; 56 uint64_t timeStamp; 57 uint32_t pid; 58 uint32_t tid; 59 std::string level; 60 std::string tag; 61 std::string context; 62 }; 63 struct PbreaderDataSegment { 64 std::shared_ptr<std::string> seg; 65 uint64_t timeStamp{INVALID_TIME}; 66 std::atomic<BuiltinClocks> clockId; 67 DataSourceType dataType; 68 std::atomic<ParseStatus> status{TS_PARSE_STATUS_INIT}; 69 ProtoReader::BytesView protoData; 70 }; 71 struct RawtraceDataSegment { 72 std::shared_ptr<std::string> seg; 73 uint64_t timeStamp; 74 std::atomic<ParseStatus> status{TS_PARSE_STATUS_INIT}; 75 }; 76 77 class TracePoint { 78 public: TracePoint()79 TracePoint() {} TracePoint(const TracePoint & point)80 TracePoint(const TracePoint &point) 81 : phase_(point.phase_), 82 tgid_(point.tgid_), 83 name_(point.name_), 84 value_(point.value_), 85 categoryGroup_(point.categoryGroup_), 86 chainId_(point.chainId_), 87 spanId_(point.spanId_), 88 parentSpanId_(point.parentSpanId_), 89 flag_(point.flag_), 90 args_(point.args_), 91 funcPrefixId_(point.funcPrefixId_), 92 funcPrefix_(point.funcPrefix_), 93 funcArgs_(point.funcArgs_) 94 { 95 } 96 void operator=(const TracePoint &point) 97 { 98 phase_ = point.phase_; 99 tgid_ = point.tgid_; 100 name_ = point.name_; 101 value_ = point.value_; 102 categoryGroup_ = point.categoryGroup_; 103 chainId_ = point.chainId_; 104 spanId_ = point.spanId_; 105 parentSpanId_ = point.parentSpanId_; 106 flag_ = point.flag_; 107 args_ = point.args_; 108 funcPrefixId_ = point.funcPrefixId_; 109 funcPrefix_ = point.funcPrefix_; 110 funcArgs_ = point.funcArgs_; 111 } 112 char phase_ = '\0'; 113 uint32_t tgid_ = 0; 114 std::string name_ = ""; 115 int64_t value_ = 0; 116 std::string categoryGroup_ = ""; 117 // Distributed Data 118 std::string chainId_ = ""; 119 std::string spanId_ = ""; 120 std::string parentSpanId_ = ""; 121 std::string flag_ = ""; 122 std::string args_ = ""; 123 uint32_t funcPrefixId_ = 0; 124 std::string funcPrefix_ = ""; 125 std::string funcArgs_ = ""; 126 }; 127 128 enum class SplitDataDataType { SPLIT_FILE_DATA = 0, SPLIT_FILE_JSON }; 129 struct HtraceSplitResult { 130 int32_t type; 131 union { 132 struct { 133 uint8_t *address; 134 uint64_t size; 135 } buffer; 136 struct { 137 uint64_t offset; 138 uint64_t size; 139 } originSeg; 140 }; 141 }; 142 143 struct RawTraceFileHeader { 144 uint16_t magicNumber; 145 uint8_t fileType; 146 uint16_t versionNumber; 147 uint32_t reserved; 148 } __attribute__((aligned(4))); 149 150 enum class RawTraceContentType : uint8_t { 151 CONTENT_TYPE_DEFAULT = 0, 152 CONTENT_TYPE_EVENTS_FORMAT = 1, 153 CONTENT_TYPE_CMDLINES = 2, 154 CONTENT_TYPE_TGIDS = 3, 155 CONTENT_TYPE_CPU_RAW = 4, 156 CONTENT_TYPE_HEADER_PAGE = 30, 157 CONTENT_TYPE_PRINTK_FORMATS = 31, 158 CONTENT_TYPE_KALLSYMS = 32 159 }; 160 enum class RawTraceFileType : uint8_t { FILE_RAW_TRACE = 0, HM_FILE_RAW_TRACE = 1 }; 161 } // namespace TraceStreamer 162 } // namespace SysTuning 163 #endif // _BYTRACE_COMMON_TYPES_H_ 164