linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Arnaldo Carvalho de Melo <acme@kernel.org>
To: Ingo Molnar <mingo@kernel.org>, Thomas Gleixner <tglx@linutronix.de>
Cc: Jiri Olsa <jolsa@kernel.org>, Namhyung Kim <namhyung@kernel.org>,
	Clark Williams <williams@redhat.com>,
	linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org,
	Jin Yao <yao.jin@linux.intel.com>,
	Alexander Shishkin <alexander.shishkin@linux.intel.com>,
	Andi Kleen <ak@linux.intel.com>,
	Kan Liang <kan.liang@linux.intel.com>,
	Peter Zijlstra <peterz@infradead.org>,
	Arnaldo Carvalho de Melo <acme@redhat.com>
Subject: [PATCH 39/47] perf metricgroup: Scale the metric result
Date: Sun,  1 Sep 2019 09:23:18 -0300	[thread overview]
Message-ID: <20190901122326.5793-40-acme@kernel.org> (raw)
In-Reply-To: <20190901122326.5793-1-acme@kernel.org>

From: Jin Yao <yao.jin@linux.intel.com>

Some metrics define the scale unit, such as

    {
        "BriefDescription": "Intel Optane DC persistent memory read latency (ns). Derived from unc_m_pmm_rpq_occupancy.all",
        "Counter": "0,1,2,3",
        "EventCode": "0xE0",
        "EventName": "UNC_M_PMM_READ_LATENCY",
        "MetricExpr": "UNC_M_PMM_RPQ_OCCUPANCY.ALL / UNC_M_PMM_RPQ_INSERTS / UNC_M_CLOCKTICKS",
        "MetricName": "UNC_M_PMM_READ_LATENCY",
        "PerPkg": "1",
        "ScaleUnit": "6000000000ns",
        "UMask": "0x1",
        "Unit": "iMC"
    },

For above example, the ratio should be,

ratio = (UNC_M_PMM_RPQ_OCCUPANCY.ALL / UNC_M_PMM_RPQ_INSERTS / UNC_M_CLOCKTICKS) * 6000000000

But in current code, the ratio is not scaled ( * 6000000000)

With this patch, the ratio is scaled and the unit (ns) is printed.

For example,
  #    219.4 ns  UNC_M_PMM_READ_LATENCY

Signed-off-by: Jin Yao <yao.jin@linux.intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lore.kernel.org/lkml/20190828055932.8269-4-yao.jin@linux.intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/util/metricgroup.c |  3 +++
 tools/perf/util/metricgroup.h |  1 +
 tools/perf/util/stat-shadow.c | 38 +++++++++++++++++++++++++----------
 3 files changed, 31 insertions(+), 11 deletions(-)

diff --git a/tools/perf/util/metricgroup.c b/tools/perf/util/metricgroup.c
index 33f5e2101874..f474a29f1b69 100644
--- a/tools/perf/util/metricgroup.c
+++ b/tools/perf/util/metricgroup.c
@@ -87,6 +87,7 @@ struct egroup {
 	const char **ids;
 	const char *metric_name;
 	const char *metric_expr;
+	const char *metric_unit;
 };
 
 static bool record_evsel(int *ind, struct evsel **start,
@@ -182,6 +183,7 @@ static int metricgroup__setup_events(struct list_head *groups,
 		}
 		expr->metric_expr = eg->metric_expr;
 		expr->metric_name = eg->metric_name;
+		expr->metric_unit = eg->metric_unit;
 		expr->metric_events = metric_events;
 		list_add(&expr->nd, &me->head);
 	}
@@ -453,6 +455,7 @@ static int metricgroup__add_metric(const char *metric, struct strbuf *events,
 			eg->idnum = idnum;
 			eg->metric_name = pe->metric_name;
 			eg->metric_expr = pe->metric_expr;
+			eg->metric_unit = pe->unit;
 			list_add_tail(&eg->nd, group_list);
 			ret = 0;
 		}
