• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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  * 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 // /sys/kernel/debug/tracing/events/header_page
46 // kernel source ring_buffer.c struct buffer_data_page
47 struct PageHeader {
48     uint64_t timestamp = 0;
49     uint64_t size = 0; // data size
50     uint8_t overwrite = 0;
51     uint8_t* startpos = nullptr;
52     uint8_t* endpos = nullptr;
53 };
54 
55 enum ProtoFieldType {
56     PROTO_TYPE_UNKNOWN = 0,
57     PROTO_TYPE_DOUBLE,
58     PROTO_TYPE_FLOAT,
59     PROTO_TYPE_INT64,
60     PROTO_TYPE_UINT64,
61     PROTO_TYPE_INT32,
62     PROTO_TYPE_FIXED64,
63     PROTO_TYPE_FIXED32,
64     PROTO_TYPE_BOOL,
65     PROTO_TYPE_STRING,
66     PROTO_TYPE_GROUP, // DEPRECATED (PROTO2 ONLY)
67     PROTO_TYPE_MESSAGE,
68     PROTO_TYPE_BYTES,
69     PROTO_TYPE_UINT32,
70     PROTO_TYPE_ENUM,
71     PROTO_TYPE_SFIXED32,
72     PROTO_TYPE_SFIXED64,
73     PROTO_TYPE_SINT32,
74     PROTO_TYPE_SINT64,
75     PROTO_TYPE_MAX,
76 };
77 
78 enum EventFieldType {
79     FIELD_TYPE_INVALID = 0,
80     FIELD_TYPE_BOOL,
81     FIELD_TYPE_INT8,
82     FIELD_TYPE_UINT8,
83     FIELD_TYPE_INT16,
84     FIELD_TYPE_UINT16,
85     FIELD_TYPE_INT32,
86     FIELD_TYPE_UINT32,
87     FIELD_TYPE_INT64,
88     FIELD_TYPE_UINT64,
89     FIELD_TYPE_FIXEDCSTRING,
90     FIELD_TYPE_CSTRING,
91     FIELD_TYPE_STRINGPTR,
92     FIELD_TYPE_INODE32,
93     FIELD_TYPE_INODE64,
94     FIELD_TYPE_PID32,
95     FIELD_TYPE_COMMONPID32,
96     FIELD_TYPE_DEVID32,
97     FIELD_TYPE_DEVID64,
98     FIELD_TYPE_DATALOC,
99     FIELD_TYPE_SYMADDR32,
100     FIELD_TYPE_SYMADDR64,
101 };
102 
103 // used to store content of each cpu stats data, likes /sys/kernel/debug/tracing/per_cpu/cpu0/stats.
104 struct PerCpuStats {
105     uint64_t cpuIndex = 0;
106     uint64_t entries = 0;
107     uint64_t overrun = 0;
108     uint64_t commitOverrun = 0;
109     uint64_t bytes = 0;
110     double oldestEventTs = 0.0;
111     double nowTs = 0.0;
112     uint64_t droppedEvents = 0;
113     uint64_t readEvents = 0;
114 };
115 
116 struct FieldFormat {
117     uint16_t offset = 0;
118     uint16_t size = 0;
119     uint8_t isSigned = 0;
120     EventFieldType filedType = FIELD_TYPE_INVALID;
121     ProtoFieldType protoType = PROTO_TYPE_UNKNOWN;
122     std::string name = "";
123     std::string typeName = "";
124 };
125 
126 struct CommonFiledIndex {
127     static constexpr int INVALID_IDX = -1;
128     int type = INVALID_IDX;
129     int flags = INVALID_IDX;
130     int preemt = INVALID_IDX;
131     int pid = INVALID_IDX;
132 };
133 
134 struct EventFormat {
135     uint32_t eventId = 0;
136     uint32_t eventSize = 0;
137     std::string eventName = "";
138     std::string eventType = "";
139     std::vector<FieldFormat> fields = {};
140     std::vector<FieldFormat> commonFields = {};
141     CommonFiledIndex commonIndex = {};
142 };
143 
144 struct PageHeaderFormat {
145     FieldFormat timestamp = {};
146     FieldFormat commit = {};
147     FieldFormat overwrite = {};
148 };
149 FTRACE_NS_END
150 #endif
151