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: Andi Kleen <ak@linux.intel.com>
Acked-by: Jiri Olsa <jolsa@kernel.org>
Link: http://lkml.kernel.org/r/20170320201711.14142-13-andi@firstfloor.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
This commit is contained in:
Andi Kleen
2017-03-20 13:17:10 -07:00
committed by Arnaldo Carvalho de Melo
parent 7f372a636d
commit 9628481423
9 changed files with 34 additions and 8 deletions

View File

@@ -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,
char *desc, char *long_desc,
char *pmu, char *unit, char *perpkg,
char *metric_expr)
char *metric_expr,
char *metric_name)
{
struct perf_entry_data *pd = data;
FILE *outfp = pd->outfp;
@@ -318,6 +319,8 @@ static int print_events_table_entry(void *data, char *name, char *event,
fprintf(outfp, "\t.perpkg = \"%s\",\n", perpkg);
if (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");
return 0;
@@ -366,7 +369,8 @@ int json_events(const char *fn,
int (*func)(void *data, char *name, char *event, char *desc,
char *long_desc,
char *pmu, char *unit, char *perpkg,
char *metric_expr),
char *metric_expr,
char *metric_name),
void *data)
{
int err = -EIO;
@@ -393,6 +397,7 @@ int json_events(const char *fn,
char *perpkg = NULL;
char *unit = NULL;
char *metric_expr = NULL;
char *metric_name = NULL;
unsigned long long eventcode = 0;
struct msrmap *msr = NULL;
jsmntok_t *msrval = NULL;
@@ -469,6 +474,8 @@ int json_events(const char *fn,
addfield(map, &unit, "", "", val);
} else if (json_streq(map, field, "PerPkg")) {
addfield(map, &perpkg, "", "", val);
} else if (json_streq(map, field, "MetricName")) {
addfield(map, &metric_name, "", "", val);
} else if (json_streq(map, field, "MetricExpr")) {
addfield(map, &metric_expr, "", "", val);
for (s = metric_expr; *s; s++)
@@ -497,7 +504,7 @@ int json_events(const char *fn,
fixname(name);
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(desc);
free(name);
@@ -508,6 +515,7 @@ int json_events(const char *fn,
free(perpkg);
free(unit);
free(metric_expr);
free(metric_name);
if (err)
break;
tok += j;

View File

@@ -5,7 +5,8 @@ int json_events(const char *fn,
int (*func)(void *data, char *name, char *event, char *desc,
char *long_desc,
char *pmu,
char *unit, char *perpkg, char *metric_expr),
char *unit, char *perpkg, char *metric_expr,
char *metric_name),
void *data);
char *get_cpu_str(void);

View File

@@ -14,6 +14,7 @@ struct pmu_event {
const char *unit;
const char *perpkg;
const char *metric_expr;
const char *metric_name;
};
/*