perf strlist: Make dupstr be the default and part of an extensible config parm

So that we can pass more info to strlist__new() without having to change
its function signature, just adding entries to the strlist_config struct
with sensible defaults for when those fields are not specified.

Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Borislav Petkov <bp@suse.de>
Cc: David Ahern <dsahern@gmail.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/n/tip-5uaaler4931i0s9sedxjquhq@git.kernel.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent ab7322af
...@@ -363,7 +363,7 @@ int cmd_buildid_cache(int argc, const char **argv, ...@@ -363,7 +363,7 @@ int cmd_buildid_cache(int argc, const char **argv,
setup_pager(); setup_pager();
if (add_name_list_str) { if (add_name_list_str) {
list = strlist__new(true, add_name_list_str); list = strlist__new(add_name_list_str, NULL);
if (list) { if (list) {
strlist__for_each(pos, list) strlist__for_each(pos, list)
if (build_id_cache__add_file(pos->s)) { if (build_id_cache__add_file(pos->s)) {
...@@ -381,7 +381,7 @@ int cmd_buildid_cache(int argc, const char **argv, ...@@ -381,7 +381,7 @@ int cmd_buildid_cache(int argc, const char **argv,
} }
if (remove_name_list_str) { if (remove_name_list_str) {
list = strlist__new(true, remove_name_list_str); list = strlist__new(remove_name_list_str, NULL);
if (list) { if (list) {
strlist__for_each(pos, list) strlist__for_each(pos, list)
if (build_id_cache__remove_file(pos->s)) { if (build_id_cache__remove_file(pos->s)) {
...@@ -399,7 +399,7 @@ int cmd_buildid_cache(int argc, const char **argv, ...@@ -399,7 +399,7 @@ int cmd_buildid_cache(int argc, const char **argv,
} }
if (purge_name_list_str) { if (purge_name_list_str) {
list = strlist__new(true, purge_name_list_str); list = strlist__new(purge_name_list_str, NULL);
if (list) { if (list) {
strlist__for_each(pos, list) strlist__for_each(pos, list)
if (build_id_cache__purge_path(pos->s)) { if (build_id_cache__purge_path(pos->s)) {
...@@ -420,7 +420,7 @@ int cmd_buildid_cache(int argc, const char **argv, ...@@ -420,7 +420,7 @@ int cmd_buildid_cache(int argc, const char **argv,
ret = build_id_cache__fprintf_missing(session, stdout); ret = build_id_cache__fprintf_missing(session, stdout);
if (update_name_list_str) { if (update_name_list_str) {
list = strlist__new(true, update_name_list_str); list = strlist__new(update_name_list_str, NULL);
if (list) { if (list) {
strlist__for_each(pos, list) strlist__for_each(pos, list)
if (build_id_cache__update_file(pos->s)) { if (build_id_cache__update_file(pos->s)) {
......
...@@ -2931,7 +2931,7 @@ int cmd_trace(int argc, const char **argv, const char *prefix __maybe_unused) ...@@ -2931,7 +2931,7 @@ int cmd_trace(int argc, const char **argv, const char *prefix __maybe_unused)
trace.not_ev_qualifier = *s == '!'; trace.not_ev_qualifier = *s == '!';
if (trace.not_ev_qualifier) if (trace.not_ev_qualifier)
++s; ++s;
trace.ev_qualifier = strlist__new(true, s); trace.ev_qualifier = strlist__new(s, NULL);
if (trace.ev_qualifier == NULL) { if (trace.ev_qualifier == NULL) {
fputs("Not enough memory to parse event qualifier", fputs("Not enough memory to parse event qualifier",
trace.output); trace.output);
......
...@@ -291,7 +291,7 @@ int build_id_cache__list_build_ids(const char *pathname, ...@@ -291,7 +291,7 @@ int build_id_cache__list_build_ids(const char *pathname,
struct dirent *d; struct dirent *d;
int ret = 0; int ret = 0;
list = strlist__new(true, NULL); list = strlist__new(NULL, NULL);
dir_name = build_id_cache__dirname_from_path(pathname, false, false); dir_name = build_id_cache__dirname_from_path(pathname, false, false);
if (!list || !dir_name) { if (!list || !dir_name) {
ret = -ENOMEM; ret = -ENOMEM;
......
...@@ -250,7 +250,7 @@ struct machine *machines__findnew(struct machines *machines, pid_t pid) ...@@ -250,7 +250,7 @@ struct machine *machines__findnew(struct machines *machines, pid_t pid)
static struct strlist *seen; static struct strlist *seen;
if (!seen) if (!seen)
seen = strlist__new(true, NULL); seen = strlist__new(NULL, NULL);
if (!strlist__has_entry(seen, path)) { if (!strlist__has_entry(seen, path)) {
pr_err("Can't access file %s\n", path); pr_err("Can't access file %s\n", path);
......
...@@ -2066,7 +2066,7 @@ static struct strlist *get_probe_trace_command_rawlist(int fd) ...@@ -2066,7 +2066,7 @@ static struct strlist *get_probe_trace_command_rawlist(int fd)
char *p; char *p;
struct strlist *sl; struct strlist *sl;
sl = strlist__new(true, NULL); sl = strlist__new(NULL, NULL);
fp = fdopen(dup(fd), "r"); fp = fdopen(dup(fd), "r");
while (!feof(fp)) { while (!feof(fp)) {
...@@ -2362,7 +2362,7 @@ static struct strlist *get_probe_trace_event_names(int fd, bool include_group) ...@@ -2362,7 +2362,7 @@ static struct strlist *get_probe_trace_event_names(int fd, bool include_group)
rawlist = get_probe_trace_command_rawlist(fd); rawlist = get_probe_trace_command_rawlist(fd);
if (!rawlist) if (!rawlist)
return NULL; return NULL;
sl = strlist__new(true, NULL); sl = strlist__new(NULL, NULL);
strlist__for_each(ent, rawlist) { strlist__for_each(ent, rawlist) {
ret = parse_probe_trace_command(ent->s, &tev); ret = parse_probe_trace_command(ent->s, &tev);
if (ret < 0) if (ret < 0)
......
...@@ -1355,7 +1355,7 @@ static int add_available_vars(Dwarf_Die *sc_die, struct probe_finder *pf) ...@@ -1355,7 +1355,7 @@ static int add_available_vars(Dwarf_Die *sc_die, struct probe_finder *pf)
vl->point.offset); vl->point.offset);
/* Find local variables */ /* Find local variables */
vl->vars = strlist__new(true, NULL); vl->vars = strlist__new(NULL, NULL);
if (vl->vars == NULL) if (vl->vars == NULL)
return -ENOMEM; return -ENOMEM;
af->child = true; af->child = true;
......
...@@ -133,7 +133,7 @@ int strlist__parse_list(struct strlist *slist, const char *s) ...@@ -133,7 +133,7 @@ int strlist__parse_list(struct strlist *slist, const char *s)
return *s ? strlist__parse_list_entry(slist, s) : 0; return *s ? strlist__parse_list_entry(slist, s) : 0;
} }
struct strlist *strlist__new(bool dupstr, const char *list) struct strlist *strlist__new(const char *list, const struct strlist_config *config)
{ {
struct strlist *slist = malloc(sizeof(*slist)); struct strlist *slist = malloc(sizeof(*slist));
...@@ -143,7 +143,7 @@ struct strlist *strlist__new(bool dupstr, const char *list) ...@@ -143,7 +143,7 @@ struct strlist *strlist__new(bool dupstr, const char *list)
slist->rblist.node_new = strlist__node_new; slist->rblist.node_new = strlist__node_new;
slist->rblist.node_delete = strlist__node_delete; slist->rblist.node_delete = strlist__node_delete;
slist->dupstr = dupstr; slist->dupstr = config ? !config->dont_dupstr : true;
if (list && strlist__parse_list(slist, list) != 0) if (list && strlist__parse_list(slist, list) != 0)
goto out_error; goto out_error;
} }
......
...@@ -16,7 +16,11 @@ struct strlist { ...@@ -16,7 +16,11 @@ struct strlist {
bool dupstr; bool dupstr;
}; };
struct strlist *strlist__new(bool dupstr, const char *slist); struct strlist_config {
bool dont_dupstr;
};
struct strlist *strlist__new(const char *slist, const struct strlist_config *config);
void strlist__delete(struct strlist *slist); void strlist__delete(struct strlist *slist);
void strlist__remove(struct strlist *slist, struct str_node *sn); void strlist__remove(struct strlist *slist, struct str_node *sn);
......
...@@ -1906,7 +1906,7 @@ int setup_list(struct strlist **list, const char *list_str, ...@@ -1906,7 +1906,7 @@ int setup_list(struct strlist **list, const char *list_str,
if (list_str == NULL) if (list_str == NULL)
return 0; return 0;
*list = strlist__new(true, list_str); *list = strlist__new(list_str, NULL);
if (!*list) { if (!*list) {
pr_err("problems parsing %s list\n", list_name); pr_err("problems parsing %s list\n", list_name);
return -1; return -1;
......
...@@ -196,7 +196,8 @@ static struct thread_map *thread_map__new_by_pid_str(const char *pid_str) ...@@ -196,7 +196,8 @@ static struct thread_map *thread_map__new_by_pid_str(const char *pid_str)
pid_t pid, prev_pid = INT_MAX; pid_t pid, prev_pid = INT_MAX;
char *end_ptr; char *end_ptr;
struct str_node *pos; struct str_node *pos;
struct strlist *slist = strlist__new(false, pid_str); struct strlist_config slist_config = { .dont_dupstr = true, };
struct strlist *slist = strlist__new(pid_str, &slist_config);
if (!slist) if (!slist)
return NULL; return NULL;
...@@ -266,13 +267,14 @@ static struct thread_map *thread_map__new_by_tid_str(const char *tid_str) ...@@ -266,13 +267,14 @@ static struct thread_map *thread_map__new_by_tid_str(const char *tid_str)
pid_t tid, prev_tid = INT_MAX; pid_t tid, prev_tid = INT_MAX;
char *end_ptr; char *end_ptr;
struct str_node *pos; struct str_node *pos;
struct strlist_config slist_config = { .dont_dupstr = true, };
struct strlist *slist; struct strlist *slist;
/* perf-stat expects threads to be generated even if tid not given */ /* perf-stat expects threads to be generated even if tid not given */
if (!tid_str) if (!tid_str)
return thread_map__new_dummy(); return thread_map__new_dummy();
slist = strlist__new(false, tid_str); slist = strlist__new(tid_str, &slist_config);
if (!slist) if (!slist)
return NULL; return NULL;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment