1 /* 2 * Copyright (c) Huawei Technologies Co., Ltd. 2021. 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 * Description: StreamTransporter class define 16 */ 17 #ifndef FTRACE_COMMON_TYPE_H 18 #define FTRACE_COMMON_TYPE_H 19 #include <string> 20 #include <vector> 21 #include "ftrace_namespace.h" 22 23 FTRACE_NS_BEGIN 24 enum PerCpuTraceStatus { 25 TRACE_START = 0, 26 TRACE_END = 1, 27 }; 28 29 // refers kernel enum ring_buffer_type: 30 // https://github.com/torvalds/linux/blob/v4.19/include/linux/ring_buffer.h#L55 31 enum EventBufferType { 32 BUFFER_TYPE_PADDING = 29, 33 BUFFER_TYPE_TIME_EXTEND = 30, 34 BUFFER_TYPE_TIME_STAMP = 31, 35 }; 36 37 // refers kernel struct ring_buffer_event: 38 // https://github.com/torvalds/linux/blob/v4.19/include/linux/ring_buffer.h#L15 39 struct FtraceEventHeader { 40 uint32_t typeLen : 5; 41 uint32_t timeDelta : 27; 42 uint32_t array[0]; 43 }; 44 45 struct HmTraceHeader { 46 unsigned short commonType; 47 unsigned char commonFlags; 48 unsigned char commonPreemptCount; 49 int commonPid; 50 }; 51 52 struct RmqConsumerData { 53 uint64_t timeStamp; 54 uint64_t length; 55 uint8_t coreId; 56 uint8_t data[]; 57 }; 58 59 struct RmqEntry { 60 uint32_t timeStampOffset; 61 uint16_t size; 62 uint8_t data[]; 63 } __attribute__((packed)); 64 65 // /sys/kernel/debug/tracing/events/header_page 66 // kernel source ring_buffer.c struct buffer_data_page 67 struct PageHeader { 68 uint64_t timestamp = 0; 69 uint64_t size = 0; // data size 70 uint8_t overwrite = 0; 71 uint8_t* startpos = nullptr; 72 uint8_t* endpos = nullptr; 73 }; 74 75 enum ProtoFieldType { 76 PROTO_TYPE_UNKNOWN = 0, 77 PROTO_TYPE_DOUBLE, 78 PROTO_TYPE_FLOAT, 79 PROTO_TYPE_INT64, 80 PROTO_TYPE_UINT64, 81 PROTO_TYPE_INT32, 82 PROTO_TYPE_FIXED64, 83 PROTO_TYPE_FIXED32, 84 PROTO_TYPE_BOOL, 85 PROTO_TYPE_STRING, 86 PROTO_TYPE_GROUP, // DEPRECATED (PROTO2 ONLY) 87 PROTO_TYPE_MESSAGE, 88 PROTO_TYPE_BYTES, 89 PROTO_TYPE_UINT32, 90 PROTO_TYPE_ENUM, 91 PROTO_TYPE_SFIXED32, 92 PROTO_TYPE_SFIXED64, 93 PROTO_TYPE_SINT32, 94 PROTO_TYPE_SINT64, 95 PROTO_TYPE_MAX, 96 }; 97 98 enum EventFieldType { 99 FIELD_TYPE_INVALID = 0, 100 FIELD_TYPE_BOOL, 101 FIELD_TYPE_INT8, 102 FIELD_TYPE_UINT8, 103 FIELD_TYPE_INT16, 104 FIELD_TYPE_UINT16, 105 FIELD_TYPE_INT32, 106 FIELD_TYPE_UINT32, 107 FIELD_TYPE_INT64, 108 FIELD_TYPE_UINT64, 109 FIELD_TYPE_FIXEDCSTRING, 110 FIELD_TYPE_CSTRING, 111 FIELD_TYPE_STRINGPTR, 112 FIELD_TYPE_INODE32, 113 FIELD_TYPE_INODE64, 114 FIELD_TYPE_PID32, 115 FIELD_TYPE_COMMONPID32, 116 FIELD_TYPE_DEVID32, 117 FIELD_TYPE_DEVID64, 118 FIELD_TYPE_DATALOC, 119 FIELD_TYPE_SYMADDR32, 120 FIELD_TYPE_SYMADDR64, 121 }; 122 123 // used to store content of each cpu stats data, likes /sys/kernel/debug/tracing/per_cpu/cpu0/stats. 124 struct PerCpuStats { 125 uint64_t cpuIndex = 0; 126 uint64_t entries = 0; 127 uint64_t overrun = 0; 128 uint64_t commitOverrun = 0; 129 uint64_t bytes = 0; 130 double oldestEventTs = 0.0; 131 double nowTs = 0.0; 132 uint64_t droppedEvents = 0; 133 uint64_t readEvents = 0; 134 }; 135 136 struct FieldFormat { 137 uint16_t offset = 0; 138 uint16_t size = 0; 139 uint8_t isSigned = 0; 140 EventFieldType filedType = FIELD_TYPE_INVALID; 141 ProtoFieldType protoType = PROTO_TYPE_UNKNOWN; 142 std::string name = ""; 143 std::string typeName = ""; 144 }; 145 146 struct CommonFiledIndex { 147 static constexpr int INVALID_IDX = -1; 148 int type = INVALID_IDX; 149 int flags = INVALID_IDX; 150 int preemt = INVALID_IDX; 151 int pid = INVALID_IDX; 152 }; 153 154 struct EventFormat { 155 uint32_t eventId = 0; 156 uint32_t eventSize = 0; 157 std::string eventName = ""; 158 std::string eventType = ""; 159 std::vector<FieldFormat> fields = {}; 160 std::vector<FieldFormat> commonFields = {}; 161 CommonFiledIndex commonIndex = {}; 162 }; 163 164 struct PageHeaderFormat { 165 FieldFormat timestamp = {}; 166 FieldFormat commit = {}; 167 FieldFormat overwrite = {}; 168 }; 169 FTRACE_NS_END 170 #endif 171