perf evlist: Introduce add_newtp method
authorArnaldo Carvalho de Melo <acme@redhat.com>
Wed, 3 Oct 2012 14:40:22 +0000 (11:40 -0300)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Wed, 3 Oct 2012 14:41:22 +0000 (11:41 -0300)
To reduce the boilerplate of creating and adding a new tracepoint to an
evlist.

Cc: David Ahern <dsahern@gmail.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Namhyung Kim <namhyung@gmail.com>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/n/tip-4z90i79gnmsza2czv2dhdrb7@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/builtin-trace.c
tools/perf/util/evlist.c
tools/perf/util/evlist.h

index 76b1202c03c80e7edb33d3f2de5028295f0043fd..dec8ced61fb00c2bc7114346db3edaf0f7dd89b7 100644 (file)
@@ -200,24 +200,12 @@ static int trace__run(struct trace *trace)
                goto out;
        }
 
-       evsel = perf_evsel__newtp("raw_syscalls", "sys_enter", 0);
-       if (evsel == NULL) {
-               printf("Couldn't read the raw_syscalls:sys_enter tracepoint information!\n");
+       if (perf_evlist__add_newtp(evlist, "raw_syscalls", "sys_enter", trace__sys_enter) ||
+           perf_evlist__add_newtp(evlist, "raw_syscalls", "sys_exit", trace__sys_exit)) {
+               printf("Couldn't read the raw_syscalls tracepoints information!\n");
                goto out_delete_evlist;
        }
 
-       evsel->handler.func = trace__sys_enter;
-       perf_evlist__add(evlist, evsel);
-
-       evsel = perf_evsel__newtp("raw_syscalls", "sys_exit", 1);
-       if (evsel == NULL) {
-               printf("Couldn't read the raw_syscalls:sys_exit tracepoint information!\n");
-               goto out_delete_evlist;
-       }
-
-       evsel->handler.func = trace__sys_exit;
-       perf_evlist__add(evlist, evsel);
-
        err = perf_evlist__create_maps(evlist, &trace->opts.target);
        if (err < 0) {
                printf("Problems parsing the target to trace, check your options!\n");
index ae89686102f4a7224d0f425fb26ad3712f17c616..6a2809fd257ef518a65cd1a28659c8f431d54cf7 100644 (file)
@@ -285,6 +285,20 @@ out:
        return err;
 }
 
+int perf_evlist__add_newtp(struct perf_evlist *evlist,
+                          const char *sys, const char *name, void *handler)
+{
+       struct perf_evsel *evsel;
+
+       evsel = perf_evsel__newtp(sys, name, evlist->nr_entries);
+       if (evsel == NULL)
+               return -1;
+
+       evsel->handler.func = handler;
+       perf_evlist__add(evlist, evsel);
+       return 0;
+}
+
 void perf_evlist__disable(struct perf_evlist *evlist)
 {
        int cpu, thread;
index 3f1fb66be02203e925d8f01b38338d90b66d344a..ac98b010f1c92d2ea2151f99aa9e45725383d560 100644 (file)
@@ -72,6 +72,9 @@ int perf_evlist__set_tracepoints_handlers(struct perf_evlist *evlist,
 #define perf_evlist__set_tracepoints_handlers_array(evlist, array) \
        perf_evlist__set_tracepoints_handlers(evlist, array, ARRAY_SIZE(array))
 
+int perf_evlist__add_newtp(struct perf_evlist *evlist,
+                          const char *sys, const char *name, void *handler);
+
 int perf_evlist__set_filter(struct perf_evlist *evlist, const char *filter);
 
 struct perf_evsel *