diff options
| author | Arnaldo Carvalho de Melo <acme@redhat.com> | 2011-10-26 06:00:55 -0400 |
|---|---|---|
| committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2011-10-26 11:06:36 -0400 |
| commit | ae55795ef2d9ba71d46e4111b87a4d0cde93abea (patch) | |
| tree | dcd1afdaa5942cb661774f4c4b96353327ae1f28 | |
| parent | 1056d3dd9416740ec7d31348ca5f55009dc06bf3 (diff) | |
perf ui: Reimplement the popup windows using libslang
Just another step in stopping the use of libnewt in perf.
Cc: David Ahern <dsahern@gmail.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/n/tip-vtxnmz1t1807ykprapnk9njl@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
| -rw-r--r-- | tools/perf/util/annotate.c | 9 | ||||
| -rw-r--r-- | tools/perf/util/debug.h | 1 | ||||
| -rw-r--r-- | tools/perf/util/ui/browsers/annotate.c | 14 | ||||
| -rw-r--r-- | tools/perf/util/ui/setup.c | 8 | ||||
| -rw-r--r-- | tools/perf/util/ui/util.c | 110 | ||||
| -rw-r--r-- | tools/perf/util/ui/util.h | 2 |
6 files changed, 77 insertions, 67 deletions
diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c index bc8f4773d4d8..119e996035c8 100644 --- a/tools/perf/util/annotate.c +++ b/tools/perf/util/annotate.c | |||
| @@ -310,9 +310,12 @@ fallback: | |||
| 310 | } | 310 | } |
| 311 | err = -ENOENT; | 311 | err = -ENOENT; |
| 312 | dso->annotate_warned = 1; | 312 | dso->annotate_warned = 1; |
| 313 | pr_err("Can't annotate %s: No vmlinux file%s was found in the " | 313 | pr_err("Can't annotate %s:\n\n" |
| 314 | "path.\nPlease use 'perf buildid-cache -av vmlinux' or " | 314 | "No vmlinux file%s\nwas found in the path.\n\n" |
| 315 | "--vmlinux vmlinux.\n", | 315 | "Please use:\n\n" |
| 316 | " perf buildid-cache -av vmlinux\n\n" | ||
| 317 | "or:\n\n" | ||
| 318 | " --vmlinux vmlinux", | ||
| 316 | sym->name, build_id_msg ?: ""); | 319 | sym->name, build_id_msg ?: ""); |
| 317 | goto out_free_filename; | 320 | goto out_free_filename; |
| 318 | } | 321 | } |
diff --git a/tools/perf/util/debug.h b/tools/perf/util/debug.h index 510adaccba84..9c59b9551ada 100644 --- a/tools/perf/util/debug.h +++ b/tools/perf/util/debug.h | |||
| @@ -29,5 +29,6 @@ int ui_helpline__show_help(const char *format, va_list ap); | |||
| 29 | 29 | ||
| 30 | void ui__warning(const char *format, ...) __attribute__((format(printf, 1, 2))); | 30 | void ui__warning(const char *format, ...) __attribute__((format(printf, 1, 2))); |
| 31 | void ui__warning_paranoid(void); | 31 | void ui__warning_paranoid(void); |
| 32 | void ui__error(const char *format, ...) __attribute__((format(printf, 1, 2))); | ||
| 32 | 33 | ||
| 33 | #endif /* __PERF_DEBUG_H */ | 34 | #endif /* __PERF_DEBUG_H */ |
diff --git a/tools/perf/util/ui/browsers/annotate.c b/tools/perf/util/ui/browsers/annotate.c index 4e0cb7fea7d9..0575905d1205 100644 --- a/tools/perf/util/ui/browsers/annotate.c +++ b/tools/perf/util/ui/browsers/annotate.c | |||
| @@ -1,6 +1,9 @@ | |||
| 1 | #include "../../util.h" | ||
| 1 | #include "../browser.h" | 2 | #include "../browser.h" |
| 2 | #include "../helpline.h" | 3 | #include "../helpline.h" |
| 3 | #include "../libslang.h" | 4 | #include "../libslang.h" |
| 5 | #include "../ui.h" | ||
| 6 | #include "../util.h" | ||
| 4 | #include "../../annotate.h" | 7 | #include "../../annotate.h" |
| 5 | #include "../../hist.h" | 8 | #include "../../hist.h" |
| 6 | #include "../../sort.h" | 9 | #include "../../sort.h" |
| @@ -8,15 +11,6 @@ | |||
| 8 | #include <pthread.h> | 11 | #include <pthread.h> |
| 9 | #include <newt.h> | 12 | #include <newt.h> |
| 10 | 13 | ||
| 11 | static void ui__error_window(const char *fmt, ...) | ||
| 12 | { | ||
| 13 | va_list ap; | ||
| 14 | |||
| 15 | va_start(ap, fmt); | ||
| 16 | newtWinMessagev((char *)"Error", (char *)"Ok", (char *)fmt, ap); | ||
| 17 | va_end(ap); | ||
| 18 | } | ||
| 19 | |||
| 20 | struct annotate_browser { | 14 | struct annotate_browser { |
| 21 | struct ui_browser b; | 15 | struct ui_browser b; |
| 22 | struct rb_root entries; | 16 | struct rb_root entries; |
| @@ -400,7 +394,7 @@ int symbol__tui_annotate(struct symbol *sym, struct map *map, int evidx, | |||
| 400 | return -1; | 394 | return -1; |
| 401 | 395 | ||
| 402 | if (symbol__annotate(sym, map, sizeof(struct objdump_line_rb_node)) < 0) { | 396 | if (symbol__annotate(sym, map, sizeof(struct objdump_line_rb_node)) < 0) { |
| 403 | ui__error_window(ui_helpline__last_msg); | 397 | ui__error("%s", ui_helpline__last_msg); |
| 404 | return -1; | 398 | return -1; |
| 405 | } | 399 | } |
| 406 | 400 | ||
diff --git a/tools/perf/util/ui/setup.c b/tools/perf/util/ui/setup.c index c4e025fbd6b9..85a69faa09aa 100644 --- a/tools/perf/util/ui/setup.c +++ b/tools/perf/util/ui/setup.c | |||
| @@ -146,10 +146,10 @@ void setup_browser(bool fallback_to_pager) | |||
| 146 | void exit_browser(bool wait_for_ok) | 146 | void exit_browser(bool wait_for_ok) |
| 147 | { | 147 | { |
| 148 | if (use_browser > 0) { | 148 | if (use_browser > 0) { |
| 149 | if (wait_for_ok) { | 149 | if (wait_for_ok) |
| 150 | char title[] = "Fatal Error", ok[] = "Ok"; | 150 | ui__question_window("Fatal Error", |
| 151 | newtWinMessage(title, ok, ui_helpline__last_msg); | 151 | ui_helpline__last_msg, |
| 152 | } | 152 | "Press any key...", 0); |
| 153 | ui__exit(); | 153 | ui__exit(); |
| 154 | } | 154 | } |
| 155 | } | 155 | } |
diff --git a/tools/perf/util/ui/util.c b/tools/perf/util/ui/util.c index 37e6fe081a58..ef9b79332fe8 100644 --- a/tools/perf/util/ui/util.c +++ b/tools/perf/util/ui/util.c | |||
| @@ -1,6 +1,5 @@ | |||
| 1 | #include <newt.h> | 1 | #include "../util.h" |
| 2 | #include <signal.h> | 2 | #include <signal.h> |
| 3 | #include <stdio.h> | ||
| 4 | #include <stdbool.h> | 3 | #include <stdbool.h> |
| 5 | #include <string.h> | 4 | #include <string.h> |
| 6 | #include <sys/ttydefaults.h> | 5 | #include <sys/ttydefaults.h> |
| @@ -12,6 +11,7 @@ | |||
| 12 | #include "helpline.h" | 11 | #include "helpline.h" |
| 13 | #include "ui.h" | 12 | #include "ui.h" |
| 14 | #include "util.h" | 13 | #include "util.h" |
| 14 | #include "libslang.h" | ||
| 15 | 15 | ||
| 16 | static void ui_browser__argv_write(struct ui_browser *browser, | 16 | static void ui_browser__argv_write(struct ui_browser *browser, |
| 17 | void *entry, int row) | 17 | void *entry, int row) |
| @@ -56,23 +56,6 @@ static int popup_menu__run(struct ui_browser *menu) | |||
| 56 | return key; | 56 | return key; |
| 57 | } | 57 | } |
| 58 | 58 | ||
| 59 | static void newt_form__set_exit_keys(newtComponent self) | ||
| 60 | { | ||
| 61 | newtFormAddHotKey(self, NEWT_KEY_LEFT); | ||
| 62 | newtFormAddHotKey(self, NEWT_KEY_ESCAPE); | ||
| 63 | newtFormAddHotKey(self, 'Q'); | ||
| 64 | newtFormAddHotKey(self, 'q'); | ||
| 65 | newtFormAddHotKey(self, CTRL('c')); | ||
| 66 | } | ||
| 67 | |||
| 68 | static newtComponent newt_form__new(void) | ||
| 69 | { | ||
| 70 | newtComponent self = newtForm(NULL, NULL, 0); | ||
| 71 | if (self) | ||
| 72 | newt_form__set_exit_keys(self); | ||
| 73 | return self; | ||
| 74 | } | ||
| 75 | |||
| 76 | int ui__popup_menu(int argc, char * const argv[]) | 59 | int ui__popup_menu(int argc, char * const argv[]) |
| 77 | { | 60 | { |
| 78 | struct ui_browser menu = { | 61 | struct ui_browser menu = { |
| @@ -86,17 +69,13 @@ int ui__popup_menu(int argc, char * const argv[]) | |||
| 86 | return popup_menu__run(&menu); | 69 | return popup_menu__run(&menu); |
| 87 | } | 70 | } |
| 88 | 71 | ||
| 89 | int ui__help_window(const char *text) | 72 | int ui__question_window(const char *title, const char *text, |
| 73 | const char *exit_msg, int delay_secs) | ||
| 90 | { | 74 | { |
| 91 | struct newtExitStruct es; | 75 | int x, y; |
| 92 | newtComponent tb, form = newt_form__new(); | ||
| 93 | int rc = -1; | ||
| 94 | int max_len = 0, nr_lines = 0; | 76 | int max_len = 0, nr_lines = 0; |
| 95 | const char *t; | 77 | const char *t; |
| 96 | 78 | ||
| 97 | if (form == NULL) | ||
| 98 | return -1; | ||
| 99 | |||
| 100 | t = text; | 79 | t = text; |
| 101 | while (1) { | 80 | while (1) { |
| 102 | const char *sep = strchr(t, '\n'); | 81 | const char *sep = strchr(t, '\n'); |
| @@ -113,28 +92,56 @@ int ui__help_window(const char *text) | |||
| 113 | t = sep + 1; | 92 | t = sep + 1; |
| 114 | } | 93 | } |
| 115 | 94 | ||
| 116 | tb = newtTextbox(0, 0, max_len, nr_lines, 0); | 95 | max_len += 2; |
| 117 | if (tb == NULL) | 96 | nr_lines += 4; |
| 118 | goto out_destroy_form; | 97 | y = SLtt_Screen_Rows / 2 - nr_lines / 2, |
| 119 | 98 | x = SLtt_Screen_Cols / 2 - max_len / 2; | |
| 120 | newtTextboxSetText(tb, text); | 99 | |
| 121 | newtFormAddComponent(form, tb); | 100 | SLsmg_set_color(0); |
| 122 | newtCenteredWindow(max_len, nr_lines, NULL); | 101 | SLsmg_draw_box(y, x++, nr_lines, max_len); |
| 123 | newtFormRun(form, &es); | 102 | if (title) { |
| 124 | newtPopWindow(); | 103 | SLsmg_gotorc(y, x + 1); |
| 125 | rc = 0; | 104 | SLsmg_write_string((char *)title); |
| 126 | out_destroy_form: | 105 | } |
| 127 | newtFormDestroy(form); | 106 | SLsmg_gotorc(++y, x); |
| 128 | return rc; | 107 | nr_lines -= 2; |
| 108 | max_len -= 2; | ||
| 109 | SLsmg_write_wrapped_string((unsigned char *)text, y, x, | ||
| 110 | nr_lines, max_len, 1); | ||
| 111 | SLsmg_gotorc(y + nr_lines - 2, x); | ||
| 112 | SLsmg_write_nstring((char *)" ", max_len); | ||
| 113 | SLsmg_gotorc(y + nr_lines - 1, x); | ||
| 114 | SLsmg_write_nstring((char *)exit_msg, max_len); | ||
| 115 | SLsmg_refresh(); | ||
| 116 | return ui__getch(delay_secs); | ||
| 129 | } | 117 | } |
| 130 | 118 | ||
| 131 | static const char yes[] = "Yes", no[] = "No", | 119 | int ui__help_window(const char *text) |
| 132 | warning_str[] = "Warning!", ok[] = "Ok"; | 120 | { |
| 121 | return ui__question_window("Help", text, "Press any key...", 0); | ||
| 122 | } | ||
| 133 | 123 | ||
| 134 | bool ui__dialog_yesno(const char *msg) | 124 | bool ui__dialog_yesno(const char *msg) |
| 135 | { | 125 | { |
| 136 | /* newtWinChoice should really be accepting const char pointers... */ | 126 | int answer = ui__question_window(NULL, msg, "Enter: Yes, ESC: No", 0); |
| 137 | return newtWinChoice(NULL, (char *)yes, (char *)no, (char *)msg) == 1; | 127 | |
| 128 | return answer == K_ENTER; | ||
| 129 | } | ||
| 130 | |||
| 131 | static void __ui__warning(const char *title, const char *format, va_list args) | ||
| 132 | { | ||
| 133 | char *s; | ||
| 134 | |||
| 135 | if (use_browser > 0 && vasprintf(&s, format, args) > 0) { | ||
| 136 | pthread_mutex_lock(&ui__lock); | ||
| 137 | ui__question_window(title, s, "Press any key...", 0); | ||
| 138 | pthread_mutex_unlock(&ui__lock); | ||
| 139 | free(s); | ||
| 140 | return; | ||
| 141 | } | ||
| 142 | |||
| 143 | fprintf(stderr, "%s:\n", title); | ||
| 144 | vfprintf(stderr, format, args); | ||
| 138 | } | 145 | } |
| 139 | 146 | ||
| 140 | void ui__warning(const char *format, ...) | 147 | void ui__warning(const char *format, ...) |
| @@ -142,12 +149,15 @@ void ui__warning(const char *format, ...) | |||
| 142 | va_list args; | 149 | va_list args; |
| 143 | 150 | ||
| 144 | va_start(args, format); | 151 | va_start(args, format); |
| 145 | if (use_browser > 0) { | 152 | __ui__warning("Warning", format, args); |
| 146 | pthread_mutex_lock(&ui__lock); | 153 | va_end(args); |
| 147 | newtWinMessagev((char *)warning_str, (char *)ok, | 154 | } |
| 148 | (char *)format, args); | 155 | |
| 149 | pthread_mutex_unlock(&ui__lock); | 156 | void ui__error(const char *format, ...) |
| 150 | } else | 157 | { |
| 151 | vfprintf(stderr, format, args); | 158 | va_list args; |
| 159 | |||
| 160 | va_start(args, format); | ||
| 161 | __ui__warning("Error", format, args); | ||
| 152 | va_end(args); | 162 | va_end(args); |
| 153 | } | 163 | } |
diff --git a/tools/perf/util/ui/util.h b/tools/perf/util/ui/util.h index e53c3d334903..9a25538d4735 100644 --- a/tools/perf/util/ui/util.h +++ b/tools/perf/util/ui/util.h | |||
| @@ -7,5 +7,7 @@ int ui__getch(int delay_secs); | |||
| 7 | int ui__popup_menu(int argc, char * const argv[]); | 7 | int ui__popup_menu(int argc, char * const argv[]); |
| 8 | int ui__help_window(const char *text); | 8 | int ui__help_window(const char *text); |
| 9 | bool ui__dialog_yesno(const char *msg); | 9 | bool ui__dialog_yesno(const char *msg); |
| 10 | int ui__question_window(const char *title, const char *text, | ||
| 11 | const char *exit_msg, int delay_secs); | ||
| 10 | 12 | ||
| 11 | #endif /* _PERF_UI_UTIL_H_ */ | 13 | #endif /* _PERF_UI_UTIL_H_ */ |
