Skip to content

Commit fb821c9

Browse files
namhyungolsajiri
authored andcommitted
perf ui: Get rid of callback from __hpp__fmt()
The callback was used by TUI for determining color of folded sign using percent of first field/column. But it cannot be used anymore since it now support dynamic reordering of output field. So move the logic to the hist_browser__show_entry(). Signed-off-by: Namhyung Kim <namhyung@kernel.org> Acked-by: Ingo Molnar <mingo@kernel.org> Link: http://lkml.kernel.org/r/1400480762-22852-8-git-send-email-namhyung@kernel.org Signed-off-by: Jiri Olsa <jolsa@kernel.org>
1 parent 26d8b33 commit fb821c9

File tree

4 files changed

+34
-62
lines changed

4 files changed

+34
-62
lines changed

tools/perf/ui/browsers/hists.c

Lines changed: 23 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -616,35 +616,6 @@ struct hpp_arg {
616616
bool current_entry;
617617
};
618618

619-
static int __hpp__overhead_callback(struct perf_hpp *hpp, bool front)
620-
{
621-
struct hpp_arg *arg = hpp->ptr;
622-
623-
if (arg->current_entry && arg->b->navkeypressed)
624-
ui_browser__set_color(arg->b, HE_COLORSET_SELECTED);
625-
else
626-
ui_browser__set_color(arg->b, HE_COLORSET_NORMAL);
627-
628-
if (front) {
629-
if (!symbol_conf.use_callchain)
630-
return 0;
631-
632-
slsmg_printf("%c ", arg->folded_sign);
633-
return 2;
634-
}
635-
636-
return 0;
637-
}
638-
639-
static int __hpp__color_callback(struct perf_hpp *hpp, bool front __maybe_unused)
640-
{
641-
struct hpp_arg *arg = hpp->ptr;
642-
643-
if (!arg->current_entry || !arg->b->navkeypressed)
644-
ui_browser__set_color(arg->b, HE_COLORSET_NORMAL);
645-
return 0;
646-
}
647-
648619
static int __hpp__slsmg_color_printf(struct perf_hpp *hpp, const char *fmt, ...)
649620
{
650621
struct hpp_arg *arg = hpp->ptr;
@@ -665,7 +636,7 @@ static int __hpp__slsmg_color_printf(struct perf_hpp *hpp, const char *fmt, ...)
665636
return ret;
666637
}
667638

