diff options
author | Namhyung Kim <namhyung@kernel.org> | 2014-03-02 20:14:03 -0500 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2014-03-14 17:08:38 -0400 |
commit | 4a62109fe94f68a57b239c1516f97497a4d15c14 (patch) | |
tree | 23c29b70f99eec34e3f929d95e6c6accb4d875c1 /tools | |
parent | 9b0d2fb86d4737b2cda39bc9c9a8e368cec38960 (diff) |
perf ui/gtk: Reuse generic __hpp__fmt() code
The __hpp__color_fmt used in the gtk code can be replace by the generic
code with small change in print_fn callback.
This is a preparation to upcoming changes and no functional changes
intended.
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Acked-by: Pekka Enberg <penberg@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: Pekka Enberg <penberg@kernel.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: http://lkml.kernel.org/r/1393809254-4480-3-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/gtk/hists.c | 73 | ||||
-rw-r--r-- | tools/perf/ui/hist.c | 9 | ||||
-rw-r--r-- | tools/perf/util/hist.h | 6 |
3 files changed, 19 insertions, 69 deletions
diff --git a/tools/perf/ui/gtk/hists.c b/tools/perf/ui/gtk/hists.c index 5b95c44f3435..3dab00e748f2 100644 --- a/tools/perf/ui/gtk/hists.c +++ b/tools/perf/ui/gtk/hists.c | |||
@@ -8,16 +8,22 @@ | |||
8 | 8 | ||
9 | #define MAX_COLUMNS 32 | 9 | #define MAX_COLUMNS 32 |
10 | 10 | ||
11 | static int __percent_color_snprintf(char *buf, size_t size, double percent) | 11 | static int __percent_color_snprintf(char *buf, size_t size, const char *fmt, ...) |
12 | { | 12 | { |
13 | int ret = 0; | 13 | int ret = 0; |
14 | va_list args; | ||
15 | double percent; | ||
14 | const char *markup; | 16 | const char *markup; |
15 | 17 | ||
18 | va_start(args, fmt); | ||
19 | percent = va_arg(args, double); | ||
20 | va_end(args); | ||
21 | |||
16 | markup = perf_gtk__get_percent_color(percent); | 22 | markup = perf_gtk__get_percent_color(percent); |
17 | if (markup) | 23 | if (markup) |
18 | ret += scnprintf(buf, size, markup); | 24 | ret += scnprintf(buf, size, markup); |
19 | 25 | ||
20 | ret += scnprintf(buf + ret, size - ret, " %6.2f%%", percent); | 26 | ret += scnprintf(buf + ret, size - ret, fmt, percent); |
21 | 27 | ||
22 | if (markup) | 28 | if (markup) |
23 | ret += scnprintf(buf + ret, size - ret, "</span>"); | 29 | ret += scnprintf(buf + ret, size - ret, "</span>"); |
@@ -25,66 +31,6 @@ static int __percent_color_snprintf(char *buf, size_t size, double percent) | |||
25 | return ret; | 31 | return ret; |
26 | } | 32 | } |
27 | 33 | ||
28 | |||
29 | static int __hpp__color_fmt(struct perf_hpp *hpp, struct hist_entry *he, | ||
30 | u64 (*get_field)(struct hist_entry *)) | ||
31 | { | ||
32 | int ret; | ||
33 | double percent = 0.0; | ||
34 | struct hists *hists = he->hists; | ||
35 | struct perf_evsel *evsel = hists_to_evsel(hists); | ||
36 | |||
37 | if (hists->stats.total_period) | ||
38 | percent = 100.0 * get_field(he) / hists->stats.total_period; | ||
39 | |||
40 | ret = __percent_color_snprintf(hpp->buf, hpp->size, percent); | ||
41 | |||
42 | if (perf_evsel__is_group_event(evsel)) { | ||
43 | int prev_idx, idx_delta; | ||
44 | struct hist_entry *pair; | ||
45 | int nr_members = evsel->nr_members; | ||
46 | |||
47 | prev_idx = perf_evsel__group_idx(evsel); | ||
48 | |||
49 | list_for_each_entry(pair, &he->pairs.head, pairs.node) { | ||
50 | u64 period = get_field(pair); | ||
51 | u64 total = pair->hists->stats.total_period; | ||
52 | |||
53 | evsel = hists_to_evsel(pair->hists); | ||
54 | idx_delta = perf_evsel__group_idx(evsel) - prev_idx - 1; | ||
55 | |||
56 | while (idx_delta--) { | ||
57 | /* | ||
58 | * zero-fill group members in the middle which | ||
59 | * have no sample | ||
60 | */ | ||
61 | ret += __percent_color_snprintf(hpp->buf + ret, | ||
62 | hpp->size - ret, | ||
63 | 0.0); | ||
64 | } | ||
65 | |||
66 | percent = 100.0 * period / total; | ||
67 | ret += __percent_color_snprintf(hpp->buf + ret, | ||
68 | hpp->size - ret, | ||
69 | percent); | ||
70 | |||
71 | prev_idx = perf_evsel__group_idx(evsel); | ||
72 | } | ||
73 | |||
74 | idx_delta = nr_members - prev_idx - 1; | ||
75 | |||
76 | while (idx_delta--) { | ||
77 | /* | ||
78 | * zero-fill group members at last which have no sample | ||
79 | */ | ||
80 | ret += __percent_color_snprintf(hpp->buf + ret, | ||
81 | hpp->size - ret, | ||
82 | 0.0); | ||
83 | } | ||
84 | } | ||
85 | return ret; | ||
86 | } | ||
87 | |||
88 | #define __HPP_COLOR_PERCENT_FN(_type, _field) \ | 34 | #define __HPP_COLOR_PERCENT_FN(_type, _field) \ |
89 | static u64 he_get_##_field(struct hist_entry *he) \ | 35 | static u64 he_get_##_field(struct hist_entry *he) \ |
90 | { \ | 36 | { \ |
@@ -95,7 +41,8 @@ static int perf_gtk__hpp_color_##_type(struct perf_hpp_fmt *fmt __maybe_unused, | |||
95 | struct perf_hpp *hpp, \ | 41 | struct perf_hpp *hpp, \ |
96 | struct hist_entry *he) \ | 42 | struct hist_entry *he) \ |
97 | { \ | 43 | { \ |
98 | return __hpp__color_fmt(hpp, he, he_get_##_field); \ | 44 | return __hpp__fmt(hpp, he, he_get_##_field, " %6.2f%%", \ |
45 | __percent_color_snprintf, true); \ | ||
99 | } | 46 | } |
100 | 47 | ||
101 | __HPP_COLOR_PERCENT_FN(overhead, period) | 48 | __HPP_COLOR_PERCENT_FN(overhead, period) |
diff --git a/tools/perf/ui/hist.c b/tools/perf/ui/hist.c index 6094562c9523..085353435f07 100644 --- a/tools/perf/ui/hist.c +++ b/tools/perf/ui/hist.c | |||
@@ -8,12 +8,9 @@ | |||
8 | 8 | ||
9 | /* hist period print (hpp) functions */ | 9 | /* hist period print (hpp) functions */ |
10 | 10 | ||
11 | typedef int (*hpp_snprint_fn)(char *buf, size_t size, const char *fmt, ...); | 11 | int __hpp__fmt(struct perf_hpp *hpp, struct hist_entry *he, |
12 | 12 | u64 (*get_field)(struct hist_entry *), | |
13 | static int __hpp__fmt(struct perf_hpp *hpp, struct hist_entry *he, | 13 | const char *fmt, hpp_snprint_fn print_fn, bool fmt_percent) |
14 | u64 (*get_field)(struct hist_entry *), | ||
15 | const char *fmt, hpp_snprint_fn print_fn, | ||
16 | bool fmt_percent) | ||
17 | { | 14 | { |
18 | int ret; | 15 | int ret; |
19 | struct hists *hists = he->hists; | 16 | struct hists *hists = he->hists; |
diff --git a/tools/perf/util/hist.h b/tools/perf/util/hist.h index a59743fa3ef7..97f924ec6af9 100644 --- a/tools/perf/util/hist.h +++ b/tools/perf/util/hist.h | |||
@@ -166,6 +166,12 @@ void perf_hpp__init(void); | |||
166 | void perf_hpp__column_register(struct perf_hpp_fmt *format); | 166 | void perf_hpp__column_register(struct perf_hpp_fmt *format); |
167 | void perf_hpp__column_enable(unsigned col); | 167 | void perf_hpp__column_enable(unsigned col); |
168 | 168 | ||
169 | typedef int (*hpp_snprint_fn)(char *buf, size_t size, const char *fmt, ...); | ||
170 | |||
171 | int __hpp__fmt(struct perf_hpp *hpp, struct hist_entry *he, | ||
172 | u64 (*get_field)(struct hist_entry *), | ||
173 | const char *fmt, hpp_snprint_fn print_fn, bool fmt_percent); | ||
174 | |||
169 | static inline size_t perf_hpp__use_color(void) | 175 | static inline size_t perf_hpp__use_color(void) |
170 | { | 176 | { |
171 | return !symbol_conf.field_sep; | 177 | return !symbol_conf.field_sep; |