Adding pmu_aliases_parse_multi function to parse and add
aliases from single file. The file format follows the
alias format, each line for single alias. Each line
must contains 'name' term, like:

  name=BR_MISP_EXEC.ALL_BRANCHES,event=0x89,umask=0xff
  name=BR_MISP_EXEC.COND,event=0x89,umask=0x1

Signed-off-by: Jiri Olsa <jo...@redhat.com>
Cc: Corey Ashford <cjash...@linux.vnet.ibm.com>
Cc: Frederic Weisbecker <fweis...@gmail.com>
Cc: Ingo Molnar <mi...@elte.hu>
Cc: Namhyung Kim <namhy...@kernel.org>
Cc: Paul Mackerras <pau...@samba.org>
Cc: Peter Zijlstra <a.p.zijls...@chello.nl>
Cc: Arnaldo Carvalho de Melo <a...@redhat.com>
Cc: Andi Kleen <a...@linux.intel.com>
Cc: Stephane Eranian <eran...@google.com>
---
 tools/perf/util/pmu.c | 23 +++++++++++++++++++++++
 tools/perf/util/pmu.h |  2 ++
 2 files changed, 25 insertions(+)

diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c
index 0d45ccd..68d6c86 100644
--- a/tools/perf/util/pmu.c
+++ b/tools/perf/util/pmu.c
@@ -146,11 +146,34 @@ static int perf_pmu__new_alias(struct list_head *list, 
char *name, char *data)
                }
        }
 
+       pr_debug3("adding alias '%s' => '%s'\n", name, data);
+
        alias->name = strdup(name);
        list_add_tail(&alias->list, list);
        return 0;
 }
 
+int pmu_aliases_parse_multi(char *path, struct list_head *head)
+{
+       FILE *file;
+       char *data = NULL;
+       size_t len;
+       int ret = -EINVAL;
+
+       file = fopen(path, "r");
+       if (!file)
+               return -EINVAL;
+
+       while ((getline(&data, &len, file)) != -1) {
+               ret = perf_pmu__new_alias(head, NULL, data);
+               free(data);
+               data = NULL;
+       }
+
+       fclose(file);
+       return ret;
+}
+
 /*
  * Process all the sysfs attributes located under the directory
  * specified in 'dir' parameter.
diff --git a/tools/perf/util/pmu.h b/tools/perf/util/pmu.h
index 54cd809..add249b 100644
--- a/tools/perf/util/pmu.h
+++ b/tools/perf/util/pmu.h
@@ -43,5 +43,7 @@ struct perf_pmu *perf_pmu__scan(struct perf_pmu *pmu);
 
 char *perf_pmu__event_name(struct list_head *head_terms, bool remove);
 
+int pmu_aliases_parse_multi(char *path, struct list_head *head);
+
 int perf_pmu__test(void);
 #endif /* __PMU_H */
-- 
1.7.11.7

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Reply via email to