From bea0fc8a8dedc072f7a1ce790ad0ab435f5c9c78 Mon Sep 17 00:00:00 2001 From: Ryan Cheng Date: Wed, 18 Jan 2023 10:41:16 -0800 Subject: [PATCH 1/2] Revert "Fix random_alnum_string in BPF.cc." This reverts commit 44d4590fba68634f0ea4ce897383abf957b67102. --- src/cc/api/BPF.cc | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/cc/api/BPF.cc b/src/cc/api/BPF.cc index fe41474ee913..25eaf1f6e67b 100644 --- a/src/cc/api/BPF.cc +++ b/src/cc/api/BPF.cc @@ -856,14 +856,14 @@ bool BPF::add_module(std::string module) namespace { -std::string random_alnum_string(const int len) { +std::string random_alnum_string(int len) { static constexpr char kDict[] = "0123456789abcdefghijklmnopqrstuvwxyz"; - static std::mt19937 gen; - static std::uniform_int_distribution dist(0, sizeof(kDict) - 2); + static std::random_device rd; + std::uniform_int_distribution dist(0, sizeof(kDict)-1); std::string res; - res.resize(len); + res.reserve(len); for (int i = 0; i < len; ++i) { - res[i] = kDict[dist(gen)]; + res.push_back(kDict[dist(rd)]); } return res; } From 424de3f38d8e1e1066cff124377ea58c9aa8e422 Mon Sep 17 00:00:00 2001 From: Ryan Cheng Date: Wed, 18 Jan 2023 10:47:36 -0800 Subject: [PATCH 2/2] Revert "Shorten a name that is too long for attaching uprobe" This reverts commit 93f866ae530904a0089cf410cf4c5c1238210d03. --- src/cc/api/BPF.cc | 38 -------------------------------------- src/cc/api/BPF.h | 3 --- 2 files changed, 41 deletions(-) diff --git a/src/cc/api/BPF.cc b/src/cc/api/BPF.cc index 25eaf1f6e67b..b6d095526969 100644 --- a/src/cc/api/BPF.cc +++ b/src/cc/api/BPF.cc @@ -23,7 +23,6 @@ #include #include #include -#include #include #include #include @@ -854,34 +853,6 @@ bool BPF::add_module(std::string module) false : true; } -namespace { - -std::string random_alnum_string(int len) { - static constexpr char kDict[] = "0123456789abcdefghijklmnopqrstuvwxyz"; - static std::random_device rd; - std::uniform_int_distribution dist(0, sizeof(kDict)-1); - std::string res; - res.reserve(len); - for (int i = 0; i < len; ++i) { - res.push_back(kDict[dist(rd)]); - } - return res; -} - -constexpr size_t kEventNameSizeLimit = 224; - -std::string shorten_event_name(const std::string& name) { - constexpr size_t kRandomSuffixLen = 16; - std::string res; - res.reserve(kEventNameSizeLimit); - res.assign(name); - res.resize(kEventNameSizeLimit - kRandomSuffixLen); - res.append(random_alnum_string(kRandomSuffixLen)); - return res; -} - -} // namespace - std::string BPF::get_uprobe_event(const std::string& binary_path, uint64_t offset, bpf_probe_attach_type type, pid_t pid) { @@ -890,15 +861,6 @@ std::string BPF::get_uprobe_event(const std::string& binary_path, res += "_0x" + uint_to_hex(offset); if (pid != -1) res += "_" + std::to_string(pid); - if (res.size() > kEventNameSizeLimit) { - auto iter = name_map_.find(res); - if (iter != name_map_.end()) { - return iter->second; - } - std::string shortend_name = shorten_event_name(res); - name_map_[res] = shortend_name; - return shortend_name; - } return res; } diff --git a/src/cc/api/BPF.h b/src/cc/api/BPF.h index e90cda5e9751..00ec8e8cb529 100644 --- a/src/cc/api/BPF.h +++ b/src/cc/api/BPF.h @@ -341,9 +341,6 @@ class BPF { std::string all_bpf_program_; std::map kprobes_; - // For uprobes, if the binary path is longer than 250, we'll shorten them. And then keep the - // mapping. - std::map name_map_; std::map uprobes_; std::map tracepoints_; std::map raw_tracepoints_;