Skip to content

Commit 7fa46cb

Browse files
Jin Yaoacmel
authored andcommitted
perf report: Sort by sampled cycles percent per block for tui
Previous patch has implemented a new option "--total-cycles". But only stdio mode is supported. This patch supports the tui mode and support '--percent-limit'. For example, perf record -b ./div perf report --total-cycles --percent-limit 1 # Samples: 2753248 of event 'cycles' Sampled Cycles% Sampled Cycles Avg Cycles% Avg Cycles [Program Block Range] Shared Object 26.04% 2.8M 0.40% 18 [div.c:42 -> div.c:39] div 15.17% 1.2M 0.16% 7 [random_r.c:357 -> random_r.c:380] libc-2.27.so 5.11% 402.0K 0.04% 2 [div.c:27 -> div.c:28] div 4.87% 381.6K 0.04% 2 [random.c:288 -> random.c:291] libc-2.27.so 4.53% 381.0K 0.04% 2 [div.c:40 -> div.c:40] div 3.85% 300.9K 0.02% 1 [div.c:22 -> div.c:25] div 3.08% 241.1K 0.02% 1 [rand.c:26 -> rand.c:27] libc-2.27.so 3.06% 240.0K 0.02% 1 [random.c:291 -> random.c:291] libc-2.27.so 2.78% 215.7K 0.02% 1 [random.c:298 -> random.c:298] libc-2.27.so 2.52% 198.3K 0.02% 1 [random.c:293 -> random.c:293] libc-2.27.so 2.36% 184.8K 0.02% 1 [rand.c:28 -> rand.c:28] libc-2.27.so 2.33% 180.5K 0.02% 1 [random.c:295 -> random.c:295] libc-2.27.so 2.28% 176.7K 0.02% 1 [random.c:295 -> random.c:295] libc-2.27.so 2.20% 168.8K 0.02% 1 [rand@plt+0 -> rand@plt+0] div 1.98% 158.2K 0.02% 1 [random_r.c:388 -> random_r.c:388] libc-2.27.so 1.57% 123.3K 0.02% 1 [div.c:42 -> div.c:44] div 1.44% 116.0K 0.42% 19 [random_r.c:357 -> random_r.c:394] libc-2.27.so -------------------------------------------------- v7: --- 1. Since we have used use_browser in report__browse_block_hists to support stdio mode, now we also add supporting for tui. 2. Move block tui browser code from ui/browsers/hists.c to block-info.c. v6: --- Create report__tui_browse_block_hists in block-info.c (codes are moved from builtin-report.c). v5: --- Fix a crash issue when running perf report without '--total-cycles'. The issue is because the internal flag is renamed from 'total_cycles' to 'total_cycles_mode' in previous patch but this patch still uses 'total_cycles' to check if the '--total-cycles' option is enabled, which causes the code to be inconsistent. v4: --- Since the block collection is moved out of printing in previous patch, this patch is updated accordingly for tui supporting. v3: --- Minor change since the function name is changed: block_total_cycles_percent -> block_info__total_cycles_percent Signed-off-by: Jin Yao <yao.jin@linux.intel.com> Reviewed-by: Jiri Olsa <jolsa@kernel.org> Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com> Cc: Andi Kleen <ak@linux.intel.com> Cc: Jin Yao <yao.jin@intel.com> Cc: Kan Liang <kan.liang@linux.intel.com> Cc: Peter Zijlstra <peterz@infradead.org> Link: http://lore.kernel.org/lkml/20191107074719.26139-8-yao.jin@linux.intel.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
1 parent 0b49f83 commit 7fa46cb

4 files changed

Lines changed: 103 additions & 7 deletions

File tree

‎tools/perf/builtin-report.c‎

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,22 @@ static size_t hists__fprintf_nr_sample_events(struct hists *hists, struct report
485485
return ret + fprintf(fp, "\n#\n");
486486
}
487487

488+
static int perf_evlist__tui_block_hists_browse(struct evlist *evlist,
489+
struct report *rep)
490+
{
491+
struct evsel *pos;
492+
int i = 0, ret;
493+
494+
evlist__for_each_entry(evlist, pos) {
495+
ret = report__browse_block_hists(&rep->block_reports[i++].hist,
496+
rep->min_percent, pos);
497+
if (ret != 0)
498+
return ret;
499+
}
500+
501+
return 0;
502+
}
503+
488504
static int perf_evlist__tty_browse_hists(struct evlist *evlist,
489505
struct report *rep,
490506
const char *help)
@@ -595,6 +611,11 @@ static int report__browse_hists(struct report *rep)
595611

