diff options
author | Arnaldo Carvalho de Melo <acme@redhat.com> | 2010-08-10 13:54:09 -0400 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2010-08-10 15:09:41 -0400 |
commit | 211ef12771e759a08e10c3c606e6a8b1663519e7 (patch) | |
tree | f9881f574f9a7508ce47d125daad0a089bef5add /tools/perf/util/newt.c | |
parent | 34cea7f7c0620c964676eece258ef431a6608bce (diff) |
perf ui: Move annotate browser to util/ui/browsers/
LKML-Reference: <new-submission>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf/util/newt.c')
-rw-r--r-- | tools/perf/util/newt.c | 132 |
1 files changed, 2 insertions, 130 deletions
diff --git a/tools/perf/util/newt.c b/tools/perf/util/newt.c index c0986d342954..f1882589c826 100644 --- a/tools/perf/util/newt.c +++ b/tools/perf/util/newt.c | |||
@@ -1,16 +1,7 @@ | |||
1 | #define _GNU_SOURCE | 1 | #define _GNU_SOURCE |
2 | #include <stdio.h> | 2 | #include <stdio.h> |
3 | #undef _GNU_SOURCE | 3 | #undef _GNU_SOURCE |
4 | /* | 4 | #include "ui/libslang.h" |
5 | * slang versions <= 2.0.6 have a "#if HAVE_LONG_LONG" that breaks | ||
6 | * the build if it isn't defined. Use the equivalent one that glibc | ||
7 | * has on features.h. | ||
8 | */ | ||
9 | #include <features.h> | ||
10 | #ifndef HAVE_LONG_LONG | ||
11 | #define HAVE_LONG_LONG __GLIBC_HAVE_LONG_LONG | ||
12 | #endif | ||
13 | #include <slang.h> | ||
14 | #include <signal.h> | 5 | #include <signal.h> |
15 | #include <stdlib.h> | 6 | #include <stdlib.h> |
16 | #include <elf.h> | 7 | #include <elf.h> |
@@ -26,17 +17,6 @@ | |||
26 | #include "ui/browser.h" | 17 | #include "ui/browser.h" |
27 | #include "ui/helpline.h" | 18 | #include "ui/helpline.h" |
28 | 19 | ||
29 | #if SLANG_VERSION < 20104 | ||
30 | #define slsmg_printf(msg, args...) SLsmg_printf((char *)msg, ##args) | ||
31 | #define slsmg_write_nstring(msg, len) SLsmg_write_nstring((char *)msg, len) | ||
32 | #define sltt_set_color(obj, name, fg, bg) SLtt_set_color(obj,(char *)name,\ | ||
33 | (char *)fg, (char *)bg) | ||
34 | #else | ||
35 | #define slsmg_printf SLsmg_printf | ||
36 | #define slsmg_write_nstring SLsmg_write_nstring | ||
37 | #define sltt_set_color SLtt_set_color | ||
38 | #endif | ||
39 | |||
40 | newtComponent newt_form__new(void); | 20 | newtComponent newt_form__new(void); |
41 | 21 | ||
42 | static int ui_entry__read(const char *title, char *bf, size_t size, int width) | 22 | static int ui_entry__read(const char *title, char *bf, size_t size, int width) |
@@ -72,7 +52,7 @@ out_free_form: | |||
72 | return 0; | 52 | return 0; |
73 | } | 53 | } |
74 | 54 | ||
75 | static char browser__last_msg[1024]; | 55 | char browser__last_msg[1024]; |
76 | 56 | ||
77 | int browser__show_help(const char *format, va_list ap) | 57 | int browser__show_help(const char *format, va_list ap) |
78 | { | 58 | { |
@@ -192,66 +172,6 @@ static bool dialog_yesno(const char *msg) | |||
192 | return newtWinChoice(NULL, yes, no, (char *)msg) == 1; | 172 | return newtWinChoice(NULL, yes, no, (char *)msg) == 1; |
193 | } | 173 | } |
194 | 174 | ||
195 | static void ui__error_window(const char *fmt, ...) | ||
196 | { | ||
197 | va_list ap; | ||
198 | |||
199 | va_start(ap, fmt); | ||
200 | newtWinMessagev((char *)"Error", (char *)"Ok", (char *)fmt, ap); | ||
201 | va_end(ap); | ||
202 | } | ||
203 | |||
204 | static void annotate_browser__write(struct ui_browser *self, void *entry, int row) | ||
205 | { | ||
206 | struct objdump_line *ol = rb_entry(entry, struct objdump_line, node); | ||
207 | bool current_entry = ui_browser__is_current_entry(self, row); | ||
208 | int width = self->width; | ||
209 | |||
210 | if (ol->offset != -1) { | ||
211 | struct hist_entry *he = self->priv; | ||
212 | struct symbol *sym = he->ms.sym; | ||
213 | int len = he->ms.sym->end - he->ms.sym->start; | ||
214 | unsigned int hits = 0; | ||
215 | double percent = 0.0; | ||
216 | int color; | ||
217 | struct sym_priv *priv = symbol__priv(sym); | ||
218 | struct sym_ext *sym_ext = priv->ext; | ||
219 | struct sym_hist *h = priv->hist; | ||
220 | s64 offset = ol->offset; | ||
221 | struct objdump_line *next = objdump__get_next_ip_line(self->entries, ol); | ||
222 | |||
223 | while (offset < (s64)len && | ||
224 | (next == NULL || offset < next->offset)) { | ||
225 | if (sym_ext) { | ||
226 | percent += sym_ext[offset].percent; | ||
227 | } else | ||
228 | hits += h->ip[offset]; | ||
229 | |||
230 | ++offset; | ||
231 | } | ||
232 | |||
233 | if (sym_ext == NULL && h->sum) | ||
234 | percent = 100.0 * hits / h->sum; | ||
235 | |||
236 | color = ui_browser__percent_color(percent, current_entry); | ||
237 | SLsmg_set_color(color); | ||
238 | slsmg_printf(" %7.2f ", percent); | ||
239 | if (!current_entry) | ||
240 | SLsmg_set_color(HE_COLORSET_CODE); | ||
241 | } else { | ||
242 | int color = ui_browser__percent_color(0, current_entry); | ||
243 | SLsmg_set_color(color); | ||
244 | slsmg_write_nstring(" ", 9); | ||
245 | } | ||
246 | |||
247 | SLsmg_write_char(':'); | ||
248 | slsmg_write_nstring(" ", 8); | ||
249 | if (!*ol->line) | ||
250 | slsmg_write_nstring(" ", width - 18); | ||
251 | else | ||
252 | slsmg_write_nstring(ol->line, width - 18); | ||
253 | } | ||
254 | |||
255 | static char *callchain_list__sym_name(struct callchain_list *self, | 175 | static char *callchain_list__sym_name(struct callchain_list *self, |
256 | char *bf, size_t bfsize) | 176 | char *bf, size_t bfsize) |
257 | { | 177 | { |
@@ -262,54 +182,6 @@ static char *callchain_list__sym_name(struct callchain_list *self, | |||
262 | return bf; | 182 | return bf; |
263 | } | 183 | } |
264 | 184 | ||
265 | int hist_entry__tui_annotate(struct hist_entry *self) | ||
266 | { | ||
267 | struct newtExitStruct es; | ||
268 | struct objdump_line *pos, *n; | ||
269 | LIST_HEAD(head); | ||
270 | struct ui_browser browser = { | ||
271 | .entries = &head, | ||
272 | .refresh = ui_browser__list_head_refresh, | ||
273 | .seek = ui_browser__list_head_seek, | ||
274 | .write = annotate_browser__write, | ||
275 | .priv = self, | ||
276 | }; | ||
277 | int ret; | ||
278 | |||
279 | if (self->ms.sym == NULL) | ||
280 | return -1; | ||
281 | |||
282 | if (self->ms.map->dso->annotate_warned) | ||
283 | return -1; | ||
284 | |||
285 | if (hist_entry__annotate(self, &head) < 0) { | ||
286 | ui__error_window(browser__last_msg); | ||
287 | return -1; | ||
288 | } | ||
289 | |||
290 | ui_helpline__push("Press <- or ESC to exit"); | ||
291 | |||
292 | list_for_each_entry(pos, &head, node) { | ||
293 | size_t line_len = strlen(pos->line); | ||
294 | if (browser.width < line_len) | ||
295 | browser.width = line_len; | ||
296 | ++browser.nr_entries; | ||
297 | } | ||
298 | |||
299 | browser.width += 18; /* Percentage */ | ||
300 | ui_browser__show(&browser, self->ms.sym->name); | ||
301 | newtFormAddHotKey(browser.form, ' '); | ||
302 | ret = ui_browser__run(&browser, &es); | ||
303 | newtFormDestroy(browser.form); | ||
304 | newtPopWindow(); | ||
305 | list_for_each_entry_safe(pos, n, &head, node) { | ||
306 | list_del(&pos->node); | ||
307 | objdump_line__free(pos); | ||
308 | } | ||
309 | ui_helpline__pop(); | ||
310 | return ret; | ||
311 | } | ||
312 | |||
313 | /* -------------------------------------------------------------------- */ | 185 | /* -------------------------------------------------------------------- */ |
314 | 186 | ||
315 | struct map_browser { | 187 | struct map_browser { |