Skip to content

Commit

Permalink
Add bcc_usdt_enable_fully_specified_probe to avoid usdt provider coll…
Browse files Browse the repository at this point in the history
…isions
  • Loading branch information
dalehamel authored and yonghong-song committed Apr 24, 2019
1 parent 6c79331 commit 4a51c75
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 8 deletions.
2 changes: 2 additions & 0 deletions src/cc/bcc_usdt.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ int bcc_usdt_get_argument(void *usdt, const char *provider_name,
struct bcc_usdt_argument *argument);

int bcc_usdt_enable_probe(void *, const char *, const char *);
#define BCC_USDT_HAS_FULLY_SPECIFIED_PROBE
int bcc_usdt_enable_fully_specified_probe(void *, const char *, const char *, const char *);
const char *bcc_usdt_genargs(void **ctx_array, int len);
const char *bcc_usdt_get_probe_argctype(
void *ctx, const char* probe_name, const int arg_index
Expand Down
1 change: 1 addition & 0 deletions src/cc/usdt.h
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ class Context {
Probe *get(int pos) { return probes_[pos].get(); }

bool enable_probe(const std::string &probe_name, const std::string &fn_name);
bool enable_probe(const std::string &provider_name, const std::string &probe_name, const std::string &fn_name);

typedef void (*each_cb)(struct bcc_usdt *);
void each(each_cb callback);
Expand Down
46 changes: 38 additions & 8 deletions src/cc/usdt/usdt.cc
Original file line number Diff line number Diff line change
Expand Up @@ -295,24 +295,46 @@ Probe *Context::get(const std::string &provider_name,

bool Context::enable_probe(const std::string &probe_name,
const std::string &fn_name) {
return enable_probe("", probe_name, fn_name);
}

bool Context::enable_probe(const std::string &provider_name,
const std::string &probe_name,
const std::string &fn_name) {
if (pid_stat_ && pid_stat_->is_stale())
return false;

// FIXME: we may have issues here if the context has two same probes's
// but different providers. For example, libc:setjmp and rtld:setjmp,
// libc:lll_futex_wait and rtld:lll_futex_wait.
unsigned int matches = 0;
Probe *found_probe = nullptr;
for (auto &p : probes_) {
if (p->name_ == probe_name) {
if (found_probe != nullptr) {
fprintf(stderr, "Two same-name probes (%s) but different providers\n",
probe_name.c_str());
return false;
if (found_probe == nullptr && provider_name == "")
{
found_probe = p.get();
matches++;
}
else if (found_probe != nullptr && provider_name == "")
{
fprintf(stderr, "Found duplicate provider (%s) for underspecified probe (%s)\n",
p->provider().c_str(), p->name().c_str());
matches++;
} else if (provider_name != "" && p->provider() == provider_name)
{
found_probe = p.get();
matches++;
}
found_probe = p.get();
}
}

if (matches > 1) {
fprintf(stderr, "Found %i duplicate providers for underpecified probe (%s)\n",
matches, fn_name.c_str());
return false;
} else if(matches < 1) {
fprintf(stderr, "No matches found for probe (%s)\n", fn_name.c_str());
return false;
}

if (found_probe != nullptr)
return found_probe->enable(fn_name);

Expand Down Expand Up @@ -448,6 +470,14 @@ int bcc_usdt_enable_probe(void *usdt, const char *probe_name,
return ctx->enable_probe(probe_name, fn_name) ? 0 : -1;
}

int bcc_usdt_enable_fully_specified_probe(void *usdt,
const char *provider_name,
const char *probe_name,
const char *fn_name) {
USDT::Context *ctx = static_cast<USDT::Context *>(usdt);
return ctx->enable_probe(provider_name, probe_name, fn_name) ? 0 : -1;
}

const char *bcc_usdt_genargs(void **usdt_array, int len) {
static std::string storage_;
std::ostringstream stream;
Expand Down

0 comments on commit 4a51c75

Please sign in to comment.