iovisor / iovisor/bcc

Can't trace multiple USDT locations in a shared object

Open
#1,774 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
C
Stars
22.7k
Forks
4.1k
Avg merge
10d 4h
Merged PRs (30d)
3

Description

The following example currently fails, I wonder would it be feasible to support this scenario?

```
# cat ~/utest.py
#!/usr/bin/python

import time
from bcc import BPF, USDT

bpf_text = """
struct usdt_t {
char usdt[128];
};

BPF_HASH(stats, struct usdt_t, u64, 2);

static char *key1 = "thread__sleep__begin";
int do_trace1(void *ctx) {
struct usdt_t key = {};
__builtin_memcpy(&key.usdt, key1, sizeof(key.usdt));
u64 zero = 0, *val;
val = stats.lookup_or_init(&key, &zero);
(*val)++;
return 0;
}

static char *key2 = "thread__sleep__end";
int do_trace2(void *ctx) {
struct usdt_t key = {};
__builtin_memcpy(&key.usdt, key2, sizeof(key.usdt));
u64 zero = 0, *val;
val = stats.lookup_or_init(&key, &zero);
(*val)++;
return 0;
}
"""

contexts = []
u1 = USDT(path="/usr/lib/jvm/java-9-openjdk-9.0.4.11-6.fc28.x86_64/lib/server/libjvm.so")
u1.enable_probe("thread__sleep__begin", "do_trace1")
contexts.append(u1)
u2 = USDT(path="/usr/lib/jvm/java-9-openjdk-9.0.4.11-6.fc28.x86_64/lib/server/libjvm.so")
u2.enable_probe("thread__sleep__end", "do_trace2")
contexts.append(u2)
b = BPF(text=bpf_text, usdt_contexts=contexts)
while True:
time.sleep(1)
s = b["stats"]
for k, v in s.items():
print(k.usdt.decode("ASCII") + " = " + str(v.value))
# python2 ~/utest.py
Traceback (most recent call last):
File "/root/utest.py", line 41, in
b = BPF(text=bpf_text, usdt_contexts=contexts)
File "/usr/lib/python2.7/site-packages/bcc/__init__.py", line 302, in __init__
"locations")
Exception: can't generate USDT probe arguments; possible cause is missing pid
when a probe in a shared object has multiple locations
```

Thanks.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the USDT and BPF initialization path in bcc/__init__.py around the reported line 302, using the two USDT contexts and the shared libjvm.so example as the reproduction. Check how probe locations are handled when no pid is supplied; done means both probes can be attached from the script without the missing-pid exception.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
observability
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.