Commit 8cc0bda6 authored by Teng Qin's avatar Teng Qin Committed by yonghong-song

Add move constructor to C++ USDT instance (#1962)

* Small fix on C++ USDT implementation

Fix an logging error, and small optimization on initialization

* Add move constructor to C++ USDT instance
parent 6d85aca0
...@@ -59,10 +59,13 @@ StatusTuple BPF::init(const std::string& bpf_program, ...@@ -59,10 +59,13 @@ StatusTuple BPF::init(const std::string& bpf_program,
const std::vector<USDT>& usdt) { const std::vector<USDT>& usdt) {
std::string all_bpf_program; std::string all_bpf_program;
usdt_.reserve(usdt.size());
for (const auto& u : usdt) { for (const auto& u : usdt) {
usdt_.emplace_back(u); 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(); auto flags_len = cflags.size();
...@@ -733,6 +736,18 @@ USDT::USDT(const USDT& usdt) ...@@ -733,6 +736,18 @@ USDT::USDT(const USDT& usdt)
name_(usdt.name_), name_(usdt.name_),
probe_func_(usdt.probe_func_) {} 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 { bool USDT::operator==(const USDT& other) const {
return (provider_ == other.provider_) && (name_ == other.name_) && return (provider_ == other.provider_) && (name_ == other.name_) &&
(binary_path_ == other.binary_path_) && (pid_ == other.pid_) && (binary_path_ == other.binary_path_) && (pid_ == other.pid_) &&
......
...@@ -245,6 +245,7 @@ class USDT { ...@@ -245,6 +245,7 @@ class USDT {
USDT(const std::string& binary_path, pid_t pid, const std::string& provider, USDT(const std::string& binary_path, pid_t pid, const std::string& provider,
const std::string& name, const std::string& probe_func); const std::string& name, const std::string& probe_func);
USDT(const USDT& usdt); USDT(const USDT& usdt);
USDT(USDT&& usdt) noexcept;
StatusTuple init(); StatusTuple init();
...@@ -252,7 +253,7 @@ class USDT { ...@@ -252,7 +253,7 @@ class USDT {
std::string print_name() const { std::string print_name() const {
return provider_ + ":" + name_ + " from binary " + binary_path_ + " PID " + 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) { friend std::ostream& operator<<(std::ostream& out, const USDT& usdt) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment