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

perf kvm: Add TUI mode for stat report

Since we have supported histograms list and prepared the dimensions in
the tool, this patch adds TUI mode for stat report. It also adds UI
progress for sorting for better user experience.

Committer notes:

kvm_display() is only used by functions enclosed in:

#if defined(HAVE_KVM_STAT_SUPPORT) && defined(HAVE_LIBTRACEEVENT)

So do it with this new function as well.

Signed-off-by: Leo Yan <leo.yan@linaro.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: James Clark <james.clark@arm.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: John Garry <john.g.garry@oracle.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: linux-arm-kernel@lists.infradead.org
Link: https://lore.kernel.org/r/20230315145112.186603-2-leo.yan@linaro.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Leo Yan and committed by
Arnaldo Carvalho de Melo
984f16cd 32a5c2b8

+108 -2
+107 -2
tools/perf/builtin-kvm.c
··· 23 23 #include "util/data.h" 24 24 #include "util/ordered-events.h" 25 25 #include "util/kvm-stat.h" 26 + #include "ui/browsers/hists.h" 27 + #include "ui/progress.h" 26 28 #include "ui/ui.h" 27 29 #include "util/string2.h" 28 30 ··· 498 496 499 497 static int kvm_hists__init(void) 500 498 { 499 + kvm_hists.list.nr_header_lines = 1; 501 500 __hists__init(&kvm_hists.hists, &kvm_hists.list); 502 501 perf_hpp_list__init(&kvm_hists.list); 503 502 return kvm_hpp_list__parse(&kvm_hists.list, NULL, "ev_name"); ··· 509 506 perf_hpp__reset_output_field(&kvm_hists.list); 510 507 return kvm_hpp_list__parse(&kvm_hists.list, output, sort); 511 508 } 509 + static void print_result(struct perf_kvm_stat *kvm); 510 + 511 + #ifdef HAVE_SLANG_SUPPORT 512 + static void kvm_browser__update_nr_entries(struct hist_browser *hb) 513 + { 514 + struct rb_node *nd = rb_first_cached(&hb->hists->entries); 515 + u64 nr_entries = 0; 516 + 517 + for (; nd; nd = rb_next(nd)) { 518 + struct hist_entry *he = rb_entry(nd, struct hist_entry, 519 + rb_node); 520 + 521 + if (!he->filtered) 522 + nr_entries++; 523 + } 524 + 525 + hb->nr_non_filtered_entries = nr_entries; 526 + } 527 + 528 + static int kvm_browser__title(struct hist_browser *browser, 529 + char *buf, size_t size) 530 + { 531 + scnprintf(buf, size, "KVM event statistics (%lu entries)", 532 + browser->nr_non_filtered_entries); 533 + return 0; 534 + } 535 + 536 + static struct hist_browser* 537 + perf_kvm_browser__new(struct hists *hists) 538 + { 539 + struct hist_browser *browser = hist_browser__new(hists); 540 + 541 + if (browser) 542 + browser->title = kvm_browser__title; 543 + 544 + return browser; 545 + } 546 + 547 + static int kvm__hists_browse(struct hists *hists) 548 + { 549 + struct hist_browser *browser; 550 + int key = -1; 551 + 552 + browser = perf_kvm_browser__new(hists); 553 + if (browser == NULL) 554 + return -1; 555 + 556 + /* reset abort key so that it can get Ctrl-C as a key */ 557 + SLang_reset_tty(); 558 + SLang_init_tty(0, 0, 0); 559 + 560 + kvm_browser__update_nr_entries(browser); 561 + 562 + while (1) { 563 + key = hist_browser__run(browser, "? - help", true, 0); 564 + 565 + switch (key) { 566 + case 'q': 567 + goto out; 568 + default: 569 + break; 570 + } 571 + } 572 + 573 + out: 574 + hist_browser__delete(browser); 575 + return 0; 576 + } 577 + 578 + static void kvm_display(struct perf_kvm_stat *kvm) 579 + { 580 + if (!use_browser) 581 + print_result(kvm); 582 + else 583 + kvm__hists_browse(&kvm_hists.hists); 584 + } 585 + 586 + #else 587 + 588 + static void kvm_display(struct perf_kvm_stat *kvm) 589 + { 590 + use_browser = 0; 591 + print_result(kvm); 592 + } 593 + 594 + #endif /* HAVE_SLANG_SUPPORT */ 595 + 512 596 #endif // defined(HAVE_KVM_STAT_SUPPORT) && defined(HAVE_LIBTRACEEVENT) 513 597 514 598 static const char *get_filename_for_perf_kvm(void) ··· 1062 972 1063 973 static void sort_result(struct perf_kvm_stat *kvm) 1064 974 { 975 + struct ui_progress prog; 1065 976 const char *output_columns = "ev_name,sample,percent_sample," 1066 977 "time,percent_time,max_t,min_t,mean_t"; 1067 978 1068 979 kvm_hists__reinit(output_columns, kvm->sort_key); 980 + ui_progress__init(&prog, kvm_hists.hists.nr_entries, "Sorting..."); 1069 981 hists__collapse_resort(&kvm_hists.hists, NULL); 1070 982 hists__output_resort_cb(&kvm_hists.hists, NULL, filter_cb); 983 + ui_progress__finish(); 1071 984 } 1072 985 1073 986 static void print_vcpu_info(struct perf_kvm_stat *kvm) ··· 1672 1579 if (!register_kvm_events_ops(kvm)) 1673 1580 goto exit; 1674 1581 1675 - setup_pager(); 1582 + if (kvm->use_stdio) { 1583 + use_browser = 0; 1584 + setup_pager(); 1585 + } else { 1586 + use_browser = 1; 1587 + } 1588 + 1589 + setup_browser(false); 1676 1590 1677 1591 kvm_hists__init(); 1678 1592 ··· 1688 1588 goto exit; 1689 1589 1690 1590 sort_result(kvm); 1691 - print_result(kvm); 1591 + kvm_display(kvm); 1692 1592 1693 1593 exit: 1694 1594 return ret; ··· 1795 1695 OPT_STRING('p', "pid", &kvm->opts.target.pid, "pid", 1796 1696 "analyze events only for given process id(s)"), 1797 1697 OPT_BOOLEAN('f', "force", &kvm->force, "don't complain, do it"), 1698 + OPT_BOOLEAN(0, "stdio", &kvm->use_stdio, "use the stdio interface"), 1798 1699 OPT_END() 1799 1700 }; 1800 1701 ··· 1812 1711 usage_with_options(kvm_events_report_usage, 1813 1712 kvm_events_report_options); 1814 1713 } 1714 + 1715 + #ifndef HAVE_SLANG_SUPPORT 1716 + kvm->use_stdio = true; 1717 + #endif 1815 1718 1816 1719 if (!kvm->opts.target.pid) 1817 1720 kvm->opts.target.system_wide = true;
+1
tools/perf/util/kvm-stat.h
··· 103 103 unsigned int display_time; 104 104 bool live; 105 105 bool force; 106 + bool use_stdio; 106 107 }; 107 108 108 109 struct kvm_reg_events_ops {