All of lore.kernel.org
 help / color / mirror / Atom feed
From: Arnaldo Carvalho de Melo <acme@kernel.org>
To: Ingo Molnar <mingo@kernel.org>
Cc: 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 23/75] perf annotate: Compute average IPC and IPC coverage per symbol
Date: Thu,  6 Dec 2018 18:25:10 -0300	[thread overview]
Message-ID: <20181206212602.20474-24-acme@kernel.org> (raw)
In-Reply-To: <20181206212602.20474-1-acme@kernel.org>

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

Add support to 'perf report' annotate view or 'perf annotate --stdio2'
to aggregate the IPC derived from timed LBRs per symbol. We compute the
average IPC and the IPC coverage percentage.

For example:

  $ perf annotate --stdio2

  Percent  IPC Cycle (Average IPC: 2.30, IPC Coverage: 54.8%)

                          Disassembly of section .text:

                          000000000003aac0 <random@@GLIBC_2.2.5>:
    8.32  3.28              sub    $0x18,%rsp
          3.28              mov    $0x1,%esi
          3.28              xor    %eax,%eax
          3.28              cmpl   $0x0,argp_program_version_hook@@GLIBC_2.2.5+0x1e0
   11.57  3.28     1      ↓ je     20
                            lock   cmpxchg %esi,__abort_msg@@GLIBC_PRIVATE+0x8a0
                          ↓ jne    29
                          ↓ jmp    43
   11.57  1.10        20:   cmpxchg %esi,__abort_msg@@GLIBC_PRIVATE+0x8a0
    0.00  1.10     1      ↓ je     43
                      29:   lea    __abort_msg@@GLIBC_PRIVATE+0x8a0,%rdi
                            sub    $0x80,%rsp
                          → callq  __lll_lock_wait_private
                            add    $0x80,%rsp
    0.00  3.00        43:   lea    __ctype_b@GLIBC_2.2.5+0x38,%rdi
          3.00              lea    0xc(%rsp),%rsi
    8.49  3.00     1      → callq  __random_r
    7.91  1.94              cmpl   $0x0,argp_program_version_hook@@GLIBC_2.2.5+0x1e0
    0.00  1.94     1      ↓ je     68
                            lock   decl   __abort_msg@@GLIBC_PRIVATE+0x8a0
                          ↓ jne    70
                          ↓ jmp    8a
    0.00  2.00        68:   decl   __abort_msg@@GLIBC_PRIVATE+0x8a0
   21.56  2.00     1      ↓ je     8a
                      70:   lea    __abort_msg@@GLIBC_PRIVATE+0x8a0,%rdi
                            sub    $0x80,%rsp
                          → callq  __lll_unlock_wake_private
                            add    $0x80,%rsp
   21.56  2.90        8a:   movslq 0xc(%rsp),%rax
          2.90              add    $0x18,%rsp
    9.03  2.90     1      ← retq

It shows for this symbol the average IPC is 2.30 and the IPC coverage is
54.8%.

Signed-off-by: Jin Yao <yao.jin@linux.intel.com>
Reviewed-by: Ingo Molnar <mingo@kernel.org>
Reviewed-by: Jiri Olsa <jolsa@kernel.org>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/1543586097-27632-2-git-send-email-yao.jin@linux.intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/util/annotate.c | 41 +++++++++++++++++++++++++++++++++++---
 tools/perf/util/annotate.h |  5 +++++
 2 files changed, 43 insertions(+), 3 deletions(-)

diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c
index 6936daf89ddd..4b2b1b09b8f1 100644
--- a/tools/perf/util/annotate.c
+++ b/tools/perf/util/annotate.c
@@ -1000,6 +1000,7 @@ static unsigned annotation__count_insn(struct annotation *notes, u64 start, u64
 static void annotation__count_and_fill(struct annotation *notes, u64 start, u64 end, struct cyc_hist *ch)
 {
 	unsigned n_insn;
+	unsigned int cover_insn = 0;
 	u64 offset;
 
 	n_insn = annotation__count_insn(notes, start, end);
@@ -1013,21 +1014,34 @@ static void annotation__count_and_fill(struct annotation *notes, u64 start, u64
 		for (offset = start; offset <= end; offset++) {
 			struct annotation_line *al = notes->offsets[offset];
 
-			if (al)
+			if (al && al->ipc == 0.0) {
 				al->ipc = ipc;
+				cover_insn++;
+			}
+		}
+
+		if (cover_insn) {
+			notes->hit_cycles += ch->cycles;
+			notes->hit_insn += n_insn * ch->num;
+			notes->cover_insn += cover_insn;
 		}
 	}
 }
 
 void annotation__compute_ipc(struct annotation *notes, size_t size)
 {
-	u64 offset;
+	s64 offset;
 
 	if (!notes->src || !notes->src->cycles_hist)
 		return;
 
+	notes->total_insn = annotation__count_insn(notes, 0, size - 1);
+	notes->hit_cycles = 0;
+	notes->hit_insn = 0;
+	notes->cover_insn = 0;
+
 	pthread_mutex_lock(&notes->lock);
-	for (offset = 0; offset < size; ++offset) {
+	for (offset = size - 1; offset >= 0; --offset) {
 		struct cyc_hist *ch;
 
 		ch = &notes->src->cycles_hist[offset];
@@ -2563,6 +2577,22 @@ static void disasm_line__write(struct disasm_line *dl, struct annotation *notes,
 	disasm_line__scnprintf(dl, bf, size, !notes->options->use_offset);
 }
 
+static void ipc_coverage_string(char *bf, int size, struct annotation *notes)
+{
+	double ipc = 0.0, coverage = 0.0;
+
+	if (notes->hit_cycles)
+		ipc = notes->hit_insn / ((double)notes->hit_cycles);
+
+	if (notes->total_insn) {
+		coverage = notes->cover_insn * 100.0 /
+			((double)notes->total_insn);
+	}
+
+	scnprintf(bf, size, "(Average IPC: %.2f, IPC Coverage: %.1f%%)",
+		  ipc, coverage);
+}
+
 static void __annotation_line__write(struct annotation_line *al, struct annotation *notes,
 				     bool first_line, bool current_entry, bool change_color, int width,
 				     void *obj, unsigned int percent_type,
@@ -2658,6 +2688,11 @@ static void __annotation_line__write(struct annotation_line *al, struct annotati
 					    ANNOTATION__MINMAX_CYCLES_WIDTH - 1,
 					    "Cycle(min/max)");
 		}
+
+		if (show_title && !*al->line) {
+			ipc_coverage_string(bf, sizeof(bf), notes);
+			obj__printf(obj, "%*s", ANNOTATION__AVG_IPC_WIDTH, bf);
+		}
 	}
 
 	obj__printf(obj, " ");
diff --git a/tools/perf/util/annotate.h b/tools/perf/util/annotate.h
index 5399ba2321bb..fb6463730ba4 100644
--- a/tools/perf/util/annotate.h
+++ b/tools/perf/util/annotate.h
@@ -64,6 +64,7 @@ bool ins__is_fused(struct arch *arch, const char *ins1, const char *ins2);
 #define ANNOTATION__IPC_WIDTH 6
 #define ANNOTATION__CYCLES_WIDTH 6
 #define ANNOTATION__MINMAX_CYCLES_WIDTH 19
+#define ANNOTATION__AVG_IPC_WIDTH 36
 
 struct annotation_options {
 	bool hide_src_code,
@@ -262,6 +263,10 @@ struct annotation {
 	pthread_mutex_t		lock;
 	u64			max_coverage;
 	u64			start;
+	u64			hit_cycles;
+	u64			hit_insn;
+	unsigned int		total_insn;
+	unsigned int		cover_insn;
 	struct annotation_options *options;
 	struct annotation_line	**offsets;
 	int			nr_events;
-- 
2.19.2


  parent reply	other threads:[~2018-12-06 21:28 UTC|newest]

Thread overview: 83+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-12-06 21:24 [GIT PULL 00/75] perf/core improvements and fixes Arnaldo Carvalho de Melo
2018-12-06 21:24 ` Arnaldo Carvalho de Melo
2018-12-06 21:24 ` [PATCH 01/75] perf build: Give better hint about devel package for libssl Arnaldo Carvalho de Melo
2018-12-06 21:24 ` [PATCH 02/75] perf stat: Fix shadow stats for clock events Arnaldo Carvalho de Melo
2018-12-06 21:24 ` [PATCH 03/75] perf stat: Fix CSV mode column output for non-cgroup events Arnaldo Carvalho de Melo
2018-12-06 21:24 ` [PATCH 04/75] perf map: Remove extra indirection from map__find() Arnaldo Carvalho de Melo
2018-12-06 21:24 ` [PATCH 05/75] perf env: Also consider env->arch == NULL as local operation Arnaldo Carvalho de Melo
2018-12-06 21:24 ` [PATCH 06/75] perf machine: Record if a arch has a single user/kernel address space Arnaldo Carvalho de Melo
2018-12-06 21:24 ` [PATCH 07/75] perf thread: Add fallback functions for cases where cpumode is insufficient Arnaldo Carvalho de Melo
2018-12-06 21:24 ` [PATCH 08/75] perf tools: Use fallback for sample_addr_correlates_sym() cases Arnaldo Carvalho de Melo
2018-12-06 21:24 ` [PATCH 09/75] perf script: Use fallbacks for branch stacks Arnaldo Carvalho de Melo
2018-12-06 21:24 ` [PATCH 10/75] tools lib traceevent: Fix compile warnings in tools/lib/traceevent/event-parse.c Arnaldo Carvalho de Melo
2018-12-06 21:24 ` [PATCH 11/75] perf tests record: Allow for 'sleep' being 'coreutils' Arnaldo Carvalho de Melo
2018-12-06 21:24 ` [PATCH 12/75] perf test: Fix perf_event_attr test failure Arnaldo Carvalho de Melo
2018-12-06 21:25 ` [PATCH 13/75] tools include: Adopt ERR_CAST() from the kernel err.h header Arnaldo Carvalho de Melo
2018-12-06 21:25 ` [PATCH 14/75] perf bpf: Use ERR_CAST instead of ERR_PTR(PTR_ERR()) Arnaldo Carvalho de Melo
2018-12-06 21:25 ` [PATCH 15/75] perf top: Allow passing a kallsyms file Arnaldo Carvalho de Melo
2018-12-06 21:25 ` [PATCH 16/75] perf intel-pt: Fix error with config term "pt=0" Arnaldo Carvalho de Melo
2018-12-06 21:25 ` [PATCH 17/75] tools build feature: Check if libaio is available Arnaldo Carvalho de Melo
2018-12-06 21:25 ` [PATCH 18/75] perf mmap: Map data buffer for preserving collected data Arnaldo Carvalho de Melo
2018-12-06 21:25 ` [PATCH 19/75] perf record: Enable asynchronous trace writing Arnaldo Carvalho de Melo
2018-12-06 21:25 ` [PATCH 20/75] perf record: Extend trace writing to multi AIO Arnaldo Carvalho de Melo
2018-12-06 21:25 ` [PATCH 21/75] perf beauty mmap_flags: Check if the arch has a mmap.h file Arnaldo Carvalho de Melo
2018-12-06 21:25 ` [PATCH 22/75] tools lib traceevent: Add sanity check to is_timestamp_in_us() Arnaldo Carvalho de Melo
2018-12-06 21:25 ` Arnaldo Carvalho de Melo [this message]
2018-12-06 21:25 ` [PATCH 24/75] perf annotate: Create a annotate2 flag in struct symbol Arnaldo Carvalho de Melo
2018-12-06 21:25 ` [PATCH 25/75] perf report: Display average IPC and IPC coverage per symbol Arnaldo Carvalho de Melo
2018-12-06 21:25 ` [PATCH 26/75] perf report: Documentation average IPC and IPC coverage Arnaldo Carvalho de Melo
2018-12-06 21:25 ` [PATCH 27/75] tools lib traceevent: Implement new API tep_get_ref() Arnaldo Carvalho de Melo
2018-12-06 21:25 ` [PATCH 28/75] tools lib traceevent: Added support for pkg-config Arnaldo Carvalho de Melo
2018-12-06 21:25 ` [PATCH 29/75] tools lib traceevent: Install trace-seq.h API header file Arnaldo Carvalho de Melo
2018-12-06 21:25 ` [PATCH 30/75] tools lib traceevent, perf tools: Rename 'struct tep_event_format' to 'struct tep_event' Arnaldo Carvalho de Melo
2018-12-06 21:25 ` [PATCH 31/75] tools lib traceevent: Rename tep_free_format() to tep_free_event() Arnaldo Carvalho de Melo
2018-12-06 21:25 ` [PATCH 32/75] perf tools: traceevent API cleanup, remove __tep_data2host*() Arnaldo Carvalho de Melo
2018-12-06 21:25 ` [PATCH 33/75] tools lib traceevent: traceevent API cleanup Arnaldo Carvalho de Melo
2018-12-06 21:25 ` [PATCH 34/75] perf beauty mmap_flags: Fixed syntax error Fixed missing ']' error Arnaldo Carvalho de Melo
2018-12-06 21:25 ` [PATCH 35/75] perf cs-etm: Support for ARM A32/T32 instruction sets in CoreSight trace Arnaldo Carvalho de Melo
2018-12-06 21:25   ` Arnaldo Carvalho de Melo
2018-12-06 21:25 ` [PATCH 36/75] perf tests ARM: Disable breakpoint tests 32-bit Arnaldo Carvalho de Melo
2018-12-06 21:25 ` [PATCH 37/75] perf vendor events intel: Fix diverse typos Arnaldo Carvalho de Melo
2018-12-06 21:25 ` [PATCH 38/75] tools lib traceevent: Fix diverse typos in comments Arnaldo Carvalho de Melo
2018-12-06 21:25 ` [PATCH 39/75] perf tools Documentation: Fix diverse typos Arnaldo Carvalho de Melo
2018-12-06 21:25 ` [PATCH 40/75] perf bpf-loader: Fix debugging message typo Arnaldo Carvalho de Melo
2018-12-06 21:25 ` [PATCH 41/75] perf tools: Fix diverse comment typos Arnaldo Carvalho de Melo
2018-12-06 21:25 ` [PATCH 42/75] tools lib subcmd: Fix a few source code " Arnaldo Carvalho de Melo
2018-12-06 21:25 ` [PATCH 43/75] perf tools: Allow specifying proc-map-timeout in config file Arnaldo Carvalho de Melo
2018-12-06 21:25 ` [PATCH 44/75] perf trace: We need to consider "nr" if "__syscall_nr" is not there Arnaldo Carvalho de Melo
2018-12-06 21:25 ` [PATCH 45/75] perf tools: Support 'srccode' output Arnaldo Carvalho de Melo
2018-12-06 21:25 ` [PATCH 46/75] perf ordered_events: Rework show_progress for __ordered_events__flush Arnaldo Carvalho de Melo
2018-12-06 21:25 ` [PATCH 47/75] perf ordered_events: Add private data member Arnaldo Carvalho de Melo
2018-12-06 21:25 ` [PATCH 48/75] perf top: Save and display the lost count stats Arnaldo Carvalho de Melo
2018-12-06 21:25 ` [PATCH 49/75] perf top: Move lost events warning to helpline Arnaldo Carvalho de Melo
2018-12-06 21:25 ` [PATCH 50/75] perf top: Add processing thread Arnaldo Carvalho de Melo
2018-12-06 21:25 ` [PATCH 51/75] perf top: Use cond variable instead of a lock Arnaldo Carvalho de Melo
2018-12-06 21:25 ` [PATCH 52/75] perf top: Set the 'session_done' volatile variable when exiting Arnaldo Carvalho de Melo
2018-12-06 21:25 ` [PATCH 53/75] perf top: Drop samples which are behind the refresh rate Arnaldo Carvalho de Melo
2018-12-06 21:25 ` [PATCH 54/75] perf top: Save and display the drop count stats Arnaldo Carvalho de Melo
2018-12-06 21:25 ` [PATCH 55/75] perf top: Display slow reader warning when droping samples Arnaldo Carvalho de Melo
2018-12-06 21:25 ` [PATCH 56/75] perf top: Move perf_top__reset_sample_counters() to after counts display Arnaldo Carvalho de Melo
2018-12-06 21:25 ` [PATCH 57/75] perf cs-etm: Add configuration for ETMv3 trace protocol Arnaldo Carvalho de Melo
2018-12-06 21:25   ` Arnaldo Carvalho de Melo
2018-12-06 21:25 ` [PATCH 58/75] perf cs-etm: Add support for ETMv3 trace decoding Arnaldo Carvalho de Melo
2018-12-06 21:25   ` Arnaldo Carvalho de Melo
2018-12-06 21:25 ` [PATCH 59/75] perf cs-etm: Add support for PTMv1.1 decoding Arnaldo Carvalho de Melo
2018-12-06 21:25   ` Arnaldo Carvalho de Melo
2018-12-06 21:25 ` [PATCH 60/75] perf dso: Fix unchecked usage of strncpy() Arnaldo Carvalho de Melo
2018-12-06 21:25 ` [PATCH 61/75] perf header: " Arnaldo Carvalho de Melo
2018-12-06 21:25 ` [PATCH 62/75] " Arnaldo Carvalho de Melo
2018-12-06 21:25 ` [PATCH 63/75] perf help: Remove needless use " Arnaldo Carvalho de Melo
2018-12-06 21:25 ` [PATCH 64/75] perf svghelper: Fix unchecked usage " Arnaldo Carvalho de Melo
2018-12-06 21:25 ` [PATCH 65/75] perf ui helpline: Use strlcpy() as a shorter form of strncpy() + explicit set nul Arnaldo Carvalho de Melo
2018-12-06 21:25 ` [PATCH 66/75] perf probe: Fix unchecked usage of strncpy() Arnaldo Carvalho de Melo
2018-12-06 21:25 ` [PATCH 67/75] perf parse-events: " Arnaldo Carvalho de Melo
2018-12-06 21:25 ` [PATCH 68/75] perf vendor events intel: Fix Load_Miss_Real_Latency on SKL/SKX Arnaldo Carvalho de Melo
2018-12-06 21:25 ` [PATCH 69/75] perf record: Fix memory leak on AIO objects deallocation Arnaldo Carvalho de Melo
2018-12-06 21:25 ` [PATCH 70/75] perf config: Modify size factor of snprintf Arnaldo Carvalho de Melo
2018-12-06 21:25 ` [PATCH 71/75] perf annotate: Introduce basic support for ARC Arnaldo Carvalho de Melo
2018-12-06 21:25   ` Arnaldo Carvalho de Melo
2018-12-06 21:25   ` Arnaldo Carvalho de Melo
2018-12-06 21:25 ` [PATCH 72/75] perf ordered_events: Add ordered_events__flush_time interface Arnaldo Carvalho de Melo
2018-12-06 21:26 ` [PATCH 73/75] perf trace: Move event delivery to a new deliver_event() function Arnaldo Carvalho de Melo
2018-12-06 21:26 ` [PATCH 74/75] perf ordered_events: Add first_time() method Arnaldo Carvalho de Melo
2018-12-06 21:26 ` [PATCH 75/75] perf trace: Add ordered processing 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=20181206212602.20474-24-acme@kernel.org \
    --to=acme@kernel.org \
    --cc=acme@redhat.com \
    --cc=ak@linux.intel.com \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=kan.liang@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=peterz@infradead.org \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.