diff options
| author | Namhyung Kim <namhyung.kim@lge.com> | 2012-09-02 22:53:09 -0400 |
|---|---|---|
| committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2012-09-08 12:20:13 -0400 |
| commit | f5951d56a2ab4181b96806a4746895aaa5a3d72e (patch) | |
| tree | bcc13e3c0d639fb4098db5eb69a8a52e465eb226 /tools/perf | |
| parent | 7e62ef44e89e7b7f2c48090a048f2a5dffa838c7 (diff) | |
perf hists browser: Use perf_hpp__format functions
Override hpp->color functions for TUI. Because line coloring is done
outside of the function, it just sets the percent value and pass it.
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: http://lkml.kernel.org/r/1346640790-17197-5-git-send-email-namhyung@kernel.org
[ committer note: Keep previous layout by showing the overhead at column 1 ]
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf')
| -rw-r--r-- | tools/perf/ui/browsers/hists.c | 96 | ||||
| -rw-r--r-- | tools/perf/ui/tui/setup.c | 4 |
2 files changed, 77 insertions, 23 deletions
diff --git a/tools/perf/ui/browsers/hists.c b/tools/perf/ui/browsers/hists.c index 81bd8c2af730..5a5739bbe6ac 100644 --- a/tools/perf/ui/browsers/hists.c +++ b/tools/perf/ui/browsers/hists.c | |||
| @@ -28,6 +28,8 @@ struct hist_browser { | |||
| 28 | bool has_symbols; | 28 | bool has_symbols; |
| 29 | }; | 29 | }; |
| 30 | 30 | ||
| 31 | extern void hist_browser__init_hpp(void); | ||
| 32 | |||
| 31 | static int hists__browser_title(struct hists *hists, char *bf, size_t size, | 33 | static int hists__browser_title(struct hists *hists, char *bf, size_t size, |
| 32 | const char *ev_name); | 34 | const char *ev_name); |
| 33 | 35 | ||
| @@ -563,14 +565,47 @@ static int hist_browser__show_callchain(struct hist_browser *browser, | |||
| 563 | return row - first_row; | 565 | return row - first_row; |
| 564 | } | 566 | } |
| 565 | 567 | ||
| 568 | #define HPP__COLOR_FN(_name, _field) \ | ||
| 569 | static int hist_browser__hpp_color_ ## _name(struct perf_hpp *hpp, \ | ||
| 570 | struct hist_entry *he) \ | ||
| 571 | { \ | ||
| 572 | double percent = 100.0 * he->_field / hpp->total_period; \ | ||
| 573 | *(double *)hpp->ptr = percent; \ | ||
| 574 | return scnprintf(hpp->buf, hpp->size, "%5.2f%%", percent); \ | ||
| 575 | } | ||
| 576 | |||
| 577 | HPP__COLOR_FN(overhead, period) | ||
| 578 | HPP__COLOR_FN(overhead_sys, period_sys) | ||
| 579 | HPP__COLOR_FN(overhead_us, period_us) | ||
| 580 | HPP__COLOR_FN(overhead_guest_sys, period_guest_sys) | ||
| 581 | HPP__COLOR_FN(overhead_guest_us, period_guest_us) | ||
| 582 | |||
| 583 | #undef HPP__COLOR_FN | ||
| 584 | |||
| 585 | void hist_browser__init_hpp(void) | ||
| 586 | { | ||
| 587 | perf_hpp__init(false, false); | ||
| 588 | |||
| 589 | perf_hpp__format[PERF_HPP__OVERHEAD].color = | ||
| 590 | hist_browser__hpp_color_overhead; | ||
| 591 | perf_hpp__format[PERF_HPP__OVERHEAD_SYS].color = | ||
| 592 | hist_browser__hpp_color_overhead_sys; | ||
| 593 | perf_hpp__format[PERF_HPP__OVERHEAD_US].color = | ||
| 594 | hist_browser__hpp_color_overhead_us; | ||
| 595 | perf_hpp__format[PERF_HPP__OVERHEAD_GUEST_SYS].color = | ||
| 596 | hist_browser__hpp_color_overhead_guest_sys; | ||
| 597 | perf_hpp__format[PERF_HPP__OVERHEAD_GUEST_US].color = | ||
| 598 | hist_browser__hpp_color_overhead_guest_us; | ||
| 599 | } | ||
| 600 | |||
| 566 | static int hist_browser__show_entry(struct hist_browser *browser, | 601 | static int hist_browser__show_entry(struct hist_browser *browser, |
| 567 | struct hist_entry *entry, | 602 | struct hist_entry *entry, |
| 568 | unsigned short row) | 603 | unsigned short row) |
| 569 | { | 604 | { |
| 570 | char s[256]; | 605 | char s[256]; |
| 571 | double percent; | 606 | double percent; |
| 572 | int printed = 0; | 607 | int i, printed = 0; |
| 573 | int width = browser->b.width - 6; /* The percentage */ | 608 | int width = browser->b.width - 1; |
| 574 | char folded_sign = ' '; | 609 | char folded_sign = ' '; |
| 575 | bool current_entry = ui_browser__is_current_entry(&browser->b, row); | 610 | bool current_entry = ui_browser__is_current_entry(&browser->b, row); |
| 576 | off_t row_offset = entry->row_offset; | 611 | off_t row_offset = entry->row_offset; |
| @@ -586,35 +621,50 @@ static int hist_browser__show_entry(struct hist_browser *browser, | |||
| 586 | } | 621 | } |
| 587 | 622 | ||
| 588 | if (row_offset == 0) { | 623 | if (row_offset == 0) { |
| 589 | hist_entry__sort_snprintf(entry, s, sizeof(s), browser->hists); | 624 | struct perf_hpp hpp = { |
| 590 | percent = (entry->period * 100.0) / browser->hists->stats.total_period; | 625 | .buf = s, |
| 626 | .size = sizeof(s), | ||
| 627 | .total_period = browser->hists->stats.total_period, | ||
| 628 | }; | ||
| 591 | 629 | ||
| 592 | ui_browser__set_percent_color(&browser->b, percent, current_entry); | 630 | ui_browser__gotorc(&browser->b, row, 1); |
| 593 | ui_browser__gotorc(&browser->b, row, 0); | ||
| 594 | if (symbol_conf.use_callchain) { | ||
| 595 | slsmg_printf("%c ", folded_sign); | ||
| 596 | width -= 2; | ||
| 597 | } | ||
| 598 | 631 | ||
| 599 | slsmg_printf(" %5.2f%%", percent); | 632 | for (i = 0; i < PERF_HPP__MAX_INDEX; i++) { |
| 633 | if (!perf_hpp__format[i].cond) | ||
| 634 | continue; | ||
| 600 | 635 | ||
| 601 | /* The scroll bar isn't being used */ | 636 | if (i) { |
| 602 | if (!browser->b.navkeypressed) | 637 | slsmg_printf(" "); |
| 603 | width += 1; | 638 | width -= 2; |
| 639 | } | ||
| 604 | 640 | ||
| 605 | if (!current_entry || !browser->b.navkeypressed) | 641 | if (perf_hpp__format[i].color) { |
| 606 | ui_browser__set_color(&browser->b, HE_COLORSET_NORMAL); | 642 | hpp.ptr = &percent; |
| 643 | /* It will set percent for us. See HPP__COLOR_FN above. */ | ||
| 644 | width -= perf_hpp__format[i].color(&hpp, entry); | ||
| 607 | 645 | ||
| 608 | if (symbol_conf.show_nr_samples) { | 646 | ui_browser__set_percent_color(&browser->b, percent, current_entry); |
| 609 | slsmg_printf(" %11u", entry->nr_events); | 647 | |
| 610 | width -= 12; | 648 | if (i == 0 && symbol_conf.use_callchain) { |
| 611 | } | 649 | slsmg_printf("%c ", folded_sign); |
| 650 | width -= 2; | ||
| 651 | } | ||
| 652 | |||
| 653 | slsmg_printf("%s", s); | ||
| 612 | 654 | ||
| 613 | if (symbol_conf.show_total_period) { | 655 | if (!current_entry || !browser->b.navkeypressed) |
| 614 | slsmg_printf(" %12" PRIu64, entry->period); | 656 | ui_browser__set_color(&browser->b, HE_COLORSET_NORMAL); |
| 615 | width -= 13; | 657 | } else { |
| 658 | width -= perf_hpp__format[i].entry(&hpp, entry); | ||
| 659 | slsmg_printf("%s", s); | ||
| 660 | } | ||
| 616 | } | 661 | } |
| 617 | 662 | ||
| 663 | /* The scroll bar isn't being used */ | ||
| 664 | if (!browser->b.navkeypressed) | ||
| 665 | width += 1; | ||
| 666 | |||
| 667 | hist_entry__sort_snprintf(entry, s, sizeof(s), browser->hists); | ||
| 618 | slsmg_write_nstring(s, width); | 668 | slsmg_write_nstring(s, width); |
| 619 | ++row; | 669 | ++row; |
| 620 | ++printed; | 670 | ++printed; |
diff --git a/tools/perf/ui/tui/setup.c b/tools/perf/ui/tui/setup.c index 4c936e09931c..4dc0887c04f1 100644 --- a/tools/perf/ui/tui/setup.c +++ b/tools/perf/ui/tui/setup.c | |||
| @@ -15,6 +15,8 @@ static volatile int ui__need_resize; | |||
| 15 | 15 | ||
| 16 | extern struct perf_error_ops perf_tui_eops; | 16 | extern struct perf_error_ops perf_tui_eops; |
| 17 | 17 | ||
| 18 | extern void hist_browser__init_hpp(void); | ||
| 19 | |||
| 18 | void ui__refresh_dimensions(bool force) | 20 | void ui__refresh_dimensions(bool force) |
| 19 | { | 21 | { |
| 20 | if (force || ui__need_resize) { | 22 | if (force || ui__need_resize) { |
| @@ -124,6 +126,8 @@ int ui__init(void) | |||
| 124 | signal(SIGTERM, ui__signal); | 126 | signal(SIGTERM, ui__signal); |
| 125 | 127 | ||
| 126 | perf_error__register(&perf_tui_eops); | 128 | perf_error__register(&perf_tui_eops); |
| 129 | |||
| 130 | hist_browser__init_hpp(); | ||
| 127 | out: | 131 | out: |
| 128 | return err; | 132 | return err; |
| 129 | } | 133 | } |
