mirror of https://lore.kernel.org/lkml/
 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 v1 2/5] perf, tools: Save event scaling factors in perf.data
Date: Thu,  9 Nov 2017 06:55:25 -0800	[thread overview]
Message-ID: <20171109145528.23371-3-andi@firstfloor.org> (raw)
In-Reply-To: <20171109145528.23371-1-andi@firstfloor.org>

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

To process metrics, perf script needs to know the scaling
factors reported by sysfs for events. Save the scaling factors
in the perf.data metadata in a new SCALE header.

Signed-off-by: Andi Kleen <ak@linux.intel.com>
---
 tools/perf/Documentation/perf.data-file-format.txt |  8 +++
 tools/perf/util/header.c                           | 60 ++++++++++++++++++++++
 tools/perf/util/header.h                           |  1 +
 3 files changed, 69 insertions(+)

diff --git a/tools/perf/Documentation/perf.data-file-format.txt b/tools/perf/Documentation/perf.data-file-format.txt
index 15e8b48077ba..dc91d0578f46 100644
--- a/tools/perf/Documentation/perf.data-file-format.txt
+++ b/tools/perf/Documentation/perf.data-file-format.txt
@@ -261,6 +261,14 @@ struct {
 	struct perf_header_string map;
 }[number_of_cache_levels];
 
+	HEADER_SCALE = 21,
+
+Save scaling factor of events. One entry for each event in the same
+order as other events in the header.
+
+	u32 	nr;
+	double	scale[nr];
+
 	other bits are reserved and should ignored for now
 	HEADER_FEAT_BITS	= 256,
 
diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c
index 605bbd5404fb..4f1d23cfb9b0 100644
--- a/tools/perf/util/header.c
+++ b/tools/perf/util/header.c
@@ -2147,6 +2147,65 @@ static int process_cache(struct feat_fd *ff, void *data __maybe_unused)
 	return -1;
 }
 
+static int write_scale(struct feat_fd *ff, struct perf_evlist *evlist)
+{
+	u32 num;
+	struct perf_evsel *evsel;
+
+	num = 0;
+	evlist__for_each_entry (evlist, evsel)
+		num++;
+
+	if (do_write(ff, &num, sizeof num) < 0)
+		return -1;
+	evlist__for_each_entry (evlist, evsel) {
+		if (do_write(ff, &evsel->scale, sizeof(double)) < 0)
+			return -1;
+	}
+	return 0;
+}
+
+static void print_scale(struct feat_fd *ff, FILE *fp)
+{
+	struct perf_session *session;
+	struct perf_evsel *evsel;
+	int num = 0;
+
+	session = container_of(ff->ph, struct perf_session, header);
+
+	num = 0;
+	evlist__for_each_entry(session->evlist, evsel) {
+		fprintf(fp, "# event %d %s scale %f\n",
+			num++,
+			evsel->name,
+			evsel->scale);
+	}
+}
+
+static int process_scale(struct feat_fd *ff, void *data __maybe_unused)
+{
+	u32 cnt;
+	struct perf_evsel *evsel;
+	struct perf_session *session;
+
+	session = container_of(ff->ph, struct perf_session, header);
+	if (do_read_u32(ff, &cnt))
+		return -1;
+	evlist__for_each_entry(session->evlist, evsel) {
+		if (__do_read(ff, &evsel->scale, sizeof(double)))
+			return -1;
+		if (ff->ph->needs_swap)
+			mem_bswap_64(&evsel->scale, sizeof(double));
+		if (--cnt <= 0)
+			break;
+	}
+	if (cnt) {
+		pr_debug("missing scale descriptors\n");
+		return 1;
+	}
+	return 0;
+}
+
 struct feature_ops {
 	int (*write)(struct feat_fd *ff, struct perf_evlist *evlist);
 	void (*print)(struct feat_fd *ff, FILE *fp);
@@ -2204,6 +2263,7 @@ static const struct feature_ops feat_ops[HEADER_LAST_FEATURE] = {
 	FEAT_OPN(AUXTRACE,	auxtrace,	false),
 	FEAT_OPN(STAT,		stat,		false),
 	FEAT_OPN(CACHE,		cache,		true),
+	FEAT_OPN(SCALE,		scale,		true),
 };
 
 struct header_print_data {
diff --git a/tools/perf/util/header.h b/tools/perf/util/header.h
index f7a16ee527b8..d13d9520191f 100644
--- a/tools/perf/util/header.h
+++ b/tools/perf/util/header.h
@@ -33,6 +33,7 @@ enum {
 	HEADER_AUXTRACE,
 	HEADER_STAT,
 	HEADER_CACHE,
+	HEADER_SCALE,
 	HEADER_LAST_FEATURE,
 	HEADER_FEAT_BITS	= 256,
 };
-- 
2.13.6

  parent reply	other threads:[~2017-11-09 14:55 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-11-09 14:55 Add fine grained sampled metrics for perf script Andi Kleen
2017-11-09 14:55 ` [PATCH v1 1/5] perf, tools: Document some missing perf.data headers Andi Kleen
2017-11-13  8:54   ` Jiri Olsa
2017-11-13 18:23     ` Arnaldo Carvalho de Melo
2017-11-18  8:28   ` [tip:perf/core] perf " tip-bot for Andi Kleen
2017-11-09 14:55 ` Andi Kleen [this message]
2017-11-13  9:02   ` [PATCH v1 2/5] perf, tools: Save event scaling factors in perf.data Jiri Olsa
2017-11-09 14:55 ` [PATCH v1 3/5] perf, tools, script: Allow printing period for non freq mode groups Andi Kleen
2017-11-13  9:11   ` Jiri Olsa
2017-11-13 18:23     ` Arnaldo Carvalho de Melo
2017-11-18  8:29   ` [tip:perf/core] perf " tip-bot for Andi Kleen
2017-11-09 14:55 ` [PATCH v1 4/5] perf, tools: Add fallback in perf_evsel__nr_cpus for no map Andi Kleen
2017-11-13  9:22   ` Jiri Olsa
2017-11-14  5:03     ` Andi Kleen
2017-11-09 14:55 ` [PATCH v1 5/5] perf, tools, script: Allow computing metrics in perf script Andi Kleen
2017-11-13  9:30   ` Jiri Olsa
2017-11-13 18:23     ` Arnaldo Carvalho de Melo

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=20171109145528.23371-3-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

Powered by JetHome