596612
switch (use_browser) {
597613
case 1:
614+
if (rep->total_cycles_mode) {
615+
ret = perf_evlist__tui_block_hists_browse(evlist, rep);
616+
break;
617+
}
618+
598619
ret = perf_evlist__tui_browse_hists(evlist, help, NULL,
599620
rep->min_percent,
600621
&session->header.env,
@@ -1396,12 +1417,8 @@ int cmd_report(int argc, const char **argv)
13961417
if (report.total_cycles_mode) {
13971418
if (sort__mode != SORT_MODE__BRANCH)
13981419
report.total_cycles_mode = false;
1399-
else if (!report.use_stdio) {
1400-
pr_err("Error: --total-cycles can be only used together with --stdio\n");
1401-
goto error;
1402-
} else {
1420+
else
14031421
sort_order = "sym";
1404-
}
14051422
}
14061423

14071424
if (strcmp(input_name, "-") != 0)

‎tools/perf/ui/browsers/hists.c‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "../../util/sort.h"
2727
#include "../../util/top.h"
2828
#include "../../util/thread.h"
29+
#include "../../util/block-info.h"
2930
#include "../../arch/common.h"
3031
#include "../../perf.h"
3132

@@ -1783,7 +1784,11 @@ static unsigned int hist_browser__refresh(struct ui_browser *browser)
17831784
continue;
17841785
}
17851786

1786-
percent = hist_entry__get_percent_limit(h);
1787+
if (symbol_conf.report_individual_block)
1788+
percent = block_info__total_cycles_percent(h);
1789+
else
1790+
percent = hist_entry__get_percent_limit(h);
1791+
17871792
if (percent < hb->min_pcnt)
17881793
continue;
17891794

‎tools/perf/ui/browsers/hists.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "ui/browser.h"
66

77
struct annotation_options;
8+
struct evsel;
89

910
struct hist_browser {
1011
struct ui_browser b;
@@ -15,6 +16,7 @@ struct hist_browser {
1516
struct pstack *pstack;
1617
struct perf_env *env;
1718
struct annotation_options *annotation_opts;
19+
struct evsel *block_evsel;
1820
int print_seq;
1921
bool show_dso;
2022
bool show_headers;

‎tools/perf/util/block-info.c‎

Lines changed: 73 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "map.h"
1111
#include "srcline.h"
1212
#include "evlist.h"
13+
#include "ui/browsers/hists.h"
1314

1415
static struct block_header_column {
1516
const char *name;
@@ -438,16 +439,87 @@ struct block_report *block_info__create_report(struct evlist *evlist,
438439
return block_reports;
439440
}
440441

442+
#ifdef HAVE_SLANG_SUPPORT
443+
static int block_hists_browser__title(struct hist_browser *browser, char *bf,
444+
size_t size)
445+
{
446+
struct hists *hists = evsel__hists(browser->block_evsel);
447+
const char *evname = perf_evsel__name(browser->block_evsel);
448+
unsigned long nr_samples = hists->stats.nr_events[PERF_RECORD_SAMPLE];
449+
int ret;
450+
451+
ret = scnprintf(bf, size, "# Samples: %lu", nr_samples);
452+
if (evname)
453+
scnprintf(bf + ret, size - ret, " of event '%s'", evname);
454+
455+
return 0;
456+
}
457+
458+
static int block_hists_tui_browse(struct block_hist *bh, struct evsel *evsel,
459+
float min_percent)
460+
{
461+
struct hists *hists = &bh->block_hists;
462+
struct hist_browser *browser;
463+
int key = -1;
464+
static const char help[] =
465+
" q Quit \n";
466+
467+
browser = hist_browser__new(hists);
468+
if (!browser)
469+
return -1;
470+
471+
browser->block_evsel = evsel;
472+
browser->title = block_hists_browser__title;
473+
browser->min_pcnt = min_percent;
474+
475+
/* reset abort key so that it can get Ctrl-C as a key */
476+
SLang_reset_tty();
477+
SLang_init_tty(0, 0, 0);
478+
479+
while (1) {
480+
key = hist_browser__run(browser, "? - help", true);
481+
482+
switch (key) {
483+
case 'q':
484+
goto out;
485+
case '?':
486+
ui_browser__help_window(&browser->b, help);
487+
break;
488+
default:
489+
break;
490+
}
491+
}
492+
493+
out:
494+
hist_browser__delete(browser);
495+
return 0;
496+
}
497+
#else
498+
static int block_hists_tui_browse(struct block_hist *bh __maybe_unused,
499+
struct evsel *evsel __maybe_unused,
500+
float min_percent __maybe_unused)
501+
{
502+
return 0;
503+
}
504+
#endif
505+
441506
int report__browse_block_hists(struct block_hist *bh, float min_percent,
442-
struct evsel *evsel __maybe_unused)
507+
struct evsel *evsel)
443508
{
509+
int ret;
510+
444511
switch (use_browser) {
445512
case 0:
446513
symbol_conf.report_individual_block = true;
447514
hists__fprintf(&bh->block_hists, true, 0, 0, min_percent,
448515
stdout, true);
449516
hists__delete_entries(&bh->block_hists);
450517
return 0;
518+
case 1:
519+
symbol_conf.report_individual_block = true;
520+
ret = block_hists_tui_browse(bh, evsel, min_percent);
521+
hists__delete_entries(&bh->block_hists);
522+
return ret;
451523
default:
452524
return -1;
453525
}

0 commit comments

Comments
 (0)