Commit 6aec3099 authored by 4ast's avatar 4ast Committed by GitHub

Merge pull request #1336 from palmtenor/noinstance

Do not create instance for kprobe
parents 08dbf13f f4543fcd
...@@ -392,12 +392,10 @@ void * bpf_attach_kprobe(int progfd, enum bpf_probe_attach_type attach_type, con ...@@ -392,12 +392,10 @@ void * bpf_attach_kprobe(int progfd, enum bpf_probe_attach_type attach_type, con
{ {
int kfd; int kfd;
char buf[256]; char buf[256];
char new_name[128]; char event_alias[128];
struct perf_reader *reader = NULL; struct perf_reader *reader = NULL;
static char *event_type = "kprobe"; static char *event_type = "kprobe";
int n;
snprintf(new_name, sizeof(new_name), "%s_bcc_%d", ev_name, getpid());
reader = perf_reader_new(cb, NULL, NULL, cb_cookie, probe_perf_reader_page_cnt); reader = perf_reader_new(cb, NULL, NULL, cb_cookie, probe_perf_reader_page_cnt);
if (!reader) if (!reader)
goto error; goto error;
...@@ -409,8 +407,9 @@ void * bpf_attach_kprobe(int progfd, enum bpf_probe_attach_type attach_type, con ...@@ -409,8 +407,9 @@ void * bpf_attach_kprobe(int progfd, enum bpf_probe_attach_type attach_type, con
goto error; goto error;
} }
snprintf(event_alias, sizeof(event_alias), "%s_bcc_%d", ev_name, getpid());
snprintf(buf, sizeof(buf), "%c:%ss/%s %s", attach_type==BPF_PROBE_ENTRY ? 'p' : 'r', snprintf(buf, sizeof(buf), "%c:%ss/%s %s", attach_type==BPF_PROBE_ENTRY ? 'p' : 'r',
event_type, new_name, fn_name); event_type, event_alias, fn_name);
if (write(kfd, buf, strlen(buf)) < 0) { if (write(kfd, buf, strlen(buf)) < 0) {
if (errno == EINVAL) if (errno == EINVAL)
fprintf(stderr, "check dmesg output for possible cause\n"); fprintf(stderr, "check dmesg output for possible cause\n");
...@@ -419,24 +418,10 @@ void * bpf_attach_kprobe(int progfd, enum bpf_probe_attach_type attach_type, con ...@@ -419,24 +418,10 @@ void * bpf_attach_kprobe(int progfd, enum bpf_probe_attach_type attach_type, con
} }
close(kfd); close(kfd);
if (access("/sys/kernel/debug/tracing/instances", F_OK) != -1) { snprintf(buf, sizeof(buf), "/sys/kernel/debug/tracing/events/%ss/%s", event_type, event_alias);
snprintf(buf, sizeof(buf), "/sys/kernel/debug/tracing/instances/bcc_%d", getpid());
if (access(buf, F_OK) == -1) {
if (mkdir(buf, 0755) == -1)
goto retry;
}
n = snprintf(buf, sizeof(buf), "/sys/kernel/debug/tracing/instances/bcc_%d/events/%ss/%s",
getpid(), event_type, new_name);
if (n < sizeof(buf) && bpf_attach_tracing_event(progfd, buf, reader, pid, cpu, group_fd) == 0)
goto out;
snprintf(buf, sizeof(buf), "/sys/kernel/debug/tracing/instances/bcc_%d", getpid());
rmdir(buf);
}
retry:
snprintf(buf, sizeof(buf), "/sys/kernel/debug/tracing/events/%ss/%s", event_type, new_name);
if (bpf_attach_tracing_event(progfd, buf, reader, pid, cpu, group_fd) < 0) if (bpf_attach_tracing_event(progfd, buf, reader, pid, cpu, group_fd) < 0)
goto error; goto error;
out:
return reader; return reader;
error: error:
...@@ -586,14 +571,7 @@ static int bpf_detach_probe(const char *ev_name, const char *event_type) ...@@ -586,14 +571,7 @@ static int bpf_detach_probe(const char *ev_name, const char *event_type)
int bpf_detach_kprobe(const char *ev_name) int bpf_detach_kprobe(const char *ev_name)
{ {
char buf[256]; return bpf_detach_probe(ev_name, "kprobe");
int ret = bpf_detach_probe(ev_name, "kprobe");
snprintf(buf, sizeof(buf), "/sys/kernel/debug/tracing/instances/bcc_%d", getpid());
if (access(buf, F_OK) != -1) {
rmdir(buf);
}
return ret;
} }
int bpf_detach_uprobe(const char *ev_name) int bpf_detach_uprobe(const char *ev_name)
......
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