• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef EBPF_DATA_STD_TYPE_H
16 #define EBPF_DATA_STD_TYPE_H
17 #ifndef is_linux
18 #include "dfx_nonlinux_define.h"
19 #else
20 #include <elf.h>
21 #endif
22 #include <map>
23 #include "ts_common.h"
24 namespace SysTuning {
25 namespace EbpfStdtype {
26 struct EbpfDataHeader {
27     static constexpr uint32_t EBPF_DATA_HEADER_SIZE = 1024;
28     static constexpr uint64_t HEADER_MAGIC = 0x454C494646504245uLL;
29     struct HeaderData {
30         uint64_t magic = HEADER_MAGIC;
31         uint32_t headSize = EBPF_DATA_HEADER_SIZE;
32         uint32_t version;
33         uint32_t clock;
34         uint32_t cmdLineLen;
35     } __attribute__((packed));
36     static constexpr uint32_t EBPF_COMMAND_MAX_SIZE = EBPF_DATA_HEADER_SIZE - sizeof(HeaderData);
37     HeaderData header;
38     char cmdline[EBPF_COMMAND_MAX_SIZE] = {'\0'};
39 };
40 
41 enum EBPF_DATA_TYPE {
42     ITEM_EVENT_MAPS = 0,
43     ITEM_SYMBOL_INFO,
44     ITEM_EVENT_FS,
45     ITEM_EVENT_VM,
46     ITEM_EVENT_BIO,
47     ITEM_EVENT_STR,
48     ITEM_EVENT_KENEL_SYMBOL_INFO = 0x10001,
49 };
50 
51 struct EbpfTypeAndLength {
52     uint32_t type = 0;
53     uint32_t length = 0;
54 } __attribute__((packed));
55 const uint32_t EBPF_TITLE_SIZE = sizeof(EbpfTypeAndLength);
56 
57 struct MapsFixedHeader {
58     uint64_t start = 0;
59     uint64_t end = 0;
60     uint32_t offset = 0;
61     uint32_t pid = 0;
62     uint32_t fileNameLen = 0;
63 } __attribute__((packed));
64 
65 enum SYSTEM_ENTRY_VALUE { ELF32_SYM = 16, ELF64_SYM = 24 };
66 
67 struct ElfEventFixedHeader {
68     uint64_t textVaddr = 0;
69     uint32_t textOffset = 0;
70     uint32_t strTabLen = 0;
71     uint32_t symTabLen = 0;
72     uint32_t fileNameLen = 0;
73     // value range: SYSTEM_ENTRY_LENGTH
74     uint32_t symEntLen = 0;
75 } __attribute__((packed));
76 // the data following are
77 // uint8_t aa[strTabLen] // xx, bb, cc, dd
78 // uint8_t bb[symTabLen] //symEntLen elf64_sym, lef32_sym
79 
80 const int32_t ARGS_MAX = 4;
81 const int32_t MAX_TRACER_SIZE = 8;
82 const int32_t SINGLE_IP_SIZE = 8;
83 const int32_t MAX_FS_EVENT_SZIE = 16;
84 const int32_t MAX_PROCESS_NAME_SZIE = 16;
85 struct FsFixedHeader {
86     uint32_t pid = 0;
87     uint32_t tid = 0;
88     char tracerName[MAX_TRACER_SIZE] = {0};
89     uint64_t startTime = 0;
90     uint64_t endTime = 0;
91     char eventType[MAX_FS_EVENT_SZIE] = {0};
92     int32_t ret = 0;
93     uint16_t nrUserIPs = 0;
94     uint16_t type = 0;
95     uint64_t args[ARGS_MAX] = {0};
96     char processName[MAX_PROCESS_NAME_SZIE] = {0};
97 } __attribute__((packed));
98 // the data following are ips ...
99 
100 const int32_t MAX_TRACER_NAME_LEN = 8;
101 const int32_t MAX_TYPE_NAME_LEN = 16;
102 const int32_t MAX_COMM_LEN = 16;
103 struct PagedMemoryFixedHeader {
104     uint32_t pid = 0;
105     uint32_t tid = 0;
106     char tagName[MAX_TRACER_NAME_LEN] = {0};
107     uint64_t startTime = 0;
108     uint64_t endTime = 0;
109     char typeName[MAX_TYPE_NAME_LEN] = {0};
110     uint64_t addr = 0;
111     uint32_t size = 0;
112     uint16_t nips = 0;
113     uint16_t type = 0;
114     char comm[MAX_COMM_LEN] = {0};
115 } __attribute__((packed));
116 
117 struct BIOFixedHeader {
118     uint32_t pid = 0;
119     uint32_t tid = 0;
120     char processName[MAX_PROCESS_NAME_SZIE] = {0};
121     uint64_t startTime = 0;
122     uint64_t endTime = 0;
123     uint32_t prio = 0;
124     uint32_t size = 0;
125     uint64_t blkcnt = 0;
126     uint32_t nips = 0;
127     uint32_t type = 0;
128     char typeName[MAX_PROCESS_NAME_SZIE] = {0};
129 } __attribute__((packed));
130 
131 struct StrEventFixedHeader {
132     uint32_t pid = 0;
133     uint32_t tid = 0;
134     uint64_t startTime = 0;
135     uint32_t srcTracer = 0;
136     uint32_t srcType = 0;
137     uint32_t strLen = 0;
138     uint32_t padding = 0;
139 } __attribute__((packed));
140 
141 struct KernelSymbolInfoHeader {
142     uint64_t vaddrStart = 0;
143     uint64_t vaddrEnd = 0;
144     uint32_t symTabLen = 0;
145     uint32_t strTabLen = 0;
146     // char* symTab = 0; // this is following the struct
147     // char* strTab = 0; // the symbols will follow the symTab
148 } __attribute__((packed));
149 
150 struct KernelSymItem {
151     uint64_t value = 0;
152     uint32_t size = 0;
153     uint32_t nameOffset = 0;
154 } __attribute__((packed));
155 
156 // EBPF clock relation
157 enum EbpfClockType {
158     EBPF_CLOCK_REALTIME = 0,
159     EBPF_CLOCK_BOOTTIME,
160     EBPF_CLOCK_MONOTONIC,
161     EBPF_CLOCK_MONOTONIC_RAW,
162 };
163 
164 const std::map<uint32_t, uint32_t> ebpfToTSClockType_ = {
165     {EBPF_CLOCK_REALTIME, TS_CLOCK_REALTIME},
166     {EBPF_CLOCK_BOOTTIME, TS_CLOCK_BOOTTIME},
167     {EBPF_CLOCK_MONOTONIC, TS_MONOTONIC},
168     {EBPF_CLOCK_MONOTONIC_RAW, TS_MONOTONIC_RAW},
169 };
170 
171 struct EbpfSymbolInfo {
EbpfSymbolInfoEbpfSymbolInfo172     EbpfSymbolInfo() {}
EbpfSymbolInfoEbpfSymbolInfo173     explicit EbpfSymbolInfo(bool invalidValue) : flag(invalidValue) {}
174     bool flag = false;
175     DataIndex symbolIndex = INVALID_UINT64;
176     DataIndex filePathIndex = INVALID_UINT64;
177     DataIndex vaddr = INVALID_UINT64;
178 };
179 // file system event type
180 enum FUC_SUB_TYPE {
181     SYS_OPENAT2 = 1,
182     SYS_READ = 2,
183     SYS_WRITE = 3,
184     SYS_PREAD64 = 4,
185     SYS_PWRITE64 = 5,
186     SYS_READV = 6,
187     SYS_WRITEV = 7,
188     SYS_PREADV = 8,
189     SYS_PWRITEV = 9,
190     SYS_CLOSE = 10,
191 };
192 
193 const std::map<FUC_SUB_TYPE, const std::string> subTypeToName = {
194     {SYS_OPENAT2, "openat2"},   {SYS_READ, "read"},   {SYS_WRITE, "write"},   {SYS_PREAD64, "pread64"},
195     {SYS_PWRITE64, "pwrite64"}, {SYS_READV, "readv"}, {SYS_WRITEV, "writev"}, {SYS_PREADV, "preadv"},
196     {SYS_PWRITEV, "pwritev"},   {SYS_CLOSE, "close"}};
197 
198 enum FUC_SUMMARY_TYPE {
199     OPEN = 0,
200     CLOSE = 1,
201     READ = 2,
202     WRITE = 3,
203 };
204 const std::map<uint32_t, uint32_t> fucSubToSummaryType = {
205     {SYS_OPENAT2, OPEN}, {SYS_READ, READ},    {SYS_WRITE, WRITE}, {SYS_PREAD64, READ},  {SYS_PWRITE64, WRITE},
206     {SYS_READV, READ},   {SYS_WRITEV, WRITE}, {SYS_PREADV, READ}, {SYS_PWRITEV, WRITE}, {SYS_CLOSE, CLOSE},
207 };
208 const uint32_t MIN_USER_IP = 0xffffffff;
209 } // namespace EbpfStdtype
210 } // namespace SysTuning
211 #endif // EBPF_DATA_STD_TYPE_H
212