StatusTuple BPF::init_usdt(const USDT& usdt) {
USDT u(usdt);
StatusTuple init_stp = u.init();
- if (init_stp.code() != 0) {
+ if (!init_stp.ok()) {
return init_stp;
}
usdt_.reserve(usdt.size());
for (const auto& u : usdt) {
StatusTuple init_stp = init_usdt(u);
- if (init_stp.code() != 0) {
+ if (!init_stp.ok()) {
init_fail_reset();
return init_stp;
}
BPF::~BPF() {
auto res = detach_all();
- if (res.code() != 0)
+ if (!res.ok())
std::cerr << "Failed to detach all probes on destruction: " << std::endl
<< res.msg() << std::endl;
bcc_free_buildsymcache(bsymcache_);
for (auto& it : kprobes_) {
auto res = detach_kprobe_event(it.first, it.second);
- if (res.code() != 0) {
+ if (!res.ok()) {
error_msg += "Failed to detach kprobe event " + it.first + ": ";
error_msg += res.msg() + "\n";
has_error = true;
for (auto& it : uprobes_) {
auto res = detach_uprobe_event(it.first, it.second);
- if (res.code() != 0) {
+ if (!res.ok()) {
error_msg += "Failed to detach uprobe event " + it.first + ": ";
error_msg += res.msg() + "\n";
has_error = true;
for (auto& it : tracepoints_) {
auto res = detach_tracepoint_event(it.first, it.second);
- if (res.code() != 0) {
+ if (!res.ok()) {
error_msg += "Failed to detach Tracepoint " + it.first + ": ";
error_msg += res.msg() + "\n";
has_error = true;
for (auto& it : raw_tracepoints_) {
auto res = detach_raw_tracepoint_event(it.first, it.second);
- if (res.code() != 0) {
+ if (!res.ok()) {
error_msg += "Failed to detach Raw tracepoint " + it.first + ": ";
error_msg += res.msg() + "\n";
has_error = true;
for (auto& it : perf_buffers_) {
auto res = it.second->close_all_cpu();
- if (res.code() != 0) {
+ if (!res.ok()) {
error_msg += "Failed to close perf buffer " + it.first + ": ";
error_msg += res.msg() + "\n";
has_error = true;
for (auto& it : perf_event_arrays_) {
auto res = it.second->close_all_cpu();
- if (res.code() != 0) {
+ if (!res.ok()) {
error_msg += "Failed to close perf event array " + it.first + ": ";
error_msg += res.msg() + "\n";
has_error = true;
for (auto& it : perf_events_) {
auto res = detach_perf_event_all_cpu(it.second);
- if (res.code() != 0) {
+ if (!res.ok()) {
error_msg += res.msg() + "\n";
has_error = true;
}
StatusTuple r(0);
r = string_to_key(key_str, key);
- if (r.code() != 0)
+ if (!r.ok())
return r;
if (!lookup(key, value))
StatusTuple r(0);
r = string_to_key(key_str, key);
- if (r.code() != 0)
+ if (!r.ok())
return r;
if (!lookup(key, value))
for (size_t i = 0; i < ncpus; i++) {
r = leaf_to_string(value + i * desc.leaf_size, value_str.at(i));
- if (r.code() != 0)
+ if (!r.ok())
return r;
}
return StatusTuple::OK();
StatusTuple r(0);
r = string_to_key(key_str, key);
- if (r.code() != 0)
+ if (!r.ok())
return r;
r = string_to_leaf(value_str, value);
- if (r.code() != 0)
+ if (!r.ok())
return r;
if (!update(key, value))
StatusTuple r(0);
r = string_to_key(key_str, key);
- if (r.code() != 0)
+ if (!r.ok())
return r;
if (value_str.size() != ncpus)
for (size_t i = 0; i < ncpus; i++) {
r = string_to_leaf(value_str.at(i), value + i * desc.leaf_size);
- if (r.code() != 0)
+ if (!r.ok())
return r;
}
StatusTuple r(0);
r = string_to_key(key_str, key);
- if (r.code() != 0)
+ if (!r.ok())
return r;
if (!remove(key))
}
r = key_to_string(&i, key_str);
- if (r.code() != 0)
+ if (!r.ok())
return r;
r = leaf_to_string(value.get(), value_str);
- if (r.code() != 0)
+ if (!r.ok())
return r;
res.emplace_back(key_str, value_str);
}
if (!this->lookup(key.get(), value.get()))
break;
r = key_to_string(key.get(), key_str);
- if (r.code() != 0)
+ if (!r.ok())
return r;
r = leaf_to_string(value.get(), value_str);
- if (r.code() != 0)
+ if (!r.ok())
return r;
res.emplace_back(key_str, value_str);
if (!this->next(key.get(), key.get()))
for (int i : cpus) {
auto res = open_on_cpu(cb, lost_cb, i, cb_cookie, page_cnt);
- if (res.code() != 0) {
+ if (!res.ok()) {
TRY2(close_all_cpu());
return res;
}
opened_cpus.push_back(it.first);
for (int i : opened_cpus) {
auto res = close_on_cpu(i);
- if (res.code() != 0) {
+ if (!res.ok()) {
errors += "Failed to close CPU" + std::to_string(i) + " perf buffer: ";
errors += res.msg() + "\n";
has_error = true;
BPFPerfBuffer::~BPFPerfBuffer() {
auto res = close_all_cpu();
- if (res.code() != 0)
+ if (!res.ok())
std::cerr << "Failed to close all perf buffer on destruction: " << res.msg()
<< std::endl;
}
for (int i : cpus) {
auto res = open_on_cpu(i, type, config);
- if (res.code() != 0) {
+ if (!res.ok()) {
TRY2(close_all_cpu());
return res;
}
opened_cpus.push_back(it.first);
for (int i : opened_cpus) {
auto res = close_on_cpu(i);
- if (res.code() != 0) {
+ if (!res.ok()) {
errors += "Failed to close CPU" + std::to_string(i) + " perf event: ";
errors += res.msg() + "\n";
has_error = true;
BPFPerfEventArray::~BPFPerfEventArray() {
auto res = close_all_cpu();
- if (res.code() != 0) {
+ if (!res.ok()) {
std::cerr << "Failed to close all perf buffer on destruction: " << res.msg()
<< std::endl;
}
while (true) {
r = get_value(cur, value);
- if (r.code() != 0)
+ if (!r.ok())
break;
res.emplace_back(cur, value);
if (!this->next(&cur, &cur))
#define TRY2(CMD) \
do { \
ebpf::StatusTuple __stp = (CMD); \
- if (__stp.code() != 0) { \
+ if (!__stp.ok()) { \
return __stp; \
} \
} while (0)
ebpf::cc::TypeCheck type_check(parser_->scopes_.get(), proto_parser_->scopes_.get());
auto ret = type_check.visit(parser_->root_node_);
- if (ret.code() != 0 || ret.msg().size()) {
+ if (!ret.ok() || ret.msg().size()) {
fprintf(stderr, "Type error @line=%d: %s\n", ret.code(), ret.msg().c_str());
return -1;
}
codegen_ = ebpf::make_unique<ebpf::cc::CodegenLLVM>(mod, parser_->scopes_.get(), proto_parser_->scopes_.get());
ret = codegen_->visit(parser_->root_node_, ts, id, maps_ns);
- if (ret.code() != 0 || ret.msg().size()) {
+ if (!ret.ok() || ret.msg().size()) {
fprintf(stderr, "Codegen error @line=%d: %s\n", ret.code(), ret.msg().c_str());
return ret.code();
}