aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf
diff options
context:
space:
mode:
authorArnaldo Carvalho de Melo <acme@redhat.com>2013-01-24 14:17:27 -0500
committerArnaldo Carvalho de Melo <acme@redhat.com>2013-01-24 14:40:53 -0500
commitffe0fb769a6db3b6027d9228b6fecb6b352e4834 (patch)
tree2989ffadf34b1e16316af7d82104d3130ba3073c /tools/perf
parent5a3d04d6dc9050b4b4562f5c66aea23f0aa1c003 (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>
Diffstat (limited to 'tools/perf')
-rw-r--r--tools/perf/builtin-top.c2
-rw-r--r--tools/perf/util/intlist.c27
-rw-r--r--tools/perf/util/intlist.h2
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
76struct intlist *intlist__new(void) 76static 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
95struct 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;
110out_delete:
111 intlist__delete(ilist);
112 return NULL;
88} 113}
89 114
90void intlist__delete(struct intlist *ilist) 115void 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
18struct intlist *intlist__new(void); 18struct intlist *intlist__new(const char *slist);
19void intlist__delete(struct intlist *ilist); 19void intlist__delete(struct intlist *ilist);
20 20
21void intlist__remove(struct intlist *ilist, struct int_node *in); 21void intlist__remove(struct intlist *ilist, struct int_node *in);