diff options
author | Arnaldo Carvalho de Melo <acme@redhat.com> | 2011-10-26 10:04:37 -0400 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2011-10-26 11:15:07 -0400 |
commit | 4610e4137b5fb93042a248928a2c0049ef7d4190 (patch) | |
tree | 163cd2366d5870a67619aa4774cfc04cf7a97d6f | |
parent | 0458122db0a2ebd1d3779469cb6184d8b195be09 (diff) |
perf ui browser: Handle K_RESIZE in dialog windows
Just provide wrappers for things like ui__warning, ui__dialog_yesno and
if they return K_RESIZE, refresh dimensions, redraw the entries, etc.
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-3ih7hyk9weryxaxb501sfq4u@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
-rw-r--r-- | tools/perf/util/debug.c | 7 | ||||
-rw-r--r-- | tools/perf/util/debug.h | 6 | ||||
-rw-r--r-- | tools/perf/util/ui/browser.c | 40 | ||||
-rw-r--r-- | tools/perf/util/ui/browser.h | 5 | ||||
-rw-r--r-- | tools/perf/util/ui/browsers/hists.c | 22 | ||||
-rw-r--r-- | tools/perf/util/ui/helpline.c | 6 | ||||
-rw-r--r-- | tools/perf/util/ui/helpline.h | 2 | ||||
-rw-r--r-- | tools/perf/util/ui/util.c | 27 | ||||
-rw-r--r-- | tools/perf/util/ui/util.h | 5 |
9 files changed, 94 insertions, 26 deletions
diff --git a/tools/perf/util/debug.c b/tools/perf/util/debug.c index 55634038af6b..26817daa2961 100644 --- a/tools/perf/util/debug.c +++ b/tools/perf/util/debug.c | |||
@@ -47,19 +47,20 @@ int dump_printf(const char *fmt, ...) | |||
47 | } | 47 | } |
48 | 48 | ||
49 | #ifdef NO_NEWT_SUPPORT | 49 | #ifdef NO_NEWT_SUPPORT |
50 | void ui__warning(const char *format, ...) | 50 | int ui__warning(const char *format, ...) |
51 | { | 51 | { |
52 | va_list args; | 52 | va_list args; |
53 | 53 | ||
54 | va_start(args, format); | 54 | va_start(args, format); |
55 | vfprintf(stderr, format, args); | 55 | vfprintf(stderr, format, args); |
56 | va_end(args); | 56 | va_end(args); |
57 | return 0; | ||
57 | } | 58 | } |
58 | #endif | 59 | #endif |
59 | 60 | ||
60 | void ui__error_paranoid(void) | 61 | int ui__error_paranoid(void) |
61 | { | 62 | { |
62 | ui__error("Permission error - are you root?\n" | 63 | return ui__error("Permission error - are you root?\n" |
63 | "Consider tweaking /proc/sys/kernel/perf_event_paranoid:\n" | 64 | "Consider tweaking /proc/sys/kernel/perf_event_paranoid:\n" |
64 | " -1 - Not paranoid at all\n" | 65 | " -1 - Not paranoid at all\n" |
65 | " 0 - Disallow raw tracepoint access for unpriv\n" | 66 | " 0 - Disallow raw tracepoint access for unpriv\n" |
diff --git a/tools/perf/util/debug.h b/tools/perf/util/debug.h index 16cc75227d2b..f2ce88d04f54 100644 --- a/tools/perf/util/debug.h +++ b/tools/perf/util/debug.h | |||
@@ -27,10 +27,10 @@ static inline void ui_progress__update(u64 curr __used, u64 total __used, | |||
27 | extern char ui_helpline__last_msg[]; | 27 | extern char ui_helpline__last_msg[]; |
28 | int ui_helpline__show_help(const char *format, va_list ap); | 28 | int ui_helpline__show_help(const char *format, va_list ap); |
29 | #include "ui/progress.h" | 29 | #include "ui/progress.h" |
30 | void ui__error(const char *format, ...) __attribute__((format(printf, 1, 2))); | 30 | int ui__error(const char *format, ...) __attribute__((format(printf, 1, 2))); |
31 | #endif | 31 | #endif |
32 | 32 | ||
33 | void ui__warning(const char *format, ...) __attribute__((format(printf, 1, 2))); | 33 | int ui__warning(const char *format, ...) __attribute__((format(printf, 1, 2))); |
34 | void ui__error_paranoid(void); | 34 | int ui__error_paranoid(void); |
35 | 35 | ||
36 | #endif /* __PERF_DEBUG_H */ | 36 | #endif /* __PERF_DEBUG_H */ |
diff --git a/tools/perf/util/ui/browser.c b/tools/perf/util/ui/browser.c index 8607efa13564..d2051be04f12 100644 --- a/tools/perf/util/ui/browser.c +++ b/tools/perf/util/ui/browser.c | |||
@@ -169,6 +169,46 @@ void ui_browser__refresh_dimensions(struct ui_browser *self) | |||
169 | self->x = 0; | 169 | self->x = 0; |
170 | } | 170 | } |
171 | 171 | ||
172 | void ui_browser__handle_resize(struct ui_browser *browser) | ||
173 | { | ||
174 | ui__refresh_dimensions(false); | ||
175 | ui_browser__show(browser, browser->title, ui_helpline__current); | ||
176 | ui_browser__refresh(browser); | ||
177 | } | ||
178 | |||
179 | int ui_browser__warning(struct ui_browser *browser, const char *format, ...) | ||
180 | { | ||
181 | va_list args; | ||
182 | int key; | ||
183 | |||
184 | va_start(args, format); | ||
185 | while ((key = __ui__warning("Warning!", format, args)) == K_RESIZE) | ||
186 | ui_browser__handle_resize(browser); | ||
187 | va_end(args); | ||
188 | |||
189 | return key; | ||
190 | } | ||
191 | |||
192 | int ui_browser__help_window(struct ui_browser *browser, const char *text) | ||
193 | { | ||
194 | int key; | ||
195 | |||
196 | while ((key = ui__help_window(text)) == K_RESIZE) | ||
197 | ui_browser__handle_resize(browser); | ||
198 | |||
199 | return key; | ||
200 | } | ||
201 | |||
202 | bool ui_browser__dialog_yesno(struct ui_browser *browser, const char *text) | ||
203 | { | ||
204 | int key; | ||
205 | |||
206 | while ((key = ui__dialog_yesno(text)) == K_RESIZE) | ||
207 | ui_browser__handle_resize(browser); | ||
208 | |||
209 | return key == K_ENTER || toupper(key) == 'Y'; | ||
210 | } | ||
211 | |||
172 | void ui_browser__reset_index(struct ui_browser *self) | 212 | void ui_browser__reset_index(struct ui_browser *self) |
173 | { | 213 | { |
174 | self->index = self->top_idx = 0; | 214 | self->index = self->top_idx = 0; |
diff --git a/tools/perf/util/ui/browser.h b/tools/perf/util/ui/browser.h index 81a8d2afaa9b..fb1c59883e6a 100644 --- a/tools/perf/util/ui/browser.h +++ b/tools/perf/util/ui/browser.h | |||
@@ -43,6 +43,11 @@ void ui_browser__hide(struct ui_browser *self); | |||
43 | int ui_browser__refresh(struct ui_browser *self); | 43 | int ui_browser__refresh(struct ui_browser *self); |
44 | int ui_browser__run(struct ui_browser *browser, int delay_secs); | 44 | int ui_browser__run(struct ui_browser *browser, int delay_secs); |
45 | void ui_browser__update_nr_entries(struct ui_browser *browser, u32 nr_entries); | 45 | void ui_browser__update_nr_entries(struct ui_browser *browser, u32 nr_entries); |
46 | void ui_browser__handle_resize(struct ui_browser *browser); | ||
47 | |||
48 | int ui_browser__warning(struct ui_browser *browser, const char *format, ...); | ||
49 | int ui_browser__help_window(struct ui_browser *browser, const char *text); | ||
50 | bool ui_browser__dialog_yesno(struct ui_browser *browser, const char *text); | ||
46 | 51 | ||
47 | void ui_browser__argv_seek(struct ui_browser *browser, off_t offset, int whence); | 52 | void ui_browser__argv_seek(struct ui_browser *browser, off_t offset, int whence); |
48 | unsigned int ui_browser__argv_refresh(struct ui_browser *browser); | 53 | unsigned int ui_browser__argv_refresh(struct ui_browser *browser); |
diff --git a/tools/perf/util/ui/browsers/hists.c b/tools/perf/util/ui/browsers/hists.c index 44210d471719..b8733c0770cd 100644 --- a/tools/perf/util/ui/browsers/hists.c +++ b/tools/perf/util/ui/browsers/hists.c | |||
@@ -17,6 +17,7 @@ | |||
17 | #include "../browser.h" | 17 | #include "../browser.h" |
18 | #include "../helpline.h" | 18 | #include "../helpline.h" |
19 | #include "../util.h" | 19 | #include "../util.h" |
20 | #include "../ui.h" | ||
20 | #include "map.h" | 21 | #include "map.h" |
21 | 22 | ||
22 | struct hist_browser { | 23 | struct hist_browser { |
@@ -882,7 +883,7 @@ static int perf_evsel__hists_browse(struct perf_evsel *evsel, int nr_events, | |||
882 | goto out_free_stack; | 883 | goto out_free_stack; |
883 | case 'a': | 884 | case 'a': |
884 | if (!browser->has_symbols) { | 885 | if (!browser->has_symbols) { |
885 | ui__warning( | 886 | ui_browser__warning(&browser->b, |
886 | "Annotation is only available for symbolic views, " | 887 | "Annotation is only available for symbolic views, " |
887 | "include \"sym\" in --sort to use it."); | 888 | "include \"sym\" in --sort to use it."); |
888 | continue; | 889 | continue; |
@@ -900,7 +901,8 @@ static int perf_evsel__hists_browse(struct perf_evsel *evsel, int nr_events, | |||
900 | case K_F1: | 901 | case K_F1: |
901 | case 'h': | 902 | case 'h': |
902 | case '?': | 903 | case '?': |
903 | ui__help_window("h/?/F1 Show this window\n" | 904 | ui_browser__help_window(&browser->b, |
905 | "h/?/F1 Show this window\n" | ||
904 | "UP/DOWN/PGUP\n" | 906 | "UP/DOWN/PGUP\n" |
905 | "PGDN/SPACE Navigate\n" | 907 | "PGDN/SPACE Navigate\n" |
906 | "q/ESC/CTRL+C Exit browser\n\n" | 908 | "q/ESC/CTRL+C Exit browser\n\n" |
@@ -939,7 +941,8 @@ static int perf_evsel__hists_browse(struct perf_evsel *evsel, int nr_events, | |||
939 | } | 941 | } |
940 | case K_ESC: | 942 | case K_ESC: |
941 | if (!left_exits && | 943 | if (!left_exits && |
942 | !ui__dialog_yesno("Do you really want to exit?")) | 944 | !ui_browser__dialog_yesno(&browser->b, |
945 | "Do you really want to exit?")) | ||
943 | continue; | 946 | continue; |
944 | /* Fall thru */ | 947 | /* Fall thru */ |
945 | case 'q': | 948 | case 'q': |
@@ -992,6 +995,7 @@ add_exit_option: | |||
992 | 995 | ||
993 | if (choice == annotate) { | 996 | if (choice == annotate) { |
994 | struct hist_entry *he; | 997 | struct hist_entry *he; |
998 | int err; | ||
995 | do_annotate: | 999 | do_annotate: |
996 | he = hist_browser__selected_entry(browser); | 1000 | he = hist_browser__selected_entry(browser); |
997 | if (he == NULL) | 1001 | if (he == NULL) |
@@ -1000,10 +1004,12 @@ do_annotate: | |||
1000 | * Don't let this be freed, say, by hists__decay_entry. | 1004 | * Don't let this be freed, say, by hists__decay_entry. |
1001 | */ | 1005 | */ |
1002 | he->used = true; | 1006 | he->used = true; |
1003 | hist_entry__tui_annotate(he, evsel->idx, nr_events, | 1007 | err = hist_entry__tui_annotate(he, evsel->idx, nr_events, |
1004 | timer, arg, delay_secs); | 1008 | timer, arg, delay_secs); |
1005 | he->used = false; | 1009 | he->used = false; |
1006 | ui_browser__update_nr_entries(&browser->b, browser->hists->nr_entries); | 1010 | ui_browser__update_nr_entries(&browser->b, browser->hists->nr_entries); |
1011 | if (err) | ||
1012 | ui_browser__handle_resize(&browser->b); | ||
1007 | } else if (choice == browse_map) | 1013 | } else if (choice == browse_map) |
1008 | map__browse(browser->selection->map); | 1014 | map__browse(browser->selection->map); |
1009 | else if (choice == zoom_dso) { | 1015 | else if (choice == zoom_dso) { |
@@ -1132,7 +1138,8 @@ browse_hists: | |||
1132 | pos = list_entry(pos->node.prev, struct perf_evsel, node); | 1138 | pos = list_entry(pos->node.prev, struct perf_evsel, node); |
1133 | goto browse_hists; | 1139 | goto browse_hists; |
1134 | case K_ESC: | 1140 | case K_ESC: |
1135 | if (!ui__dialog_yesno("Do you really want to exit?")) | 1141 | if (!ui_browser__dialog_yesno(&menu->b, |
1142 | "Do you really want to exit?")) | ||
1136 | continue; | 1143 | continue; |
1137 | /* Fall thru */ | 1144 | /* Fall thru */ |
1138 | case 'q': | 1145 | case 'q': |
@@ -1144,7 +1151,8 @@ browse_hists: | |||
1144 | case K_LEFT: | 1151 | case K_LEFT: |
1145 | continue; | 1152 | continue; |
1146 | case K_ESC: | 1153 | case K_ESC: |
1147 | if (!ui__dialog_yesno("Do you really want to exit?")) | 1154 | if (!ui_browser__dialog_yesno(&menu->b, |
1155 | "Do you really want to exit?")) | ||
1148 | continue; | 1156 | continue; |
1149 | /* Fall thru */ | 1157 | /* Fall thru */ |
1150 | case 'q': | 1158 | case 'q': |
diff --git a/tools/perf/util/ui/helpline.c b/tools/perf/util/ui/helpline.c index 600243d766c0..6ef3c5691762 100644 --- a/tools/perf/util/ui/helpline.c +++ b/tools/perf/util/ui/helpline.c | |||
@@ -1,6 +1,7 @@ | |||
1 | #define _GNU_SOURCE | 1 | #define _GNU_SOURCE |
2 | #include <stdio.h> | 2 | #include <stdio.h> |
3 | #include <stdlib.h> | 3 | #include <stdlib.h> |
4 | #include <string.h> | ||
4 | 5 | ||
5 | #include "../debug.h" | 6 | #include "../debug.h" |
6 | #include "helpline.h" | 7 | #include "helpline.h" |
@@ -11,12 +12,17 @@ void ui_helpline__pop(void) | |||
11 | { | 12 | { |
12 | } | 13 | } |
13 | 14 | ||
15 | char ui_helpline__current[512]; | ||
16 | |||
14 | void ui_helpline__push(const char *msg) | 17 | void ui_helpline__push(const char *msg) |
15 | { | 18 | { |
19 | const size_t sz = sizeof(ui_helpline__current); | ||
20 | |||
16 | SLsmg_gotorc(SLtt_Screen_Rows - 1, 0); | 21 | SLsmg_gotorc(SLtt_Screen_Rows - 1, 0); |
17 | SLsmg_set_color(0); | 22 | SLsmg_set_color(0); |
18 | SLsmg_write_nstring((char *)msg, SLtt_Screen_Cols); | 23 | SLsmg_write_nstring((char *)msg, SLtt_Screen_Cols); |
19 | SLsmg_refresh(); | 24 | SLsmg_refresh(); |
25 | strncpy(ui_helpline__current, msg, sz)[sz - 1] = '\0'; | ||
20 | } | 26 | } |
21 | 27 | ||
22 | void ui_helpline__vpush(const char *fmt, va_list ap) | 28 | void ui_helpline__vpush(const char *fmt, va_list ap) |
diff --git a/tools/perf/util/ui/helpline.h b/tools/perf/util/ui/helpline.h index fdcbc0270acd..7bab6b34e35e 100644 --- a/tools/perf/util/ui/helpline.h +++ b/tools/perf/util/ui/helpline.h | |||
@@ -11,4 +11,6 @@ void ui_helpline__vpush(const char *fmt, va_list ap); | |||
11 | void ui_helpline__fpush(const char *fmt, ...); | 11 | void ui_helpline__fpush(const char *fmt, ...); |
12 | void ui_helpline__puts(const char *msg); | 12 | void ui_helpline__puts(const char *msg); |
13 | 13 | ||
14 | extern char ui_helpline__current[]; | ||
15 | |||
14 | #endif /* _PERF_UI_HELPLINE_H_ */ | 16 | #endif /* _PERF_UI_HELPLINE_H_ */ |
diff --git a/tools/perf/util/ui/util.c b/tools/perf/util/ui/util.c index ef9b79332fe8..45daa7c41dad 100644 --- a/tools/perf/util/ui/util.c +++ b/tools/perf/util/ui/util.c | |||
@@ -121,43 +121,48 @@ int ui__help_window(const char *text) | |||
121 | return ui__question_window("Help", text, "Press any key...", 0); | 121 | return ui__question_window("Help", text, "Press any key...", 0); |
122 | } | 122 | } |
123 | 123 | ||
124 | bool ui__dialog_yesno(const char *msg) | 124 | int ui__dialog_yesno(const char *msg) |
125 | { | 125 | { |
126 | int answer = ui__question_window(NULL, msg, "Enter: Yes, ESC: No", 0); | 126 | return ui__question_window(NULL, msg, "Enter: Yes, ESC: No", 0); |
127 | |||
128 | return answer == K_ENTER; | ||
129 | } | 127 | } |
130 | 128 | ||
131 | static void __ui__warning(const char *title, const char *format, va_list args) | 129 | int __ui__warning(const char *title, const char *format, va_list args) |
132 | { | 130 | { |
133 | char *s; | 131 | char *s; |
134 | 132 | ||
135 | if (use_browser > 0 && vasprintf(&s, format, args) > 0) { | 133 | if (use_browser > 0 && vasprintf(&s, format, args) > 0) { |
134 | int key; | ||
135 | |||
136 | pthread_mutex_lock(&ui__lock); | 136 | pthread_mutex_lock(&ui__lock); |
137 | ui__question_window(title, s, "Press any key...", 0); | 137 | key = ui__question_window(title, s, "Press any key...", 0); |
138 | pthread_mutex_unlock(&ui__lock); | 138 | pthread_mutex_unlock(&ui__lock); |
139 | free(s); | 139 | free(s); |
140 | return; | 140 | return key; |
141 | } | 141 | } |
142 | 142 | ||
143 | fprintf(stderr, "%s:\n", title); | 143 | fprintf(stderr, "%s:\n", title); |
144 | vfprintf(stderr, format, args); | 144 | vfprintf(stderr, format, args); |
145 | return K_ESC; | ||
145 | } | 146 | } |
146 | 147 | ||
147 | void ui__warning(const char *format, ...) | 148 | int ui__warning(const char *format, ...) |
148 | { | 149 | { |
150 | int key; | ||
149 | va_list args; | 151 | va_list args; |
150 | 152 | ||
151 | va_start(args, format); | 153 | va_start(args, format); |
152 | __ui__warning("Warning", format, args); | 154 | key = __ui__warning("Warning", format, args); |
153 | va_end(args); | 155 | va_end(args); |
156 | return key; | ||
154 | } | 157 | } |
155 | 158 | ||
156 | void ui__error(const char *format, ...) | 159 | int ui__error(const char *format, ...) |
157 | { | 160 | { |
161 | int key; | ||
158 | va_list args; | 162 | va_list args; |
159 | 163 | ||
160 | va_start(args, format); | 164 | va_start(args, format); |
161 | __ui__warning("Error", format, args); | 165 | key = __ui__warning("Error", format, args); |
162 | va_end(args); | 166 | va_end(args); |
167 | return key; | ||
163 | } | 168 | } |
diff --git a/tools/perf/util/ui/util.h b/tools/perf/util/ui/util.h index 9a25538d4735..2d1738bd71c8 100644 --- a/tools/perf/util/ui/util.h +++ b/tools/perf/util/ui/util.h | |||
@@ -1,13 +1,14 @@ | |||
1 | #ifndef _PERF_UI_UTIL_H_ | 1 | #ifndef _PERF_UI_UTIL_H_ |
2 | #define _PERF_UI_UTIL_H_ 1 | 2 | #define _PERF_UI_UTIL_H_ 1 |
3 | 3 | ||
4 | #include <stdbool.h> | 4 | #include <stdarg.h> |
5 | 5 | ||
6 | int ui__getch(int delay_secs); | 6 | 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 | int ui__dialog_yesno(const char *msg); |
10 | int ui__question_window(const char *title, const char *text, | 10 | int ui__question_window(const char *title, const char *text, |
11 | const char *exit_msg, int delay_secs); | 11 | const char *exit_msg, int delay_secs); |
12 | int __ui__warning(const char *title, const char *format, va_list args); | ||
12 | 13 | ||
13 | #endif /* _PERF_UI_UTIL_H_ */ | 14 | #endif /* _PERF_UI_UTIL_H_ */ |