diff options
author | Arnaldo Carvalho de Melo <acme@redhat.com> | 2012-09-26 16:13:07 -0400 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2012-09-26 17:29:19 -0400 |
commit | 82fe1c290cd26a3d092beb1e9755647d284a4134 (patch) | |
tree | 785e13a27c399e9a74ef5de89cd5324e61d9c2a6 /tools | |
parent | e48ffe2bd49936314d367a8c6b5eaaa17d581d13 (diff) |
perf tools: Use perf_evsel__newtp in the event parser
Elliminating code duplication.
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-9v4zl7ldlp8v6azrpsu5lupk@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools')
-rw-r--r-- | tools/perf/util/parse-events.c | 46 |
1 files changed, 16 insertions, 30 deletions
diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c index bf5d033ee1b4..aed38e4b9dfa 100644 --- a/tools/perf/util/parse-events.c +++ b/tools/perf/util/parse-events.c | |||
@@ -356,42 +356,28 @@ int parse_events_add_cache(struct list_head **list, int *idx, | |||
356 | return add_event(list, idx, &attr, name); | 356 | return add_event(list, idx, &attr, name); |
357 | } | 357 | } |
358 | 358 | ||
359 | static int add_tracepoint(struct list_head **list, int *idx, | 359 | static int add_tracepoint(struct list_head **listp, int *idx, |
360 | char *sys_name, char *evt_name) | 360 | char *sys_name, char *evt_name) |
361 | { | 361 | { |
362 | struct perf_event_attr attr; | 362 | struct perf_evsel *evsel; |
363 | char name[MAX_NAME_LEN]; | 363 | struct list_head *list = *listp; |
364 | char evt_path[MAXPATHLEN]; | ||
365 | char id_buf[4]; | ||
366 | u64 id; | ||
367 | int fd; | ||
368 | |||
369 | snprintf(evt_path, MAXPATHLEN, "%s/%s/%s/id", tracing_events_path, | ||
370 | sys_name, evt_name); | ||
371 | |||
372 | fd = open(evt_path, O_RDONLY); | ||
373 | if (fd < 0) | ||
374 | return -1; | ||
375 | 364 | ||
376 | if (read(fd, id_buf, sizeof(id_buf)) < 0) { | 365 | if (!list) { |
377 | close(fd); | 366 | list = malloc(sizeof(*list)); |
378 | return -1; | 367 | if (!list) |
368 | return -ENOMEM; | ||
369 | INIT_LIST_HEAD(list); | ||
379 | } | 370 | } |
380 | 371 | ||
381 | close(fd); | 372 | evsel = perf_evsel__newtp(sys_name, evt_name, (*idx)++); |
382 | id = atoll(id_buf); | 373 | if (!evsel) { |
383 | 374 | free(list); | |
384 | memset(&attr, 0, sizeof(attr)); | 375 | return -ENOMEM; |
385 | attr.config = id; | 376 | } |
386 | attr.type = PERF_TYPE_TRACEPOINT; | ||
387 | attr.sample_type |= PERF_SAMPLE_RAW; | ||
388 | attr.sample_type |= PERF_SAMPLE_TIME; | ||
389 | attr.sample_type |= PERF_SAMPLE_CPU; | ||
390 | attr.sample_type |= PERF_SAMPLE_PERIOD; | ||
391 | attr.sample_period = 1; | ||
392 | 377 | ||
393 | snprintf(name, MAX_NAME_LEN, "%s:%s", sys_name, evt_name); | 378 | list_add_tail(&evsel->node, list); |
394 | return add_event(list, idx, &attr, name); | 379 | *listp = list; |
380 | return 0; | ||
395 | } | 381 | } |
396 | 382 | ||
397 | static int add_tracepoint_multi(struct list_head **list, int *idx, | 383 | static int add_tracepoint_multi(struct list_head **list, int *idx, |