Skip to content

Commit cf95800

Browse files
committed
perf ui browser: Use libslang to read keys
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-uy6s534uqxq8tenh6s3k8ocj@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
1 parent 29208e5 commit cf95800

9 files changed

Lines changed: 125 additions & 64 deletions

File tree

‎tools/perf/Makefile‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,7 @@ else
472472
LIB_H += util/ui/browser.h
473473
LIB_H += util/ui/browsers/map.h
474474
LIB_H += util/ui/helpline.h
475+
LIB_H += util/ui/keysyms.h
475476
LIB_H += util/ui/libslang.h
476477
LIB_H += util/ui/progress.h
477478
LIB_H += util/ui/util.h

‎tools/perf/builtin-annotate.c‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ static void hists__find_annotations(struct hists *self, int evidx,
118118
int nr_events)
119119
{
120120
struct rb_node *nd = rb_first(&self->entries), *next;
121-
int key = KEY_RIGHT;
121+
int key = K_RIGHT;
122122

123123
while (nd) {
124124
struct hist_entry *he = rb_entry(nd, struct hist_entry, rb_node);
@@ -130,7 +130,7 @@ static void hists__find_annotations(struct hists *self, int evidx,
130130
notes = symbol__annotation(he->ms.sym);
131131
if (notes->src == NULL) {
132132
find_next:
133-
if (key == KEY_LEFT)
133+
if (key == K_LEFT)
134134
nd = rb_prev(nd);
135135
else
136136
nd = rb_next(nd);
@@ -141,10 +141,10 @@ static void hists__find_annotations(struct hists *self, int evidx,
141141
key = hist_entry__tui_annotate(he, evidx, nr_events,
142142
NULL, NULL, 0);
143143
switch (key) {
144-
case KEY_RIGHT:
144+
case K_RIGHT:
145145
next = rb_next(nd);
146146
break;
147-
case KEY_LEFT:
147+
case K_LEFT:
148148
next = rb_prev(nd);
149149
break;
150150
default:

‎tools/perf/util/hist.h‎

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -125,16 +125,13 @@ static inline int hist_entry__tui_annotate(struct hist_entry *self __used,
125125
{
126126
return 0;
127127
}
128-
#define KEY_LEFT -1
129-
#define KEY_RIGHT -2
128+
#define K_LEFT -1
129+
#define K_RIGHT -2
130130
#else
131-
#include <newt.h>
131+
#include "ui/keysyms.h"
132132
int hist_entry__tui_annotate(struct hist_entry *he, int evidx, int nr_events,
133133
void(*timer)(void *arg), void *arg, int delay_secs);
134134

135-
#define KEY_LEFT NEWT_KEY_LEFT
136-
#define KEY_RIGHT NEWT_KEY_RIGHT
137-
138135
int perf_evlist__tui_browse_hists(struct perf_evlist *evlist, const char *help,
139136
void(*timer)(void *arg), void *arg,
140137
int refresh);

‎tools/perf/util/ui/browser.c‎

Lines changed: 53 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,9 @@
1111
#include <sys/ttydefaults.h>
1212
#include "browser.h"
1313
#include "helpline.h"
14+
#include "keysyms.h"
1415
#include "../color.h"
1516

16-
int newtGetKey(void);
17-
1817
static int ui_browser__percent_color(struct ui_browser *browser,
1918
double percent, bool current)
2019
{
@@ -292,16 +291,55 @@ void ui_browser__update_nr_entries(struct ui_browser *browser, u32 nr_entries)
292291
browser->seek(browser, browser->top_idx, SEEK_SET);
293292
}
294293

294+
static int ui__getch(int delay_secs)
295+
{
296+
struct timeval timeout, *ptimeout = delay_secs ? &timeout : NULL;
297+
fd_set read_set;
298+
int err, key;
299+
300+
FD_ZERO(&read_set);
301+
FD_SET(0, &read_set);
302+
303+
if (delay_secs) {
304+
timeout.tv_sec = delay_secs;
305+
timeout.tv_usec = 0;
306+
}
307+
308+
err = select(1, &read_set, NULL, NULL, ptimeout);
309+
310+
if (err == 0)
311+
return K_TIMER;
312+
313+
if (err == -1) {
314+
if (errno == EINTR)
315+
return K_RESIZE;
316+
return K_ERROR;
317+
}
318+
319+
key = SLang_getkey();
320+
if (key != K_ESC)
321+
return key;
322+
323+
FD_ZERO(&read_set);
324+
FD_SET(0, &read_set);
325+
timeout.tv_sec = 0;
326+
timeout.tv_usec = 20;
327+
err = select(1, &read_set, NULL, NULL, &timeout);
328+
if (err == 0)
329+
return K_ESC;
330+
331+
SLang_ungetkey(key);
332+
return SLkp_getkey();
333+
}
334+
295335
int ui_browser__run(struct ui_browser *self, int delay_secs)
296336
{
297337
int err, key;
298-
struct timeval timeout, *ptimeout = delay_secs ? &timeout : NULL;
299338

300339
pthread__unblock_sigwinch();
301340

302341
while (1) {
303342
off_t offset;
304-
fd_set read_set;
305343

306344
pthread_mutex_lock(&ui__lock);
307345
err = __ui_browser__refresh(self);
@@ -310,20 +348,9 @@ int ui_browser__run(struct ui_browser *self, int delay_secs)
310348
if (err < 0)
311349
break;
312350

313-
FD_ZERO(&read_set);
314-
FD_SET(0, &read_set);
351+
key = ui__getch(delay_secs);
315352

316-
if (delay_secs) {
317-
timeout.tv_sec = delay_secs;
318-
timeout.tv_usec = 0;
319-
}
320-
321-
err = select(1, &read_set, NULL, NULL, ptimeout);
322-
if (err > 0 && FD_ISSET(0, &read_set))
323-
key = newtGetKey();
324-
else if (err == 0)
325-
break;
326-
else {
353+
if (key == K_RESIZE) {
327354
pthread_mutex_lock(&ui__lock);
328355
SLtt_get_screen_size();
329356
SLsmg_reinit_smg();
@@ -335,9 +362,9 @@ int ui_browser__run(struct ui_browser *self, int delay_secs)
335362
}
336363

337364
if (self->use_navkeypressed && !self->navkeypressed) {
338-
if (key == NEWT_KEY_DOWN || key == NEWT_KEY_UP ||
339-
key == NEWT_KEY_PGDN || key == NEWT_KEY_PGUP ||
340-
key == NEWT_KEY_HOME || key == NEWT_KEY_END ||
365+
if (key == K_DOWN || key == K_UP ||
366+
key == K_PGDN || key == K_PGUP ||
367+
key == K_HOME || key == K_END ||
341368
key == ' ') {
342369
self->navkeypressed = true;
343370
continue;
@@ -346,7 +373,7 @@ int ui_browser__run(struct ui_browser *self, int delay_secs)
346373
}
347374

348375
switch (key) {
349-
case NEWT_KEY_DOWN:
376+
case K_DOWN:
350377
if (self->index == self->nr_entries - 1)
351378
break;
352379
++self->index;
@@ -355,7 +382,7 @@ int ui_browser__run(struct ui_browser *self, int delay_secs)
355382
self->seek(self, +1, SEEK_CUR);
356383
}
357384
break;
358-
case NEWT_KEY_UP:
385+
case K_UP:
359386
if (self->index == 0)
360387
break;
361388
--self->index;
@@ -364,7 +391,7 @@ int ui_browser__run(struct ui_browser *self, int delay_secs)
364391
self->seek(self, -1, SEEK_CUR);
365392
}
366393
break;
367-
case NEWT_KEY_PGDN:
394+
case K_PGDN:
368395
case ' ':
369396
if (self->top_idx + self->height > self->nr_entries - 1)
370397
break;
@@ -376,7 +403,7 @@ int ui_browser__run(struct ui_browser *self, int delay_secs)
376403
self->top_idx += offset;
377404
self->seek(self, +offset, SEEK_CUR);
378405
break;
379-
case NEWT_KEY_PGUP:
406+
case K_PGUP:
380407
if (self->top_idx == 0)
381408
break;
382409

@@ -389,10 +416,10 @@ int ui_browser__run(struct ui_browser *self, int delay_secs)
389416
self->top_idx -= offset;
390417
self->seek(self, -offset, SEEK_CUR);
391418
break;
392-
case NEWT_KEY_HOME:
419+
case K_HOME:
393420
ui_browser__reset_index(self);
394421
break;
395-
case NEWT_KEY_END:
422+
case K_END:
396423
offset = self->height - 1;
397424
if (offset >= self->nr_entries)
398425
offset = self->nr_entries - 1;

‎tools/perf/util/ui/browsers/annotate.c‎

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "../../sort.h"
77
#include "../../symbol.h"
88
#include <pthread.h>
9+
#include <newt.h>
910

1011
static void ui__error_window(const char *fmt, ...)
1112
{
@@ -265,26 +266,22 @@ static int annotate_browser__run(struct annotate_browser *self, int evidx,
265266
}
266267

267268
switch (key) {
268-
case -1:
269-
/*
270-
* FIXME we need to check if it was
271-
* es.reason == NEWT_EXIT_TIMER
272-
*/
269+
case K_TIMER:
273270
if (timer != NULL)
274271
timer(arg);
275272

276273
if (delay_secs != 0)
277274
symbol__annotate_decay_histogram(sym, evidx);
278275
continue;
279-
case NEWT_KEY_TAB:
276+
case K_TAB:
280277
if (nd != NULL) {
281278
nd = rb_prev(nd);
282279
if (nd == NULL)
283280
nd = rb_last(&self->entries);
284281
} else
285282
nd = self->curr_hot;
286283
break;
287-
case NEWT_KEY_UNTAB:
284+
case K_UNTAB:
288285
if (nd != NULL)
289286
nd = rb_next(nd);
290287
if (nd == NULL)
@@ -299,8 +296,8 @@ static int annotate_browser__run(struct annotate_browser *self, int evidx,
299296
if (annotate_browser__toggle_source(self))
300297
ui_helpline__puts(help);
301298
continue;
302-
case NEWT_KEY_ENTER:
303-
case NEWT_KEY_RIGHT:
299+
case K_ENTER:
300+
case K_RIGHT:
304301
if (self->selection == NULL) {
305302
ui_helpline__puts("Huh? No selection. Report to linux-kernel@vger.kernel.org");
306303
continue;
@@ -350,8 +347,8 @@ static int annotate_browser__run(struct annotate_browser *self, int evidx,
350347
timer, arg, delay_secs);
351348
}
352349
continue;
353-
case NEWT_KEY_LEFT:
354-
case NEWT_KEY_ESCAPE:
350+
case K_LEFT:
351+
case K_ESC:
355352
case 'q':
356353
case CTRL('c'):
357354
goto out;

‎tools/perf/util/ui/browsers/hists.c‎

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ static int hist_browser__run(struct hist_browser *self, const char *ev_name,
344344
/* Expand the whole world. */
345345
hist_browser__set_folding(self, true);
346346
break;
347-
case NEWT_KEY_ENTER:
347+
case K_ENTER:
348348
if (hist_browser__toggle_fold(self))
349349
break;
350350
/* fall thru */
@@ -872,8 +872,8 @@ static int perf_evsel__hists_browse(struct perf_evsel *evsel, int nr_events,
872872
}
873873

874874
switch (key) {
875-
case NEWT_KEY_TAB:
876-
case NEWT_KEY_UNTAB:
875+
case K_TAB:
876+
case K_UNTAB:
877877
if (nr_events == 1)
878878
continue;
879879
/*
@@ -891,7 +891,7 @@ static int perf_evsel__hists_browse(struct perf_evsel *evsel, int nr_events,
891891
goto zoom_dso;
892892
case 't':
893893
goto zoom_thread;
894-
case NEWT_KEY_F1:
894+
case K_F1:
895895
case 'h':
896896
case '?':
897897
ui__help_window("h/?/F1 Show this window\n"
@@ -909,11 +909,11 @@ static int perf_evsel__hists_browse(struct perf_evsel *evsel, int nr_events,
909909
"d Zoom into current DSO\n"
910910
"t Zoom into current Thread\n");
911911
continue;
912-
case NEWT_KEY_ENTER:
913-
case NEWT_KEY_RIGHT:
912+
case K_ENTER:
913+
case K_RIGHT:
914914
/* menu */
915915
break;
916-
case NEWT_KEY_LEFT: {
916+
case K_LEFT: {
917917
const void *top;
918918

919919
if (pstack__empty(fstack)) {
@@ -931,7 +931,7 @@ static int perf_evsel__hists_browse(struct perf_evsel *evsel, int nr_events,
931931
goto zoom_out_thread;
932932
continue;
933933
}
934-
case NEWT_KEY_ESCAPE:
934+
case K_ESC:
935935
if (!left_exits &&
936936
!ui__dialog_yesno("Do you really want to exit?"))
937937
continue;
@@ -1091,12 +1091,11 @@ static int perf_evsel_menu__run(struct perf_evsel_menu *menu,
10911091
key = ui_browser__run(&menu->b, delay_secs);
10921092

10931093
switch (key) {
1094-
case -1:
1095-
/* FIXME we need to check if it was es.reason == NEWT_EXIT_TIMER */
1094+
case K_TIMER:
10961095
timer(arg);
10971096
continue;
1098-
case NEWT_KEY_RIGHT:
1099-
case NEWT_KEY_ENTER:
1097+
case K_RIGHT:
1098+
case K_ENTER:
11001099
if (!menu->selection)
11011100
continue;
11021101
pos = menu->selection;
@@ -1114,19 +1113,19 @@ static int perf_evsel_menu__run(struct perf_evsel_menu *menu,
11141113
arg, delay_secs);
11151114
ui_browser__show_title(&menu->b, title);
11161115
switch (key) {
1117-
case NEWT_KEY_TAB:
1116+
case K_TAB:
11181117
if (pos->node.next == &evlist->entries)
11191118
pos = list_entry(evlist->entries.next, struct perf_evsel, node);
11201119
else
11211120
pos = list_entry(pos->node.next, struct perf_evsel, node);
11221121
goto browse_hists;
1123-
case NEWT_KEY_UNTAB:
1122+
case K_UNTAB:
11241123
if (pos->node.prev == &evlist->entries)
11251124
pos = list_entry(evlist->entries.prev, struct perf_evsel, node);
11261125
else
11271126
pos = list_entry(pos->node.prev, struct perf_evsel, node);
11281127
goto browse_hists;
1129-
case NEWT_KEY_ESCAPE:
1128+
case K_ESC:
11301129
if (!ui__dialog_yesno("Do you really want to exit?"))
11311130
continue;
11321131
/* Fall thru */
@@ -1136,9 +1135,9 @@ static int perf_evsel_menu__run(struct perf_evsel_menu *menu,
11361135
default:
11371136
continue;
11381137
}
1139-
case NEWT_KEY_LEFT:
1138+
case K_LEFT:
11401139
continue;
1141-
case NEWT_KEY_ESCAPE:
1140+
case K_ESC:
11421141
if (!ui__dialog_yesno("Do you really want to exit?"))
11431142
continue;
11441143
/* Fall thru */

0 commit comments

Comments
 (0)