Skip to content

Commit

Permalink
Deduplicate USDT probe locations
Browse files Browse the repository at this point in the history
  • Loading branch information
palmtenor authored and drzaeus77 committed Sep 13, 2017
1 parent 486d348 commit 488c119
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/cc/usdt.h
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ class Probe {
return largest_arg_type(arg_index);
}

void finalize_locations();
bool need_enable() const { return semaphore_ != 0x0; }
bool enable(const std::string &fn_name);
bool disable();
Expand Down
17 changes: 17 additions & 0 deletions src/cc/usdt/usdt.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <algorithm>
#include <cstring>
#include <sstream>
#include <unordered_set>
Expand Down Expand Up @@ -197,6 +198,18 @@ void Probe::add_location(uint64_t addr, const char *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 *p) {
Context *ctx = static_cast<Context *>(p);
Expand Down Expand Up @@ -294,6 +307,8 @@ Context::Context(const std::string &bin_path)
loaded_ = true;
}
}
for (const auto &probe : probes_)
probe->finalize_locations();
}

Context::Context(int pid) : pid_(pid), pid_stat_(pid),
Expand All @@ -313,6 +328,8 @@ Context::Context(int pid) : pid_(pid), pid_stat_(pid),

loaded_ = true;
}
for (const auto &probe : probes_)
probe->finalize_locations();
}

Context::~Context() {
Expand Down

0 comments on commit 488c119

Please sign in to comment.