ebpf::BPF bpf;
auto init_res = bpf.init(BPF_PROGRAM);
- if (init_res.code() != 0) {
+ if (!init_res.ok()) {
std::cerr << init_res.msg() << std::endl;
return 1;
}
auto cgroup_array = bpf.get_cgroup_array("cgroup");
auto update_res = cgroup_array.update_value(0, argv[1]);
- if (update_res.code() != 0) {
+ if (!update_res.ok()) {
std::cerr << update_res.msg() << std::endl;
return 1;
}
auto attach_res =
bpf.attach_kprobe("vfs_open", "on_vfs_open");
- if (attach_res.code() != 0) {
+ if (!attach_res.ok()) {
std::cerr << attach_res.msg() << std::endl;
return 1;
}
std::cout << line << std::endl;
auto detach_res = bpf.detach_kprobe("vfs_open");
- if (detach_res.code() != 0) {
+ if (!detach_res.ok()) {
std::cerr << detach_res.msg() << std::endl;
return 1;
}
int main(int argc, char** argv) {
ebpf::BPF bpf;
auto init_res = bpf.init(BPF_PROGRAM);
- if (init_res.code() != 0) {
+ if (!init_res.ok()) {
std::cerr << init_res.msg() << std::endl;
return 1;
}
auto attach_res =
bpf.attach_kprobe("finish_task_switch", "task_switch_event");
- if (attach_res.code() != 0) {
+ if (!attach_res.ok()) {
std::cerr << attach_res.msg() << std::endl;
return 1;
}
}
auto detach_res = bpf.detach_kprobe("finish_task_switch");
- if (detach_res.code() != 0) {
+ if (!detach_res.ok()) {
std::cerr << detach_res.msg() << std::endl;
return 1;
}
ebpf::BPF* bpf = new ebpf::BPF();
auto init_res = bpf->init(BPF_PROGRAM, {}, {u});
- if (init_res.code() != 0) {
+ if (!init_res.ok()) {
std::cerr << init_res.msg() << std::endl;
return 1;
}
auto attach_res = bpf->attach_usdt_all();
- if (attach_res.code() != 0) {
+ if (!attach_res.ok()) {
std::cerr << attach_res.msg() << std::endl;
return 1;
} else {
}
auto open_res = bpf->open_perf_buffer("events", &handle_output);
- if (open_res.code() != 0) {
+ if (!open_res.ok()) {
std::cerr << open_res.msg() << std::endl;
return 1;
}
int main() {
ebpf::BPF bpf;
auto init_res = bpf.init(BPF_PROGRAM);
- if (init_res.code() != 0) {
+ if (!init_res.ok()) {
std::cerr << init_res.msg() << std::endl;
return 1;
}
std::string clone_fnname = bpf.get_syscall_fnname("clone");
auto attach_res = bpf.attach_kprobe(clone_fnname, "on_sys_clone");
- if (attach_res.code() != 0) {
+ if (!attach_res.ok()) {
std::cerr << attach_res.msg() << std::endl;
return 1;
}
std::cout << line << std::endl;
// Detach the probe if we got at least one line.
auto detach_res = bpf.detach_kprobe(clone_fnname);
- if (detach_res.code() != 0) {
+ if (!detach_res.ok()) {
std::cerr << detach_res.msg() << std::endl;
return 1;
}
int main() {
ebpf::BPF bpf;
auto res = bpf.init(BPF_PROGRAM);
- if (res.code() != 0) {
+ if (!res.ok()) {
std::cerr << res.msg() << std::endl;
return 1;
}
int prog_fd;
res = bpf.load_func("kfunc____x64_sys_openat", BPF_PROG_TYPE_TRACING, prog_fd);
- if (res.code() != 0) {
+ if (!res.ok()) {
std::cerr << res.msg() << std::endl;
return 1;
}
}
res = bpf.load_func("kretfunc____x64_sys_openat", BPF_PROG_TYPE_TRACING, prog_fd);
- if (res.code() != 0) {
+ if (!res.ok()) {
std::cerr << res.msg() << std::endl;
return 1;
}
}
auto open_res = bpf.open_perf_buffer("events", &handle_output);
- if (open_res.code() != 0) {
+ if (!open_res.ok()) {
std::cerr << open_res.msg() << std::endl;
return 1;
}
int prog_fd;
auto res = bpf.load_func("kmod_ret____x64_sys_openat",
BPF_PROG_TYPE_TRACING, prog_fd, BPF_F_SLEEPABLE);
- if (res.code() != 0) {
+ if (!res.ok()) {
std::cerr << res.msg() << std::endl;
return 1;
}
uint32_t key = 0;
struct fname_buf val;
res = fname_table.get_value(key, val);
- if (res.code() != 0) {
+ if (!res.ok()) {
close(attach_fd);
std::cerr << res.msg() << std::endl;
return 1;
int prog_fd;
auto res = bpf.load_func("kmod_ret__security_file_open",
BPF_PROG_TYPE_TRACING, prog_fd);
- if (res.code() != 0) {
+ if (!res.ok()) {
std::cerr << res.msg() << std::endl;
return 1;
}
auto count_table = bpf.get_array_table<uint32_t>("count");
uint32_t key = 0, val = 0;
res = count_table.get_value(key, val);
- if (res.code() != 0) {
+ if (!res.ok()) {
close(attach_fd);
std::cerr << res.msg() << std::endl;
return 1;
int main() {
ebpf::BPF bpf;
auto res = bpf.init(BPF_PROGRAM);
- if (res.code() != 0) {
+ if (!res.ok()) {
std::cerr << res.msg() << std::endl;
return 1;
}
uint32_t key = 0, val = getpid();
auto pid_table = bpf.get_array_table<uint32_t>("target_pid");
res = pid_table.update_value(key, val);
- if (res.code() != 0) {
+ if (!res.ok()) {
std::cerr << res.msg() << std::endl;
return 1;
}
int main(int argc, char** argv) {
ebpf::BPF bpf;
auto init_res = bpf.init(BPF_PROGRAM);
- if (init_res.code() != 0) {
+ if (!init_res.ok()) {
std::cerr << init_res.msg() << std::endl;
return 1;
}
auto attach_ref_res =
bpf.attach_perf_event(PERF_TYPE_HARDWARE, PERF_COUNT_HW_CACHE_REFERENCES,
"on_cache_ref", 100, 0);
- if (attach_ref_res.code() != 0) {
+ if (!attach_ref_res.ok()) {
std::cerr << attach_ref_res.msg() << std::endl;
return 1;
}
auto attach_miss_res = bpf.attach_perf_event(
PERF_TYPE_HARDWARE, PERF_COUNT_HW_CACHE_MISSES, "on_cache_miss", 100, 0);
- if (attach_miss_res.code() != 0) {
+ if (!attach_miss_res.ok()) {
std::cerr << attach_miss_res.msg() << std::endl;
return 1;
}
bpf = new ebpf::BPF(0, nullptr, true, "", allow_rlimit);
auto init_res = bpf->init(BPF_PROGRAM, cflags, {});
- if (init_res.code() != 0) {
+ if (!init_res.ok()) {
std::cerr << init_res.msg() << std::endl;
return 1;
}
if (argc == 3) {
auto cgroup_array = bpf->get_cgroup_array("cgroup");
auto update_res = cgroup_array.update_value(0, argv[2]);
- if (update_res.code() != 0) {
+ if (!update_res.ok()) {
std::cerr << update_res.msg() << std::endl;
return 1;
}
auto attach_res =
bpf->attach_raw_tracepoint("urandom_read", "on_urandom_read");
- if (attach_res.code() != 0) {
+ if (!attach_res.ok()) {
std::cerr << attach_res.msg() << std::endl;
return 1;
}
auto open_res = bpf->open_perf_buffer("events", &handle_output);
- if (open_res.code() != 0) {
+ if (!open_res.ok()) {
std::cerr << open_res.msg() << std::endl;
return 1;
}
ebpf::BPF bpf;
auto init_res = bpf.init(BPF_PROGRAM);
- if (init_res.code() != 0) {
+ if (!init_res.ok()) {
std::cerr << init_res.msg() << std::endl;
return 1;
}
auto attach_res =
bpf.attach_uprobe(mysql_path, ALLOC_QUERY_FUNC, "probe_mysql_query");
- if (attach_res.code() != 0) {
+ if (!attach_res.ok()) {
std::cerr << attach_res.msg() << std::endl;
return 1;
}
}
auto detach_res = bpf.detach_uprobe(mysql_path, ALLOC_QUERY_FUNC);
- if (detach_res.code() != 0) {
+ if (!detach_res.ok()) {
std::cerr << detach_res.msg() << std::endl;
return 1;
}
int main() {
ebpf::BPF bpf;
auto res = bpf.init(BPF_PROGRAM);
- if (res.code() != 0) {
+ if (!res.ok()) {
std::cerr << res.msg() << std::endl;
return 1;
}
auto sk_table = bpf.get_sk_storage_table<unsigned long long>("sk_data_map");
res = sk_table.update_value(sockfd1, v1);
- if (res.code() != 0) {
+ if (!res.ok()) {
std::cerr << "sk_data_map sockfd1 update failure: " << res.msg() << std::endl;
close(sockfd2);
close(sockfd1);
}
res = sk_table.update_value(sockfd2, v2);
- if (res.code() != 0) {
+ if (!res.ok()) {
std::cerr << "sk_data_map sockfd2 update failure: " << res.msg() << std::endl;
close(sockfd2);
close(sockfd1);
int prog_fd;
res = bpf.load_func("bpf_iter__bpf_sk_storage_map", BPF_PROG_TYPE_TRACING, prog_fd);
- if (res.code() != 0) {
+ if (!res.ok()) {
std::cerr << res.msg() << std::endl;
return 1;
}
int main(int argc, char** argv) {
ebpf::BPF bpf;
auto init_res = bpf.init(BPF_PROGRAM);
- if (init_res.code() != 0) {
+ if (!init_res.ok()) {
std::cerr << init_res.msg() << std::endl;
return 1;
}
auto attach_res = bpf.attach_kprobe("tcp_sendmsg", "on_tcp_send");
- if (attach_res.code() != 0) {
+ if (!attach_res.ok()) {
std::cerr << attach_res.msg() << std::endl;
return 1;
}
sleep(probe_time);
auto detach_res = bpf.detach_kprobe("tcp_sendmsg");
- if (detach_res.code() != 0) {
+ if (!detach_res.ok()) {
std::cerr << detach_res.msg() << std::endl;
return 1;
}
int main() {
ebpf::BPF bpf;
auto res = bpf.init(BPF_PROGRAM);
- if (res.code() != 0) {
+ if (!res.ok()) {
std::cerr << res.msg() << std::endl;
return 1;
}
int prog_fd;
res = bpf.load_func("bpf_iter__task", BPF_PROG_TYPE_TRACING, prog_fd);
- if (res.code() != 0) {
+ if (!res.ok()) {
std::cerr << res.msg() << std::endl;
return 1;
}
std::to_string(kPythonStackProgIdx));
auto initRes = bpf_.init(PYPERF_BPF_PROGRAM, cflags);
- if (initRes.code() != 0) {
+ if (!initRes.ok()) {
std::fprintf(stderr, "Failed to compiled PyPerf BPF programs: %s\n",
initRes.msg().c_str());
return PyPerfResult::INIT_FAIL;
int progFd = -1;
auto loadRes =
bpf_.load_func(kPythonStackFuncName, BPF_PROG_TYPE_PERF_EVENT, progFd);
- if (loadRes.code() != 0) {
+ if (!loadRes.ok()) {
std::fprintf(stderr, "Failed to load BPF program %s: %s\n",
kPythonStackFuncName.c_str(), loadRes.msg().c_str());
return PyPerfResult::INIT_FAIL;
auto progTable = bpf_.get_prog_table(kProgsTableName);
auto updateRes = progTable.update_value(kPythonStackProgIdx, progFd);
- if (updateRes.code() != 0) {
+ if (!updateRes.ok()) {
std::fprintf(stderr,
"Failed to set BPF program %s FD %d to program table: %s\n",
kPythonStackFuncName.c_str(), progFd, updateRes.msg().c_str());
auto openRes = bpf_.open_perf_buffer(
kSamplePerfBufName, &handleSampleCallback, &handleLostSamplesCallback,
this, kPerfBufSizePages);
- if (openRes.code() != 0) {
+ if (!openRes.ok()) {
std::fprintf(stderr, "Unable to open Perf Buffer: %s\n",
openRes.msg().c_str());
return PyPerfResult::PERF_BUF_OPEN_FAIL;
// Attach to CPU cycles
auto attachRes =
bpf_.attach_perf_event(0, 0, kOnEventFuncName, sampleRate, 0);
- if (attachRes.code() != 0) {
+ if (!attachRes.ok()) {
std::fprintf(stderr, "Attach to CPU cycles event failed: %s\n",
attachRes.msg().c_str());
return PyPerfResult::EVENT_ATTACH_FAIL;
// Detach the event
auto detachRes = bpf_.detach_perf_event(0, 0);
- if (detachRes.code() != 0) {
+ if (!detachRes.ok()) {
std::fprintf(stderr, "Detach CPU cycles event failed: %s\n",
detachRes.msg().c_str());
return PyPerfResult::EVENT_DETACH_FAIL;