[PATCH 4/8] perf tools: Add pmu interface to parse single file of aliases

From: Jiri Olsa
Date: Sat Jan 26 2013 - 15:04:20 EST


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 <jolsa@xxxxxxxxxx>
Cc: Corey Ashford <cjashfor@xxxxxxxxxxxxxxxxxx>
Cc: Frederic Weisbecker <fweisbec@xxxxxxxxx>
Cc: Ingo Molnar <mingo@xxxxxxx>
Cc: Namhyung Kim <namhyung@xxxxxxxxxx>
Cc: Paul Mackerras <paulus@xxxxxxxxx>
Cc: Peter Zijlstra <a.p.zijlstra@xxxxxxxxx>
Cc: Arnaldo Carvalho de Melo <acme@xxxxxxxxxx>
Cc: Andi Kleen <ak@xxxxxxxxxxxxxxx>
Cc: Stephane Eranian <eranian@xxxxxxxxxx>
---
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 majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/