linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andi Kleen <andi@firstfloor.org>
To: acme@kernel.org
Cc: jolsa@kernel.org, linux-kernel@vger.kernel.org,
	Andi Kleen <ak@linux.intel.com>
Subject: [PATCH 12/13] perf, tools: Add support for MetricName JSON attribute
Date: Mon, 20 Mar 2017 13:17:10 -0700	[thread overview]
Message-ID: <20170320201711.14142-13-andi@firstfloor.org> (raw)
In-Reply-To: <20170320201711.14142-1-andi@firstfloor.org>

From: Andi Kleen <ak@linux.intel.com>

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>
---
 tools/perf/pmu-events/jevents.c    | 14 +++++++++++---
 tools/perf/pmu-events/jevents.h    |  3 ++-
 tools/perf/pmu-events/pmu-events.h |  1 +
 tools/perf/util/evsel.c            |  1 +
 tools/perf/util/evsel.h            |  1 +
 tools/perf/util/parse-events.c     |  1 +
 tools/perf/util/pmu.c              | 15 ++++++++++++---
 tools/perf/util/pmu.h              |  2 ++
 tools/perf/util/stat-shadow.c      |  4 +++-
 9 files changed, 34 insertions(+), 8 deletions(-)

diff --git a/tools/perf/pmu-events/jevents.c b/tools/perf/pmu-events/jevents.c
index 0735dc2a167a..81f2ef3b15cf 100644
--- a/tools/perf/pmu-events/jevents.c
+++ b/tools/perf/pmu-events/jevents.c
@@ -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;
diff --git a/tools/perf/pmu-events/jevents.h b/tools/perf/pmu-events/jevents.h
index 57e111bf2168..611fac01913d 100644
--- a/tools/perf/pmu-events/jevents.h
+++ b/tools/perf/pmu-events/jevents.h
@@ -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);
 
