diff options
| author | Arnaldo Carvalho de Melo <acme@redhat.com> | 2013-01-24 14:17:27 -0500 |
|---|---|---|
| committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2013-01-24 14:40:53 -0500 |
| commit | ffe0fb769a6db3b6027d9228b6fecb6b352e4834 (patch) | |
| tree | 2989ffadf34b1e16316af7d82104d3130ba3073c | |
| parent | 5a3d04d6dc9050b4b4562f5c66aea23f0aa1c003 (diff) | |
perf tools: Allow passing a list to intlist__new
Just like strlist allows passing a list of entries to parse.
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-em50vqvvmlnc6k9tw4xtixus@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
| -rw-r--r-- | tools/perf/builtin-top.c | 2 | ||||
| -rw-r--r-- | tools/perf/util/intlist.c | 27 | ||||
| -rw-r--r-- | tools/perf/util/intlist.h | 2 |
3 files changed, 28 insertions, 3 deletions
diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c index e05ba817f8ce..7978c8117b7f 100644 --- a/tools/perf/builtin-top.c +++ b/tools/perf/builtin-top.c | |||
| @@ -694,7 +694,7 @@ static void perf_event__process_sample(struct perf_tool *tool, | |||
| 694 | static struct intlist *seen; | 694 | static struct intlist *seen; |
| 695 | 695 | ||
| 696 | if (!seen) | 696 | if (!seen) |
| 697 | seen = intlist__new(); | 697 | seen = intlist__new(NULL); |
| 698 | 698 | ||
| 699 | if (!intlist__has_entry(seen, event->ip.pid)) { | 699 | if (!intlist__has_entry(seen, event->ip.pid)) { |
| 700 | pr_err("Can't find guest [%d]'s kernel information\n", | 700 | pr_err("Can't find guest [%d]'s kernel information\n", |
diff --git a/tools/perf/util/intlist.c b/tools/perf/util/intlist.c index cbf0c32ce403..11a8d86f7fea 100644 --- a/tools/perf/util/intlist.c +++ b/tools/perf/util/intlist.c | |||
| @@ -73,7 +73,26 @@ struct int_node *intlist__find(struct intlist *ilist, int i) | |||
| 73 | return node; | 73 | return node; |
| 74 | } | 74 | } |
| 75 | 75 | ||
| 76 | struct intlist *intlist__new(void) | 76 | static int intlist__parse_list(struct intlist *ilist, const char *s) |
| 77 | { | ||
| 78 | char *sep; | ||
| 79 | int err; | ||
| 80 | |||
| 81 | do { | ||
| 82 | long value = strtol(s, &sep, 10); | ||
| 83 | err = -EINVAL; | ||
| 84 | if (*sep != ',' && *sep != '\0') | ||
| 85 | break; | ||
| 86 | err = intlist__add(ilist, value); | ||
| 87 | if (err) | ||
| 88 | break; | ||
| 89 | s = sep + 1; | ||
| 90 | } while (*sep != '\0'); | ||
| 91 | |||
| 92 | return err; | ||
| 93 | } | ||
| 94 | |||
| 95 | struct intlist *intlist__new(const char *slist) | ||
| 77 | { | 96 | { |
| 78 | struct intlist *ilist = malloc(sizeof(*ilist)); | 97 | struct intlist *ilist = malloc(sizeof(*ilist)); |
| 79 | 98 | ||
| @@ -82,9 +101,15 @@ struct intlist *intlist__new(void) | |||
| 82 | ilist->rblist.node_cmp = intlist__node_cmp; | 101 | ilist->rblist.node_cmp = intlist__node_cmp; |
| 83 | ilist->rblist.node_new = intlist__node_new; | 102 | ilist->rblist.node_new = intlist__node_new; |
| 84 | ilist->rblist.node_delete = intlist__node_delete; | 103 | ilist->rblist.node_delete = intlist__node_delete; |
| 104 | |||
| 105 | if (slist && intlist__parse_list(ilist, slist)) | ||
| 106 | goto out_delete; | ||
| 85 | } | 107 | } |
| 86 | 108 | ||
| 87 | return ilist; | 109 | return ilist; |
| 110 | out_delete: | ||
| 111 | intlist__delete(ilist); | ||
| 112 | return NULL; | ||
| 88 | } | 113 | } |
| 89 | 114 | ||
| 90 | void intlist__delete(struct intlist *ilist) | 115 | void intlist__delete(struct intlist *ilist) |
diff --git a/tools/perf/util/intlist.h b/tools/perf/util/intlist.h index 6d63ab90db50..62351dad848f 100644 --- a/tools/perf/util/intlist.h +++ b/tools/perf/util/intlist.h | |||
| @@ -15,7 +15,7 @@ struct intlist { | |||
| 15 | struct rblist rblist; | 15 | struct rblist rblist; |
| 16 | }; | 16 | }; |
| 17 | 17 | ||
| 18 | struct intlist *intlist__new(void); | 18 | struct intlist *intlist__new(const char *slist); |
| 19 | void intlist__delete(struct intlist *ilist); | 19 | void intlist__delete(struct intlist *ilist); |
| 20 | 20 | ||
| 21 | void intlist__remove(struct intlist *ilist, struct int_node *in); | 21 | void intlist__remove(struct intlist *ilist, struct int_node *in); |