diff --git a/tools/perf/util/metricgroup.h b/tools/perf/util/metricgroup.h
index e5092f6404ae..475c7f912864 100644
--- a/tools/perf/util/metricgroup.h
+++ b/tools/perf/util/metricgroup.h
@@ -20,6 +20,7 @@ struct metric_expr {
 	struct list_head nd;
 	const char *metric_expr;
 	const char *metric_name;
+	const char *metric_unit;
 	struct evsel **metric_events;
 };
 
diff --git a/tools/perf/util/stat-shadow.c b/tools/perf/util/stat-shadow.c
index 2ed5e0066c70..696d263f6eb6 100644
--- a/tools/perf/util/stat-shadow.c
+++ b/tools/perf/util/stat-shadow.c
@@ -715,6 +715,7 @@ static void generic_metric(struct perf_stat_config *config,
 			   struct evsel **metric_events,
 			   char *name,
 			   const char *metric_name,
+			   const char *metric_unit,
 			   double avg,
 			   int cpu,
 			   struct perf_stat_output_ctx *out,
@@ -722,7 +723,7 @@ static void generic_metric(struct perf_stat_config *config,
 {
 	print_metric_t print_metric = out->print_metric;
 	struct parse_ctx pctx;
-	double ratio;
+	double ratio, scale;
 	int i;
 	void *ctxp = out->ctx;
 	char *n, *pn;
@@ -732,7 +733,6 @@ static void generic_metric(struct perf_stat_config *config,
 	for (i = 0; metric_events[i]; i++) {
 		struct saved_value *v;
 		struct stats *stats;
-		double scale;
 
 		if (!strcmp(metric_events[i]->name, "duration_time")) {
 			stats = &walltime_nsecs_stats;
@@ -762,16 +762,32 @@ static void generic_metric(struct perf_stat_config *config,
 	if (!metric_events[i]) {
 		const char *p = metric_expr;
 
-		if (expr__parse(&ratio, &pctx, &p) == 0)
-			print_metric(config, ctxp, NULL, "%8.1f",
-				metric_name ?
-				metric_name :
-				out->force_header ?  name : "",
-				ratio);
-		else
+		if (expr__parse(&ratio, &pctx, &p) == 0) {
+			char *unit;
+			char metric_bf[64];
+
+			if (metric_unit && metric_name) {
+				if (perf_pmu__convert_scale(metric_unit,
+					&unit, &scale) >= 0) {
+					ratio *= scale;
+				}
+
+				scnprintf(metric_bf, sizeof(metric_bf),
+					  "%s  %s", unit, metric_name);
+				print_metric(config, ctxp, NULL, "%8.1f",
+					     metric_bf, ratio);
+			} else {
+				print_metric(config, ctxp, NULL, "%8.1f",
+					metric_name ?
+					metric_name :
+					out->force_header ?  name : "",
+					ratio);
+			}
+		} else {
 			print_metric(config, ctxp, NULL, NULL,
 				     out->force_header ?
 				     (metric_name ? metric_name : name) : "", 0);
+		}
 	} else
 		print_metric(config, ctxp, NULL, NULL, "", 0);
 
@@ -992,7 +1008,7 @@ void perf_stat__print_shadow_stats(struct perf_stat_config *config,
 			print_metric(config, ctxp, NULL, NULL, name, 0);
 	} else if (evsel->metric_expr) {
 		generic_metric(config, evsel->metric_expr, evsel->metric_events, evsel->name,
-				evsel->metric_name, avg, cpu, out, st);
+				evsel->metric_name, NULL, avg, cpu, out, st);
 	} else if (runtime_stat_n(st, STAT_NSECS, 0, cpu) != 0) {
 		char unit = 'M';
 		char unit_buf[10];
@@ -1021,7 +1037,7 @@ void perf_stat__print_shadow_stats(struct perf_stat_config *config,
 				out->new_line(config, ctxp);
 			generic_metric(config, mexp->metric_expr, mexp->metric_events,
 					evsel->name, mexp->metric_name,
-					avg, cpu, out, st);
+					mexp->metric_unit, avg, cpu, out, st);
 		}
 	}
 	if (num == 0)
-- 
2.21.0


  parent reply	other threads:[~2019-09-01 12:25 UTC|newest]

Thread overview: 49+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-01 12:22 [GIT PULL] perf/core improvements and fixes Arnaldo Carvalho de Melo
2019-09-01 12:22 ` [PATCH 01/47] perf c2c: Display proper cpu count in nodes column Arnaldo Carvalho de Melo
2019-09-01 12:22 ` [PATCH 02/47] perf timechart: Refactor svg_build_topology_map() Arnaldo Carvalho de Melo
2019-09-01 12:22 ` [PATCH 03/47] perf svghelper: Replace MAX_NR_CPUS with perf_env::nr_cpus_online Arnaldo Carvalho de Melo
2019-09-01 12:22 ` [PATCH 04/47] perf stat: Replace MAX_NR_CPUS with cpu__max_cpu() Arnaldo Carvalho de Melo
2019-09-01 12:22 ` [PATCH 05/47] perf session: Replace MAX_NR_CPUS with perf_env::nr_cpus_online Arnaldo Carvalho de Melo
2019-09-01 12:22 ` [PATCH 06/47] perf machine: " Arnaldo Carvalho de Melo
2019-09-01 12:22 ` [PATCH 07/47] perf header: Replace MAX_NR_CPUS with cpu__max_cpu() Arnaldo Carvalho de Melo
2019-09-01 12:22 ` [PATCH 08/47] libperf: Warn when exceeding MAX_NR_CPUS in cpumap Arnaldo Carvalho de Melo
2019-09-01 12:22 ` [PATCH 09/47] perf tools: Remove needless libtraceevent include directives Arnaldo Carvalho de Melo
2019-09-01 12:22 ` [PATCH 10/47] perf header: Move CPUINFO_PROC to the only file where it is used Arnaldo Carvalho de Melo
2019-09-01 12:22 ` [PATCH 11/47] perf tools: Move everything related to sys_perf_event_open() to perf-sys.h Arnaldo Carvalho de Melo
2019-09-01 12:22 ` [PATCH 12/47] perf time-utils: Adopt rdclock() from perf.h Arnaldo Carvalho de Melo
2019-09-01 12:22 ` [PATCH 13/47] perf tools: Remove needless perf.h include directive from headers Arnaldo Carvalho de Melo
2019-09-01 12:22 ` [PATCH 14/47] perf tools: Remove perf.h from source files not needing it Arnaldo Carvalho de Melo
2019-09-01 12:22 ` [PATCH 15/47] perf tools: Remove debug.h from header " Arnaldo Carvalho de Melo
2019-09-01 12:22 ` [PATCH 16/47] perf debug: Remove needless include directives from debug.h Arnaldo Carvalho de Melo
2019-09-01 12:22 ` [PATCH 17/47] perf env: Remove env.h from other headers where just a fwd decl is needed Arnaldo Carvalho de Melo
2019-09-01 12:22 ` [PATCH 18/47] perf event: Remove needless include directives from event.h Arnaldo Carvalho de Melo
2019-09-01 12:22 ` [PATCH 19/47] libtraceevent, perf tools: Changes in tep_print_event_* APIs Arnaldo Carvalho de Melo
2019-09-01 12:22 ` [PATCH 20/47] libtraceevent: Remove tep_register_trace_clock() Arnaldo Carvalho de Melo
2019-09-01 12:23 ` [PATCH 21/47] libtraceevent: Change users plugin directory Arnaldo Carvalho de Melo
2019-09-01 12:23 ` [PATCH 22/47] perf dso: Adopt DSO related macros from symbol.h Arnaldo Carvalho de Melo
2019-09-01 12:23 ` [PATCH 23/47] perf symbol: Move C++ demangle defines to the only file using it Arnaldo Carvalho de Melo
2019-09-01 12:23 ` [PATCH 24/47] perf symbols: Add missing linux/refcount.h to symbol.h Arnaldo Carvalho de Melo
2019-09-01 12:23 ` [PATCH 25/47] perf symbols: Move symsrc prototypes to a separate header Arnaldo Carvalho de Melo
2019-09-01 12:23 ` [PATCH 26/47] perf dsos: Move the dsos struct and its methods to separate source files Arnaldo Carvalho de Melo
2019-09-01 12:23 ` [PATCH 27/47] perf hist: Remove needless ui/progress.h from hist.h Arnaldo Carvalho de Melo
2019-09-01 12:23 ` [PATCH 28/47] perf tools: Move 'struct events_stats' and prototypes to separate header Arnaldo Carvalho de Melo
2019-09-01 12:23 ` [PATCH 29/47] perf tools: Remove needless sort.h include directives Arnaldo Carvalho de Melo
2019-09-01 12:23 ` [PATCH 30/47] perf probe: No need for symbol.h, symbol_conf is enough Arnaldo Carvalho de Melo
2019-09-01 12:23 ` [PATCH 31/47] perf tools: Remove needless map.h include directives Arnaldo Carvalho de Melo
2019-09-01 12:23 ` [PATCH 32/47] perf tools: Remove needless thread.h " Arnaldo Carvalho de Melo
2019-09-01 12:23 ` [PATCH 33/47] perf tools: Remove needless thread_map.h " Arnaldo Carvalho de Melo
2019-09-01 12:23 ` [PATCH 34/47] perf tools: Remove needless evlist.h " Arnaldo Carvalho de Melo
2019-09-01 12:23 ` [PATCH 35/47] " Arnaldo Carvalho de Melo
2019-09-01 12:23 ` [PATCH 36/47] perf auxtrace: Uninline functions that touch perf_session Arnaldo Carvalho de Melo
2019-09-01 12:23 ` [PATCH 37/47] perf symbols: Move mem_info and branch_info out of symbol.h Arnaldo Carvalho de Melo
2019-09-01 12:23 ` [PATCH 38/47] perf pmu: Change convert_scale from static to global Arnaldo Carvalho de Melo
2019-09-01 12:23 ` Arnaldo Carvalho de Melo [this message]
2019-09-01 12:23 ` [PATCH 40/47] perf metricgroup: Support multiple events for metricgroup Arnaldo Carvalho de Melo
2019-09-01 12:23 ` [PATCH 41/47] objtool: Move x86 insn decoder to a common location Arnaldo Carvalho de Melo
2019-09-01 12:23 ` [PATCH 42/47] perf: Update .gitignore file Arnaldo Carvalho de Melo
2019-09-01 12:23 ` [PATCH 43/47] perf intel-pt: Remove inat.c from build dependency list Arnaldo Carvalho de Melo
2019-09-01 12:23 ` [PATCH 44/47] perf intel-pt: Use shared x86 insn decoder Arnaldo Carvalho de Melo
2019-09-01 12:23 ` [PATCH 45/47] perf build: Ignore intentional differences for the " Arnaldo Carvalho de Melo
2019-09-01 12:23 ` [PATCH 46/47] objtool: Update sync-check.sh from perf's check-headers.sh Arnaldo Carvalho de Melo
2019-09-01 12:23 ` [PATCH 47/47] objtool: Ignore intentional differences for the x86 insn decoder Arnaldo Carvalho de Melo
2019-09-02  7:14 ` [GIT PULL] perf/core improvements and fixes Ingo Molnar

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=20190901122326.5793-40-acme@kernel.org \
    --to=acme@kernel.org \
    --cc=acme@redhat.com \
    --cc=ak@linux.intel.com \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=jolsa@kernel.org \
    --cc=kan.liang@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=namhyung@kernel.org \
    --cc=peterz@infradead.org \
    --cc=tglx@linutronix.de \
    --cc=williams@redhat.com \
    --cc=yao.jin@linux.intel.com \
    /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).