summaryrefslogtreecommitdiff
path: root/tools/perf/util/probe-event.c
diff options
context:
space:
mode:
authorNamhyung Kim <namhyung@kernel.org>2015-09-04 21:15:59 +0900
committerArnaldo Carvalho de Melo <acme@redhat.com>2015-09-04 12:33:02 -0300
commit844dffa598b55fca6a83a856214fc0cfc3da24e5 (patch)
tree494cfb1872067638d48e22c55bbd4bb459b9a460 /tools/perf/util/probe-event.c
parent86c2786994bd7c0d4b525bbfbe42ac540d0b8166 (diff)
perf probe: Split add_perf_probe_events()
The add_perf_probe_events() does 3 things: 1. convert all perf events to trace events 2. add all trace events to kernel 3. cleanup all trace events But sometimes we need to do something with the trace events. So split the funtion into three, so that it can access intermediate trace events via struct __event_package if needed. Signed-off-by: Namhyung Kim <namhyung@kernel.org> Acked-by: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com> Cc: Jiri Olsa <jolsa@redhat.com> Cc: Peter Zijlstra <a.p.zijlstra@chello.nl> Cc: Wang Nan <wangnan0@huawei.com> Cc: pi3orama@163.com Link: http://lkml.kernel.org/r/1441368963-11565-1-git-send-email-namhyung@kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf/util/probe-event.c')
-rw-r--r--tools/perf/util/probe-event.c39
1 files changed, 35 insertions, 4 deletions
diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c
index eb5f18b75402..2c762f41e7a5 100644
--- a/tools/perf/util/probe-event.c
+++ b/tools/perf/util/probe-event.c
@@ -2765,9 +2765,10 @@ struct __event_package {
int ntevs;
};
-int add_perf_probe_events(struct perf_probe_event *pevs, int npevs)
+static int convert_perf_probe_events(struct perf_probe_event *pevs, int npevs,
+ struct __event_package **ppkgs)
{
- int i, j, ret;
+ int i, ret;
struct __event_package *pkgs;
ret = 0;
@@ -2792,12 +2793,21 @@ int add_perf_probe_events(struct perf_probe_event *pevs, int npevs)
ret = convert_to_probe_trace_events(pkgs[i].pev,
&pkgs[i].tevs);
if (ret < 0)
- goto end;
+ return ret;
pkgs[i].ntevs = ret;
}
/* This just release blacklist only if allocated */
kprobe_blacklist__release();
+ *ppkgs = pkgs;
+
+ return 0;
+}
+
+static int apply_perf_probe_events(struct __event_package *pkgs, int npevs)
+{
+ int i, ret = 0;
+
/* Loop 2: add all events */
for (i = 0; i < npevs; i++) {
ret = __add_probe_trace_events(pkgs[i].pev, pkgs[i].tevs,
@@ -2806,7 +2816,16 @@ int add_perf_probe_events(struct perf_probe_event *pevs, int npevs)
if (ret < 0)
break;
}
-end:
+ return ret;
+}
+
+static void cleanup_perf_probe_events(struct __event_package *pkgs, int npevs)
+{
+ int i, j;
+
+ if (pkgs == NULL)
+ return;
+
/* Loop 3: cleanup and free trace events */
for (i = 0; i < npevs; i++) {
for (j = 0; j < pkgs[i].ntevs; j++)
@@ -2815,6 +2834,18 @@ end:
}
free(pkgs);
exit_symbol_maps();
+}
+
+int add_perf_probe_events(struct perf_probe_event *pevs, int npevs)
+{
+ int ret;
+ struct __event_package *pkgs = NULL;
+
+ ret = convert_perf_probe_events(pevs, npevs, &pkgs);
+ if (ret == 0)
+ ret = apply_perf_probe_events(pkgs, npevs);
+
+ cleanup_perf_probe_events(pkgs, npevs);
return ret;
}