/
types.h
180 lines (158 loc) · 3.56 KB
/
types.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
#pragma once
#include <ostream>
#include <sstream>
#include <string>
#include <vector>
#include <unistd.h>
namespace bpftrace {
const int MAX_STACK_SIZE = 1024;
const int DEFAULT_STACK_SIZE = 127;
const int STRING_SIZE = 64;
const int COMM_SIZE = 16;
enum class Type
{
none,
integer,
hist,
lhist,
count,
sum,
min,
max,
avg,
stats,
kstack,
ustack,
string,
ksym,
usym,
cast,
join,
probe,
username,
inet,
stack_mode,
array,
};
std::ostream &operator<<(std::ostream &os, Type type);
enum class StackMode
{
bpftrace,
perf,
};
struct StackType
{
size_t limit = DEFAULT_STACK_SIZE;
StackMode mode = StackMode::bpftrace;
bool operator ==(const StackType &obj) const {
return limit == obj.limit && mode == obj.mode;
}
};
class SizedType
{
public:
SizedType() : type(Type::none), size(0) { }
SizedType(Type type, size_t size_, const std::string &cast_type = "")
: type(type), size(size_), cast_type(cast_type) { }
SizedType(Type type, StackType stack_type_)
: SizedType(type, 8) {
stack_type = stack_type_;
}
Type type;
Type elem_type; // Array element type if accessing elements of an array
size_t size;
StackType stack_type;
std::string cast_type;
bool is_internal = false;
bool is_pointer = false;
bool is_tparg = false;
size_t pointee_size;
bool IsArray() const;
bool IsStack() const;
bool operator==(const SizedType &t) const;
};
std::ostream &operator<<(std::ostream &os, const SizedType &type);
enum class ProbeType
{
invalid,
kprobe,
kretprobe,
uprobe,
uretprobe,
usdt,
tracepoint,
profile,
interval,
software,
hardware,
};
struct ProbeItem
{
std::string name;
std::string abbr;
ProbeType type;
};
const std::vector<ProbeItem> PROBE_LIST =
{
{ "kprobe", "k", ProbeType::kprobe },
{ "kretprobe", "kr", ProbeType::kretprobe },
{ "uprobe", "u", ProbeType::uprobe },
{ "uretprobe", "ur", ProbeType::uretprobe },
{ "usdt", "U", ProbeType::usdt },
{ "BEGIN", "BEGIN", ProbeType::uprobe },
{ "END", "END", ProbeType::uprobe },
{ "tracepoint", "t", ProbeType::tracepoint },
{ "profile", "p", ProbeType::profile },
{ "interval", "i", ProbeType::interval },
{ "software", "s", ProbeType::software },
{ "hardware", "h", ProbeType::hardware }
};
std::string typestr(Type t);
ProbeType probetype(const std::string &type);
std::string probetypeName(const std::string &type);
std::string probetypeName(ProbeType t);
class Probe
{
public:
ProbeType type;
std::string path; // file path if used
std::string attach_point; // probe name (last component)
std::string orig_name; // original full probe name,
// before wildcard expansion
std::string name; // full probe name
std::string ns; // for USDT probes, if provider namespace not from path
uint64_t loc; // for USDT probes
int index = 0;
int freq;
};
enum class AsyncAction
{
// printf reserves 0-9999 for printf_ids
syscall = 10000, // system reserves 10000-19999 for printf_ids
exit = 20000,
print,
clear,
zero,
time,
join,
};
uint64_t asyncactionint(AsyncAction a);
} // namespace bpftrace
namespace std {
template<>
struct hash<bpftrace::StackType>
{
size_t operator()(const bpftrace::StackType& obj) const
{
switch (obj.mode) {
case bpftrace::StackMode::bpftrace:
return std::hash<std::string>()("bpftrace#" + to_string(obj.limit));
case bpftrace::StackMode::perf:
return std::hash<std::string>()("perf#" + to_string(obj.limit));
// TODO (mmarchini): enable -Wswitch-enum and disable -Wswitch-default
default:
abort();
}
}
};
}