Skip to content

Commit

Permalink
perf pmu: Split perf_pmu__new_alias()
Browse files Browse the repository at this point in the history
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 <sukadev@linux.vnet.ibm.com>
Acked-by: Jiri Olsa <jolsa@redhat.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Madhavan Srinivasan <maddy@linux.vnet.ibm.com>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: linuxppc-dev@lists.ozlabs.org
Link: http://lkml.kernel.org/r/1433921123-25327-5-git-send-email-sukadev@linux.vnet.ibm.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
  • Loading branch information
Sukadev Bhattiprolu authored and Arnaldo Carvalho de Melo committed Jun 23, 2015
1 parent c5de47f commit 70c646e
Showing 1 changed file with 27 additions and 15 deletions.
42 changes: 27 additions & 15 deletions tools/perf/util/pmu.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down

0 comments on commit 70c646e

Please sign in to comment.