Commit-ID:  70c646e0e47b51c8fa431f9ec1962f7d6e512860
Gitweb:     http://git.kernel.org/tip/70c646e0e47b51c8fa431f9ec1962f7d6e512860
Author:     Sukadev Bhattiprolu <[email protected]>
AuthorDate: Wed, 10 Jun 2015 00:25:08 -0700
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Tue, 23 Jun 2015 18:21:30 -0300

perf pmu: Split perf_pmu__new_alias()

Separate the event parsing code in perf_pmu__new_alias() out into a
separate function __perf_pmu__new_alias() so that code can be called
indepdently.

This is based on an earlier patch from Andi Kleen.

Signed-off-by: Sukadev Bhattiprolu <[email protected]>
Acked-by: Jiri Olsa <[email protected]>
Cc: Andi Kleen <[email protected]>
Cc: Madhavan Srinivasan <[email protected]>
Cc: Michael Ellerman <[email protected]>
Cc: Namhyung Kim <[email protected]>
Cc: [email protected]
Link: 
http://lkml.kernel.org/r/[email protected]
Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
---
 tools/perf/util/pmu.c | 42 +++++++++++++++++++++++++++---------------
 1 file changed, 27 insertions(+), 15 deletions(-)

diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c
index c6b16b1..7bcb8c3 100644
--- a/tools/perf/util/pmu.c
+++ b/tools/perf/util/pmu.c
@@ -206,17 +206,12 @@ static int perf_pmu__parse_snapshot(struct perf_pmu_alias 
*alias,
        return 0;
 }
 
-static int perf_pmu__new_alias(struct list_head *list, char *dir, char *name, 
FILE *file)
+static int __perf_pmu__new_alias(struct list_head *list, char *dir, char *name,
+                                char *desc __maybe_unused, char *val)
 {
        struct perf_pmu_alias *alias;
-       char buf[256];
        int ret;
 
-       ret = fread(buf, 1, sizeof(buf), file);
-       if (ret == 0)
-               return -EINVAL;
-       buf[ret] = 0;
-
        alias = malloc(sizeof(*alias));
        if (!alias)
                return -ENOMEM;
@@ -226,26 +221,43 @@ static int perf_pmu__new_alias(struct list_head *list, 
char *dir, char *name, FI
        alias->unit[0] = '\0';
        alias->per_pkg = false;
 
-       ret = parse_events_terms(&alias->terms, buf);
+       ret = parse_events_terms(&alias->terms, val);
        if (ret) {
+               pr_err("Cannot parse alias %s: %d\n", val, ret);
                free(alias);
                return ret;
        }
 
        alias->name = strdup(name);
-       /*
-        * load unit name and scale if available
-        */
-       perf_pmu__parse_unit(alias, dir, name);
-       perf_pmu__parse_scale(alias, dir, name);
-       perf_pmu__parse_per_pkg(alias, dir, name);
-       perf_pmu__parse_snapshot(alias, dir, name);
+       if (dir) {
+               /*
+                * load unit name and scale if available
+                */
+               perf_pmu__parse_unit(alias, dir, name);
+               perf_pmu__parse_scale(alias, dir, name);
+               perf_pmu__parse_per_pkg(alias, dir, name);
+               perf_pmu__parse_snapshot(alias, dir, name);
+       }
 
        list_add_tail(&alias->list, list);
 
        return 0;
 }
 
+static int perf_pmu__new_alias(struct list_head *list, char *dir, char *name, 
FILE *file)
+{
+       char buf[256];
+       int ret;
+
+       ret = fread(buf, 1, sizeof(buf), file);
+       if (ret == 0)
+               return -EINVAL;
+
+       buf[ret] = 0;
+
+       return __perf_pmu__new_alias(list, dir, name, NULL, buf);
+}
+
 static inline bool pmu_alias_info_file(char *name)
 {
        size_t len;
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
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