From 7a3e71e0d806070071f53271705b0c511c0359fc Mon Sep 17 00:00:00 2001 From: Jiri Olsa Date: Sat, 4 Aug 2018 15:05:02 +0200 Subject: perf annotate: Make symbol__annotate_fprintf2() local There's no outside user of it. Signed-off-by: Jiri Olsa Cc: Alexander Shishkin Cc: David Ahern Cc: Namhyung Kim Cc: Peter Zijlstra Cc: Stephane Eranian Link: https://lkml.kernel.org/r/20180804130521.11408-2-jolsa@kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/annotate.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tools/perf/util/annotate.c') diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c index f91775b4bc3c..b6e7d0d56622 100644 --- a/tools/perf/util/annotate.c +++ b/tools/perf/util/annotate.c @@ -2129,7 +2129,7 @@ static void FILE__write_graph(void *fp, int graph) fputs(s, fp); } -int symbol__annotate_fprintf2(struct symbol *sym, FILE *fp) +static int symbol__annotate_fprintf2(struct symbol *sym, FILE *fp) { struct annotation *notes = symbol__annotation(sym); struct annotation_write_ops ops = { -- cgit v1.2.3-59-g8ed1b From 5ecf7d30eb4f9c046f5284f20133d7b69729c315 Mon Sep 17 00:00:00 2001 From: Jiri Olsa Date: Sat, 4 Aug 2018 15:05:03 +0200 Subject: perf annotate: Make annotation_line__max_percent static There's no outside user of it. Signed-off-by: Jiri Olsa Cc: Alexander Shishkin Cc: David Ahern Cc: Namhyung Kim Cc: Peter Zijlstra Cc: Stephane Eranian Link: http://lkml.kernel.org/r/20180804130521.11408-3-jolsa@kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/annotate.c | 3 ++- tools/perf/util/annotate.h | 1 - 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'tools/perf/util/annotate.c') diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c index b6e7d0d56622..956c9b19d81c 100644 --- a/tools/perf/util/annotate.c +++ b/tools/perf/util/annotate.c @@ -2441,7 +2441,8 @@ bool ui__has_annotation(void) } -double annotation_line__max_percent(struct annotation_line *al, struct annotation *notes) +static double annotation_line__max_percent(struct annotation_line *al, + struct annotation *notes) { double percent_max = 0.0; int i; diff --git a/tools/perf/util/annotate.h b/tools/perf/util/annotate.h index 5f24fc9dcc7c..a93502d0c582 100644 --- a/tools/perf/util/annotate.h +++ b/tools/perf/util/annotate.h @@ -169,7 +169,6 @@ struct annotation_write_ops { void (*write_graph)(void *obj, int graph); }; -double annotation_line__max_percent(struct annotation_line *al, struct annotation *notes); void annotation_line__write(struct annotation_line *al, struct annotation *notes, struct annotation_write_ops *ops); -- cgit v1.2.3-59-g8ed1b From 0683d13c1afbf5cca147b6f578d1463be132b11b Mon Sep 17 00:00:00 2001 From: Jiri Olsa Date: Sat, 4 Aug 2018 15:05:04 +0200 Subject: perf annotate: Get rid of annotation__scnprintf_samples_period() We have more current function tto get the title for annotation, which is hists__scnprintf_title. They both have same output as far as the annotation's header line goes. They differ in counting of the nr_samples, hists__scnprintf_title provides more accurate number based on the setup of the symbol_conf.filter_relative variable. Plus it also displays any uid/thread/dso/socket filters/zooms if there are set any, which annotation__scnprintf_samples_period does not. Signed-off-by: Jiri Olsa Tested-by: Arnaldo Carvalho de Melo Cc: Alexander Shishkin Cc: David Ahern Cc: Namhyung Kim Cc: Peter Zijlstra Cc: Stephane Eranian Link: http://lkml.kernel.org/r/20180804130521.11408-4-jolsa@kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/ui/browsers/annotate.c | 3 +-- tools/perf/util/annotate.c | 44 ++------------------------------------- tools/perf/util/annotate.h | 7 ------- 3 files changed, 3 insertions(+), 51 deletions(-) (limited to 'tools/perf/util/annotate.c') diff --git a/tools/perf/ui/browsers/annotate.c b/tools/perf/ui/browsers/annotate.c index 3b4f1c10ff57..d264916d2648 100644 --- a/tools/perf/ui/browsers/annotate.c +++ b/tools/perf/ui/browsers/annotate.c @@ -624,8 +624,7 @@ static int annotate_browser__run(struct annotate_browser *browser, char title[256]; int key; - annotation__scnprintf_samples_period(notes, title, sizeof(title), evsel); - + hists__scnprintf_title(hists, title, sizeof(title)); if (annotate_browser__show(&browser->b, title, help) < 0) return -1; diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c index 956c9b19d81c..0d40cee13f6b 100644 --- a/tools/perf/util/annotate.c +++ b/tools/perf/util/annotate.c @@ -2389,7 +2389,7 @@ int symbol__tty_annotate2(struct symbol *sym, struct map *map, { struct dso *dso = map->dso; struct rb_root source_line = RB_ROOT; - struct annotation *notes = symbol__annotation(sym); + struct hists *hists = evsel__hists(evsel); char buf[1024]; if (symbol__annotate2(sym, map, evsel, opts, NULL) < 0) @@ -2401,7 +2401,7 @@ int symbol__tty_annotate2(struct symbol *sym, struct map *map, print_summary(&source_line, dso->long_name); } - annotation__scnprintf_samples_period(notes, buf, sizeof(buf), evsel); + hists__scnprintf_title(hists, buf, sizeof(buf)); fprintf(stdout, "%s\n%s() %s\n", buf, sym->name, dso->long_name); symbol__annotate_fprintf2(sym, stdout); @@ -2689,46 +2689,6 @@ out_free_offsets: return -1; } -int __annotation__scnprintf_samples_period(struct annotation *notes, - char *bf, size_t size, - struct perf_evsel *evsel, - bool show_freq) -{ - const char *ev_name = perf_evsel__name(evsel); - char buf[1024], ref[30] = " show reference callgraph, "; - char sample_freq_str[64] = ""; - unsigned long nr_samples = 0; - int nr_members = 1; - bool enable_ref = false; - u64 nr_events = 0; - char unit; - int i; - - if (perf_evsel__is_group_event(evsel)) { - perf_evsel__group_desc(evsel, buf, sizeof(buf)); - ev_name = buf; - nr_members = evsel->nr_members; - } - - for (i = 0; i < nr_members; i++) { - struct sym_hist *ah = annotation__histogram(notes, evsel->idx + i); - - nr_samples += ah->nr_samples; - nr_events += ah->period; - } - - if (symbol_conf.show_ref_callgraph && strstr(ev_name, "call-graph=no")) - enable_ref = true; - - if (show_freq) - scnprintf(sample_freq_str, sizeof(sample_freq_str), " %d Hz,", evsel->attr.sample_freq); - - nr_samples = convert_unit(nr_samples, &unit); - return scnprintf(bf, size, "Samples: %lu%c of event%s '%s',%s%sEvent count (approx.): %" PRIu64, - nr_samples, unit, evsel->nr_members > 1 ? "s" : "", - ev_name, sample_freq_str, enable_ref ? ref : " ", nr_events); -} - #define ANNOTATION__CFG(n) \ { .name = #n, .value = &annotation__default_options.n, } diff --git a/tools/perf/util/annotate.h b/tools/perf/util/annotate.h index a93502d0c582..d06f14c656c6 100644 --- a/tools/perf/util/annotate.h +++ b/tools/perf/util/annotate.h @@ -177,13 +177,6 @@ int __annotation__scnprintf_samples_period(struct annotation *notes, struct perf_evsel *evsel, bool show_freq); -static inline int annotation__scnprintf_samples_period(struct annotation *notes, - char *bf, size_t size, - struct perf_evsel *evsel) -{ - return __annotation__scnprintf_samples_period(notes, bf, size, evsel, true); -} - int disasm_line__scnprintf(struct disasm_line *dl, char *bf, size_t size, bool raw); size_t disasm__fprintf(struct list_head *head, FILE *fp); void symbol__calc_percent(struct symbol *sym, struct perf_evsel *evsel); -- cgit v1.2.3-59-g8ed1b From c2f938ba5aa61ba60e9217848e666c783cbcce1c Mon Sep 17 00:00:00 2001 From: Jiri Olsa Date: Sat, 4 Aug 2018 15:05:05 +0200 Subject: perf annotate: Rename struct annotation_line::samples* to data* The name 'samples*' is little confusing because we have nested 'struct sym_hist_entry' under annotation_line struct, which holds 'nr_samples' as well. Also the holding struct name is 'annotation_data' so the 'data' name fits better. Signed-off-by: Jiri Olsa Cc: Alexander Shishkin Cc: David Ahern Cc: Namhyung Kim Cc: Peter Zijlstra Cc: Stephane Eranian Link: http://lkml.kernel.org/r/20180804130521.11408-5-jolsa@kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/ui/browsers/annotate.c | 10 ++++---- tools/perf/util/annotate.c | 52 +++++++++++++++++++-------------------- tools/perf/util/annotate.h | 4 +-- 3 files changed, 33 insertions(+), 33 deletions(-) (limited to 'tools/perf/util/annotate.c') diff --git a/tools/perf/ui/browsers/annotate.c b/tools/perf/ui/browsers/annotate.c index d264916d2648..d648d1e153f3 100644 --- a/tools/perf/ui/browsers/annotate.c +++ b/tools/perf/ui/browsers/annotate.c @@ -227,10 +227,10 @@ static int disasm__cmp(struct annotation_line *a, struct annotation_line *b) { int i; - for (i = 0; i < a->samples_nr; i++) { - if (a->samples[i].percent == b->samples[i].percent) + for (i = 0; i < a->data_nr; i++) { + if (a->data[i].percent == b->data[i].percent) continue; - return a->samples[i].percent < b->samples[i].percent; + return a->data[i].percent < b->data[i].percent; } return 0; } @@ -314,8 +314,8 @@ static void annotate_browser__calc_percent(struct annotate_browser *browser, continue; } - for (i = 0; i < pos->al.samples_nr; i++) { - struct annotation_data *sample = &pos->al.samples[i]; + for (i = 0; i < pos->al.data_nr; i++) { + struct annotation_data *sample = &pos->al.data[i]; if (max_percent < sample->percent) max_percent = sample->percent; diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c index 0d40cee13f6b..e4cb8963db1a 100644 --- a/tools/perf/util/annotate.c +++ b/tools/perf/util/annotate.c @@ -1108,7 +1108,7 @@ annotation_line__new(struct annotate_args *args, size_t privsize) if (perf_evsel__is_group_event(evsel)) nr = evsel->nr_members; - size += sizeof(al->samples[0]) * nr; + size += sizeof(al->data[0]) * nr; al = zalloc(size); if (al) { @@ -1117,7 +1117,7 @@ annotation_line__new(struct annotate_args *args, size_t privsize) al->offset = args->offset; al->line = strdup(args->line); al->line_nr = args->line_nr; - al->samples_nr = nr; + al->data_nr = nr; } return al; @@ -1309,15 +1309,15 @@ annotation_line__print(struct annotation_line *al, struct symbol *sym, u64 start const char *color; struct annotation *notes = symbol__annotation(sym); - for (i = 0; i < al->samples_nr; i++) { - struct annotation_data *sample = &al->samples[i]; + for (i = 0; i < al->data_nr; i++) { + struct annotation_data *sample = &al->data[i]; if (sample->percent > max_percent) max_percent = sample->percent; } - if (al->samples_nr > nr_percent) - nr_percent = al->samples_nr; + if (al->data_nr > nr_percent) + nr_percent = al->data_nr; if (max_percent < min_pcnt) return -1; @@ -1351,7 +1351,7 @@ annotation_line__print(struct annotation_line *al, struct symbol *sym, u64 start } for (i = 0; i < nr_percent; i++) { - struct annotation_data *sample = &al->samples[i]; + struct annotation_data *sample = &al->data[i]; color = get_percent_color(sample->percent); @@ -1788,12 +1788,12 @@ static void annotation__calc_percent(struct annotation *notes, next = annotation_line__next(al, ¬es->src->source); end = next ? next->offset : len; - for (i = 0; i < al->samples_nr; i++) { + for (i = 0; i < al->data_nr; i++) { struct annotation_data *sample; struct sym_hist *hist; hist = annotation__histogram(notes, evsel->idx + i); - sample = &al->samples[i]; + sample = &al->data[i]; calc_percent(hist, sample, al->offset, end); } @@ -1859,8 +1859,8 @@ static void insert_source_line(struct rb_root *root, struct annotation_line *al) ret = strcmp(iter->path, al->path); if (ret == 0) { - for (i = 0; i < al->samples_nr; i++) - iter->samples[i].percent_sum += al->samples[i].percent; + for (i = 0; i < al->data_nr; i++) + iter->data[i].percent_sum += al->data[i].percent; return; } @@ -1870,8 +1870,8 @@ static void insert_source_line(struct rb_root *root, struct annotation_line *al) p = &(*p)->rb_right; } - for (i = 0; i < al->samples_nr; i++) - al->samples[i].percent_sum = al->samples[i].percent; + for (i = 0; i < al->data_nr; i++) + al->data[i].percent_sum = al->data[i].percent; rb_link_node(&al->rb_node, parent, p); rb_insert_color(&al->rb_node, root); @@ -1881,10 +1881,10 @@ static int cmp_source_line(struct annotation_line *a, struct annotation_line *b) { int i; - for (i = 0; i < a->samples_nr; i++) { - if (a->samples[i].percent_sum == b->samples[i].percent_sum) + for (i = 0; i < a->data_nr; i++) { + if (a->data[i].percent_sum == b->data[i].percent_sum) continue; - return a->samples[i].percent_sum > b->samples[i].percent_sum; + return a->data[i].percent_sum > b->data[i].percent_sum; } return 0; @@ -1949,8 +1949,8 @@ static void print_summary(struct rb_root *root, const char *filename) int i; al = rb_entry(node, struct annotation_line, rb_node); - for (i = 0; i < al->samples_nr; i++) { - percent = al->samples[i].percent_sum; + for (i = 0; i < al->data_nr; i++) { + percent = al->data[i].percent_sum; color = get_percent_color(percent); color_fprintf(stdout, color, " %7.2f", percent); @@ -2355,10 +2355,10 @@ static void annotation__calc_lines(struct annotation *notes, struct map *map, double percent_max = 0.0; int i; - for (i = 0; i < al->samples_nr; i++) { + for (i = 0; i < al->data_nr; i++) { struct annotation_data *sample; - sample = &al->samples[i]; + sample = &al->data[i]; if (sample->percent > percent_max) percent_max = sample->percent; @@ -2448,8 +2448,8 @@ static double annotation_line__max_percent(struct annotation_line *al, int i; for (i = 0; i < notes->nr_events; i++) { - if (al->samples[i].percent > percent_max) - percent_max = al->samples[i].percent; + if (al->data[i].percent > percent_max) + percent_max = al->data[i].percent; } return percent_max; @@ -2515,15 +2515,15 @@ static void __annotation_line__write(struct annotation_line *al, struct annotati int i; for (i = 0; i < notes->nr_events; i++) { - obj__set_percent_color(obj, al->samples[i].percent, current_entry); + obj__set_percent_color(obj, al->data[i].percent, current_entry); if (notes->options->show_total_period) { - obj__printf(obj, "%11" PRIu64 " ", al->samples[i].he.period); + obj__printf(obj, "%11" PRIu64 " ", al->data[i].he.period); } else if (notes->options->show_nr_samples) { obj__printf(obj, "%6" PRIu64 " ", - al->samples[i].he.nr_samples); + al->data[i].he.nr_samples); } else { obj__printf(obj, "%6.2f ", - al->samples[i].percent); + al->data[i].percent); } } } else { diff --git a/tools/perf/util/annotate.h b/tools/perf/util/annotate.h index d06f14c656c6..58aa14c55bab 100644 --- a/tools/perf/util/annotate.h +++ b/tools/perf/util/annotate.h @@ -122,8 +122,8 @@ struct annotation_line { char *path; u32 idx; int idx_asm; - int samples_nr; - struct annotation_data samples[0]; + int data_nr; + struct annotation_data data[0]; }; struct disasm_line { -- cgit v1.2.3-59-g8ed1b From 0440af74dcd0f32b134b1c4d47dc25f0bb539ded Mon Sep 17 00:00:00 2001 From: Jiri Olsa Date: Sat, 4 Aug 2018 15:05:06 +0200 Subject: perf annotate: Rename local sample variables to data Based on previous rename, changing also the local variable names to fit properly. Signed-off-by: Jiri Olsa Cc: Alexander Shishkin Cc: David Ahern Cc: Namhyung Kim Cc: Peter Zijlstra Cc: Stephane Eranian Link: http://lkml.kernel.org/r/20180804130521.11408-6-jolsa@kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/annotate.c | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) (limited to 'tools/perf/util/annotate.c') diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c index e4cb8963db1a..8bd278a71004 100644 --- a/tools/perf/util/annotate.c +++ b/tools/perf/util/annotate.c @@ -1310,10 +1310,10 @@ annotation_line__print(struct annotation_line *al, struct symbol *sym, u64 start struct annotation *notes = symbol__annotation(sym); for (i = 0; i < al->data_nr; i++) { - struct annotation_data *sample = &al->data[i]; + struct annotation_data *data = &al->data[i]; - if (sample->percent > max_percent) - max_percent = sample->percent; + if (data->percent > max_percent) + max_percent = data->percent; } if (al->data_nr > nr_percent) @@ -1351,18 +1351,18 @@ annotation_line__print(struct annotation_line *al, struct symbol *sym, u64 start } for (i = 0; i < nr_percent; i++) { - struct annotation_data *sample = &al->data[i]; + struct annotation_data *data = &al->data[i]; - color = get_percent_color(sample->percent); + color = get_percent_color(data->percent); if (symbol_conf.show_total_period) color_fprintf(stdout, color, " %11" PRIu64, - sample->he.period); + data->he.period); else if (symbol_conf.show_nr_samples) color_fprintf(stdout, color, " %7" PRIu64, - sample->he.nr_samples); + data->he.nr_samples); else - color_fprintf(stdout, color, " %7.2f", sample->percent); + color_fprintf(stdout, color, " %7.2f", data->percent); } printf(" : "); @@ -1754,7 +1754,7 @@ out_close_stdout: } static void calc_percent(struct sym_hist *hist, - struct annotation_data *sample, + struct annotation_data *data, s64 offset, s64 end) { unsigned int hits = 0; @@ -1767,9 +1767,9 @@ static void calc_percent(struct sym_hist *hist, } if (hist->nr_samples) { - sample->he.period = period; - sample->he.nr_samples = hits; - sample->percent = 100.0 * hits / hist->nr_samples; + data->he.period = period; + data->he.nr_samples = hits; + data->percent = 100.0 * hits / hist->nr_samples; } } @@ -1789,13 +1789,13 @@ static void annotation__calc_percent(struct annotation *notes, end = next ? next->offset : len; for (i = 0; i < al->data_nr; i++) { - struct annotation_data *sample; + struct annotation_data *data; struct sym_hist *hist; - hist = annotation__histogram(notes, evsel->idx + i); - sample = &al->data[i]; + hist = annotation__histogram(notes, evsel->idx + i); + data = &al->data[i]; - calc_percent(hist, sample, al->offset, end); + calc_percent(hist, data, al->offset, end); } } } @@ -2356,12 +2356,12 @@ static void annotation__calc_lines(struct annotation *notes, struct map *map, int i; for (i = 0; i < al->data_nr; i++) { - struct annotation_data *sample; + struct annotation_data *data; - sample = &al->data[i]; + data = &al->data[i]; - if (sample->percent > percent_max) - percent_max = sample->percent; + if (data->percent > percent_max) + percent_max = data->percent; } if (percent_max <= 0.5) -- cgit v1.2.3-59-g8ed1b From 48a1e4f2381387a097ea9f7897c5c32e9aaa708d Mon Sep 17 00:00:00 2001 From: Jiri Olsa Date: Sat, 4 Aug 2018 15:05:07 +0200 Subject: perf annotate: Rename hist to sym_hist in annotation__calc_percent We will need to bring in 'struct hists' variable in this scope, so it's better we do this rename first. Signed-off-by: Jiri Olsa Cc: Alexander Shishkin Cc: David Ahern Cc: Namhyung Kim Cc: Peter Zijlstra Cc: Stephane Eranian Link: http://lkml.kernel.org/r/20180804130521.11408-7-jolsa@kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/annotate.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'tools/perf/util/annotate.c') diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c index 8bd278a71004..728603636adc 100644 --- a/tools/perf/util/annotate.c +++ b/tools/perf/util/annotate.c @@ -1753,7 +1753,7 @@ out_close_stdout: goto out_free_command; } -static void calc_percent(struct sym_hist *hist, +static void calc_percent(struct sym_hist *sym_hist, struct annotation_data *data, s64 offset, s64 end) { @@ -1761,15 +1761,15 @@ static void calc_percent(struct sym_hist *hist, u64 period = 0; while (offset < end) { - hits += hist->addr[offset].nr_samples; - period += hist->addr[offset].period; + hits += sym_hist->addr[offset].nr_samples; + period += sym_hist->addr[offset].period; ++offset; } - if (hist->nr_samples) { + if (sym_hist->nr_samples) { data->he.period = period; data->he.nr_samples = hits; - data->percent = 100.0 * hits / hist->nr_samples; + data->percent = 100.0 * hits / sym_hist->nr_samples; } } @@ -1790,12 +1790,12 @@ static void annotation__calc_percent(struct annotation *notes, for (i = 0; i < al->data_nr; i++) { struct annotation_data *data; - struct sym_hist *hist; + struct sym_hist *sym_hist; - hist = annotation__histogram(notes, evsel->idx + i); + sym_hist = annotation__histogram(notes, evsel->idx + i); data = &al->data[i]; - calc_percent(hist, data, al->offset, end); + calc_percent(sym_hist, data, al->offset, end); } } } -- cgit v1.2.3-59-g8ed1b From 2bcf73069b0722c92a84c0fd57df542890a74904 Mon Sep 17 00:00:00 2001 From: Jiri Olsa Date: Sat, 4 Aug 2018 15:05:08 +0200 Subject: perf annotate: Loop group events directly in annotation__calc_percent() We need to bring in 'struct hists' object and for that we need 'struct perf_evsel' object in the scope. Switching the group data loop with the evsel group loop. It does the same thing, but it brings evsel object, that we can use later get the 'struct hists' object. Signed-off-by: Jiri Olsa Cc: Alexander Shishkin Cc: David Ahern Cc: Namhyung Kim Cc: Peter Zijlstra Cc: Stephane Eranian Link: http://lkml.kernel.org/r/20180804130521.11408-8-jolsa@kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/annotate.c | 13 ++++++++----- tools/perf/util/evsel.h | 7 +++++++ 2 files changed, 15 insertions(+), 5 deletions(-) (limited to 'tools/perf/util/annotate.c') diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c index 728603636adc..34d4bb73aa84 100644 --- a/tools/perf/util/annotate.c +++ b/tools/perf/util/annotate.c @@ -1774,13 +1774,14 @@ static void calc_percent(struct sym_hist *sym_hist, } static void annotation__calc_percent(struct annotation *notes, - struct perf_evsel *evsel, s64 len) + struct perf_evsel *leader, s64 len) { struct annotation_line *al, *next; + struct perf_evsel *evsel; list_for_each_entry(al, ¬es->src->source, node) { s64 end; - int i; + int i = 0; if (al->offset == -1) continue; @@ -1788,12 +1789,14 @@ static void annotation__calc_percent(struct annotation *notes, next = annotation_line__next(al, ¬es->src->source); end = next ? next->offset : len; - for (i = 0; i < al->data_nr; i++) { + for_each_group_evsel(evsel, leader) { struct annotation_data *data; struct sym_hist *sym_hist; - sym_hist = annotation__histogram(notes, evsel->idx + i); - data = &al->data[i]; + BUG_ON(i >= al->data_nr); + + sym_hist = annotation__histogram(notes, evsel->idx); + data = &al->data[i++]; calc_percent(sym_hist, data, al->offset, end); } diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h index 973c03167947..163c960614d3 100644 --- a/tools/perf/util/evsel.h +++ b/tools/perf/util/evsel.h @@ -452,11 +452,18 @@ static inline int perf_evsel__group_idx(struct perf_evsel *evsel) return evsel->idx - evsel->leader->idx; } +/* Iterates group WITHOUT the leader. */ #define for_each_group_member(_evsel, _leader) \ for ((_evsel) = list_entry((_leader)->node.next, struct perf_evsel, node); \ (_evsel) && (_evsel)->leader == (_leader); \ (_evsel) = list_entry((_evsel)->node.next, struct perf_evsel, node)) +/* Iterates group WITH the leader. */ +#define for_each_group_evsel(_evsel, _leader) \ +for ((_evsel) = _leader; \ + (_evsel) && (_evsel)->leader == (_leader); \ + (_evsel) = list_entry((_evsel)->node.next, struct perf_evsel, node)) + static inline bool perf_evsel__has_branch_callstack(const struct perf_evsel *evsel) { return evsel->attr.branch_sample_type & PERF_SAMPLE_BRANCH_CALL_STACK; -- cgit v1.2.3-59-g8ed1b From 6d9f0c2d5ef7568c29fa5927748c4915a9c7760a Mon Sep 17 00:00:00 2001 From: Jiri Olsa Date: Sat, 4 Aug 2018 15:05:09 +0200 Subject: perf annotate: Switch struct annotation_data::percent to array So we can hold multiple percent values for annotation line. The first member of this array is current local hits percent value (PERCENT_HITS_LOCAL index), so no functional change is expected. Adding annotation_data__percent function to return requested percent value from struct annotation_data. Signed-off-by: Jiri Olsa Cc: Alexander Shishkin Cc: David Ahern Cc: Namhyung Kim Cc: Peter Zijlstra Cc: Stephane Eranian Link: http://lkml.kernel.org/r/20180804130521.11408-9-jolsa@kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/ui/browsers/annotate.c | 9 ++++--- tools/perf/util/annotate.c | 57 ++++++++++++++++++++++++++------------- tools/perf/util/annotate.h | 13 ++++++++- 3 files changed, 56 insertions(+), 23 deletions(-) (limited to 'tools/perf/util/annotate.c') diff --git a/tools/perf/ui/browsers/annotate.c b/tools/perf/ui/browsers/annotate.c index d648d1e153f3..81876c3923d2 100644 --- a/tools/perf/ui/browsers/annotate.c +++ b/tools/perf/ui/browsers/annotate.c @@ -315,10 +315,13 @@ static void annotate_browser__calc_percent(struct annotate_browser *browser, } for (i = 0; i < pos->al.data_nr; i++) { - struct annotation_data *sample = &pos->al.data[i]; + double percent; - if (max_percent < sample->percent) - max_percent = sample->percent; + percent = annotation_data__percent(&pos->al.data[i], + PERCENT_HITS_LOCAL); + + if (max_percent < percent) + max_percent = percent; } if (max_percent < 0.01 && pos->al.ipc == 0) { diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c index 34d4bb73aa84..074adb2a831e 100644 --- a/tools/perf/util/annotate.c +++ b/tools/perf/util/annotate.c @@ -1310,10 +1310,13 @@ annotation_line__print(struct annotation_line *al, struct symbol *sym, u64 start struct annotation *notes = symbol__annotation(sym); for (i = 0; i < al->data_nr; i++) { - struct annotation_data *data = &al->data[i]; + double percent; + + percent = annotation_data__percent(&al->data[i], + PERCENT_HITS_LOCAL); - if (data->percent > max_percent) - max_percent = data->percent; + if (percent > max_percent) + max_percent = percent; } if (al->data_nr > nr_percent) @@ -1352,8 +1355,10 @@ annotation_line__print(struct annotation_line *al, struct symbol *sym, u64 start for (i = 0; i < nr_percent; i++) { struct annotation_data *data = &al->data[i]; + double percent; - color = get_percent_color(data->percent); + percent = annotation_data__percent(data, PERCENT_HITS_LOCAL); + color = get_percent_color(percent); if (symbol_conf.show_total_period) color_fprintf(stdout, color, " %11" PRIu64, @@ -1362,7 +1367,7 @@ annotation_line__print(struct annotation_line *al, struct symbol *sym, u64 start color_fprintf(stdout, color, " %7" PRIu64, data->he.nr_samples); else - color_fprintf(stdout, color, " %7.2f", data->percent); + color_fprintf(stdout, color, " %7.2f", percent); } printf(" : "); @@ -1769,7 +1774,7 @@ static void calc_percent(struct sym_hist *sym_hist, if (sym_hist->nr_samples) { data->he.period = period; data->he.nr_samples = hits; - data->percent = 100.0 * hits / sym_hist->nr_samples; + data->percent[PERCENT_HITS_LOCAL] = 100.0 * hits / sym_hist->nr_samples; } } @@ -1862,8 +1867,10 @@ static void insert_source_line(struct rb_root *root, struct annotation_line *al) ret = strcmp(iter->path, al->path); if (ret == 0) { - for (i = 0; i < al->data_nr; i++) - iter->data[i].percent_sum += al->data[i].percent; + for (i = 0; i < al->data_nr; i++) { + iter->data[i].percent_sum += annotation_data__percent(&al->data[i], + PERCENT_HITS_LOCAL); + } return; } @@ -1873,8 +1880,10 @@ static void insert_source_line(struct rb_root *root, struct annotation_line *al) p = &(*p)->rb_right; } - for (i = 0; i < al->data_nr; i++) - al->data[i].percent_sum = al->data[i].percent; + for (i = 0; i < al->data_nr; i++) { + al->data[i].percent_sum = annotation_data__percent(&al->data[i], + PERCENT_HITS_LOCAL); + } rb_link_node(&al->rb_node, parent, p); rb_insert_color(&al->rb_node, root); @@ -2359,12 +2368,13 @@ static void annotation__calc_lines(struct annotation *notes, struct map *map, int i; for (i = 0; i < al->data_nr; i++) { - struct annotation_data *data; + double percent; - data = &al->data[i]; + percent = annotation_data__percent(&al->data[i], + PERCENT_HITS_LOCAL); - if (data->percent > percent_max) - percent_max = data->percent; + if (percent > percent_max) + percent_max = percent; } if (percent_max <= 0.5) @@ -2451,8 +2461,13 @@ static double annotation_line__max_percent(struct annotation_line *al, int i; for (i = 0; i < notes->nr_events; i++) { - if (al->data[i].percent > percent_max) - percent_max = al->data[i].percent; + double percent; + + percent = annotation_data__percent(&al->data[i], + PERCENT_HITS_LOCAL); + + if (percent > percent_max) + percent_max = percent; } return percent_max; @@ -2518,15 +2533,19 @@ static void __annotation_line__write(struct annotation_line *al, struct annotati int i; for (i = 0; i < notes->nr_events; i++) { - obj__set_percent_color(obj, al->data[i].percent, current_entry); + double percent; + + percent = annotation_data__percent(&al->data[i], + PERCENT_HITS_LOCAL); + + obj__set_percent_color(obj, percent, current_entry); if (notes->options->show_total_period) { obj__printf(obj, "%11" PRIu64 " ", al->data[i].he.period); } else if (notes->options->show_nr_samples) { obj__printf(obj, "%6" PRIu64 " ", al->data[i].he.nr_samples); } else { - obj__printf(obj, "%6.2f ", - al->data[i].percent); + obj__printf(obj, "%6.2f ", percent); } } } else { diff --git a/tools/perf/util/annotate.h b/tools/perf/util/annotate.h index 58aa14c55bab..0afbf8075fca 100644 --- a/tools/perf/util/annotate.h +++ b/tools/perf/util/annotate.h @@ -101,8 +101,13 @@ struct sym_hist_entry { u64 period; }; +enum { + PERCENT_HITS_LOCAL, + PERCENT_MAX, +}; + struct annotation_data { - double percent; + double percent[PERCENT_MAX]; double percent_sum; struct sym_hist_entry he; }; @@ -134,6 +139,12 @@ struct disasm_line { struct annotation_line al; }; +static inline double annotation_data__percent(struct annotation_data *data, + unsigned int which) +{ + return which < PERCENT_MAX ? data->percent[which] : -1; +} + static inline struct disasm_line *disasm_line(struct annotation_line *al) { return al ? container_of(al, struct disasm_line, al) : NULL; -- cgit v1.2.3-59-g8ed1b From 75a8c1ff287b2a949b50c1c1e58a6492e21a3ac5 Mon Sep 17 00:00:00 2001 From: Jiri Olsa Date: Sat, 4 Aug 2018 15:05:10 +0200 Subject: perf annotate: Add PERCENT_HITS_GLOBAL percent value Adding and computing global hits percent value for annotation line. Storing it in struct annotation_data percent array under new PERCENT_HITS_GLOBAL index. At the moment it's not displayed, it's coming in following patches. Signed-off-by: Jiri Olsa Cc: Alexander Shishkin Cc: David Ahern Cc: Namhyung Kim Cc: Peter Zijlstra Cc: Stephane Eranian Link: http://lkml.kernel.org/r/20180804130521.11408-10-jolsa@kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/annotate.c | 8 +++++++- tools/perf/util/annotate.h | 1 + 2 files changed, 8 insertions(+), 1 deletion(-) (limited to 'tools/perf/util/annotate.c') diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c index 074adb2a831e..b7485a512da1 100644 --- a/tools/perf/util/annotate.c +++ b/tools/perf/util/annotate.c @@ -1759,6 +1759,7 @@ out_close_stdout: } static void calc_percent(struct sym_hist *sym_hist, + struct hists *hists, struct annotation_data *data, s64 offset, s64 end) { @@ -1776,6 +1777,10 @@ static void calc_percent(struct sym_hist *sym_hist, data->he.nr_samples = hits; data->percent[PERCENT_HITS_LOCAL] = 100.0 * hits / sym_hist->nr_samples; } + + if (hists->stats.nr_non_filtered_samples) + data->percent[PERCENT_HITS_GLOBAL] = 100.0 * hits / hists->stats.nr_non_filtered_samples; + } static void annotation__calc_percent(struct annotation *notes, @@ -1795,6 +1800,7 @@ static void annotation__calc_percent(struct annotation *notes, end = next ? next->offset : len; for_each_group_evsel(evsel, leader) { + struct hists *hists = evsel__hists(evsel); struct annotation_data *data; struct sym_hist *sym_hist; @@ -1803,7 +1809,7 @@ static void annotation__calc_percent(struct annotation *notes, sym_hist = annotation__histogram(notes, evsel->idx); data = &al->data[i++]; - calc_percent(sym_hist, data, al->offset, end); + calc_percent(sym_hist, hists, data, al->offset, end); } } } diff --git a/tools/perf/util/annotate.h b/tools/perf/util/annotate.h index 0afbf8075fca..3a06cb2b6e28 100644 --- a/tools/perf/util/annotate.h +++ b/tools/perf/util/annotate.h @@ -103,6 +103,7 @@ struct sym_hist_entry { enum { PERCENT_HITS_LOCAL, + PERCENT_HITS_GLOBAL, PERCENT_MAX, }; -- cgit v1.2.3-59-g8ed1b From ab371169fb7db9587f09137e93a49c6afeab16f7 Mon Sep 17 00:00:00 2001 From: Jiri Olsa Date: Sat, 4 Aug 2018 15:05:11 +0200 Subject: perf annotate: Add PERCENT_PERIOD_LOCAL percent value Adding and computing local period percent value for annotation line. Storing it in struct annotation_data percent array under new PERCENT_PERIOD_LOCAL index. At the moment it's not displayed, it's coming in following patches. Signed-off-by: Jiri Olsa Cc: Alexander Shishkin Cc: David Ahern Cc: Namhyung Kim Cc: Peter Zijlstra Cc: Stephane Eranian Link: http://lkml.kernel.org/r/20180804130521.11408-11-jolsa@kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/annotate.c | 2 ++ tools/perf/util/annotate.h | 1 + 2 files changed, 3 insertions(+) (limited to 'tools/perf/util/annotate.c') diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c index b7485a512da1..b37e8cc18668 100644 --- a/tools/perf/util/annotate.c +++ b/tools/perf/util/annotate.c @@ -1781,6 +1781,8 @@ static void calc_percent(struct sym_hist *sym_hist, if (hists->stats.nr_non_filtered_samples) data->percent[PERCENT_HITS_GLOBAL] = 100.0 * hits / hists->stats.nr_non_filtered_samples; + if (sym_hist->period) + data->percent[PERCENT_PERIOD_LOCAL] = 100.0 * period / sym_hist->period; } static void annotation__calc_percent(struct annotation *notes, diff --git a/tools/perf/util/annotate.h b/tools/perf/util/annotate.h index 3a06cb2b6e28..890b6869caa9 100644 --- a/tools/perf/util/annotate.h +++ b/tools/perf/util/annotate.h @@ -104,6 +104,7 @@ struct sym_hist_entry { enum { PERCENT_HITS_LOCAL, PERCENT_HITS_GLOBAL, + PERCENT_PERIOD_LOCAL, PERCENT_MAX, }; -- cgit v1.2.3-59-g8ed1b From e58684df912906d944967e2ce0f3ed5d5140d1e5 Mon Sep 17 00:00:00 2001 From: Jiri Olsa Date: Sat, 4 Aug 2018 15:05:12 +0200 Subject: perf annotate: Add PERCENT_PERIOD_GLOBAL percent value Adding and computing global period percent value for annotation line. Storing it in struct annotation_data percent array under new PERCENT_PERIOD_GLOBAL index. At the moment it's not displayed, it's coming in following patches. Signed-off-by: Jiri Olsa Cc: Alexander Shishkin Cc: David Ahern Cc: Namhyung Kim Cc: Peter Zijlstra Cc: Stephane Eranian Link: http://lkml.kernel.org/r/20180804130521.11408-12-jolsa@kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/annotate.c | 3 +++ tools/perf/util/annotate.h | 1 + 2 files changed, 4 insertions(+) (limited to 'tools/perf/util/annotate.c') diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c index b37e8cc18668..e890164592b0 100644 --- a/tools/perf/util/annotate.c +++ b/tools/perf/util/annotate.c @@ -1783,6 +1783,9 @@ static void calc_percent(struct sym_hist *sym_hist, if (sym_hist->period) data->percent[PERCENT_PERIOD_LOCAL] = 100.0 * period / sym_hist->period; + + if (hists->stats.total_period) + data->percent[PERCENT_PERIOD_GLOBAL] = 100.0 * period / hists->stats.total_period; } static void annotation__calc_percent(struct annotation *notes, diff --git a/tools/perf/util/annotate.h b/tools/perf/util/annotate.h index 890b6869caa9..48fe2aa6b5a8 100644 --- a/tools/perf/util/annotate.h +++ b/tools/perf/util/annotate.h @@ -105,6 +105,7 @@ enum { PERCENT_HITS_LOCAL, PERCENT_HITS_GLOBAL, PERCENT_PERIOD_LOCAL, + PERCENT_PERIOD_GLOBAL, PERCENT_MAX, }; -- cgit v1.2.3-59-g8ed1b From 796ca33d5ceb621f238021c34cff8cfaa1100623 Mon Sep 17 00:00:00 2001 From: Jiri Olsa Date: Sat, 4 Aug 2018 15:05:13 +0200 Subject: perf annotate: Add percent_type to struct annotation_options It will be used to carry user selection of percent type for annotation output. Passing the percent_type to the annotation_line__print function as the first step and making it default to current percentage type (PERCENT_HITS_LOCAL) value. Signed-off-by: Jiri Olsa Cc: Alexander Shishkin Cc: David Ahern Cc: Namhyung Kim Cc: Peter Zijlstra Cc: Stephane Eranian Link: http://lkml.kernel.org/r/20180804130521.11408-13-jolsa@kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/annotate.c | 13 ++++++++----- tools/perf/util/annotate.h | 1 + 2 files changed, 9 insertions(+), 5 deletions(-) (limited to 'tools/perf/util/annotate.c') diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c index e890164592b0..91528a065768 100644 --- a/tools/perf/util/annotate.c +++ b/tools/perf/util/annotate.c @@ -49,6 +49,7 @@ struct annotation_options annotation__default_options = { .jump_arrows = true, .annotate_src = true, .offset_level = ANNOTATION__OFFSET_JUMP_TARGETS, + .percent_type = PERCENT_HITS_LOCAL, }; static regex_t file_lineno; @@ -1297,7 +1298,8 @@ static int disasm_line__print(struct disasm_line *dl, u64 start, int addr_fmt_wi static int annotation_line__print(struct annotation_line *al, struct symbol *sym, u64 start, struct perf_evsel *evsel, u64 len, int min_pcnt, int printed, - int max_lines, struct annotation_line *queue, int addr_fmt_width) + int max_lines, struct annotation_line *queue, int addr_fmt_width, + int percent_type) { struct disasm_line *dl = container_of(al, struct disasm_line, al); static const char *prev_line; @@ -1313,7 +1315,7 @@ annotation_line__print(struct annotation_line *al, struct symbol *sym, u64 start double percent; percent = annotation_data__percent(&al->data[i], - PERCENT_HITS_LOCAL); + percent_type); if (percent > max_percent) max_percent = percent; @@ -1333,7 +1335,8 @@ annotation_line__print(struct annotation_line *al, struct symbol *sym, u64 start if (queue == al) break; annotation_line__print(queue, sym, start, evsel, len, - 0, 0, 1, NULL, addr_fmt_width); + 0, 0, 1, NULL, addr_fmt_width, + percent_type); } } @@ -1357,7 +1360,7 @@ annotation_line__print(struct annotation_line *al, struct symbol *sym, u64 start struct annotation_data *data = &al->data[i]; double percent; - percent = annotation_data__percent(data, PERCENT_HITS_LOCAL); + percent = annotation_data__percent(data, percent_type); color = get_percent_color(percent); if (symbol_conf.show_total_period) @@ -2075,7 +2078,7 @@ int symbol__annotate_printf(struct symbol *sym, struct map *map, err = annotation_line__print(pos, sym, start, evsel, len, opts->min_pcnt, printed, opts->max_lines, - queue, addr_fmt_width); + queue, addr_fmt_width, opts->percent_type); switch (err) { case 0: diff --git a/tools/perf/util/annotate.h b/tools/perf/util/annotate.h index 48fe2aa6b5a8..145dec845f33 100644 --- a/tools/perf/util/annotate.h +++ b/tools/perf/util/annotate.h @@ -82,6 +82,7 @@ struct annotation_options { int context; const char *objdump_path; const char *disassembler_style; + unsigned int percent_type; }; enum { -- cgit v1.2.3-59-g8ed1b From c849c12cf344e4b99dbf98df642b622b6c91bbfd Mon Sep 17 00:00:00 2001 From: Jiri Olsa Date: Sat, 4 Aug 2018 15:05:14 +0200 Subject: perf annotate: Pass struct annotation_options to symbol__calc_lines() Pass struct annotation_options to symbol__calc_lines(), to carry on and pass the percent_type value. Signed-off-by: Jiri Olsa Cc: Alexander Shishkin Cc: David Ahern Cc: Namhyung Kim Cc: Peter Zijlstra Cc: Stephane Eranian Link: http://lkml.kernel.org/r/20180804130521.11408-14-jolsa@kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/annotate.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) (limited to 'tools/perf/util/annotate.c') diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c index 91528a065768..2b06476c79c2 100644 --- a/tools/perf/util/annotate.c +++ b/tools/perf/util/annotate.c @@ -1868,7 +1868,8 @@ int symbol__annotate(struct symbol *sym, struct map *map, return symbol__disassemble(sym, &args); } -static void insert_source_line(struct rb_root *root, struct annotation_line *al) +static void insert_source_line(struct rb_root *root, struct annotation_line *al, + struct annotation_options *opts) { struct annotation_line *iter; struct rb_node **p = &root->rb_node; @@ -1883,7 +1884,7 @@ static void insert_source_line(struct rb_root *root, struct annotation_line *al) if (ret == 0) { for (i = 0; i < al->data_nr; i++) { iter->data[i].percent_sum += annotation_data__percent(&al->data[i], - PERCENT_HITS_LOCAL); + opts->percent_type); } return; } @@ -1896,7 +1897,7 @@ static void insert_source_line(struct rb_root *root, struct annotation_line *al) for (i = 0; i < al->data_nr; i++) { al->data[i].percent_sum = annotation_data__percent(&al->data[i], - PERCENT_HITS_LOCAL); + opts->percent_type); } rb_link_node(&al->rb_node, parent, p); @@ -2372,7 +2373,8 @@ void annotation__update_column_widths(struct annotation *notes) } static void annotation__calc_lines(struct annotation *notes, struct map *map, - struct rb_root *root) + struct rb_root *root, + struct annotation_options *opts) { struct annotation_line *al; struct rb_root tmp_root = RB_ROOT; @@ -2385,7 +2387,7 @@ static void annotation__calc_lines(struct annotation *notes, struct map *map, double percent; percent = annotation_data__percent(&al->data[i], - PERCENT_HITS_LOCAL); + opts->percent_type); if (percent > percent_max) percent_max = percent; @@ -2396,18 +2398,19 @@ static void annotation__calc_lines(struct annotation *notes, struct map *map, al->path = get_srcline(map->dso, notes->start + al->offset, NULL, false, true, notes->start + al->offset); - insert_source_line(&tmp_root, al); + insert_source_line(&tmp_root, al, opts); } resort_source_line(root, &tmp_root); } static void symbol__calc_lines(struct symbol *sym, struct map *map, - struct rb_root *root) + struct rb_root *root, + struct annotation_options *opts) { struct annotation *notes = symbol__annotation(sym); - annotation__calc_lines(notes, map, root); + annotation__calc_lines(notes, map, root, opts); } int symbol__tty_annotate2(struct symbol *sym, struct map *map, @@ -2424,7 +2427,7 @@ int symbol__tty_annotate2(struct symbol *sym, struct map *map, if (opts->print_lines) { srcline_full_filename = opts->full_path; - symbol__calc_lines(sym, map, &source_line); + symbol__calc_lines(sym, map, &source_line, opts); print_summary(&source_line, dso->long_name); } @@ -2451,7 +2454,7 @@ int symbol__tty_annotate(struct symbol *sym, struct map *map, if (opts->print_lines) { srcline_full_filename = opts->full_path; - symbol__calc_lines(sym, map, &source_line); + symbol__calc_lines(sym, map, &source_line, opts); print_summary(&source_line, dso->long_name); } -- cgit v1.2.3-59-g8ed1b From 4c650ddc2e9e8f1d8dc46f13b30b1b9a6017fb02 Mon Sep 17 00:00:00 2001 From: Jiri Olsa Date: Sat, 4 Aug 2018 15:05:15 +0200 Subject: perf annotate: Pass 'struct annotation_options' to map_symbol__annotation_dump() Pass 'struct annotation_options' to map_symbol__annotation_dump(), to carry on and pass the percent_type value. Signed-off-by: Jiri Olsa Cc: Alexander Shishkin Cc: David Ahern Cc: Namhyung Kim Cc: Peter Zijlstra Cc: Stephane Eranian Link: http://lkml.kernel.org/r/20180804130521.11408-15-jolsa@kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/ui/browsers/annotate.c | 4 ++-- tools/perf/util/annotate.c | 42 +++++++++++++++++++++------------------ tools/perf/util/annotate.h | 6 ++++-- 3 files changed, 29 insertions(+), 23 deletions(-) (limited to 'tools/perf/util/annotate.c') diff --git a/tools/perf/ui/browsers/annotate.c b/tools/perf/ui/browsers/annotate.c index 81876c3923d2..cfe611c28987 100644 --- a/tools/perf/ui/browsers/annotate.c +++ b/tools/perf/ui/browsers/annotate.c @@ -115,7 +115,7 @@ static void annotate_browser__write(struct ui_browser *browser, void *entry, int if (!browser->navkeypressed) ops.width += 1; - annotation_line__write(al, notes, &ops); + annotation_line__write(al, notes, &ops, ab->opts); if (ops.current_entry) ab->selection = al; @@ -783,7 +783,7 @@ show_sup_ins: continue; } case 'P': - map_symbol__annotation_dump(ms, evsel); + map_symbol__annotation_dump(ms, evsel, browser->opts); continue; case 't': if (notes->options->show_total_period) { diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c index 2b06476c79c2..850958bb613a 100644 --- a/tools/perf/util/annotate.c +++ b/tools/perf/util/annotate.c @@ -2156,10 +2156,11 @@ static void FILE__write_graph(void *fp, int graph) fputs(s, fp); } -static int symbol__annotate_fprintf2(struct symbol *sym, FILE *fp) +static int symbol__annotate_fprintf2(struct symbol *sym, FILE *fp, + struct annotation_options *opts) { struct annotation *notes = symbol__annotation(sym); - struct annotation_write_ops ops = { + struct annotation_write_ops wops = { .first_line = true, .obj = fp, .set_color = FILE__set_color, @@ -2173,15 +2174,16 @@ static int symbol__annotate_fprintf2(struct symbol *sym, FILE *fp) list_for_each_entry(al, ¬es->src->source, node) { if (annotation_line__filter(al, notes)) continue; - annotation_line__write(al, notes, &ops); + annotation_line__write(al, notes, &wops, opts); fputc('\n', fp); - ops.first_line = false; + wops.first_line = false; } return 0; } -int map_symbol__annotation_dump(struct map_symbol *ms, struct perf_evsel *evsel) +int map_symbol__annotation_dump(struct map_symbol *ms, struct perf_evsel *evsel, + struct annotation_options *opts) { const char *ev_name = perf_evsel__name(evsel); char buf[1024]; @@ -2203,7 +2205,7 @@ int map_symbol__annotation_dump(struct map_symbol *ms, struct perf_evsel *evsel) fprintf(fp, "%s() %s\nEvent: %s\n\n", ms->sym->name, ms->map->dso->long_name, ev_name); - symbol__annotate_fprintf2(ms->sym, fp); + symbol__annotate_fprintf2(ms->sym, fp, opts); fclose(fp); err = 0; @@ -2433,7 +2435,7 @@ int symbol__tty_annotate2(struct symbol *sym, struct map *map, hists__scnprintf_title(hists, buf, sizeof(buf)); fprintf(stdout, "%s\n%s() %s\n", buf, sym->name, dso->long_name); - symbol__annotate_fprintf2(sym, stdout); + symbol__annotate_fprintf2(sym, stdout, opts); annotated_source__purge(symbol__annotation(sym)->src); @@ -2472,7 +2474,8 @@ bool ui__has_annotation(void) static double annotation_line__max_percent(struct annotation_line *al, - struct annotation *notes) + struct annotation *notes, + unsigned int percent_type) { double percent_max = 0.0; int i; @@ -2481,7 +2484,7 @@ static double annotation_line__max_percent(struct annotation_line *al, double percent; percent = annotation_data__percent(&al->data[i], - PERCENT_HITS_LOCAL); + percent_type); if (percent > percent_max) percent_max = percent; @@ -2523,7 +2526,7 @@ call_like: 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, + void *obj, unsigned int percent_type, int (*obj__set_color)(void *obj, int color), void (*obj__set_percent_color)(void *obj, double percent, bool current), int (*obj__set_jumps_percent_color)(void *obj, int nr, bool current), @@ -2531,7 +2534,7 @@ static void __annotation_line__write(struct annotation_line *al, struct annotati void (*obj__write_graph)(void *obj, int graph)) { - double percent_max = annotation_line__max_percent(al, notes); + double percent_max = annotation_line__max_percent(al, notes, percent_type); int pcnt_width = annotation__pcnt_width(notes), cycles_width = annotation__cycles_width(notes); bool show_title = false; @@ -2552,8 +2555,7 @@ static void __annotation_line__write(struct annotation_line *al, struct annotati for (i = 0; i < notes->nr_events; i++) { double percent; - percent = annotation_data__percent(&al->data[i], - PERCENT_HITS_LOCAL); + percent = annotation_data__percent(&al->data[i], percent_type); obj__set_percent_color(obj, percent, current_entry); if (notes->options->show_total_period) { @@ -2680,13 +2682,15 @@ print_addr: } void annotation_line__write(struct annotation_line *al, struct annotation *notes, - struct annotation_write_ops *ops) + struct annotation_write_ops *wops, + struct annotation_options *opts) { - __annotation_line__write(al, notes, ops->first_line, ops->current_entry, - ops->change_color, ops->width, ops->obj, - ops->set_color, ops->set_percent_color, - ops->set_jumps_percent_color, ops->printf, - ops->write_graph); + __annotation_line__write(al, notes, wops->first_line, wops->current_entry, + wops->change_color, wops->width, wops->obj, + opts->percent_type, + wops->set_color, wops->set_percent_color, + wops->set_jumps_percent_color, wops->printf, + wops->write_graph); } int symbol__annotate2(struct symbol *sym, struct map *map, struct perf_evsel *evsel, diff --git a/tools/perf/util/annotate.h b/tools/perf/util/annotate.h index 145dec845f33..3d4579e68d28 100644 --- a/tools/perf/util/annotate.h +++ b/tools/perf/util/annotate.h @@ -185,7 +185,8 @@ struct annotation_write_ops { }; void annotation_line__write(struct annotation_line *al, struct annotation *notes, - struct annotation_write_ops *ops); + struct annotation_write_ops *ops, + struct annotation_options *opts); int __annotation__scnprintf_samples_period(struct annotation *notes, char *bf, size_t size, @@ -351,7 +352,8 @@ void symbol__annotate_zero_histogram(struct symbol *sym, int evidx); void symbol__annotate_decay_histogram(struct symbol *sym, int evidx); void annotated_source__purge(struct annotated_source *as); -int map_symbol__annotation_dump(struct map_symbol *ms, struct perf_evsel *evsel); +int map_symbol__annotation_dump(struct map_symbol *ms, struct perf_evsel *evsel, + struct annotation_options *opts); bool ui__has_annotation(void); -- cgit v1.2.3-59-g8ed1b From addba8b66f9101b0e55a151fc543ff35990bc8ef Mon Sep 17 00:00:00 2001 From: Jiri Olsa Date: Sat, 4 Aug 2018 15:05:18 +0200 Subject: perf annotate: Make local period the default percent type Currently we display the percentages in annotation output based on number of samples hits. Switching it to period based percentage by default, because it corresponds more to the time spent on the line. Signed-off-by: Jiri Olsa Tested-by: Arnaldo Carvalho de Melo Cc: Alexander Shishkin Cc: David Ahern Cc: Namhyung Kim Cc: Peter Zijlstra Cc: Stephane Eranian Link: http://lkml.kernel.org/r/20180804130521.11408-18-jolsa@kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/annotate.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tools/perf/util/annotate.c') diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c index 850958bb613a..05d15629afd0 100644 --- a/tools/perf/util/annotate.c +++ b/tools/perf/util/annotate.c @@ -49,7 +49,7 @@ struct annotation_options annotation__default_options = { .jump_arrows = true, .annotate_src = true, .offset_level = ANNOTATION__OFFSET_JUMP_TARGETS, - .percent_type = PERCENT_HITS_LOCAL, + .percent_type = PERCENT_PERIOD_LOCAL, }; static regex_t file_lineno; -- cgit v1.2.3-59-g8ed1b From 4c04868fbe931ec315ad34bb7e28e5cf725f88e4 Mon Sep 17 00:00:00 2001 From: Jiri Olsa Date: Sat, 4 Aug 2018 15:05:19 +0200 Subject: perf annotate: Display percent type in stdio output In following patches we will allow to switch percent type even for stdio annotation outputs. Adding the percent type value into the annotation outputs title. $ perf annotate --stdio Percent | Sou ... instructions:u } (2805 samples, percent: local period) --------------------------- ... ------------------------------------------------------ ... $ perf annotate --stdio2 Samples: 2K of events 'anon ... count (approx.): 156525487, [percent: local period] safe_write.c() /usr/bin/yes Percent ... Signed-off-by: Jiri Olsa Tested-by: Arnaldo Carvalho de Melo Cc: Alexander Shishkin Cc: David Ahern Cc: Namhyung Kim Cc: Peter Zijlstra Cc: Stephane Eranian Link: http://lkml.kernel.org/r/20180804130521.11408-19-jolsa@kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/annotate.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'tools/perf/util/annotate.c') diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c index 05d15629afd0..6316fa96d984 100644 --- a/tools/perf/util/annotate.c +++ b/tools/perf/util/annotate.c @@ -2056,10 +2056,12 @@ int symbol__annotate_printf(struct symbol *sym, struct map *map, evsel_name = buf; } - graph_dotted_len = printf(" %-*.*s| Source code & Disassembly of %s for %s (%" PRIu64 " samples)\n", + graph_dotted_len = printf(" %-*.*s| Source code & Disassembly of %s for %s (%" PRIu64 " samples, " + "percent: %s)\n", width, width, symbol_conf.show_total_period ? "Period" : symbol_conf.show_nr_samples ? "Samples" : "Percent", - d_filename, evsel_name, h->nr_samples); + d_filename, evsel_name, h->nr_samples, + percent_type_str(opts->percent_type)); printf("%-*.*s----\n", graph_dotted_len, graph_dotted_len, graph_dotted_line); @@ -2434,7 +2436,8 @@ int symbol__tty_annotate2(struct symbol *sym, struct map *map, } hists__scnprintf_title(hists, buf, sizeof(buf)); - fprintf(stdout, "%s\n%s() %s\n", buf, sym->name, dso->long_name); + fprintf(stdout, "%s, [percent: %s]\n%s() %s\n", + buf, percent_type_str(opts->percent_type), sym->name, dso->long_name); symbol__annotate_fprintf2(sym, stdout, opts); annotated_source__purge(symbol__annotation(sym)->src); -- cgit v1.2.3-59-g8ed1b From 88c211907720f9eb23308401305aefa25392417f Mon Sep 17 00:00:00 2001 From: Jiri Olsa Date: Sat, 4 Aug 2018 15:05:20 +0200 Subject: perf annotate: Add --percent-type option Add --percent-type option to set annotation percent type from following choices: global-period, local-period, global-hits, local-hits Examples: $ perf annotate --percent-type period-local --stdio | head -1 Percent | Source code ... es, percent: local period) $ perf annotate --percent-type hits-local --stdio | head -1 Percent | Source code ... es, percent: local hits) $ perf annotate --percent-type hits-global --stdio | head -1 Percent | Source code ... es, percent: global hits) $ perf annotate --percent-type period-global --stdio | head -1 Percent | Source code ... es, percent: global period) The local/global keywords set if the percentage is computed in the scope of the function (local) or the whole data (global). The period/hits keywords set the base the percentage is computed on - the samples period or the number of samples (hits). Signed-off-by: Jiri Olsa Tested-by: Arnaldo Carvalho de Melo Cc: Alexander Shishkin Cc: David Ahern Cc: Namhyung Kim Cc: Peter Zijlstra Cc: Stephane Eranian Link: http://lkml.kernel.org/r/20180804130521.11408-20-jolsa@kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/Documentation/perf-annotate.txt | 9 ++++++ tools/perf/builtin-annotate.c | 4 +++ tools/perf/util/annotate.c | 52 ++++++++++++++++++++++++++++++ tools/perf/util/annotate.h | 2 ++ 4 files changed, 67 insertions(+) (limited to 'tools/perf/util/annotate.c') diff --git a/tools/perf/Documentation/perf-annotate.txt b/tools/perf/Documentation/perf-annotate.txt index 749cc6055dac..e8c972f89357 100644 --- a/tools/perf/Documentation/perf-annotate.txt +++ b/tools/perf/Documentation/perf-annotate.txt @@ -118,6 +118,15 @@ OPTIONS --group:: Show event group information together +--percent-type:: + Set annotation percent type from following choices: + global-period, local-period, global-hits, local-hits + + The local/global keywords set if the percentage is computed + in the scope of the function (local) or the whole data (global). + The period/hits keywords set the base the percentage is computed + on - the samples period or the number of samples (hits). + SEE ALSO -------- linkperf:perf-record[1], linkperf:perf-report[1] diff --git a/tools/perf/builtin-annotate.c b/tools/perf/builtin-annotate.c index 8180319285af..830481b8db26 100644 --- a/tools/perf/builtin-annotate.c +++ b/tools/perf/builtin-annotate.c @@ -542,6 +542,10 @@ int cmd_annotate(int argc, const char **argv) OPT_CALLBACK_DEFAULT(0, "stdio-color", NULL, "mode", "'always' (default), 'never' or 'auto' only applicable to --stdio mode", stdio__config_color, "always"), + OPT_CALLBACK(0, "percent-type", &annotate.opts, "local-period", + "Set percent type local/global-period/hits", + annotate_parse_percent_type), + OPT_END() }; int ret; diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c index 6316fa96d984..e4268b948e0e 100644 --- a/tools/perf/util/annotate.c +++ b/tools/perf/util/annotate.c @@ -2799,3 +2799,55 @@ void annotation_config__init(void) annotation__default_options.show_total_period = symbol_conf.show_total_period; annotation__default_options.show_nr_samples = symbol_conf.show_nr_samples; } + +static unsigned int parse_percent_type(char *str1, char *str2) +{ + unsigned int type = (unsigned int) -1; + + if (!strcmp("period", str1)) { + if (!strcmp("local", str2)) + type = PERCENT_PERIOD_LOCAL; + else if (!strcmp("global", str2)) + type = PERCENT_PERIOD_GLOBAL; + } + + if (!strcmp("hits", str1)) { + if (!strcmp("local", str2)) + type = PERCENT_HITS_LOCAL; + else if (!strcmp("global", str2)) + type = PERCENT_HITS_GLOBAL; + } + + return type; +} + +int annotate_parse_percent_type(const struct option *opt, const char *_str, + int unset __maybe_unused) +{ + struct annotation_options *opts = opt->value; + unsigned int type; + char *str1, *str2; + int err = -1; + + str1 = strdup(_str); + if (!str1) + return -ENOMEM; + + str2 = strchr(str1, '-'); + if (!str2) + goto out; + + *str2++ = 0; + + type = parse_percent_type(str1, str2); + if (type == (unsigned int) -1) + type = parse_percent_type(str2, str1); + if (type != (unsigned int) -1) { + opts->percent_type = type; + err = 0; + } + +out: + free(str1); + return err; +} diff --git a/tools/perf/util/annotate.h b/tools/perf/util/annotate.h index 760a6678edff..005a5fe8a8c6 100644 --- a/tools/perf/util/annotate.h +++ b/tools/perf/util/annotate.h @@ -397,4 +397,6 @@ static inline int symbol__tui_annotate(struct symbol *sym __maybe_unused, void annotation_config__init(void); +int annotate_parse_percent_type(const struct option *opt, const char *_str, + int unset); #endif /* __PERF_ANNOTATE_H */ -- cgit v1.2.3-59-g8ed1b