The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: kan.liang@intel.com
To: acme@kernel.org, jolsa@kernel.org
Cc: a.p.zijlstra@chello.nl, luto@kernel.org, mingo@redhat.com,
	eranian@google.com, ak@linux.intel.com, mark.rutland@arm.com,
	adrian.hunter@intel.com, namhyung@kernel.org,
	linux-kernel@vger.kernel.org, Kan Liang <kan.liang@intel.com>
Subject: [PATCH V10 4/8] perf,tools: Dump per-sample freq/CPU%/CORE_BUSY% in report -D
Date: Wed, 16 Sep 2015 10:21:52 -0400	[thread overview]
Message-ID: <1442413316-33518-5-git-send-email-kan.liang@intel.com> (raw)
In-Reply-To: <1442413316-33518-1-git-send-email-kan.liang@intel.com>

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

The value from cycles/ref-cycles/TSC/ASTATE/MSTATE event in perf_sample
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 --perf-freq  ~/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/util/session.c | 18 ++++++++++++++++--
 tools/perf/util/session.h | 27 +++++++++++++++++++++++++++
 2 files changed, 43 insertions(+), 2 deletions(-)

diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c
index e8cb98d..6ba3a68 100644
--- a/tools/perf/util/session.c
+++ b/tools/perf/util/session.c
@@ -861,8 +861,12 @@ 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_sample *sample,
+				struct perf_evsel *evsel)
 {
+	u64 read_format = evsel->attr.read_format;
+	u64 cpu_max_freq = evsel->evlist->env->cpuattr.max_freq;
+
 	printf("... sample_read:\n");
 
 	if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED)
@@ -889,6 +893,16 @@ static void sample_read__printf(struct perf_sample *sample, u64 read_format)
 	} else
 		printf("..... id %016" PRIx64 ", value %016" PRIx64 "\n",
 			sample->read.one.id, sample->read.one.value);
+
+	if (perf_freq__has_freq(sample->freq))
+		printf("..... Freq %lu MHz\n",
+		       perf_freq__get_freq(sample->freq, cpu_max_freq/1000));
+	if (perf_freq__has_cpu_util(sample->freq))
+		printf("..... CPU%% %lu%%\n",
+		       perf_freq__get_cpu_util(sample->freq));
+	if (perf_freq__has_core_busy(sample->freq))
+		printf("..... CORE_BUSY%% %lu%%\n",
+		       perf_freq__get_core_busy(sample->freq));
 }
 
 static void dump_event(struct perf_evlist *evlist, union perf_event *event,
@@ -948,7 +962,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(sample, evsel);
 }
 
 static struct machine *machines__find_for_cpumode(struct machines *machines,
diff --git a/tools/perf/util/session.h b/tools/perf/util/session.h
index f70d3a1..0ee3027 100644
--- a/tools/perf/util/session.h
+++ b/tools/perf/util/session.h
@@ -67,6 +67,33 @@ static inline void perf_freq__init(unsigned int msr_pmu_type,
 			array[PERF_FREQ_REF_CYCLES] = value;
 	}
 }
+
+static inline bool perf_freq__has_freq(perf_freq_t array)
+{
+	return ((array[PERF_FREQ_CYCLES] > 0) && (array[PERF_FREQ_REF_CYCLES] > 0));
+}
+static inline u64 perf_freq__get_freq(perf_freq_t array, u64 cpu_max_freq)
+{
+	return ((array[PERF_FREQ_CYCLES] * cpu_max_freq) / array[PERF_FREQ_REF_CYCLES]);
+}
+static inline bool perf_freq__has_cpu_util(perf_freq_t array)
+{
+	return ((array[PERF_FREQ_TSC] > 0) && (array[PERF_FREQ_REF_CYCLES] > 0));
+}
+static inline u64 perf_freq__get_cpu_util(perf_freq_t array)
+{
+	return ((100 * array[PERF_FREQ_REF_CYCLES]) / array[PERF_FREQ_TSC]);
+}
+
+static inline bool perf_freq__has_core_busy(perf_freq_t array)
+{
+	return ((array[PERF_FREQ_APERF] > 0) && (array[PERF_FREQ_MPERF] > 0));
+}
+static inline u64 perf_freq__get_core_busy(perf_freq_t array)
+{
+	return ((100 * array[PERF_FREQ_APERF]) / array[PERF_FREQ_MPERF]);
+}
+
 struct perf_tool;
 
 struct perf_session *perf_session__new(struct perf_data_file *file,
-- 
1.8.3.1


  parent reply	other threads:[~2015-09-16 21:39 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-09-16 14:21 [PATCH V10 0/8] Freq/CPU%/CORE_BUSY% support kan.liang
2015-09-16 14:21 ` [PATCH V10 1/8] perf,tools: introduce generic FEAT for CPU attributes kan.liang
2015-09-16 14:21 ` [PATCH V10 2/8] perf, record: introduce --perf-freq option kan.liang
2015-09-16 14:21 ` [PATCH V10 3/8] perf,tools: caculate freq per sample kan.liang
2015-09-16 14:21 ` kan.liang [this message]
2015-09-16 14:21 ` [PATCH V10 5/8] perf,tools: caculate and save freq/CPU%/CORE_BUSY% in he_stat kan.liang
2015-09-16 14:21 ` [PATCH V10 6/8] perf,tools: only show leader's value in hpp__fmt kan.liang
2015-09-16 14:21 ` [PATCH V10 7/8] perf,tools: Introduce HPP__SINGLE_PRINT_FNS support kan.liang
2015-09-16 14:21 ` [PATCH V10 8/8] perf,tools: Show freq/CPU%/CORE_BUSY% in perf report by --perf-freq kan.liang
2015-09-28 20:05 ` [PATCH V10 0/8] Freq/CPU%/CORE_BUSY% support Liang, Kan

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=1442413316-33518-5-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