mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: kan.liang@intel.com
To: a.p.zijlstra@chello.nl, acme@kernel.org
Cc: luto@kernel.org, mingo@redhat.com, eranian@google.com,
	ak@linux.intel.com, mark.rutland@arm.com,
	adrian.hunter@intel.com, jolsa@kernel.org, namhyung@kernel.org,
	linux-kernel@vger.kernel.org, Kan Liang <kan.liang@intel.com>
Subject: [PATCH 2/5] perf,tools: Dump per-sample freq/CPU%/CORE_BUSY% in report -D
Date: Thu, 23 Jul 2015 07:49:40 -0400	[thread overview]
Message-ID: <1437652183-62080-3-git-send-email-kan.liang@intel.com> (raw)
In-Reply-To: <1437652183-62080-1-git-send-email-kan.liang@intel.com>

From: Kan Liang <kan.liang@intel.com>

The group read results from cycles/ref-cycles/TSC/ASTATE/MSTATE event
can be used to calculate the frequency, CPU Utilization and percent
performance during each sampling period.
This patch shows them in report -D.

Here is an example:

$ perf record -e
'{cycles,ref-cycles,msr/tsc/,msr/mperf/,msr/aperf/}:S' ~/tchain_edit

Here is one sample from perf report -D

1972044565107 0x3498 [0x88]: PERF_RECORD_SAMPLE(IP, 0x2): 10608/10608:
0x4005fd period: 564686 addr: 0
... sample_read:
.... group nr 5
..... id 0000000000000012, value 0000000002143901
..... id 0000000000000052, value 0000000002143896
..... id 0000000000000094, value 00000000021e443d
..... id 00000000000000d4, value 00000000021db984
..... id 0000000000000114, value 00000000021db964
..... Freq 2301 MHz
..... CPU% 98%
..... CORE_BUSY% 99%

Signed-off-by: Kan Liang <kan.liang@intel.com>
---
 tools/perf/builtin-report.c |  3 +++
 tools/perf/util/pmu.h       |  2 ++
 tools/perf/util/session.c   | 34 +++++++++++++++++++++++++++++-----
 tools/perf/util/session.h   | 38 ++++++++++++++++++++++++++++++++++++++
 4 files changed, 72 insertions(+), 5 deletions(-)

diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c
index 62cce98..0cd0573 100644
--- a/tools/perf/builtin-report.c
+++ b/tools/perf/builtin-report.c
@@ -38,6 +38,8 @@
 
 #include "util/auxtrace.h"
 
+#include "util/pmu.h"
+
 #include <dlfcn.h>
 #include <linux/bitmap.h>
 
@@ -818,6 +820,7 @@ repeat:
 		symbol_conf.cumulate_callchain = false;
 	}
 
+	msr_pmu = perf_pmu__find("msr");
 	cpu_max_freq = get_cpu_max_freq() / 1000;
 
 	if (setup_sorting() < 0) {
diff --git a/tools/perf/util/pmu.h b/tools/perf/util/pmu.h
index 7b9c8cf..e3e67aa 100644
--- a/tools/perf/util/pmu.h
+++ b/tools/perf/util/pmu.h
@@ -27,6 +27,8 @@ struct perf_pmu {
 	struct list_head list;    /* ELEM */
 };
 
+struct perf_pmu *msr_pmu;
+
 struct perf_pmu_info {
 	const char *unit;
 	double scale;
diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c
index ed9dc25..6dd20b5 100644
--- a/tools/perf/util/session.c
+++ b/tools/perf/util/session.c
@@ -17,6 +17,7 @@
 #include "asm/bug.h"
 #include "auxtrace.h"
 #include "thread-stack.h"
+#include "pmu.h"
 
 static int perf_session__deliver_event(struct perf_session *session,
 				       union perf_event *event,
@@ -851,8 +852,14 @@ static void perf_evlist__print_tstamp(struct perf_evlist *evlist,
 		printf("%" PRIu64 " ", sample->time);
 }
 
-static void sample_read__printf(struct perf_sample *sample, u64 read_format)
+static void sample_read__printf(struct perf_evlist *evlist,
+				struct perf_sample *sample,
+				u64 read_format)
 {
+	struct perf_evsel *evsel;
+	struct perf_sample_id *sid;
+	u64 data[FREQ_PERF_MAX] = { 0 };
+
 	printf("... sample_read:\n");
 
 	if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED)
@@ -875,10 +882,26 @@ static void sample_read__printf(struct perf_sample *sample, u64 read_format)
 			printf("..... id %016" PRIx64
 			       ", value %016" PRIx64 "\n",
 			       value->id, value->value);
+
+			sid = perf_evlist__id2sid(evlist, value->id);
+			evsel = sid->evsel;
+			if (evsel != NULL)
+				SET_FREQ_PERF_VALUE(evsel, data,
+						    value->value);
 		}
 	} else
 		printf("..... id %016" PRIx64 ", value %016" PRIx64 "\n",
 			sample->read.one.id, sample->read.one.value);
+
+	if (HAS_FREQ(data))
+		printf("..... Freq %lu MHz\n",
+		       (data[FREQ_PERF_CYCLES] * cpu_max_freq) / data[FREQ_PERF_REF_CYCLES]);
+	if (HAS_CPU_U(data))
+		printf("..... CPU%% %lu%%\n",
+		       (100 * data[FREQ_PERF_REF_CYCLES]) / data[FREQ_PERF_TSC]);
+	if (HAS_CORE_BUSY(data))
+		printf("..... CORE_BUSY%% %lu%%\n",
+		       (100 * data[FREQ_PERF_APERF]) / data[FREQ_PERF_MPERF]);
 }
 
 static void dump_event(struct perf_evlist *evlist, union perf_event *event,
@@ -899,8 +922,8 @@ static void dump_event(struct perf_evlist *evlist, union perf_event *event,
 	       event->header.size, perf_event__name(event->header.type));
 }
 
