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