Skip to content

Commit

Permalink
Add move constructor to C++ USDT instance (iovisor#1962)
Browse files Browse the repository at this point in the history
* Small fix on C++ USDT implementation

Fix an logging error, and small optimization on initialization

* Add move constructor to C++ USDT instance
  • Loading branch information
palmtenor authored and yonghong-song committed Sep 7, 2018
1 parent 6d85aca commit 8cc0bda
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
19 changes: 17 additions & 2 deletions src/cc/api/BPF.cc
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,13 @@ StatusTuple BPF::init(const std::string& bpf_program,
const std::vector<USDT>& usdt) {
std::string all_bpf_program;

usdt_.reserve(usdt.size());
for (const auto& u : usdt) {
usdt_.emplace_back(u);
TRY2(usdt_.back().init());
all_bpf_program += usdt_.back().program_text_;
}
for (auto& u : usdt_) {
TRY2(u.init());
all_bpf_program += u.program_text_;
}

auto flags_len = cflags.size();
Expand Down Expand Up @@ -733,6 +736,18 @@ USDT::USDT(const USDT& usdt)
name_(usdt.name_),
probe_func_(usdt.probe_func_) {}

USDT::USDT(USDT&& usdt) noexcept
: initialized_(usdt.initialized_),
binary_path_(std::move(usdt.binary_path_)),
pid_(usdt.pid_),
provider_(std::move(usdt.provider_)),
name_(std::move(usdt.name_)),
probe_func_(std::move(usdt.probe_func_)),
probe_(std::move(usdt.probe_)),
program_text_(std::move(usdt.program_text_)) {
usdt.initialized_ = false;
}

bool USDT::operator==(const USDT& other) const {
return (provider_ == other.provider_) && (name_ == other.name_) &&
(binary_path_ == other.binary_path_) && (pid_ == other.pid_) &&
Expand Down
3 changes: 2 additions & 1 deletion src/cc/api/BPF.h
Original file line number Diff line number Diff line change
Expand Up @@ -245,14 +245,15 @@ class USDT {
USDT(const std::string& binary_path, pid_t pid, const std::string& provider,
const std::string& name, const std::string& probe_func);
USDT(const USDT& usdt);
USDT(USDT&& usdt) noexcept;

StatusTuple init();

bool operator==(const USDT& other) const;

std::string print_name() const {
return provider_ + ":" + name_ + " from binary " + binary_path_ + " PID " +
std::to_string(pid_) + " for probe " + "probe_func_";
std::to_string(pid_) + " for probe " + probe_func_;
}

friend std::ostream& operator<<(std::ostream& out, const USDT& usdt) {
Expand Down

0 comments on commit 8cc0bda

Please sign in to comment.