-static void dump_sample(struct perf_evsel *evsel, union perf_event *event,
-			struct perf_sample *sample)
+static void dump_sample(struct perf_evlist *evlist, struct perf_evsel *evsel,
+			union perf_event *event, struct perf_sample *sample)
 {
 	u64 sample_type;
 
@@ -938,7 +961,7 @@ static void dump_sample(struct perf_evsel *evsel, union perf_event *event,
 		printf("... transaction: %" PRIx64 "\n", sample->transaction);
 
 	if (sample_type & PERF_SAMPLE_READ)
-		sample_read__printf(sample, evsel->attr.read_format);
+		sample_read__printf(evlist, sample, evsel->attr.read_format);
 }
 
 static struct machine *machines__find_for_cpumode(struct machines *machines,
@@ -1053,11 +1076,12 @@ static int machines__deliver_event(struct machines *machines,
 
 	switch (event->header.type) {
 	case PERF_RECORD_SAMPLE:
-		dump_sample(evsel, event, sample);
 		if (evsel == NULL) {
 			++evlist->stats.nr_unknown_id;
 			return 0;
 		}
+		dump_sample(evlist, evsel, event, sample);
+
 		if (machine == NULL) {
 			++evlist->stats.nr_unprocessable_samples;
 			return 0;
diff --git a/tools/perf/util/session.h b/tools/perf/util/session.h
index b44afc7..df2094d 100644
--- a/tools/perf/util/session.h
+++ b/tools/perf/util/session.h
@@ -42,6 +42,44 @@ struct perf_session {
 #define PRINT_IP_OPT_ONELINE	(1<<4)
 #define PRINT_IP_OPT_SRCLINE	(1<<5)
 
+#define PERF_MSR_TSC		0
+#define PERF_MSR_APERF		1
+#define PERF_MSR_MPERF		2
+
+enum perf_freq_perf_index {
+	FREQ_PERF_TSC		= 0,
+	FREQ_PERF_APERF		= 1,
+	FREQ_PERF_MPERF		= 2,
+	FREQ_PERF_CYCLES	= 3,
+	FREQ_PERF_REF_CYCLES	= 4,
+
+	FREQ_PERF_MAX
+};
+
+#define SET_FREQ_PERF_VALUE(event, array, value)			\
+{									\
+	if (event->attr.type == msr_pmu->type) {			\
+		if (event->attr.config == PERF_MSR_TSC)			\
+			array[FREQ_PERF_TSC] = value;			\
+		if (event->attr.config == PERF_MSR_APERF)		\
+			array[FREQ_PERF_APERF] = value;			\
+		if (event->attr.config == PERF_MSR_MPERF)		\
+			array[FREQ_PERF_MPERF] = value;			\
+	}								\
+	if (event->attr.type == PERF_TYPE_HARDWARE) {			\
+		if (event->attr.config == PERF_COUNT_HW_CPU_CYCLES)	\
+			array[FREQ_PERF_CYCLES] = value;		\
+		if (event->attr.config == PERF_COUNT_HW_REF_CPU_CYCLES)	\
+			array[FREQ_PERF_REF_CYCLES] = value;		\
+	}								\
+}
+
+#define HAS_FREQ(array)							\
+	((array[FREQ_PERF_CYCLES] > 0) && (array[FREQ_PERF_REF_CYCLES] > 0))
+#define HAS_CPU_U(array)						\
+	((array[FREQ_PERF_TSC] > 0) && (array[FREQ_PERF_REF_CYCLES] > 0))
+#define HAS_CORE_BUSY(array)						\
+	((array[FREQ_PERF_APERF] > 0) && (array[FREQ_PERF_MPERF] > 0))
 struct perf_tool;
 
 struct perf_session *perf_session__new(struct perf_data_file *file,
-- 
1.8.3.1


  parent reply	other threads:[~2015-07-23 19:05 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-07-23 11:49 [PATCH 0/5] Freq/CPU%/CORE_BUSY% support kan.liang
2015-07-23 11:49 ` [PATCH 1/5] perf,tools: introduce get_cpu_max_freq kan.liang
2015-07-23 11:49 ` kan.liang [this message]
2015-07-23 11:49 ` [PATCH 3/5] perf,tools: save misc sample read value in struct perf_sample kan.liang
2015-07-23 11:49 ` [PATCH 4/5] perf,tools: caculate and save freq/CPU%/CORE_BUSY% in he_stat kan.liang
2015-07-23 11:49 ` [PATCH 5/5] perf,tools: Show freq/CPU%/CORE_BUSY% in perf report --stdio kan.liang
  -- strict thread matches above, loose matches on Subject: below --
2015-07-23 11:46 [PATCH 0/5] Freq/CPU%/CORE_BUSY% support Kan Liang
2015-07-23 11:46 ` [PATCH 2/5] perf,tools: Dump per-sample freq/CPU%/CORE_BUSY% in report -D Kan Liang

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=1437652183-62080-3-git-send-email-kan.liang@intel.com \
    --to=kan.liang@intel.com \
    --cc=a.p.zijlstra@chello.nl \
    --cc=acme@kernel.org \
    --cc=adrian.hunter@intel.com \
    --cc=ak@linux.intel.com \
    --cc=eranian@google.com \
    --cc=jolsa@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luto@kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=mingo@redhat.com \
    --cc=namhyung@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