perf tools: Allow passing a list to intlist__new
Commit-ID: ffe0fb769a6db3b6027d9228b6fecb6b352e4834 Gitweb: http://git.kernel.org/tip/ffe0fb769a6db3b6027d9228b6fecb6b352e4834 Author: Arnaldo Carvalho de Melo <[email protected]> AuthorDate: Thu, 24 Jan 2013 16:17:27 -0300 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Thu, 24 Jan 2013 16:40:53 -0300
perf tools: Allow passing a list to intlist__new
Just like strlist allows passing a list of entries to parse.
Cc David Ahern <[email protected]>
Cc Frederic Weisbecker <[email protected]>
Cc Jiri Olsa <[email protected]>
Cc Mike Galbraith <[email protected]>
Cc Namhyung Kim <[email protected]>
Cc Paul Mackerras <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Stephane Eranian <[email protected]>
Signed-off-by Arnaldo Carvalho de Melo <[email protected]>
--- tools/perf/builtin-top.c | 2 +- tools/perf/util/intlist.c | 27 ++++++++++++++++++++++++++- tools/perf/util/intlist.h | 2 +- 3 files changed, 28 insertions(+), 3 deletions(-)
tools/perf/builtin-top.c +1 -1
@@ -694,7 +694,7 @@ static void perf_event__process_sample(struct perf_tool *tool,static struct intlist *seen;if (!seen) - seen =intlist__new (); + seen =intlist__new (NULL );if (!intlist__has_entry (seen, event->ip.pid)) { pr_err("Can't find guest [%d]'s kernel information\n",
tools/perf/util/intlist.c +26 -1
@@ -73,7 +73,26 @@ struct int_node *intlist__find(struct intlist *ilist, int i)return node; } -struct intlist *intlist__new (void ) +static int intlist__parse_list (struct intlist *ilist,const char *s) +{ +char *sep; +int err; + +do { +long value =strtol (s, &sep,10 ); + err = -EINVAL ; +if (*sep !=',' && *sep !='\0' ) +break ; + err =intlist__add (ilist, value); +if (err) +break ; + s = sep +1 ; + }while (*sep !='\0' ); + +return err; +} + +struct intlist *intlist__new (const char *slist) {struct intlist *ilist =malloc (sizeof (*ilist));
@@ -82,9 +101,15 @@ struct intlist *intlist__new(void) ilist->rblist.node_cmp = intlist__node_cmp; ilist->rblist.node_new = intlist__node_new; ilist->rblist.node_delete = intlist__node_delete; + +if (slist &&intlist__parse_list (ilist, slist)) + goto out_delete; }return ilist; +out_delete: +intlist__delete (ilist); +return NULL ; }void intlist__delete (struct intlist *ilist)
tools/perf/util/intlist.h +1 -1
@@ -15,7 +15,7 @@ struct intlist {struct rblist rblist; }; -struct intlist *intlist__new (void ); +struct intlist *intlist__new (const char *slist);void intlist__delete (struct intlist *ilist);void intlist__remove (struct intlist *ilist,struct int_node *in);