Commit 488c119e authored by Teng Qin's avatar Teng Qin Committed by Brenden Blanco

Deduplicate USDT probe locations

parent 486d348f
...@@ -181,6 +181,7 @@ public: ...@@ -181,6 +181,7 @@ public:
return largest_arg_type(arg_index); return largest_arg_type(arg_index);
} }
void finalize_locations();
bool need_enable() const { return semaphore_ != 0x0; } bool need_enable() const { return semaphore_ != 0x0; }
bool enable(const std::string &fn_name); bool enable(const std::string &fn_name);
bool disable(); bool disable();
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
#include <algorithm>
#include <cstring> #include <cstring>
#include <sstream> #include <sstream>
#include <unordered_set> #include <unordered_set>
...@@ -197,6 +198,18 @@ void Probe::add_location(uint64_t addr, const char *fmt) { ...@@ -197,6 +198,18 @@ void Probe::add_location(uint64_t addr, const char *fmt) {
locations_.emplace_back(addr, fmt); locations_.emplace_back(addr, fmt);
} }
void Probe::finalize_locations() {
std::sort(locations_.begin(), locations_.end(),
[](const Location &a, const Location &b) {
return a.address_ < b.address_;
});
auto last = std::unique(locations_.begin(), locations_.end(),
[](const Location &a, const Location &b) {
return a.address_ == b.address_;
});
locations_.erase(last, locations_.end());
}
void Context::_each_probe(const char *binpath, const struct bcc_elf_usdt *probe, void Context::_each_probe(const char *binpath, const struct bcc_elf_usdt *probe,
void *p) { void *p) {
Context *ctx = static_cast<Context *>(p); Context *ctx = static_cast<Context *>(p);
...@@ -294,6 +307,8 @@ Context::Context(const std::string &bin_path) ...@@ -294,6 +307,8 @@ Context::Context(const std::string &bin_path)
loaded_ = true; loaded_ = true;
} }
} }
for (const auto &probe : probes_)
probe->finalize_locations();
} }
Context::Context(int pid) : pid_(pid), pid_stat_(pid), Context::Context(int pid) : pid_(pid), pid_stat_(pid),
...@@ -313,6 +328,8 @@ Context::Context(int pid) : pid_(pid), pid_stat_(pid), ...@@ -313,6 +328,8 @@ Context::Context(int pid) : pid_(pid), pid_stat_(pid),
loaded_ = true; loaded_ = true;
} }
for (const auto &probe : probes_)
probe->finalize_locations();
} }
Context::~Context() { Context::~Context() {
......
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