Commit 96284814 authored by Andi Kleen's avatar Andi Kleen Committed by Arnaldo Carvalho de Melo

perf pmu: Add support for MetricName JSON attribute

Add support for a new JSON event attribute to name MetricExpr for better
output in perf stat.

If the event has no MetricName it uses the normal event name instead to
describe the metric.

Before

  % perf stat -a -I 1000 -e '{unc_p_clockticks,unc_p_freq_max_os_cycles}' --metric-only
           time unc_p_freq_max_os_cycles
     1.000149775     15.7
     2.000344807     19.3
     3.000502544     16.7
     4.000640656      6.6
     5.000779955      9.9

After

  % perf stat -a -I 1000 -e '{unc_p_clockticks,unc_p_freq_max_os_cycles}' --metric-only
           time freq_max_os_cycles %
     1.000149775     15.7
     2.000344807     19.3
     3.000502544     16.7
     4.000640656      6.6
     5.000779955      9.9
Signed-off-by: default avatarAndi Kleen <ak@linux.intel.com>
Acked-by: default avatarJiri Olsa <jolsa@kernel.org>
Link: http://lkml.kernel.org/r/20170320201711.14142-13-andi@firstfloor.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 7f372a63
...@@ -292,7 +292,8 @@ static void print_events_table_prefix(FILE *fp, const char *tblname) ...@@ -292,7 +292,8 @@ static void print_events_table_prefix(FILE *fp, const char *tblname)
static int print_events_table_entry(void *data, char *name, char *event, static int print_events_table_entry(void *data, char *name, char *event,
char *desc, char *long_desc, char *desc, char *long_desc,
char *pmu, char *unit, char *perpkg, char *pmu, char *unit, char *perpkg,
char *metric_expr) char *metric_expr,
char *metric_name)
{ {
struct perf_entry_data *pd = data; struct perf_entry_data *pd = data;
FILE *outfp = pd->outfp; FILE *outfp = pd->outfp;
...@@ -318,6 +319,8 @@ static int print_events_table_entry(void *data, char *name, char *event, ...@@ -318,6 +319,8 @@ static int print_events_table_entry(void *data, char *name, char *event,
fprintf(outfp, "\t.perpkg = \"%s\",\n", perpkg); fprintf(outfp, "\t.perpkg = \"%s\",\n", perpkg);
if (metric_expr) if (metric_expr)
fprintf(outfp, "\t.metric_expr = \"%s\",\n", metric_expr); fprintf(outfp, "\t.metric_expr = \"%s\",\n", metric_expr);
if (metric_name)
fprintf(outfp, "\t.metric_name = \"%s\",\n", metric_name);
fprintf(outfp, "},\n"); fprintf(outfp, "},\n");
return 0; return 0;
...@@ -366,7 +369,8 @@ int json_events(const char *fn, ...@@ -366,7 +369,8 @@ int json_events(const char *fn,
int (*func)(void *data, char *name, char *event, char *desc, int (*func)(void *data, char *name, char *event, char *desc,
char *long_desc, char *long_desc,
char *pmu, char *unit, char *perpkg, char *pmu, char *unit, char *perpkg,
char *metric_expr), char *metric_expr,
char *metric_name),
void *data) void *data)
{ {
int err = -EIO; int err = -EIO;
...@@ -393,6 +397,7 @@ int json_events(const char *fn, ...@@ -393,6 +397,7 @@ int json_events(const char *fn,
char *perpkg = NULL; char *perpkg = NULL;
char *unit = NULL; char *unit = NULL;
char *metric_expr = NULL; char *metric_expr = NULL;
char *metric_name = NULL;
unsigned long long eventcode = 0; unsigned long long eventcode = 0;
struct msrmap *msr = NULL; struct msrmap *msr = NULL;
jsmntok_t *msrval = NULL; jsmntok_t *msrval = NULL;
...@@ -469,6 +474,8 @@ int json_events(const char *fn, ...@@ -469,6 +474,8 @@ int json_events(const char *fn,
addfield(map, &unit, "", "", val); addfield(map, &unit, "", "", val);
} else if (json_streq(map, field, "PerPkg")) { } else if (json_streq(map, field, "PerPkg")) {
addfield(map, &perpkg, "", "", val); addfield(map, &perpkg, "", "", val);
} else if (json_streq(map, field, "MetricName")) {
addfield(map, &metric_name, "", "", val);
} else if (json_streq(map, field, "MetricExpr")) { } else if (json_streq(map, field, "MetricExpr")) {
addfield(map, &metric_expr, "", "", val); addfield(map, &metric_expr, "", "", val);
for (s = metric_expr; *s; s++) for (s = metric_expr; *s; s++)
...@@ -497,7 +504,7 @@ int json_events(const char *fn, ...@@ -497,7 +504,7 @@ int json_events(const char *fn,
fixname(name); fixname(name);
err = func(data, name, real_event(name, event), desc, long_desc, err = func(data, name, real_event(name, event), desc, long_desc,
pmu, unit, perpkg, metric_expr); pmu, unit, perpkg, metric_expr, metric_name);
free(event); free(event);
free(desc); free(desc);
free(name); free(name);
...@@ -508,6 +515,7 @@ int json_events(const char *fn, ...@@ -508,6 +515,7 @@ int json_events(const char *fn,
free(perpkg); free(perpkg);
free(unit); free(unit);
free(metric_expr); free(metric_expr);
free(metric_name);
if (err) if (err)
break; break;
tok += j; tok += j;
......
...@@ -5,7 +5,8 @@ int json_events(const char *fn, ...@@ -5,7 +5,8 @@ int json_events(const char *fn,
int (*func)(void *data, char *name, char *event, char *desc, int (*func)(void *data, char *name, char *event, char *desc,
char *long_desc, char *long_desc,
char *pmu, char *pmu,
char *unit, char *perpkg, char *metric_expr), char *unit, char *perpkg, char *metric_expr,
char *metric_name),
void *data); void *data);
char *get_cpu_str(void); char *get_cpu_str(void);
......
...@@ -14,6 +14,7 @@ struct pmu_event { ...@@ -14,6 +14,7 @@ struct pmu_event {
const char *unit; const char *unit;
const char *perpkg; const char *perpkg;
const char *metric_expr; const char *metric_expr;
const char *metric_name;
}; };
/* /*
......
...@@ -237,6 +237,7 @@ void perf_evsel__init(struct perf_evsel *evsel, ...@@ -237,6 +237,7 @@ void perf_evsel__init(struct perf_evsel *evsel,
perf_evsel__calc_id_pos(evsel); perf_evsel__calc_id_pos(evsel);
evsel->cmdline_group_boundary = false; evsel->cmdline_group_boundary = false;
evsel->metric_expr = NULL; evsel->metric_expr = NULL;
evsel->metric_name = NULL;
evsel->metric_events = NULL; evsel->metric_events = NULL;
evsel->collect_stat = false; evsel->collect_stat = false;
} }
......
...@@ -133,6 +133,7 @@ struct perf_evsel { ...@@ -133,6 +133,7 @@ struct perf_evsel {
int bpf_fd; int bpf_fd;
bool merged_stat; bool merged_stat;
const char * metric_expr; const char * metric_expr;
const char * metric_name;
struct perf_evsel **metric_events; struct perf_evsel **metric_events;
bool collect_stat; bool collect_stat;
}; };
......
...@@ -1256,6 +1256,7 @@ int parse_events_add_pmu(struct parse_events_evlist *data, ...@@ -1256,6 +1256,7 @@ int parse_events_add_pmu(struct parse_events_evlist *data,
evsel->per_pkg = info.per_pkg; evsel->per_pkg = info.per_pkg;
evsel->snapshot = info.snapshot; evsel->snapshot = info.snapshot;
evsel->metric_expr = info.metric_expr; evsel->metric_expr = info.metric_expr;
evsel->metric_name = info.metric_name;
} }
return evsel ? 0 : -ENOMEM; return evsel ? 0 : -ENOMEM;
......
...@@ -232,7 +232,8 @@ static int __perf_pmu__new_alias(struct list_head *list, char *dir, char *name, ...@@ -232,7 +232,8 @@ static int __perf_pmu__new_alias(struct list_head *list, char *dir, char *name,
char *desc, char *val, char *desc, char *val,
char *long_desc, char *topic, char *long_desc, char *topic,
char *unit, char *perpkg, char *unit, char *perpkg,
char *metric_expr) char *metric_expr,
char *metric_name)
{ {
struct perf_pmu_alias *alias; struct perf_pmu_alias *alias;
int ret; int ret;
...@@ -267,6 +268,7 @@ static int __perf_pmu__new_alias(struct list_head *list, char *dir, char *name, ...@@ -267,6 +268,7 @@ static int __perf_pmu__new_alias(struct list_head *list, char *dir, char *name,
} }
alias->metric_expr = metric_expr ? strdup(metric_expr) : NULL; alias->metric_expr = metric_expr ? strdup(metric_expr) : NULL;
alias->metric_name = metric_name ? strdup(metric_name): NULL;
alias->desc = desc ? strdup(desc) : NULL; alias->desc = desc ? strdup(desc) : NULL;
alias->long_desc = long_desc ? strdup(long_desc) : alias->long_desc = long_desc ? strdup(long_desc) :
desc ? strdup(desc) : NULL; desc ? strdup(desc) : NULL;
...@@ -296,7 +298,7 @@ static int perf_pmu__new_alias(struct list_head *list, char *dir, char *name, FI ...@@ -296,7 +298,7 @@ static int perf_pmu__new_alias(struct list_head *list, char *dir, char *name, FI
buf[ret] = 0; buf[ret] = 0;
return __perf_pmu__new_alias(list, dir, name, NULL, buf, NULL, NULL, NULL, return __perf_pmu__new_alias(list, dir, name, NULL, buf, NULL, NULL, NULL,
NULL, NULL); NULL, NULL, NULL);
} }
static inline bool pmu_alias_info_file(char *name) static inline bool pmu_alias_info_file(char *name)
...@@ -567,7 +569,8 @@ static void pmu_add_cpu_aliases(struct list_head *head, const char *name) ...@@ -567,7 +569,8 @@ static void pmu_add_cpu_aliases(struct list_head *head, const char *name)
(char *)pe->desc, (char *)pe->event, (char *)pe->desc, (char *)pe->event,
(char *)pe->long_desc, (char *)pe->topic, (char *)pe->long_desc, (char *)pe->topic,
(char *)pe->unit, (char *)pe->perpkg, (char *)pe->unit, (char *)pe->perpkg,
(char *)pe->metric_expr); (char *)pe->metric_expr,
(char *)pe->metric_name);
} }
out: out:
...@@ -995,6 +998,7 @@ int perf_pmu__check_alias(struct perf_pmu *pmu, struct list_head *head_terms, ...@@ -995,6 +998,7 @@ int perf_pmu__check_alias(struct perf_pmu *pmu, struct list_head *head_terms,
info->scale = 0.0; info->scale = 0.0;
info->snapshot = false; info->snapshot = false;
info->metric_expr = NULL; info->metric_expr = NULL;
info->metric_name = NULL;
list_for_each_entry_safe(term, h, head_terms, list) { list_for_each_entry_safe(term, h, head_terms, list) {
alias = pmu_find_alias(pmu, term); alias = pmu_find_alias(pmu, term);
...@@ -1011,6 +1015,7 @@ int perf_pmu__check_alias(struct perf_pmu *pmu, struct list_head *head_terms, ...@@ -1011,6 +1015,7 @@ int perf_pmu__check_alias(struct perf_pmu *pmu, struct list_head *head_terms,
if (alias->per_pkg) if (alias->per_pkg)
info->per_pkg = true; info->per_pkg = true;
info->metric_expr = alias->metric_expr; info->metric_expr = alias->metric_expr;
info->metric_name = alias->metric_name;
list_del(&term->list); list_del(&term->list);
free(term); free(term);
...@@ -1106,6 +1111,7 @@ struct sevent { ...@@ -1106,6 +1111,7 @@ struct sevent {
char *str; char *str;
char *pmu; char *pmu;
char *metric_expr; char *metric_expr;
char *metric_name;
}; };
static int cmp_sevent(const void *a, const void *b) static int cmp_sevent(const void *a, const void *b)
...@@ -1205,6 +1211,7 @@ void print_pmu_events(const char *event_glob, bool name_only, bool quiet_flag, ...@@ -1205,6 +1211,7 @@ void print_pmu_events(const char *event_glob, bool name_only, bool quiet_flag,
aliases[j].str = alias->str; aliases[j].str = alias->str;
aliases[j].pmu = pmu->name; aliases[j].pmu = pmu->name;
aliases[j].metric_expr = alias->metric_expr; aliases[j].metric_expr = alias->metric_expr;
aliases[j].metric_name = alias->metric_name;
j++; j++;
} }
if (pmu->selectable && if (pmu->selectable &&
...@@ -1241,6 +1248,8 @@ void print_pmu_events(const char *event_glob, bool name_only, bool quiet_flag, ...@@ -1241,6 +1248,8 @@ void print_pmu_events(const char *event_glob, bool name_only, bool quiet_flag,
printf("]\n"); printf("]\n");
if (verbose > 0) { if (verbose > 0) {
printf("%*s%s/%s/ ", 8, "", aliases[j].pmu, aliases[j].str); printf("%*s%s/%s/ ", 8, "", aliases[j].pmu, aliases[j].str);
if (aliases[j].metric_name)
printf(" MetricName: %s", aliases[j].metric_name);
if (aliases[j].metric_expr) if (aliases[j].metric_expr)
printf(" MetricExpr: %s", aliases[j].metric_expr); printf(" MetricExpr: %s", aliases[j].metric_expr);
putchar('\n'); putchar('\n');
......
...@@ -32,6 +32,7 @@ struct perf_pmu { ...@@ -32,6 +32,7 @@ struct perf_pmu {
struct perf_pmu_info { struct perf_pmu_info {
const char *unit; const char *unit;
const char *metric_expr; const char *metric_expr;
const char *metric_name;
double scale; double scale;
bool per_pkg; bool per_pkg;
bool snapshot; bool snapshot;
...@@ -52,6 +53,7 @@ struct perf_pmu_alias { ...@@ -52,6 +53,7 @@ struct perf_pmu_alias {
bool per_pkg; bool per_pkg;
bool snapshot; bool snapshot;
char *metric_expr; char *metric_expr;
char *metric_name;
}; };
struct perf_pmu *perf_pmu__find(const char *name); struct perf_pmu *perf_pmu__find(const char *name);
......
...@@ -803,7 +803,9 @@ void perf_stat__print_shadow_stats(struct perf_evsel *evsel, ...@@ -803,7 +803,9 @@ void perf_stat__print_shadow_stats(struct perf_evsel *evsel,
if (expr__parse(&ratio, &pctx, &p) == 0) if (expr__parse(&ratio, &pctx, &p) == 0)
print_metric(ctxp, NULL, "%8.1f", print_metric(ctxp, NULL, "%8.1f",
out->force_header ? evsel->name : "", evsel->metric_name ?
evsel->metric_name :
out->force_header ? evsel->name : "",
ratio); ratio);
else else
print_metric(ctxp, NULL, NULL, "", 0); print_metric(ctxp, NULL, NULL, "", 0);
......
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