Skip to content

Commit ace4f8f

Browse files
Jin Yaoacmel
authored andcommitted
perf annotate: Compute average IPC and IPC coverage per symbol
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>
1 parent 44e92f8 commit ace4f8f

2 files changed

Lines changed: 43 additions & 3 deletions

File tree

‎tools/perf/util/annotate.c‎

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1000,6 +1000,7 @@ static unsigned annotation__count_insn(struct annotation *notes, u64 start, u64
10001000
static void annotation__count_and_fill(struct annotation *notes, u64 start, u64 end, struct cyc_hist *ch)
10011001
{
10021002
unsigned n_insn;
1003+
unsigned int cover_insn = 0;
10031004
u64 offset;
10041005

10051006
n_insn = annotation__count_insn(notes, start, end);
@@ -1013,21 +1014,34 @@ static void annotation__count_and_fill(struct annotation *notes, u64 start, u64
10131014
for (offset = start; offset <= end; offset++) {
10141015
struct annotation_line *al = notes->offsets[offset];
10151016

1016-
if (al)
1017+
if (al && al->ipc == 0.0) {
10171018
al->ipc = ipc;
1019+
cover_insn++;
1020+
}
1021+
}
1022+
1023+
if (cover_insn) {
1024+
notes->hit_cycles += ch->cycles;
1025+
notes->hit_insn += n_insn * ch->num;
1026+
notes->cover_insn += cover_insn;
10181027
}
10191028
}
10201029
}
10211030

10221031
void annotation__compute_ipc(struct annotation *notes, size_t size)
10231032
{
1024-
u64 offset;
1033+
s64 offset;
10251034

10261035
if (!notes->src || !notes->src->cycles_hist)
10271036
return;
10281037

1038+
notes->total_insn = annotation__count_insn(notes, 0, size - 1);
1039+
notes->hit_cycles = 0;
1040+
notes->hit_insn = 0;
1041+
notes->cover_insn = 0;
1042+
10291043
pthread_mutex_lock(&notes->lock);
1030-
for (offset = 0; offset < size; ++offset) {
1044+
for (offset = size - 1; offset >= 0; --offset) {
10311045
struct cyc_hist *ch;
10321046

10331047
ch = &notes->src->cycles_hist[offset];
@@ -2563,6 +2577,22 @@ static void disasm_line__write(struct disasm_line *dl, struct annotation *notes,
25632577
disasm_line__scnprintf(dl, bf, size, !notes->options->use_offset);
25642578
}
25652579

2580+
static void ipc_coverage_string(char *bf, int size, struct annotation *notes)
2581+
{
2582+
double ipc = 0.0, coverage = 0.0;
2583+
2584+
if (notes->hit_cycles)
2585+
ipc = notes->hit_insn / ((double)notes->hit_cycles);
2586+
2587+
if (notes->total_insn) {
2588+
coverage = notes->cover_insn * 100.0 /
2589+
((double)notes->total_insn);
2590+
}
2591+
2592+
scnprintf(bf, size, "(Average IPC: %.2f, IPC Coverage: %.1f%%)",
2593+
ipc, coverage);
2594+
}
2595+
25662596
static void __annotation_line__write(struct annotation_line *al, struct annotation *notes,
25672597
bool first_line, bool current_entry, bool change_color, int width,
25682598
void *obj, unsigned int percent_type,
@@ -2658,6 +2688,11 @@ static void __annotation_line__write(struct annotation_line *al, struct annotati
26582688
ANNOTATION__MINMAX_CYCLES_WIDTH - 1,
26592689
"Cycle(min/max)");
26602690
}
2691+
2692+
if (show_title && !*al->line) {
2693+
ipc_coverage_string(bf, sizeof(bf), notes);
2694+
obj__printf(obj, "%*s", ANNOTATION__AVG_IPC_WIDTH, bf);
2695+
}
26612696
}
26622697

26632698
obj__printf(obj, " ");

‎tools/perf/util/annotate.h‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ bool ins__is_fused(struct arch *arch, const char *ins1, const char *ins2);
6464
#define ANNOTATION__IPC_WIDTH 6
6565
#define ANNOTATION__CYCLES_WIDTH 6
6666
#define ANNOTATION__MINMAX_CYCLES_WIDTH 19
67+
#define ANNOTATION__AVG_IPC_WIDTH 36
6768

6869
struct annotation_options {
6970
bool hide_src_code,
@@ -262,6 +263,10 @@ struct annotation {
262263
pthread_mutex_t lock;
263264
u64 max_coverage;
264265
u64 start;
266+
u64 hit_cycles;
267+
u64 hit_insn;
268+
unsigned int total_insn;
269+
unsigned int cover_insn;
265270
struct annotation_options *options;
266271
struct annotation_line **offsets;
267272
int nr_events;

0 commit comments

Comments
 (0)