Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf annotate: Display total number of samples with --show-total-period

To compare two records on an instruction base, with --show-total-period
option provided, display total number of samples that belong to a line
in assembly language.

New hot key 't' is introduced for 'perf annotate' TUI.

Signed-off-by: Martin Liska <mliska@suse.cz>
Cc: Andi Kleen <andi@firstfloor.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: http://lkml.kernel.org/r/5583E26D.1040407@suse.cz
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Martin Liška and committed by
Arnaldo Carvalho de Melo
0c4a5bce a5499b37

+70 -23
+2
tools/perf/builtin-annotate.c
··· 329 329 "objdump binary to use for disassembly and annotations"), 330 330 OPT_BOOLEAN(0, "group", &symbol_conf.event_group, 331 331 "Show event group information together"), 332 + OPT_BOOLEAN(0, "show-total-period", &symbol_conf.show_total_period, 333 + "Show a column with the sum of periods"), 332 334 OPT_END() 333 335 }; 334 336 int ret = hists__init();
+43 -17
tools/perf/ui/browsers/annotate.c
··· 11 11 #include "../../util/evsel.h" 12 12 #include <pthread.h> 13 13 14 + struct disasm_line_samples { 15 + double percent; 16 + u64 nr; 17 + }; 18 + 14 19 struct browser_disasm_line { 15 - struct rb_node rb_node; 16 - u32 idx; 17 - int idx_asm; 18 - int jump_sources; 20 + struct rb_node rb_node; 21 + u32 idx; 22 + int idx_asm; 23 + int jump_sources; 19 24 /* 20 25 * actual length of this array is saved on the nr_events field 21 26 * of the struct annotate_browser 22 27 */ 23 - double percent[1]; 28 + struct disasm_line_samples samples[1]; 24 29 }; 25 30 26 31 static struct annotate_browser_opt { ··· 33 28 use_offset, 34 29 jump_arrows, 35 30 show_linenr, 36 - show_nr_jumps; 31 + show_nr_jumps, 32 + show_total_period; 37 33 } annotate_browser__opts = { 38 34 .use_offset = true, 39 35 .jump_arrows = true, ··· 111 105 char bf[256]; 112 106 113 107 for (i = 0; i < ab->nr_events; i++) { 114 - if (bdl->percent[i] > percent_max) 115 - percent_max = bdl->percent[i]; 108 + if (bdl->samples[i].percent > percent_max) 109 + percent_max = bdl->samples[i].percent; 116 110 } 117 111 118 112 if (dl->offset != -1 && percent_max != 0.0) { 119 113 for (i = 0; i < ab->nr_events; i++) { 120 - ui_browser__set_percent_color(browser, bdl->percent[i], 114 + ui_browser__set_percent_color(browser, 115 + bdl->samples[i].percent, 121 116 current_entry); 122 - slsmg_printf("%6.2f ", bdl->percent[i]); 117 + if (annotate_browser__opts.show_total_period) 118 + slsmg_printf("%6" PRIu64 " ", 119 + bdl->samples[i].nr); 120 + else 121 + slsmg_printf("%6.2f ", bdl->samples[i].percent); 123 122 } 124 123 } else { 125 124 ui_browser__set_percent_color(browser, 0, current_entry); ··· 284 273 int i; 285 274 286 275 for (i = 0; i < nr_pcnt; i++) { 287 - if (a->percent[i] == b->percent[i]) 276 + if (a->samples[i].percent == b->samples[i].percent) 288 277 continue; 289 - return a->percent[i] < b->percent[i]; 278 + return a->samples[i].percent < b->samples[i].percent; 290 279 } 291 280 return 0; 292 281 } ··· 377 366 next = disasm__get_next_ip_line(&notes->src->source, pos); 378 367 379 368 for (i = 0; i < browser->nr_events; i++) { 380 - bpos->percent[i] = disasm__calc_percent(notes, 369 + u64 nr_samples; 370 + 371 + bpos->samples[i].percent = disasm__calc_percent(notes, 381 372 evsel->idx + i, 382 373 pos->offset, 383 374 next ? next->offset : len, 384 - &path); 375 + &path, &nr_samples); 376 + bpos->samples[i].nr = nr_samples; 385 377 386 - if (max_percent < bpos->percent[i]) 387 - max_percent = bpos->percent[i]; 378 + if (max_percent < bpos->samples[i].percent) 379 + max_percent = bpos->samples[i].percent; 388 380 } 389 381 390 382 if (max_percent < 0.01) { ··· 751 737 "n Search next string\n" 752 738 "o Toggle disassembler output/simplified view\n" 753 739 "s Toggle source code view\n" 740 + "t Toggle total period view\n" 754 741 "/ Search string\n" 755 742 "k Toggle line numbers\n" 756 743 "r Run available scripts\n" ··· 827 812 ui_helpline__puts("Actions are only available for 'callq', 'retq' & jump instructions."); 828 813 } 829 814 continue; 815 + case 't': 816 + annotate_browser__opts.show_total_period = 817 + !annotate_browser__opts.show_total_period; 818 + annotate_browser__update_addr_width(browser); 819 + continue; 830 820 case K_LEFT: 831 821 case K_ESC: 832 822 case 'q': ··· 852 832 int map_symbol__tui_annotate(struct map_symbol *ms, struct perf_evsel *evsel, 853 833 struct hist_browser_timer *hbt) 854 834 { 835 + /* Set default value for show_total_period. */ 836 + annotate_browser__opts.show_total_period = 837 + symbol_conf.show_total_period; 838 + 855 839 return symbol__tui_annotate(ms->sym, ms->map, evsel, hbt); 856 840 } 857 841 ··· 953 929 954 930 if (perf_evsel__is_group_event(evsel)) { 955 931 nr_pcnt = evsel->nr_members; 956 - sizeof_bdl += sizeof(double) * (nr_pcnt - 1); 932 + sizeof_bdl += sizeof(struct disasm_line_samples) * 933 + (nr_pcnt - 1); 957 934 } 958 935 959 936 if (symbol__annotate(sym, map, sizeof_bdl) < 0) { ··· 1031 1006 ANNOTATE_CFG(show_linenr), 1032 1007 ANNOTATE_CFG(show_nr_jumps), 1033 1008 ANNOTATE_CFG(use_offset), 1009 + ANNOTATE_CFG(show_total_period), 1034 1010 }; 1035 1011 1036 1012 #undef ANNOTATE_CFG
+23 -5
tools/perf/util/annotate.c
··· 654 654 } 655 655 656 656 double disasm__calc_percent(struct annotation *notes, int evidx, s64 offset, 657 - s64 end, const char **path) 657 + s64 end, const char **path, u64 *nr_samples) 658 658 { 659 659 struct source_line *src_line = notes->src->lines; 660 660 double percent = 0.0; 661 + *nr_samples = 0; 661 662 662 663 if (src_line) { 663 664 size_t sizeof_src_line = sizeof(*src_line) + ··· 672 671 *path = src_line->path; 673 672 674 673 percent += src_line->p[evidx].percent; 674 + *nr_samples += src_line->p[evidx].samples; 675 675 offset++; 676 676 } 677 677 } else { ··· 682 680 while (offset < end) 683 681 hits += h->addr[offset++]; 684 682 685 - if (h->sum) 683 + if (h->sum) { 684 + *nr_samples = hits; 686 685 percent = 100.0 * hits / h->sum; 686 + } 687 687 } 688 688 689 689 return percent; ··· 700 696 701 697 if (dl->offset != -1) { 702 698 const char *path = NULL; 699 + u64 nr_samples; 703 700 double percent, max_percent = 0.0; 704 701 double *ppercents = &percent; 702 + u64 *psamples = &nr_samples; 705 703 int i, nr_percent = 1; 706 704 const char *color; 707 705 struct annotation *notes = symbol__annotation(sym); ··· 716 710 if (perf_evsel__is_group_event(evsel)) { 717 711 nr_percent = evsel->nr_members; 718 712 ppercents = calloc(nr_percent, sizeof(double)); 719 - if (ppercents == NULL) 713 + psamples = calloc(nr_percent, sizeof(u64)); 714 + if (ppercents == NULL || psamples == NULL) { 720 715 return -1; 716 + } 721 717 } 722 718 723 719 for (i = 0; i < nr_percent; i++) { ··· 727 719 notes->src->lines ? i : evsel->idx + i, 728 720 offset, 729 721 next ? next->offset : (s64) len, 730 - &path); 722 + &path, &nr_samples); 731 723 732 724 ppercents[i] = percent; 725 + psamples[i] = nr_samples; 733 726 if (percent > max_percent) 734 727 max_percent = percent; 735 728 } ··· 768 759 769 760 for (i = 0; i < nr_percent; i++) { 770 761 percent = ppercents[i]; 762 + nr_samples = psamples[i]; 771 763 color = get_percent_color(percent); 772 - color_fprintf(stdout, color, " %7.2f", percent); 764 + 765 + if (symbol_conf.show_total_period) 766 + color_fprintf(stdout, color, " %7" PRIu64, 767 + nr_samples); 768 + else 769 + color_fprintf(stdout, color, " %7.2f", percent); 773 770 } 774 771 775 772 printf(" : "); ··· 784 769 785 770 if (ppercents != &percent) 786 771 free(ppercents); 772 + 773 + if (psamples != &nr_samples) 774 + free(psamples); 787 775 788 776 } else if (max_lines && printed >= max_lines) 789 777 return 1;
+2 -1
tools/perf/util/annotate.h
··· 72 72 int disasm_line__scnprintf(struct disasm_line *dl, char *bf, size_t size, bool raw); 73 73 size_t disasm__fprintf(struct list_head *head, FILE *fp); 74 74 double disasm__calc_percent(struct annotation *notes, int evidx, s64 offset, 75 - s64 end, const char **path); 75 + s64 end, const char **path, u64 *nr_samples); 76 76 77 77 struct sym_hist { 78 78 u64 sum; ··· 82 82 struct source_line_percent { 83 83 double percent; 84 84 double percent_sum; 85 + double samples; 85 86 }; 86 87 87 88 struct source_line {