diff --git a/tools/perf/pmu-events/pmu-events.h b/tools/perf/pmu-events/pmu-events.h
index d046e3a4ce46..569eab3688dd 100644
--- a/tools/perf/pmu-events/pmu-events.h
+++ b/tools/perf/pmu-events/pmu-events.h
@@ -14,6 +14,7 @@ struct pmu_event {
 	const char *unit;
 	const char *perpkg;
 	const char *metric_expr;
+	const char *metric_name;
 };
 
 /*
diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c
index ef2a31f6dd06..9dc7e2d6e48a 100644
--- a/tools/perf/util/evsel.c
+++ b/tools/perf/util/evsel.c
@@ -237,6 +237,7 @@ void perf_evsel__init(struct perf_evsel *evsel,
 	perf_evsel__calc_id_pos(evsel);
 	evsel->cmdline_group_boundary = false;
 	evsel->metric_expr   = NULL;
+	evsel->metric_name   = NULL;
 	evsel->metric_events = NULL;
 	evsel->collect_stat  = false;
 }
diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h
index 8f1f61826fdf..d101695c482c 100644
--- a/tools/perf/util/evsel.h
+++ b/tools/perf/util/evsel.h
@@ -133,6 +133,7 @@ struct perf_evsel {
 	int			bpf_fd;
 	bool			merged_stat;
 	const char *		metric_expr;
+	const char *		metric_name;
 	struct perf_evsel	**metric_events;
 	bool			collect_stat;
 };
diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c
index 91b8e83e307d..119eb0b65876 100644
--- a/tools/perf/util/parse-events.c
+++ b/tools/perf/util/parse-events.c
@@ -1256,6 +1256,7 @@ int parse_events_add_pmu(struct parse_events_evlist *data,
 		evsel->per_pkg = info.per_pkg;
 		evsel->snapshot = info.snapshot;
 		evsel->metric_expr = info.metric_expr;
+		evsel->metric_name = info.metric_name;
 	}
 
 	return evsel ? 0 : -ENOMEM;
diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c
index f819ad162b7c..bcf752fa345b 100644
--- a/tools/perf/util/pmu.c
+++ b/tools/perf/util/pmu.c
@@ -232,7 +232,8 @@ static int __perf_pmu__new_alias(struct list_head *list, char *dir, char *name,
 				 char *desc, char *val,
 				 char *long_desc, char *topic,
 				 char *unit, char *perpkg,
-				 char *metric_expr)
+				 char *metric_expr,
+				 char *metric_name)
 {
 	struct perf_pmu_alias *alias;
 	int ret;
@@ -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_name = metric_name ? strdup(metric_name): NULL;
 	alias->desc = desc ? strdup(desc) : NULL;
 	alias->long_desc = long_desc ? strdup(long_desc) :
 				desc ? strdup(desc) : NULL;
@@ -296,7 +298,7 @@ static int perf_pmu__new_alias(struct list_head *list, char *dir, char *name, FI
 	buf[ret] = 0;
 
 	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)
@@ -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->long_desc, (char *)pe->topic,
 				(char *)pe->unit, (char *)pe->perpkg,
-				(char *)pe->metric_expr);
+				(char *)pe->metric_expr,
+				(char *)pe->metric_name);
 	}
 
 out:
@@ -995,6 +998,7 @@ int perf_pmu__check_alias(struct perf_pmu *pmu, struct list_head *head_terms,
 	info->scale    = 0.0;
 	info->snapshot = false;
 	info->metric_expr = NULL;
+	info->metric_name = NULL;
 
 	list_for_each_entry_safe(term, h, head_terms, list) {
 		alias = pmu_find_alias(pmu, term);
@@ -1011,6 +1015,7 @@ int perf_pmu__check_alias(struct perf_pmu *pmu, struct list_head *head_terms,
 		if (alias->per_pkg)
 			info->per_pkg = true;
 		info->metric_expr = alias->metric_expr;
+		info->metric_name = alias->metric_name;
 
 		list_del(&term->list);
 		free(term);
@@ -1106,6 +1111,7 @@ struct sevent {
 	char *str;
 	char *pmu;
 	char *metric_expr;
+	char *metric_name;
 };
 
 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,
 			aliases[j].str = alias->str;
 			aliases[j].pmu = pmu->name;
 			aliases[j].metric_expr = alias->metric_expr;
+			aliases[j].metric_name = alias->metric_name;
 			j++;
 		}
 		if (pmu->selectable &&
@@ -1241,6 +1248,8 @@ void print_pmu_events(const char *event_glob, bool name_only, bool quiet_flag,
 			printf("]\n");
 			if (verbose > 0) {
 				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)
 					printf(" MetricExpr: %s", aliases[j].metric_expr);
 				putchar('\n');
diff --git a/tools/perf/util/pmu.h b/tools/perf/util/pmu.h
index 27f078ccc594..3d4b703f5d89 100644
--- a/tools/perf/util/pmu.h
+++ b/tools/perf/util/pmu.h
@@ -32,6 +32,7 @@ struct perf_pmu {
 struct perf_pmu_info {
 	const char *unit;
 	const char *metric_expr;
+	const char *metric_name;
 	double scale;
 	bool per_pkg;
 	bool snapshot;
@@ -52,6 +53,7 @@ struct perf_pmu_alias {
 	bool per_pkg;
 	bool snapshot;
 	char *metric_expr;
+	char *metric_name;
 };
 
 struct perf_pmu *perf_pmu__find(const char *name);
diff --git a/tools/perf/util/stat-shadow.c b/tools/perf/util/stat-shadow.c
index c323cce97d98..ac10cc675d39 100644
--- a/tools/perf/util/stat-shadow.c
+++ b/tools/perf/util/stat-shadow.c
@@ -803,7 +803,9 @@ void perf_stat__print_shadow_stats(struct perf_evsel *evsel,
 
 			if (expr__parse(&ratio, &pctx, &p) == 0)
 				print_metric(ctxp, NULL, "%8.1f",
-					out->force_header ? evsel->name : "",
+					evsel->metric_name ?
+					evsel->metric_name :
+					out->force_header ?  evsel->name : "",
 					ratio);
 			else
 				print_metric(ctxp, NULL, NULL, "", 0);
-- 
2.9.3

  parent reply	other threads:[~2017-03-20 20:18 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-20 20:16 perf: Improve support for uncore JSON event lists Andi Kleen
2017-03-20 20:16 ` [PATCH 01/13] perf, tools, stat: Factor out callback for collecting event values Andi Kleen
2017-03-24 18:46   ` [tip:perf/core] perf " tip-bot for Andi Kleen
2017-03-20 20:17 ` [PATCH 02/13] perf, tools, stat: Collapse identically named events Andi Kleen
2017-03-24 18:47   ` [tip:perf/core] perf " tip-bot for Andi Kleen
2017-03-20 20:17 ` [PATCH 03/13] perf, tools, stat: Handle partially bad results with merging Andi Kleen
2017-03-24 18:48   ` [tip:perf/core] perf " tip-bot for Andi Kleen
2017-03-20 20:17 ` [PATCH 04/13] perf, tools: Factor out PMU matching in parser Andi Kleen
2017-03-24 18:48   ` [tip:perf/core] perf " tip-bot for Andi Kleen
2017-03-20 20:17 ` [PATCH 05/13] perf, tools: Expand PMU events by prefix match Andi Kleen
2017-03-24 18:49   ` [tip:perf/core] perf pmu: " tip-bot for Andi Kleen
2017-03-20 20:17 ` [PATCH 06/13] perf, tools: Special case uncore_ prefix Andi Kleen
2017-03-24 18:49   ` [tip:perf/core] perf pmu: " tip-bot for Andi Kleen
2017-03-20 20:17 ` [PATCH 07/13] perf, tools: Add a simple expression parser for JSON Andi Kleen
2017-03-21 19:14   ` Arnaldo Carvalho de Melo
2017-03-21 19:15     ` Arnaldo Carvalho de Melo
2017-03-21 22:08       ` Build errors, was " Arnaldo Carvalho de Melo
2017-03-24 18:50   ` [tip:perf/core] perf " tip-bot for Andi Kleen
2017-03-20 20:17 ` [PATCH 08/13] perf, tools: Update Intel uncore JSON event files Andi Kleen
2017-03-24 18:50   ` [tip:perf/core] perf vendor events intel: " tip-bot for Andi Kleen
2017-03-20 20:17 ` [PATCH 09/13] perf, tools: Support MetricExpr header in JSON event list Andi Kleen
2017-03-24 18:51   ` [tip:perf/core] perf pmu: " tip-bot for Andi Kleen
2017-03-20 20:17 ` [PATCH 10/13] perf, tools, stat: Output JSON MetricExpr metric Andi Kleen
2017-03-21 14:48   ` Jiri Olsa
2017-03-21 15:45     ` Andi Kleen
2017-03-21 19:42       ` Arnaldo Carvalho de Melo
2017-03-21 19:49         ` Andi Kleen
2017-03-24 18:51   ` [tip:perf/core] perf " tip-bot for Andi Kleen
2017-03-20 20:17 ` [PATCH 11/13] perf, tools, list: Support printing MetricExpr with --debug Andi Kleen
2017-03-24 18:52   ` [tip:perf/core] perf " tip-bot for Andi Kleen
2017-03-20 20:17 ` Andi Kleen [this message]
2017-03-24 18:53   ` [tip:perf/core] perf pmu: Add support for MetricName JSON attribute tip-bot for Andi Kleen
2017-03-20 20:17 ` [PATCH 13/13] perf, tools, list: Move extra details printing to new option Andi Kleen
2017-03-24 18:53   ` [tip:perf/core] perf " tip-bot for Andi Kleen
2017-03-21 14:48 ` perf: Improve support for uncore JSON event lists Jiri Olsa
2017-03-21 19:53   ` Arnaldo Carvalho de Melo
  -- strict thread matches above, loose matches on Subject: below --
2017-03-10 21:24 Andi Kleen
2017-03-10 21:24 ` [PATCH 12/13] perf, tools: Add support for MetricName JSON attribute Andi Kleen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170320201711.14142-13-andi@firstfloor.org \
    --to=andi@firstfloor.org \
    --cc=acme@kernel.org \
    --cc=ak@linux.intel.com \
    --cc=jolsa@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).