From: Arnaldo Carvalho de Melo <acme@kernel.org>
To: Ingo Molnar <mingo@kernel.org>
Cc: linux-kernel@vger.kernel.org, Andi Kleen <ak@linux.intel.com>,
Jiri Olsa <jolsa@kernel.org>, Namhyung Kim <namhyung@kernel.org>,
Arnaldo Carvalho de Melo <acme@redhat.com>
Subject: [PATCH 17/26] perf annotate: Compute IPC and basic block cycles
Date: Thu, 6 Aug 2015 22:58:26 -0300 [thread overview]
Message-ID: <1438912715-4000-18-git-send-email-acme@kernel.org> (raw)
In-Reply-To: <1438912715-4000-1-git-send-email-acme@kernel.org>
From: Andi Kleen <ak@linux.intel.com>
Compute the IPC and the basic block cycles for the annotate display.
IPC is computed by counting the instructions, and then dividing the
accounted cycles by that count.
The actual IPC computation can only be done at annotate time, because we
need to parse the objdump output first to know the number of
instructions in the basic block.
The cycles/IPC are also put into the perf function annotation so that
the display code can show them.
Again basic block overlaps are not handled, with the longest winning,
but there are some heuristics to hide the IPC when the longest is not
the most common.
v2: Compute IPC correctly.
Signed-off-by: Andi Kleen <ak@linux.intel.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Link: http://lkml.kernel.org/r/1437233094-12844-6-git-send-email-andi@firstfloor.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
tools/perf/ui/browsers/annotate.c | 73 ++++++++++++++++++++++++++++++++++++++-
tools/perf/util/annotate.h | 2 ++
2 files changed, 74 insertions(+), 1 deletion(-)
diff --git a/tools/perf/ui/browsers/annotate.c b/tools/perf/ui/browsers/annotate.c
index 5995a8bd7c69..6ec179547f72 100644
--- a/tools/perf/ui/browsers/annotate.c
+++ b/tools/perf/ui/browsers/annotate.c
@@ -53,6 +53,7 @@ struct annotate_browser {
int max_jump_sources;
int nr_jumps;
bool searching_backwards;
+ bool have_cycles;
u8 addr_width;
u8 jumps_width;
u8 target_width;
@@ -390,7 +391,7 @@ static void annotate_browser__calc_percent(struct annotate_browser *browser,
max_percent = bpos->samples[i].percent;
}
- if (max_percent < 0.01) {
+ if (max_percent < 0.01 && pos->ipc == 0) {
RB_CLEAR_NODE(&bpos->rb_node);
continue;
}
@@ -869,6 +870,75 @@ int hist_entry__tui_annotate(struct hist_entry *he, struct perf_evsel *evsel,
return map_symbol__tui_annotate(&he->ms, evsel, hbt);
}
+
+static unsigned count_insn(struct annotate_browser *browser, u64 start, u64 end)
+{
+ unsigned n_insn = 0;
+ u64 offset;
+
+ for (offset = start; offset <= end; offset++) {
+ if (browser->offsets[offset])
+ n_insn++;
+ }
+ return n_insn;
+}
+
+static void count_and_fill(struct annotate_browser *browser, u64 start, u64 end,
+ struct cyc_hist *ch)
+{
+ unsigned n_insn;
+ u64 offset;
+
+ n_insn = count_insn(browser, start, end);
+ if (n_insn && ch->num && ch->cycles) {
+ float ipc = n_insn / ((double)ch->cycles / (double)ch->num);
+
+ /* Hide data when there are too many overlaps. */
+ if (ch->reset >= 0x7fff || ch->reset >= ch->num / 2)
+ return;
+
+ for (offset = start; offset <= end; offset++) {
+ struct disasm_line *dl = browser->offsets[offset];
+
+ if (dl)
+ dl->ipc = ipc;
+ }
+ }
+}
+
+/*
+ * This should probably be in util/annotate.c to share with the tty
+ * annotate, but right now we need the per byte offsets arrays,
+ * which are only here.
+ */
+static void annotate__compute_ipc(struct annotate_browser *browser, size_t size,
+ struct symbol *sym)
+{
+ u64 offset;
+ struct annotation *notes = symbol__annotation(sym);
+
+ if (!notes->src || !notes->src->cycles_hist)
+ return;
+
+ pthread_mutex_lock(¬es->lock);
+ for (offset = 0; offset < size; ++offset) {
+ struct cyc_hist *ch;
+
+ ch = ¬es->src->cycles_hist[offset];
+ if (ch && ch->cycles) {
+ struct disasm_line *dl;
+
+ if (ch->have_start)
+ count_and_fill(browser, ch->start, offset, ch);
+ dl = browser->offsets[offset];
+ if (dl && ch->num_aggr)
+ dl->cycles = ch->cycles_aggr / ch->num_aggr;
+ browser->have_cycles = true;
+ }
+ }
+ pthread_mutex_unlock(¬es->lock);
+}
+
static void annotate_browser__mark_jump_targets(struct annotate_browser *browser,
size_t size)
{
@@ -991,6 +1061,7 @@ int symbol__tui_annotate(struct symbol *sym, struct map *map,
}
annotate_browser__mark_jump_targets(&browser, size);
+ annotate__compute_ipc(&browser, size, sym);
browser.addr_width = browser.target_width = browser.min_addr_width = hex_width(size);
browser.max_addr_width = hex_width(sym->end);
diff --git a/tools/perf/util/annotate.h b/tools/perf/util/annotate.h
index a06518dca4b7..e9996092a093 100644
--- a/tools/perf/util/annotate.h
+++ b/tools/perf/util/annotate.h
@@ -59,6 +59,8 @@ struct disasm_line {
char *name;
struct ins *ins;
int line_nr;
+ float ipc;
+ u64 cycles;
struct ins_operands ops;
};
--
2.1.0
next prev parent reply other threads:[~2015-08-07 2:01 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-08-07 1:58 [GIT PULL 00/26] perf/core improvements and fixes Arnaldo Carvalho de Melo
2015-08-07 1:58 ` [PATCH 01/26] perf trace: Add total time column to summary Arnaldo Carvalho de Melo
2015-08-07 1:58 ` [PATCH 02/26] bpf: Use correct #ifdef controller for trace_call_bpf() Arnaldo Carvalho de Melo
2015-08-07 1:58 ` [PATCH 03/26] tracing, perf: Implement BPF programs attached to uprobes Arnaldo Carvalho de Melo
2015-08-07 1:58 ` [PATCH 04/26] perf tools: Introduce veprintf Arnaldo Carvalho de Melo
2015-08-07 1:58 ` [PATCH 05/26] perf tools: Add missing forward declaration of struct map to probe-event.h Arnaldo Carvalho de Melo
2015-08-07 1:58 ` [PATCH 06/26] perf stat: Introduce struct perf_stat_config Arnaldo Carvalho de Melo
2015-08-07 1:58 ` [PATCH 07/26] perf stat: Move 'scale' into " Arnaldo Carvalho de Melo
2015-08-07 1:58 ` [PATCH 08/26] perf stat: Move 'output' " Arnaldo Carvalho de Melo
2015-08-07 1:58 ` [PATCH 09/26] perf stat: Move 'interval' " Arnaldo Carvalho de Melo
2015-08-07 1:58 ` [PATCH 10/26] perf stat: Pass 'struct perf_stat_config' into process_counter() Arnaldo Carvalho de Melo
2015-08-07 1:58 ` [PATCH 11/26] perf stat: Move counter processing code into stat object Arnaldo Carvalho de Melo
2015-08-07 1:58 ` [PATCH 12/26] perf tools: Add empty Build files for architectures lacking them Arnaldo Carvalho de Melo
2015-08-07 1:58 ` [PATCH 13/26] perf tools: Add support for cycles, weight branch_info field Arnaldo Carvalho de Melo
2015-08-07 1:58 ` [PATCH 14/26] perf report: Add flag for non ANY branch mode Arnaldo Carvalho de Melo
2015-08-07 1:58 ` [PATCH 15/26] perf report: Add infrastructure for a cycles histogram Arnaldo Carvalho de Melo
2015-08-07 1:58 ` [PATCH 16/26] perf report: Add processing for cycle histograms Arnaldo Carvalho de Melo
2015-08-07 1:58 ` Arnaldo Carvalho de Melo [this message]
2015-08-07 1:58 ` [PATCH 18/26] perf annotate: Finally display IPC and cycle accounting Arnaldo Carvalho de Melo
2015-08-07 1:58 ` [PATCH 19/26] perf top: Add branch annotation code to top Arnaldo Carvalho de Melo
2015-08-07 1:58 ` [PATCH 20/26] perf report: Display cycles in branch sort mode Arnaldo Carvalho de Melo
2015-08-07 1:58 ` [PATCH 21/26] perf tools xtensa: Add DWARF register names Arnaldo Carvalho de Melo
2015-08-07 1:58 ` [PATCH 22/26] perf auxtrace: Fix period type 'i' not working Arnaldo Carvalho de Melo
2015-08-07 1:58 ` [PATCH 23/26] perf tools: Fix perf-with-kcore handling of arguments containing spaces Arnaldo Carvalho de Melo
2015-08-07 1:58 ` [PATCH 24/26] perf tools: Add perf_pmu__format_bits() Arnaldo Carvalho de Melo
2015-08-07 1:58 ` [PATCH 25/26] perf tools: Validate config term maximum value Arnaldo Carvalho de Melo
2015-08-07 1:58 ` [PATCH 26/26] perf tools: Extend the event parser maximum error index Arnaldo Carvalho de Melo
2015-08-07 7:13 ` [GIT PULL 00/26] 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=1438912715-4000-18-git-send-email-acme@kernel.org \
--to=acme@kernel.org \
--cc=acme@redhat.com \
--cc=ak@linux.intel.com \
--cc=jolsa@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@kernel.org \
--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 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.