aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorNamhyung Kim <namhyung@kernel.org>2014-03-02 20:14:05 -0500
committerArnaldo Carvalho de Melo <acme@redhat.com>2014-03-14 17:08:39 -0400
commit2f6d9009af1df0f7cba1fdfe012a089babd8c747 (patch)
tree2877d4532317b27036989960145581f42ab53779 /tools
parenta0088adcd651b8eb1a9ca9c7e6ebe1c2c5fb6273 (diff)
perf ui/tui: Reuse generic __hpp__fmt() code
The __hpp__color_fmt used in the TUI code can be replace by the generic code with small change in print_fn callback. And it also needs to move callback function to the generic __hpp__fmt(). No functional changes intended. Signed-off-by: Namhyung Kim <namhyung@kernel.org> Cc: Andi Kleen <andi@firstfloor.org> Cc: David Ahern <dsahern@gmail.com> Cc: Ingo Molnar <mingo@kernel.org> Cc: Jiri Olsa <jolsa@redhat.com> Cc: Namhyung Kim <namhyung.kim@lge.com> Cc: Paul Mackerras <paulus@samba.org> Cc: Peter Zijlstra <a.p.zijlstra@chello.nl> Link: http://lkml.kernel.org/r/1393809254-4480-5-git-send-email-namhyung@kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools')
-rw-r--r--tools/perf/ui/browsers/hists.c122
-rw-r--r--tools/perf/ui/gtk/hists.c2
-rw-r--r--tools/perf/ui/hist.c26
-rw-r--r--tools/perf/util/hist.h4
4 files changed, 63 insertions, 91 deletions
diff --git a/tools/perf/ui/browsers/hists.c b/tools/perf/ui/browsers/hists.c
index b720b92eba6e..7ec871af3f6f 100644
--- a/tools/perf/ui/browsers/hists.c
+++ b/tools/perf/ui/browsers/hists.c
@@ -587,95 +587,52 @@ struct hpp_arg {
587 bool current_entry; 587 bool current_entry;
588}; 588};
589 589
590static int __hpp__color_callchain(struct hpp_arg *arg) 590static int __hpp__overhead_callback(struct perf_hpp *hpp, bool front)
591{ 591{
592 if (!symbol_conf.use_callchain)
593 return 0;
594
595 slsmg_printf("%c ", arg->folded_sign);
596 return 2;
597}
598
599static int __hpp__color_fmt(struct perf_hpp *hpp, struct hist_entry *he,
600 u64 (*get_field)(struct hist_entry *),
601 int (*callchain_cb)(struct hpp_arg *))
602{
603 int ret = 0;
604 double percent = 0.0;
605 struct hists *hists = he->hists;
606 struct hpp_arg *arg = hpp->ptr; 592 struct hpp_arg *arg = hpp->ptr;
607 593
608 if (hists->stats.total_period) 594 if (arg->current_entry && arg->b->navkeypressed)
609 percent = 100.0 * get_field(he) / hists->stats.total_period; 595 ui_browser__set_color(arg->b, HE_COLORSET_SELECTED);
610 596 else
611 ui_browser__set_percent_color(arg->b, percent, arg->current_entry); 597 ui_browser__set_color(arg->b, HE_COLORSET_NORMAL);
612
613 if (callchain_cb)
614 ret += callchain_cb(arg);
615
616 ret += scnprintf(hpp->buf, hpp->size, "%6.2f%%", percent);
617 slsmg_printf("%s", hpp->buf);
618
619 if (symbol_conf.event_group) {
620 int prev_idx, idx_delta;
621 struct perf_evsel *evsel = hists_to_evsel(hists);
622 struct hist_entry *pair;
623 int nr_members = evsel->nr_members;
624
625 if (nr_members <= 1)
626 goto out;
627 598
628 prev_idx = perf_evsel__group_idx(evsel); 599 if (front) {
600 if (!symbol_conf.use_callchain)
601 return 0;
629 602
630 list_for_each_entry(pair, &he->pairs.head, pairs.node) { 603 slsmg_printf("%c ", arg->folded_sign);
631 u64 period = get_field(pair); 604 return 2;
632 u64 total = pair->hists->stats.total_period; 605 }
633 606
634 if (!total) 607 return 0;
635 continue; 608}
636 609
637 evsel = hists_to_evsel(pair->hists); 610static int __hpp__color_callback(struct perf_hpp *hpp, bool front __maybe_unused)
638 idx_delta = perf_evsel__group_idx(evsel) - prev_idx - 1; 611{
612 struct hpp_arg *arg = hpp->ptr;
639 613
640 while (idx_delta--) { 614 if (!arg->current_entry || !arg->b->navkeypressed)
641 /* 615 ui_browser__set_color(arg->b, HE_COLORSET_NORMAL);
642 * zero-fill group members in the middle which 616 return 0;
643 * have no sample 617}
644 */
645 ui_browser__set_percent_color(arg->b, 0.0,
646 arg->current_entry);
647 ret += scnprintf(hpp->buf, hpp->size,
648 " %6.2f%%", 0.0);
649 slsmg_printf("%s", hpp->buf);
650 }
651 618
652 percent = 100.0 * period / total; 619static int __hpp__slsmg_color_printf(struct perf_hpp *hpp, const char *fmt, ...)
653 ui_browser__set_percent_color(arg->b, percent, 620{
654 arg->current_entry); 621 struct hpp_arg *arg = hpp->ptr;
655 ret += scnprintf(hpp->buf, hpp->size, 622 int ret;
656 " %6.2f%%", percent); 623 va_list args;
657 slsmg_printf("%s", hpp->buf); 624 double percent;
658 625
659 prev_idx = perf_evsel__group_idx(evsel); 626 va_start(args, fmt);
660 } 627 percent = va_arg(args, double);
628 va_end(args);
661 629
662 idx_delta = nr_members - prev_idx - 1; 630 ui_browser__set_percent_color(arg->b, percent, arg->current_entry);
663 631
664 while (idx_delta--) { 632 ret = scnprintf(hpp->buf, hpp->size, fmt, percent);
665 /* 633 slsmg_printf("%s", hpp->buf);
666 * zero-fill group members at last which have no sample
667 */
668 ui_browser__set_percent_color(arg->b, 0.0,
669 arg->current_entry);
670 ret += scnprintf(hpp->buf, hpp->size,
671 " %6.2f%%", 0.0);
672 slsmg_printf("%s", hpp->buf);
673 }
674 }
675out:
676 if (!arg->current_entry || !arg->b->navkeypressed)
677 ui_browser__set_color(arg->b, HE_COLORSET_NORMAL);
678 634
635 advance_hpp(hpp, ret);
679 return ret; 636 return ret;
680} 637}
681 638
@@ -690,14 +647,15 @@ hist_browser__hpp_color_##_type(struct perf_hpp_fmt *fmt __maybe_unused,\
690 struct perf_hpp *hpp, \ 647 struct perf_hpp *hpp, \
691 struct hist_entry *he) \ 648 struct hist_entry *he) \
692{ \ 649{ \
693 return __hpp__color_fmt(hpp, he, __hpp_get_##_field, _cb); \ 650 return __hpp__fmt(hpp, he, __hpp_get_##_field, _cb, " %6.2f%%", \
651 __hpp__slsmg_color_printf, true); \
694} 652}
695 653
696__HPP_COLOR_PERCENT_FN(overhead, period, __hpp__color_callchain) 654__HPP_COLOR_PERCENT_FN(overhead, period, __hpp__overhead_callback)
697__HPP_COLOR_PERCENT_FN(overhead_sys, period_sys, NULL) 655__HPP_COLOR_PERCENT_FN(overhead_sys, period_sys, __hpp__color_callback)
698__HPP_COLOR_PERCENT_FN(overhead_us, period_us, NULL) 656__HPP_COLOR_PERCENT_FN(overhead_us, period_us, __hpp__color_callback)
699__HPP_COLOR_PERCENT_FN(overhead_guest_sys, period_guest_sys, NULL) 657__HPP_COLOR_PERCENT_FN(overhead_guest_sys, period_guest_sys, __hpp__color_callback)
700__HPP_COLOR_PERCENT_FN(overhead_guest_us, period_guest_us, NULL) 658__HPP_COLOR_PERCENT_FN(overhead_guest_us, period_guest_us, __hpp__color_callback)
701 659
702#undef __HPP_COLOR_PERCENT_FN 660#undef __HPP_COLOR_PERCENT_FN
703 661
diff --git a/tools/perf/ui/gtk/hists.c b/tools/perf/ui/gtk/hists.c
index 430fd555b161..7912dab6e5fb 100644
--- a/tools/perf/ui/gtk/hists.c
+++ b/tools/perf/ui/gtk/hists.c
@@ -43,7 +43,7 @@ static int perf_gtk__hpp_color_##_type(struct perf_hpp_fmt *fmt __maybe_unused,
43 struct perf_hpp *hpp, \ 43 struct perf_hpp *hpp, \
44 struct hist_entry *he) \ 44 struct hist_entry *he) \
45{ \ 45{ \
46 return __hpp__fmt(hpp, he, he_get_##_field, " %6.2f%%", \ 46 return __hpp__fmt(hpp, he, he_get_##_field, NULL, " %6.2f%%", \
47 __percent_color_snprintf, true); \ 47 __percent_color_snprintf, true); \
48} 48}
49 49
diff --git a/tools/perf/ui/hist.c b/tools/perf/ui/hist.c
index 0c427e5d37c7..ac39313a3f0c 100644
--- a/tools/perf/ui/hist.c
+++ b/tools/perf/ui/hist.c
@@ -16,15 +16,20 @@
16}) 16})
17 17
18int __hpp__fmt(struct perf_hpp *hpp, struct hist_entry *he, 18int __hpp__fmt(struct perf_hpp *hpp, struct hist_entry *he,
19 u64 (*get_field)(struct hist_entry *), 19 hpp_field_fn get_field, hpp_callback_fn callback,
20 const char *fmt, hpp_snprint_fn print_fn, bool fmt_percent) 20 const char *fmt, hpp_snprint_fn print_fn, bool fmt_percent)
21{ 21{
22 int ret; 22 int ret = 0;
23 struct hists *hists = he->hists; 23 struct hists *hists = he->hists;
24 struct perf_evsel *evsel = hists_to_evsel(hists); 24 struct perf_evsel *evsel = hists_to_evsel(hists);
25 char *buf = hpp->buf; 25 char *buf = hpp->buf;
26 size_t size = hpp->size; 26 size_t size = hpp->size;
27 27
28 if (callback) {
29 ret = callback(hpp, true);
30 advance_hpp(hpp, ret);
31 }
32
28 if (fmt_percent) { 33 if (fmt_percent) {
29 double percent = 0.0; 34 double percent = 0.0;
30 35
@@ -32,9 +37,9 @@ int __hpp__fmt(struct perf_hpp *hpp, struct hist_entry *he,
32 percent = 100.0 * get_field(he) / 37 percent = 100.0 * get_field(he) /
33 hists->stats.total_period; 38 hists->stats.total_period;
34 39
35 ret = hpp__call_print_fn(hpp, print_fn, fmt, percent); 40 ret += hpp__call_print_fn(hpp, print_fn, fmt, percent);
36 } else 41 } else
37 ret = hpp__call_print_fn(hpp, print_fn, fmt, get_field(he)); 42 ret += hpp__call_print_fn(hpp, print_fn, fmt, get_field(he));
38 43
39 if (perf_evsel__is_group_event(evsel)) { 44 if (perf_evsel__is_group_event(evsel)) {
40 int prev_idx, idx_delta; 45 int prev_idx, idx_delta;
@@ -94,6 +99,13 @@ int __hpp__fmt(struct perf_hpp *hpp, struct hist_entry *he,
94 } 99 }
95 } 100 }
96 101
102 if (callback) {
103 int __ret = callback(hpp, false);
104
105 advance_hpp(hpp, __ret);
106 ret += __ret;
107 }
108
97 /* 109 /*
98 * Restore original buf and size as it's where caller expects 110 * Restore original buf and size as it's where caller expects
99 * the result will be saved. 111 * the result will be saved.
@@ -169,7 +181,7 @@ static u64 he_get_##_field(struct hist_entry *he) \
169static int hpp__color_##_type(struct perf_hpp_fmt *fmt __maybe_unused, \ 181static int hpp__color_##_type(struct perf_hpp_fmt *fmt __maybe_unused, \
170 struct perf_hpp *hpp, struct hist_entry *he) \ 182 struct perf_hpp *hpp, struct hist_entry *he) \
171{ \ 183{ \
172 return __hpp__fmt(hpp, he, he_get_##_field, " %6.2f%%", \ 184 return __hpp__fmt(hpp, he, he_get_##_field, NULL, " %6.2f%%", \
173 hpp_color_scnprintf, true); \ 185 hpp_color_scnprintf, true); \
174} 186}
175 187
@@ -178,7 +190,7 @@ static int hpp__entry_##_type(struct perf_hpp_fmt *_fmt __maybe_unused, \
178 struct perf_hpp *hpp, struct hist_entry *he) \ 190 struct perf_hpp *hpp, struct hist_entry *he) \
179{ \ 191{ \
180 const char *fmt = symbol_conf.field_sep ? " %.2f" : " %6.2f%%"; \ 192 const char *fmt = symbol_conf.field_sep ? " %.2f" : " %6.2f%%"; \
181 return __hpp__fmt(hpp, he, he_get_##_field, fmt, \ 193 return __hpp__fmt(hpp, he, he_get_##_field, NULL, fmt, \
182 hpp_entry_scnprintf, true); \ 194 hpp_entry_scnprintf, true); \
183} 195}
184 196
@@ -192,7 +204,7 @@ static int hpp__entry_##_type(struct perf_hpp_fmt *_fmt __maybe_unused, \
192 struct perf_hpp *hpp, struct hist_entry *he) \ 204 struct perf_hpp *hpp, struct hist_entry *he) \
193{ \ 205{ \
194 const char *fmt = symbol_conf.field_sep ? " %"PRIu64 : " %11"PRIu64; \ 206 const char *fmt = symbol_conf.field_sep ? " %"PRIu64 : " %11"PRIu64; \
195 return __hpp__fmt(hpp, he, he_get_raw_##_field, fmt, \ 207 return __hpp__fmt(hpp, he, he_get_raw_##_field, NULL, fmt, \
196 hpp_entry_scnprintf, false); \ 208 hpp_entry_scnprintf, false); \
197} 209}
198 210
diff --git a/tools/perf/util/hist.h b/tools/perf/util/hist.h
index d51ed9898229..9e1cada45bb8 100644
--- a/tools/perf/util/hist.h
+++ b/tools/perf/util/hist.h
@@ -166,10 +166,12 @@ void perf_hpp__init(void);
166void perf_hpp__column_register(struct perf_hpp_fmt *format); 166void perf_hpp__column_register(struct perf_hpp_fmt *format);
167void perf_hpp__column_enable(unsigned col); 167void perf_hpp__column_enable(unsigned col);
168 168
169typedef u64 (*hpp_field_fn)(struct hist_entry *he);
170typedef int (*hpp_callback_fn)(struct perf_hpp *hpp, bool front);
169typedef int (*hpp_snprint_fn)(struct perf_hpp *hpp, const char *fmt, ...); 171typedef int (*hpp_snprint_fn)(struct perf_hpp *hpp, const char *fmt, ...);
170 172
171int __hpp__fmt(struct perf_hpp *hpp, struct hist_entry *he, 173int __hpp__fmt(struct perf_hpp *hpp, struct hist_entry *he,
172 u64 (*get_field)(struct hist_entry *), 174 hpp_field_fn get_field, hpp_callback_fn callback,
173 const char *fmt, hpp_snprint_fn print_fn, bool fmt_percent); 175 const char *fmt, hpp_snprint_fn print_fn, bool fmt_percent);
174 176
175static inline void advance_hpp(struct perf_hpp *hpp, int inc) 177static inline void advance_hpp(struct perf_hpp *hpp, int inc)