aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTeng Qin <palmtenor@gmail.com>2018-09-07 18:28:27 -0400
committeryonghong-song <ys114321@gmail.com>2018-09-07 15:28:27 -0700
commit8cc0bda6d364587735ae266b18c5d37905c92dc4 (patch)
tree1f4fef3f9725932ada95e52aa6d8c1f22b731597
parent6d85aca0e667320ae00d1b135ee093ff2cae3852 (diff)
downloadbcc-8cc0bda6d364587735ae266b18c5d37905c92dc4.zip
bcc-8cc0bda6d364587735ae266b18c5d37905c92dc4.tar.gz
bcc-8cc0bda6d364587735ae266b18c5d37905c92dc4.tar.bz2
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
-rw-r--r--src/cc/api/BPF.cc19
-rw-r--r--src/cc/api/BPF.h3
2 files changed, 19 insertions, 3 deletions
diff --git a/src/cc/api/BPF.cc b/src/cc/api/BPF.cc
index 561e1b8..cc3bf75 100644
--- a/src/cc/api/BPF.cc
+++ b/src/cc/api/BPF.cc
@@ -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();
@@ -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_) &&
diff --git a/src/cc/api/BPF.h b/src/cc/api/BPF.h
index 374c64d..b073fc2 100644
--- a/src/cc/api/BPF.h
+++ b/src/cc/api/BPF.h
@@ -245,6 +245,7 @@ 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();
@@ -252,7 +253,7 @@ class USDT {
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) {