aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorArnaldo Carvalho de Melo <acme@redhat.com>2010-08-11 09:07:43 -0400
committerArnaldo Carvalho de Melo <acme@redhat.com>2010-08-19 18:39:52 -0400
commitb50e003db13848dd74572ffd221047683313981d (patch)
tree84c50dd8f8251ffbb05bfa83b21f4a1e864efc63 /tools
parent8f9bbc408b6f704e84d0ae78e6093005ad58d4fe (diff)
perf ui browser: Return the exit key in all browsers
Make all browsers return the exit key uniformly and remove the newtExitStruct parameter, removing one more newt specific thing from the ui API. Cc: Frederic Weisbecker <fweisbec@gmail.com> Cc: Mike Galbraith <efault@gmx.de> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Stephane Eranian <eranian@google.com> LKML-Reference: <new-submission> Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools')
-rw-r--r--tools/perf/builtin-annotate.c17
-rw-r--r--tools/perf/util/ui/browser.c16
-rw-r--r--tools/perf/util/ui/browser.h2
-rw-r--r--tools/perf/util/ui/browsers/annotate.c18
-rw-r--r--tools/perf/util/ui/browsers/hists.c132
-rw-r--r--tools/perf/util/ui/browsers/map.c20
-rw-r--r--tools/perf/util/util.h13
7 files changed, 93 insertions, 125 deletions
diff --git a/tools/perf/builtin-annotate.c b/tools/perf/builtin-annotate.c
index 1478dc64bf15..20ee21d52972 100644
--- a/tools/perf/builtin-annotate.c
+++ b/tools/perf/builtin-annotate.c
@@ -321,7 +321,7 @@ static int hist_entry__tty_annotate(struct hist_entry *he)
321 321
322static void hists__find_annotations(struct hists *self) 322static void hists__find_annotations(struct hists *self)
323{ 323{
324 struct rb_node *first = rb_first(&self->entries), *nd = first; 324 struct rb_node *nd = rb_first(&self->entries), *next;
325 int key = KEY_RIGHT; 325 int key = KEY_RIGHT;
326 326
327 while (nd) { 327 while (nd) {
@@ -343,20 +343,19 @@ find_next:
343 343
344 if (use_browser > 0) { 344 if (use_browser > 0) {
345 key = hist_entry__tui_annotate(he); 345 key = hist_entry__tui_annotate(he);
346 if (is_exit_key(key))
347 break;
348 switch (key) { 346 switch (key) {
349 case KEY_RIGHT: 347 case KEY_RIGHT:
350 case '\t': 348 next = rb_next(nd);
351 nd = rb_next(nd);
352 break; 349 break;
353 case KEY_LEFT: 350 case KEY_LEFT:
354 if (nd == first) 351 next = rb_prev(nd);
355 continue;
356 nd = rb_prev(nd);
357 default:
358 break; 352 break;
353 default:
354 return;
359 } 355 }
356
357 if (next != NULL)
358 nd = next;
360 } else { 359 } else {
361 hist_entry__tty_annotate(he); 360 hist_entry__tty_annotate(he);
362 nd = rb_next(nd); 361 nd = rb_next(nd);
diff --git a/tools/perf/util/ui/browser.c b/tools/perf/util/ui/browser.c
index d237410c973b..669a98067555 100644
--- a/tools/perf/util/ui/browser.c
+++ b/tools/perf/util/ui/browser.c
@@ -204,21 +204,21 @@ int ui_browser__refresh(struct ui_browser *self)
204 return 0; 204 return 0;
205} 205}
206 206
207int ui_browser__run(struct ui_browser *self, struct newtExitStruct *es) 207int ui_browser__run(struct ui_browser *self)
208{ 208{
209 struct newtExitStruct es;
210
209 if (ui_browser__refresh(self) < 0) 211 if (ui_browser__refresh(self) < 0)
210 return -1; 212 return -1;
211 213
212 while (1) { 214 while (1) {
213 off_t offset; 215 off_t offset;
214 216
215 newtFormRun(self->form, es); 217 newtFormRun(self->form, &es);
216 218
217 if (es->reason != NEWT_EXIT_HOTKEY) 219 if (es.reason != NEWT_EXIT_HOTKEY)
218 break; 220 break;
219 if (is_exit_key(es->u.key)) 221 switch (es.u.key) {
220 return es->u.key;
221 switch (es->u.key) {
222 case NEWT_KEY_DOWN: 222 case NEWT_KEY_DOWN:
223 if (self->index == self->nr_entries - 1) 223 if (self->index == self->nr_entries - 1)
224 break; 224 break;
@@ -275,12 +275,12 @@ int ui_browser__run(struct ui_browser *self, struct newtExitStruct *es)
275 self->seek(self, -offset, SEEK_END); 275 self->seek(self, -offset, SEEK_END);
276 break; 276 break;
277 default: 277 default:
278 return es->u.key; 278 return es.u.key;
279 } 279 }
280 if (ui_browser__refresh(self) < 0) 280 if (ui_browser__refresh(self) < 0)
281 return -1; 281 return -1;
282 } 282 }
283 return 0; 283 return -1;
284} 284}
285 285
286unsigned int ui_browser__list_head_refresh(struct ui_browser *self) 286unsigned int ui_browser__list_head_refresh(struct ui_browser *self)
diff --git a/tools/perf/util/ui/browser.h b/tools/perf/util/ui/browser.h
index 27c23c277ab1..332a675e55cc 100644
--- a/tools/perf/util/ui/browser.h
+++ b/tools/perf/util/ui/browser.h
@@ -37,7 +37,7 @@ int ui_browser__show(struct ui_browser *self, const char *title,
37 const char *helpline, ...); 37 const char *helpline, ...);
38void ui_browser__hide(struct ui_browser *self); 38void ui_browser__hide(struct ui_browser *self);
39int ui_browser__refresh(struct ui_browser *self); 39int ui_browser__refresh(struct ui_browser *self);
40int ui_browser__run(struct ui_browser *self, struct newtExitStruct *es); 40int ui_browser__run(struct ui_browser *self);
41 41
42void ui_browser__rb_tree_seek(struct ui_browser *self, off_t offset, int whence); 42void ui_browser__rb_tree_seek(struct ui_browser *self, off_t offset, int whence);
43unsigned int ui_browser__rb_tree_refresh(struct ui_browser *self); 43unsigned int ui_browser__rb_tree_refresh(struct ui_browser *self);
diff --git a/tools/perf/util/ui/browsers/annotate.c b/tools/perf/util/ui/browsers/annotate.c
index a00d529caaff..a8bc2c015946 100644
--- a/tools/perf/util/ui/browsers/annotate.c
+++ b/tools/perf/util/ui/browsers/annotate.c
@@ -133,14 +133,14 @@ static void annotate_browser__set_top(struct annotate_browser *self,
133 self->curr_hot = nd; 133 self->curr_hot = nd;
134} 134}
135 135
136static int annotate_browser__run(struct annotate_browser *self, 136static int annotate_browser__run(struct annotate_browser *self)
137 struct newtExitStruct *es)
138{ 137{
139 struct rb_node *nd; 138 struct rb_node *nd;
140 struct hist_entry *he = self->b.priv; 139 struct hist_entry *he = self->b.priv;
140 int key;
141 141
142 if (ui_browser__show(&self->b, he->ms.sym->name, 142 if (ui_browser__show(&self->b, he->ms.sym->name,
143 "<- or ESC: exit, TAB/shift+TAB: cycle thru samples") < 0) 143 "<-, -> or ESC: exit, TAB/shift+TAB: cycle thru samples") < 0)
144 return -1; 144 return -1;
145 145
146 newtFormAddHotKey(self->b.form, NEWT_KEY_LEFT); 146 newtFormAddHotKey(self->b.form, NEWT_KEY_LEFT);
@@ -153,12 +153,9 @@ static int annotate_browser__run(struct annotate_browser *self,
153 } 153 }
154 154
155 while (1) { 155 while (1) {
156 ui_browser__run(&self->b, es); 156 key = ui_browser__run(&self->b);
157 157
158 if (es->reason != NEWT_EXIT_HOTKEY) 158 switch (key) {
159 break;
160
161 switch (es->u.key) {
162 case NEWT_KEY_TAB: 159 case NEWT_KEY_TAB:
163 nd = rb_prev(nd); 160 nd = rb_prev(nd);
164 if (nd == NULL) 161 if (nd == NULL)
@@ -177,12 +174,11 @@ static int annotate_browser__run(struct annotate_browser *self,
177 } 174 }
178out: 175out:
179 ui_browser__hide(&self->b); 176 ui_browser__hide(&self->b);
180 return es->u.key; 177 return key;
181} 178}
182 179
183int hist_entry__tui_annotate(struct hist_entry *self) 180int hist_entry__tui_annotate(struct hist_entry *self)
184{ 181{
185 struct newtExitStruct es;
186 struct objdump_line *pos, *n; 182 struct objdump_line *pos, *n;
187 struct objdump_line_rb_node *rbpos; 183 struct objdump_line_rb_node *rbpos;
188 LIST_HEAD(head); 184 LIST_HEAD(head);
@@ -230,7 +226,7 @@ int hist_entry__tui_annotate(struct hist_entry *self)
230 annotate_browser__set_top(&browser, browser.curr_hot); 226 annotate_browser__set_top(&browser, browser.curr_hot);
231 227
232 browser.b.width += 18; /* Percentage */ 228 browser.b.width += 18; /* Percentage */
233 ret = annotate_browser__run(&browser, &es); 229 ret = annotate_browser__run(&browser);
234 list_for_each_entry_safe(pos, n, &head, node) { 230 list_for_each_entry_safe(pos, n, &head, node) {
235 list_del(&pos->node); 231 list_del(&pos->node);
236 objdump_line__free(pos); 232 objdump_line__free(pos);
diff --git a/tools/perf/util/ui/browsers/hists.c b/tools/perf/util/ui/browsers/hists.c
index 5723091134ee..1735c48691a5 100644
--- a/tools/perf/util/ui/browsers/hists.c
+++ b/tools/perf/util/ui/browsers/hists.c
@@ -195,9 +195,9 @@ static bool hist_browser__toggle_fold(struct hist_browser *self)
195 return false; 195 return false;
196} 196}
197 197
198static int hist_browser__run(struct hist_browser *self, const char *title, 198static int hist_browser__run(struct hist_browser *self, const char *title)
199 struct newtExitStruct *es)
200{ 199{
200 int key;
201 char str[256], unit; 201 char str[256], unit;
202 unsigned long nr_events = self->hists->stats.nr_events[PERF_RECORD_SAMPLE]; 202 unsigned long nr_events = self->hists->stats.nr_events[PERF_RECORD_SAMPLE];
203 203
@@ -227,11 +227,9 @@ static int hist_browser__run(struct hist_browser *self, const char *title,
227 newtFormAddHotKey(self->b.form, NEWT_KEY_ENTER); 227 newtFormAddHotKey(self->b.form, NEWT_KEY_ENTER);
228 228
229 while (1) { 229 while (1) {
230 ui_browser__run(&self->b, es); 230 key = ui_browser__run(&self->b);
231 231
232 if (es->reason != NEWT_EXIT_HOTKEY) 232 switch (key) {
233 break;
234 switch (es->u.key) {
235 case 'D': { /* Debug */ 233 case 'D': { /* Debug */
236 static int seq; 234 static int seq;
237 struct hist_entry *h = rb_entry(self->b.top, 235 struct hist_entry *h = rb_entry(self->b.top,
@@ -251,12 +249,12 @@ static int hist_browser__run(struct hist_browser *self, const char *title,
251 break; 249 break;
252 /* fall thru */ 250 /* fall thru */
253 default: 251 default:
254 return 0; 252 goto out;
255 } 253 }
256 } 254 }
257 255out:
258 ui_browser__hide(&self->b); 256 ui_browser__hide(&self->b);
259 return 0; 257 return key;
260} 258}
261 259
262static char *callchain_list__sym_name(struct callchain_list *self, 260static char *callchain_list__sym_name(struct callchain_list *self,
@@ -687,8 +685,6 @@ static struct hist_browser *hist_browser__new(struct hists *hists)
687 685
688static void hist_browser__delete(struct hist_browser *self) 686static void hist_browser__delete(struct hist_browser *self)
689{ 687{
690 newtFormDestroy(self->b.form);
691 newtPopWindow();
692 free(self); 688 free(self);
693} 689}
694 690
@@ -725,7 +721,6 @@ int hists__browse(struct hists *self, const char *helpline, const char *ev_name)
725 struct pstack *fstack; 721 struct pstack *fstack;
726 const struct thread *thread_filter = NULL; 722 const struct thread *thread_filter = NULL;
727 const struct dso *dso_filter = NULL; 723 const struct dso *dso_filter = NULL;
728 struct newtExitStruct es;
729 char msg[160]; 724 char msg[160];
730 int key = -1; 725 int key = -1;
731 726
@@ -749,70 +744,63 @@ int hists__browse(struct hists *self, const char *helpline, const char *ev_name)
749 annotate = -2, zoom_dso = -2, zoom_thread = -2, 744 annotate = -2, zoom_dso = -2, zoom_thread = -2,
750 browse_map = -2; 745 browse_map = -2;
751 746
752 if (hist_browser__run(browser, msg, &es)) 747 key = hist_browser__run(browser, msg);
753 break;
754 748
755 thread = hist_browser__selected_thread(browser); 749 thread = hist_browser__selected_thread(browser);
756 dso = browser->selection->map ? browser->selection->map->dso : NULL; 750 dso = browser->selection->map ? browser->selection->map->dso : NULL;
757 751
758 if (es.reason == NEWT_EXIT_HOTKEY) { 752 switch (key) {
759 key = es.u.key; 753 case NEWT_KEY_F1:
760 754 goto do_help;
761 switch (key) { 755 case NEWT_KEY_TAB:
762 case NEWT_KEY_F1: 756 case NEWT_KEY_UNTAB:
763 goto do_help; 757 /*
764 case NEWT_KEY_TAB: 758 * Exit the browser, let hists__browser_tree
765 case NEWT_KEY_UNTAB: 759 * go to the next or previous
766 /* 760 */
767 * Exit the browser, let hists__browser_tree 761 goto out_free_stack;
768 * go to the next or previous 762 case 'a':
769 */ 763 if (browser->selection->map == NULL &&
770 goto out_free_stack; 764 browser->selection->map->dso->annotate_warned)
771 default:;
772 }
773
774 switch (key) {
775 case 'a':
776 if (browser->selection->map == NULL &&
777 browser->selection->map->dso->annotate_warned)
778 continue;
779 goto do_annotate;
780 case 'd':
781 goto zoom_dso;
782 case 't':
783 goto zoom_thread;
784 case 'h':
785 case '?':
786do_help:
787 ui__help_window("-> Zoom into DSO/Threads & Annotate current symbol\n"
788 "<- Zoom out\n"
789 "a Annotate current symbol\n"
790 "h/?/F1 Show this window\n"
791 "d Zoom into current DSO\n"
792 "t Zoom into current Thread\n"
793 "q/CTRL+C Exit browser");
794 continue; 765 continue;
795 default:; 766 goto do_annotate;
796 } 767 case 'd':
797 if (is_exit_key(key)) { 768 goto zoom_dso;
798 if (key == NEWT_KEY_ESCAPE && 769 case 't':
799 !ui__dialog_yesno("Do you really want to exit?")) 770 goto zoom_thread;
800 continue; 771 case 'h':
801 break; 772 case '?':
802 } 773do_help:
803 774 ui__help_window("-> Zoom into DSO/Threads & Annotate current symbol\n"
804 if (es.u.key == NEWT_KEY_LEFT) { 775 "<- Zoom out\n"
805 const void *top; 776 "a Annotate current symbol\n"
777 "h/?/F1 Show this window\n"
778 "d Zoom into current DSO\n"
779 "t Zoom into current Thread\n"
780 "q/CTRL+C Exit browser");
781 continue;
782 case NEWT_KEY_ENTER:
783 case NEWT_KEY_RIGHT:
784 /* menu */
785 break;
786 case NEWT_KEY_LEFT: {
787 const void *top;
806 788
807 if (pstack__empty(fstack)) 789 if (pstack__empty(fstack))
808 continue;
809 top = pstack__pop(fstack);
810 if (top == &dso_filter)
811 goto zoom_out_dso;
812 if (top == &thread_filter)
813 goto zoom_out_thread;
814 continue; 790 continue;
815 } 791 top = pstack__pop(fstack);
792 if (top == &dso_filter)
793 goto zoom_out_dso;
794 if (top == &thread_filter)
795 goto zoom_out_thread;
796 continue;
797 }
798 case NEWT_KEY_ESCAPE:
799 if (!ui__dialog_yesno("Do you really want to exit?"))
800 continue;
801 /* Fall thru */
802 default:
803 goto out_free_stack;
816 } 804 }
817 805
818 if (browser->selection->sym != NULL && 806 if (browser->selection->sym != NULL &&
@@ -925,10 +913,6 @@ int hists__tui_browse_tree(struct rb_root *self, const char *help)
925 const char *ev_name = __event_name(hists->type, hists->config); 913 const char *ev_name = __event_name(hists->type, hists->config);
926 914
927 key = hists__browse(hists, help, ev_name); 915 key = hists__browse(hists, help, ev_name);
928
929 if (is_exit_key(key))
930 break;
931
932 switch (key) { 916 switch (key) {
933 case NEWT_KEY_TAB: 917 case NEWT_KEY_TAB:
934 next = rb_next(nd); 918 next = rb_next(nd);
@@ -940,7 +924,7 @@ int hists__tui_browse_tree(struct rb_root *self, const char *help)
940 continue; 924 continue;
941 nd = rb_prev(nd); 925 nd = rb_prev(nd);
942 default: 926 default:
943 break; 927 return key;
944 } 928 }
945 } 929 }
946 930
diff --git a/tools/perf/util/ui/browsers/map.c b/tools/perf/util/ui/browsers/map.c
index 733daba60cd4..16b7d70f2c58 100644
--- a/tools/perf/util/ui/browsers/map.c
+++ b/tools/perf/util/ui/browsers/map.c
@@ -97,31 +97,34 @@ static int map_browser__search(struct map_browser *self)
97 return 0; 97 return 0;
98} 98}
99 99
100static int map_browser__run(struct map_browser *self, struct newtExitStruct *es) 100static int map_browser__run(struct map_browser *self)
101{ 101{
102 int key;
103
102 if (ui_browser__show(&self->b, self->map->dso->long_name, 104 if (ui_browser__show(&self->b, self->map->dso->long_name,
103 "Press <- or ESC to exit, %s / to search", 105 "Press <- or ESC to exit, %s / to search",
104 verbose ? "" : "restart with -v to use") < 0) 106 verbose ? "" : "restart with -v to use") < 0)
105 return -1; 107 return -1;
106 108
107 newtFormAddHotKey(self->b.form, NEWT_KEY_LEFT); 109 newtFormAddHotKey(self->b.form, NEWT_KEY_LEFT);
108 newtFormAddHotKey(self->b.form, NEWT_KEY_ENTER); 110 newtFormAddHotKey(self->b.form, NEWT_KEY_ESCAPE);
111 newtFormAddHotKey(self->b.form, 'Q');
112 newtFormAddHotKey(self->b.form, 'q');
113 newtFormAddHotKey(self->b.form, CTRL('c'));
109 if (verbose) 114 if (verbose)
110 newtFormAddHotKey(self->b.form, '/'); 115 newtFormAddHotKey(self->b.form, '/');
111 116
112 while (1) { 117 while (1) {
113 ui_browser__run(&self->b, es); 118 key = ui_browser__run(&self->b);
114 119
115 if (es->reason != NEWT_EXIT_HOTKEY) 120 if (verbose && key == '/')
116 break;
117 if (verbose && es->u.key == '/')
118 map_browser__search(self); 121 map_browser__search(self);
119 else 122 else
120 break; 123 break;
121 } 124 }
122 125
123 ui_browser__hide(&self->b); 126 ui_browser__hide(&self->b);
124 return 0; 127 return key;
125} 128}
126 129
127int map__browse(struct map *self) 130int map__browse(struct map *self)
@@ -135,7 +138,6 @@ int map__browse(struct map *self)
135 }, 138 },
136 .map = self, 139 .map = self,
137 }; 140 };
138 struct newtExitStruct es;
139 struct rb_node *nd; 141 struct rb_node *nd;
140 char tmp[BITS_PER_LONG / 4]; 142 char tmp[BITS_PER_LONG / 4];
141 u64 maxaddr = 0; 143 u64 maxaddr = 0;
@@ -156,5 +158,5 @@ int map__browse(struct map *self)
156 158
157 mb.addrlen = snprintf(tmp, sizeof(tmp), "%llx", maxaddr); 159 mb.addrlen = snprintf(tmp, sizeof(tmp), "%llx", maxaddr);
158 mb.b.width += mb.addrlen * 2 + 4 + mb.namelen; 160 mb.b.width += mb.addrlen * 2 + 4 + mb.namelen;
159 return map_browser__run(&mb, &es); 161 return map_browser__run(&mb);
160} 162}
diff --git a/tools/perf/util/util.h b/tools/perf/util/util.h
index f380fed74359..7562707ddd1c 100644
--- a/tools/perf/util/util.h
+++ b/tools/perf/util/util.h
@@ -266,19 +266,6 @@ bool strglobmatch(const char *str, const char *pat);
266bool strlazymatch(const char *str, const char *pat); 266bool strlazymatch(const char *str, const char *pat);
267unsigned long convert_unit(unsigned long value, char *unit); 267unsigned long convert_unit(unsigned long value, char *unit);
268 268
269#ifndef ESC
270#define ESC 27
271#endif
272
273static inline bool is_exit_key(int key)
274{
275 char up;
276 if (key == CTRL('c') || key == ESC)
277 return true;
278 up = toupper(key);
279 return up == 'Q';
280}
281
282#define _STR(x) #x 269#define _STR(x) #x
283#define STR(x) _STR(x) 270#define STR(x) _STR(x)
284 271