Skip to content

Commit ffe0fb7

Browse files
committed
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>
1 parent 5a3d04d commit ffe0fb7

3 files changed

Lines changed: 28 additions & 3 deletions

File tree

‎tools/perf/builtin-top.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -694,7 +694,7 @@ static void perf_event__process_sample(struct perf_tool *tool,
694694
static struct intlist *seen;
695695

696696
if (!seen)
697-
seen = intlist__new();
697+
seen = intlist__new(NULL);
698698

699699
if (!intlist__has_entry(seen, event->ip.pid)) {
700700
pr_err("Can't find guest [%d]'s kernel information\n",

‎tools/perf/util/intlist.c‎

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,26 @@ struct int_node *intlist__find(struct intlist *ilist, int i)
7373
return node;
7474
}
7575

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)
7796
{
7897
struct intlist *ilist = malloc(sizeof(*ilist));
7998

@@ -82,9 +101,15 @@ struct intlist *intlist__new(void)
82101
ilist->rblist.node_cmp = intlist__node_cmp;
83102
ilist->rblist.node_new = intlist__node_new;
84103
ilist->rblist.node_delete = intlist__node_delete;
104+
105+
if (slist && intlist__parse_list(ilist, slist))
106+
goto out_delete;
85107
}
86108

87109
return ilist;
110+
out_delete:
111+
intlist__delete(ilist);
112+
return NULL;
88113
}
89114

90115
void intlist__delete(struct intlist *ilist)

‎tools/perf/util/intlist.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ struct intlist {
1515
struct rblist rblist;
1616
};
1717

18-
struct intlist *intlist__new(void);
18+
struct intlist *intlist__new(const char *slist);
1919
void intlist__delete(struct intlist *ilist);
2020

2121
void intlist__remove(struct intlist *ilist, struct int_node *in);

0 commit comments

Comments
 (0)