diff options
author | Namhyung Kim <namhyung@kernel.org> | 2014-03-02 20:14:04 -0500 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2014-03-14 17:08:38 -0400 |
commit | a0088adcd651b8eb1a9ca9c7e6ebe1c2c5fb6273 (patch) | |
tree | c28143096e14256cbdc34c19f97713fb57685091 /tools/perf/ui | |
parent | 4a62109fe94f68a57b239c1516f97497a4d15c14 (diff) |
perf ui/hists: Pass struct hpp to print functions
Instead of the pointer to buffer and its size so that it can also get
private argument passed along with hpp.
This is a preparation of further change.
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-4-git-send-email-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf/ui')
-rw-r--r-- | tools/perf/ui/gtk/hists.c | 4 | ||||
-rw-r--r-- | tools/perf/ui/hist.c | 87 | ||||
-rw-r--r-- | tools/perf/ui/stdio/hist.c | 6 |
3 files changed, 69 insertions, 28 deletions
diff --git a/tools/perf/ui/gtk/hists.c b/tools/perf/ui/gtk/hists.c index 3dab00e748f2..430fd555b161 100644 --- a/tools/perf/ui/gtk/hists.c +++ b/tools/perf/ui/gtk/hists.c | |||
@@ -8,12 +8,14 @@ | |||
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, const char *fmt, ...) | 11 | static int __percent_color_snprintf(struct perf_hpp *hpp, const char *fmt, ...) |
12 | { | 12 | { |
13 | int ret = 0; | 13 | int ret = 0; |
14 | va_list args; | 14 | va_list args; |
15 | double percent; | 15 | double percent; |
16 | const char *markup; | 16 | const char *markup; |
17 | char *buf = hpp->buf; | ||
18 | size_t size = hpp->size; | ||
17 | 19 | ||
18 | va_start(args, fmt); | 20 | va_start(args, fmt); |
19 | percent = va_arg(args, double); | 21 | percent = va_arg(args, double); |
diff --git a/tools/perf/ui/hist.c b/tools/perf/ui/hist.c index 085353435f07..0c427e5d37c7 100644 --- a/tools/perf/ui/hist.c +++ b/tools/perf/ui/hist.c | |||
@@ -8,6 +8,13 @@ | |||
8 | 8 | ||
9 | /* hist period print (hpp) functions */ | 9 | /* hist period print (hpp) functions */ |
10 | 10 | ||
11 | #define hpp__call_print_fn(hpp, fn, fmt, ...) \ | ||
12 | ({ \ | ||
13 | int __ret = fn(hpp, fmt, ##__VA_ARGS__); \ | ||
14 | advance_hpp(hpp, __ret); \ | ||
15 | __ret; \ | ||
16 | }) | ||
17 | |||
11 | int __hpp__fmt(struct perf_hpp *hpp, struct hist_entry *he, | 18 | int __hpp__fmt(struct perf_hpp *hpp, struct hist_entry *he, |
12 | u64 (*get_field)(struct hist_entry *), | 19 | u64 (*get_field)(struct hist_entry *), |
13 | const char *fmt, hpp_snprint_fn print_fn, bool fmt_percent) | 20 | const char *fmt, hpp_snprint_fn print_fn, bool fmt_percent) |
@@ -15,6 +22,8 @@ int __hpp__fmt(struct perf_hpp *hpp, struct hist_entry *he, | |||
15 | int ret; | 22 | int ret; |
16 | struct hists *hists = he->hists; | 23 | struct hists *hists = he->hists; |
17 | struct perf_evsel *evsel = hists_to_evsel(hists); | 24 | struct perf_evsel *evsel = hists_to_evsel(hists); |
25 | char *buf = hpp->buf; | ||
26 | size_t size = hpp->size; | ||
18 | 27 | ||
19 | if (fmt_percent) { | 28 | if (fmt_percent) { |
20 | double percent = 0.0; | 29 | double percent = 0.0; |
@@ -23,9 +32,9 @@ int __hpp__fmt(struct perf_hpp *hpp, struct hist_entry *he, | |||
23 | percent = 100.0 * get_field(he) / | 32 | percent = 100.0 * get_field(he) / |
24 | hists->stats.total_period; | 33 | hists->stats.total_period; |
25 | 34 | ||
26 | ret = print_fn(hpp->buf, hpp->size, fmt, percent); | 35 | ret = hpp__call_print_fn(hpp, print_fn, fmt, percent); |
27 | } else | 36 | } else |
28 | ret = print_fn(hpp->buf, hpp->size, fmt, get_field(he)); | 37 | ret = hpp__call_print_fn(hpp, print_fn, fmt, get_field(he)); |
29 | 38 | ||
30 | if (perf_evsel__is_group_event(evsel)) { | 39 | if (perf_evsel__is_group_event(evsel)) { |
31 | int prev_idx, idx_delta; | 40 | int prev_idx, idx_delta; |
@@ -50,22 +59,21 @@ int __hpp__fmt(struct perf_hpp *hpp, struct hist_entry *he, | |||
50 | * have no sample | 59 | * have no sample |
51 | */ | 60 | */ |
52 | if (fmt_percent) { | 61 | if (fmt_percent) { |
53 | ret += print_fn(hpp->buf + ret, | 62 | ret += hpp__call_print_fn(hpp, print_fn, |
54 | hpp->size - ret, | 63 | fmt, 0.0); |
55 | fmt, 0.0); | ||
56 | } else { | 64 | } else { |
57 | ret += print_fn(hpp->buf + ret, | 65 | ret += hpp__call_print_fn(hpp, print_fn, |
58 | hpp->size - ret, | 66 | fmt, 0ULL); |
59 | fmt, 0ULL); | ||
60 | } | 67 | } |
61 | } | 68 | } |
62 | 69 | ||
63 | if (fmt_percent) | 70 | if (fmt_percent) { |
64 | ret += print_fn(hpp->buf + ret, hpp->size - ret, | 71 | ret += hpp__call_print_fn(hpp, print_fn, fmt, |
65 | fmt, 100.0 * period / total); | 72 | 100.0 * period / total); |
66 | else | 73 | } else { |
67 | ret += print_fn(hpp->buf + ret, hpp->size - ret, | 74 | ret += hpp__call_print_fn(hpp, print_fn, fmt, |
68 | fmt, period); | 75 | period); |
76 | } | ||
69 | 77 | ||
70 | prev_idx = perf_evsel__group_idx(evsel); | 78 | prev_idx = perf_evsel__group_idx(evsel); |
71 | } | 79 | } |
@@ -77,14 +85,22 @@ int __hpp__fmt(struct perf_hpp *hpp, struct hist_entry *he, | |||
77 | * zero-fill group members at last which have no sample | 85 | * zero-fill group members at last which have no sample |
78 | */ | 86 | */ |
79 | if (fmt_percent) { | 87 | if (fmt_percent) { |
80 | ret += print_fn(hpp->buf + ret, hpp->size - ret, | 88 | ret += hpp__call_print_fn(hpp, print_fn, |
81 | fmt, 0.0); | 89 | fmt, 0.0); |
82 | } else { | 90 | } else { |
83 | ret += print_fn(hpp->buf + ret, hpp->size - ret, | 91 | ret += hpp__call_print_fn(hpp, print_fn, |
84 | fmt, 0ULL); | 92 | fmt, 0ULL); |
85 | } | 93 | } |
86 | } | 94 | } |
87 | } | 95 | } |
96 | |||
97 | /* | ||
98 | * Restore original buf and size as it's where caller expects | ||
99 | * the result will be saved. | ||
100 | */ | ||
101 | hpp->buf = buf; | ||
102 | hpp->size = size; | ||
103 | |||
88 | return ret; | 104 | return ret; |
89 | } | 105 | } |
90 | 106 | ||
@@ -116,6 +132,34 @@ static int hpp__width_##_type(struct perf_hpp_fmt *fmt __maybe_unused, \ | |||
116 | return len; \ | 132 | return len; \ |
117 | } | 133 | } |
118 | 134 | ||
135 | static int hpp_color_scnprintf(struct perf_hpp *hpp, const char *fmt, ...) | ||
136 | { | ||
137 | va_list args; | ||
138 | ssize_t ssize = hpp->size; | ||
139 | double percent; | ||
140 | int ret; | ||
141 | |||
142 | va_start(args, fmt); | ||
143 | percent = va_arg(args, double); | ||
144 | ret = value_color_snprintf(hpp->buf, hpp->size, fmt, percent); | ||
145 | va_end(args); | ||
146 | |||
147 | return (ret >= ssize) ? (ssize - 1) : ret; | ||
148 | } | ||
149 | |||
150 | static int hpp_entry_scnprintf(struct perf_hpp *hpp, const char *fmt, ...) | ||
151 | { | ||
152 | va_list args; | ||
153 | ssize_t ssize = hpp->size; | ||
154 | int ret; | ||
155 | |||
156 | va_start(args, fmt); | ||
157 | ret = vsnprintf(hpp->buf, hpp->size, fmt, args); | ||
158 | va_end(args); | ||
159 | |||
160 | return (ret >= ssize) ? (ssize - 1) : ret; | ||
161 | } | ||
162 | |||
119 | #define __HPP_COLOR_PERCENT_FN(_type, _field) \ | 163 | #define __HPP_COLOR_PERCENT_FN(_type, _field) \ |
120 | static u64 he_get_##_field(struct hist_entry *he) \ | 164 | static u64 he_get_##_field(struct hist_entry *he) \ |
121 | { \ | 165 | { \ |
@@ -126,7 +170,7 @@ static int hpp__color_##_type(struct perf_hpp_fmt *fmt __maybe_unused, \ | |||
126 | struct perf_hpp *hpp, struct hist_entry *he) \ | 170 | struct perf_hpp *hpp, struct hist_entry *he) \ |
127 | { \ | 171 | { \ |
128 | return __hpp__fmt(hpp, he, he_get_##_field, " %6.2f%%", \ | 172 | return __hpp__fmt(hpp, he, he_get_##_field, " %6.2f%%", \ |
129 | percent_color_snprintf, true); \ | 173 | hpp_color_scnprintf, true); \ |
130 | } | 174 | } |
131 | 175 | ||
132 | #define __HPP_ENTRY_PERCENT_FN(_type, _field) \ | 176 | #define __HPP_ENTRY_PERCENT_FN(_type, _field) \ |
@@ -135,7 +179,7 @@ static int hpp__entry_##_type(struct perf_hpp_fmt *_fmt __maybe_unused, \ | |||
135 | { \ | 179 | { \ |
136 | const char *fmt = symbol_conf.field_sep ? " %.2f" : " %6.2f%%"; \ | 180 | const char *fmt = symbol_conf.field_sep ? " %.2f" : " %6.2f%%"; \ |
137 | return __hpp__fmt(hpp, he, he_get_##_field, fmt, \ | 181 | return __hpp__fmt(hpp, he, he_get_##_field, fmt, \ |
138 | scnprintf, true); \ | 182 | hpp_entry_scnprintf, true); \ |
139 | } | 183 | } |
140 | 184 | ||
141 | #define __HPP_ENTRY_RAW_FN(_type, _field) \ | 185 | #define __HPP_ENTRY_RAW_FN(_type, _field) \ |
@@ -148,7 +192,8 @@ static int hpp__entry_##_type(struct perf_hpp_fmt *_fmt __maybe_unused, \ | |||
148 | struct perf_hpp *hpp, struct hist_entry *he) \ | 192 | struct perf_hpp *hpp, struct hist_entry *he) \ |
149 | { \ | 193 | { \ |
150 | const char *fmt = symbol_conf.field_sep ? " %"PRIu64 : " %11"PRIu64; \ | 194 | const char *fmt = symbol_conf.field_sep ? " %"PRIu64 : " %11"PRIu64; \ |
151 | return __hpp__fmt(hpp, he, he_get_raw_##_field, fmt, scnprintf, false); \ | 195 | return __hpp__fmt(hpp, he, he_get_raw_##_field, fmt, \ |
196 | hpp_entry_scnprintf, false); \ | ||
152 | } | 197 | } |
153 | 198 | ||
154 | #define HPP_PERCENT_FNS(_type, _str, _field, _min_width, _unit_width) \ | 199 | #define HPP_PERCENT_FNS(_type, _str, _field, _min_width, _unit_width) \ |
diff --git a/tools/perf/ui/stdio/hist.c b/tools/perf/ui/stdio/hist.c index 831fbb77d1ff..9bad89228472 100644 --- a/tools/perf/ui/stdio/hist.c +++ b/tools/perf/ui/stdio/hist.c | |||
@@ -306,12 +306,6 @@ static size_t hist_entry__callchain_fprintf(struct hist_entry *he, | |||
306 | return hist_entry_callchain__fprintf(he, total_period, left_margin, fp); | 306 | return hist_entry_callchain__fprintf(he, total_period, left_margin, fp); |
307 | } | 307 | } |
308 | 308 | ||
309 | static inline void advance_hpp(struct perf_hpp *hpp, int inc) | ||
310 | { | ||
311 | hpp->buf += inc; | ||
312 | hpp->size -= inc; | ||
313 | } | ||
314 | |||
315 | static int hist_entry__period_snprintf(struct perf_hpp *hpp, | 309 | static int hist_entry__period_snprintf(struct perf_hpp *hpp, |
316 | struct hist_entry *he) | 310 | struct hist_entry *he) |
317 | { | 311 | { |