668-
#define __HPP_COLOR_PERCENT_FN(_type, _field, _cb) \
639+
#define __HPP_COLOR_PERCENT_FN(_type, _field) \
669640
static u64 __hpp_get_##_field(struct hist_entry *he) \
670641
{ \
671642
return he->stat._field; \
@@ -676,15 +647,15 @@ hist_browser__hpp_color_##_type(struct perf_hpp_fmt *fmt __maybe_unused,\
676647
struct perf_hpp *hpp, \
677648
struct hist_entry *he) \
678649
{ \
679-
return __hpp__fmt(hpp, he, __hpp_get_##_field, _cb, " %6.2f%%", \
650+
return __hpp__fmt(hpp, he, __hpp_get_##_field, " %6.2f%%", \
680651
__hpp__slsmg_color_printf, true); \
681652
}
682653

683-
__HPP_COLOR_PERCENT_FN(overhead, period, __hpp__overhead_callback)
684-
__HPP_COLOR_PERCENT_FN(overhead_sys, period_sys, __hpp__color_callback)
685-
__HPP_COLOR_PERCENT_FN(overhead_us, period_us, __hpp__color_callback)
686-
__HPP_COLOR_PERCENT_FN(overhead_guest_sys, period_guest_sys, __hpp__color_callback)
687-
__HPP_COLOR_PERCENT_FN(overhead_guest_us, period_guest_us, __hpp__color_callback)
654+
__HPP_COLOR_PERCENT_FN(overhead, period)
655+
__HPP_COLOR_PERCENT_FN(overhead_sys, period_sys)
656+
__HPP_COLOR_PERCENT_FN(overhead_us, period_us)
657+
__HPP_COLOR_PERCENT_FN(overhead_guest_sys, period_guest_sys)
658+
__HPP_COLOR_PERCENT_FN(overhead_guest_us, period_guest_us)
688659

689660
#undef __HPP_COLOR_PERCENT_FN
690661

@@ -729,7 +700,7 @@ static int hist_browser__show_entry(struct hist_browser *browser,
729700

730701
if (row_offset == 0) {
731702
struct hpp_arg arg = {
732-
.b = &browser->b,
703+
.b = &browser->b,
733704
.folded_sign = folded_sign,
734705
.current_entry = current_entry,
735706
};
@@ -742,11 +713,24 @@ static int hist_browser__show_entry(struct hist_browser *browser,
742713
ui_browser__gotorc(&browser->b, row, 0);
743714

744715
perf_hpp__for_each_format(fmt) {
745-
if (!first) {
716+
if (current_entry && browser->b.navkeypressed) {
717+
ui_browser__set_color(&browser->b,
718+
HE_COLORSET_SELECTED);
719+
} else {
720+
ui_browser__set_color(&browser->b,
721+
HE_COLORSET_NORMAL);
722+
}
723+
724+
if (first) {
725+
if (symbol_conf.use_callchain) {
726+
slsmg_printf("%c ", folded_sign);
727+
width -= 2;
728+
}
729+
first = false;
730+
} else {
746731
slsmg_printf(" ");
747732
width -= 2;
748733
}
749-
first = false;
750734

751735
if (fmt->color) {
752736
width -= fmt->color(fmt, &hpp, entry);

tools/perf/ui/gtk/hists.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ static int perf_gtk__hpp_color_##_type(struct perf_hpp_fmt *fmt __maybe_unused,
4343
struct perf_hpp *hpp, \
4444
struct hist_entry *he) \
4545
{ \
46-
return __hpp__fmt(hpp, he, he_get_##_field, NULL, " %6.2f%%", \
46+
return __hpp__fmt(hpp, he, he_get_##_field, " %6.2f%%", \
4747
__percent_color_snprintf, true); \
4848
}
4949

tools/perf/ui/hist.c

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,30 +16,25 @@
1616
})
1717

1818
int __hpp__fmt(struct perf_hpp *hpp, struct hist_entry *he,
19-
hpp_field_fn get_field, hpp_callback_fn callback,
20-
const char *fmt, hpp_snprint_fn print_fn, bool fmt_percent)
19+
hpp_field_fn get_field, const char *fmt,
20+
hpp_snprint_fn print_fn, bool fmt_percent)
2121
{
22-
int ret = 0;
22+
int ret;
2323
struct hists *hists = he->hists;
2424
struct perf_evsel *evsel = hists_to_evsel(hists);
2525
char *buf = hpp->buf;
2626
size_t size = hpp->size;
2727

28-
if (callback) {
29-
ret = callback(hpp, true);
30-
advance_hpp(hpp, ret);
31-
}
32-
3328
if (fmt_percent) {
3429
double percent = 0.0;
3530
u64 total = hists__total_period(hists);
3631

3732
if (total)
3833
percent = 100.0 * get_field(he) / total;
3934

40-
ret += hpp__call_print_fn(hpp, print_fn, fmt, percent);
35+
ret = hpp__call_print_fn(hpp, print_fn, fmt, percent);
4136
} else
42-
ret += hpp__call_print_fn(hpp, print_fn, fmt, get_field(he));
37+
ret = hpp__call_print_fn(hpp, print_fn, fmt, get_field(he));
4338

4439
if (perf_evsel__is_group_event(evsel)) {
4540
int prev_idx, idx_delta;
@@ -99,13 +94,6 @@ int __hpp__fmt(struct perf_hpp *hpp, struct hist_entry *he,
9994
}
10095
}
10196

102-
if (callback) {
103-
int __ret = callback(hpp, false);
104-
105-
advance_hpp(hpp, __ret);
106-
ret += __ret;
107-
}
108-
10997
/*
11098
* Restore original buf and size as it's where caller expects
11199
* the result will be saved.
@@ -235,7 +223,7 @@ static u64 he_get_##_field(struct hist_entry *he) \
235223
static int hpp__color_##_type(struct perf_hpp_fmt *fmt __maybe_unused, \
236224
struct perf_hpp *hpp, struct hist_entry *he) \
237225
{ \
238-
return __hpp__fmt(hpp, he, he_get_##_field, NULL, " %6.2f%%", \
226+
return __hpp__fmt(hpp, he, he_get_##_field, " %6.2f%%", \
239227
hpp_color_scnprintf, true); \
240228
}
241229

@@ -244,7 +232,7 @@ static int hpp__entry_##_type(struct perf_hpp_fmt *_fmt __maybe_unused, \
244232
struct perf_hpp *hpp, struct hist_entry *he) \
245233
{ \
246234
const char *fmt = symbol_conf.field_sep ? " %.2f" : " %6.2f%%"; \
247-
return __hpp__fmt(hpp, he, he_get_##_field, NULL, fmt, \
235+
return __hpp__fmt(hpp, he, he_get_##_field, fmt, \
248236
hpp_entry_scnprintf, true); \
249237
}
250238

@@ -264,7 +252,7 @@ static int hpp__entry_##_type(struct perf_hpp_fmt *_fmt __maybe_unused, \
264252
struct perf_hpp *hpp, struct hist_entry *he) \
265253
{ \
266254
const char *fmt = symbol_conf.field_sep ? " %"PRIu64 : " %11"PRIu64; \
267-
return __hpp__fmt(hpp, he, he_get_raw_##_field, NULL, fmt, \
255+
return __hpp__fmt(hpp, he, he_get_raw_##_field, fmt, \
268256
hpp_entry_scnprintf, false); \
269257
}
270258

tools/perf/util/hist.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,8 +203,8 @@ typedef int (*hpp_callback_fn)(struct perf_hpp *hpp, bool front);
203203
typedef int (*hpp_snprint_fn)(struct perf_hpp *hpp, const char *fmt, ...);
204204

205205
int __hpp__fmt(struct perf_hpp *hpp, struct hist_entry *he,
206-
hpp_field_fn get_field, hpp_callback_fn callback,
207-
const char *fmt, hpp_snprint_fn print_fn, bool fmt_percent);
206+
hpp_field_fn get_field, const char *fmt,
207+
hpp_snprint_fn print_fn, bool fmt_percent);
208208

209209
static inline void advance_hpp(struct perf_hpp *hpp, int inc)
210210
{

0 commit comments

Comments
 (0)