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.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 0458122d
...@@ -47,19 +47,20 @@ int dump_printf(const char *fmt, ...) ...@@ -47,19 +47,20 @@ int dump_printf(const char *fmt, ...)
} }
#ifdef NO_NEWT_SUPPORT #ifdef NO_NEWT_SUPPORT
void ui__warning(const char *format, ...) int ui__warning(const char *format, ...)
{ {
va_list args; va_list args;
va_start(args, format); va_start(args, format);
vfprintf(stderr, format, args); vfprintf(stderr, format, args);
va_end(args); va_end(args);
return 0;
} }
#endif #endif
void ui__error_paranoid(void) int ui__error_paranoid(void)
{ {
ui__error("Permission error - are you root?\n" return ui__error("Permission error - are you root?\n"
"Consider tweaking /proc/sys/kernel/perf_event_paranoid:\n" "Consider tweaking /proc/sys/kernel/perf_event_paranoid:\n"
" -1 - Not paranoid at all\n" " -1 - Not paranoid at all\n"
" 0 - Disallow raw tracepoint access for unpriv\n" " 0 - Disallow raw tracepoint access for unpriv\n"
......
...@@ -27,10 +27,10 @@ static inline void ui_progress__update(u64 curr __used, u64 total __used, ...@@ -27,10 +27,10 @@ static inline void ui_progress__update(u64 curr __used, u64 total __used,
extern char ui_helpline__last_msg[]; extern char ui_helpline__last_msg[];
int ui_helpline__show_help(const char *format, va_list ap); int ui_helpline__show_help(const char *format, va_list ap);
#include "ui/progress.h" #include "ui/progress.h"
void ui__error(const char *format, ...) __attribute__((format(printf, 1, 2))); int ui__error(const char *format, ...) __attribute__((format(printf, 1, 2)));
#endif #endif
void ui__warning(const char *format, ...) __attribute__((format(printf, 1, 2))); int ui__warning(const char *format, ...) __attribute__((format(printf, 1, 2)));
void ui__error_paranoid(void); int ui__error_paranoid(void);
#endif /* __PERF_DEBUG_H */ #endif /* __PERF_DEBUG_H */
...@@ -169,6 +169,46 @@ void ui_browser__refresh_dimensions(struct ui_browser *self) ...@@ -169,6 +169,46 @@ void ui_browser__refresh_dimensions(struct ui_browser *self)
self->x = 0; self->x = 0;
} }
void ui_browser__handle_resize(struct ui_browser *browser)
{
ui__refresh_dimensions(false);
ui_browser__show(browser, browser->title, ui_helpline__current);
ui_browser__refresh(browser);
}
int ui_browser__warning(struct ui_browser *browser, const char *format, ...)
{
va_list args;
int key;
va_start(args, format);
while ((key = __ui__warning("Warning!", format, args)) == K_RESIZE)
ui_browser__handle_resize(browser);
va_end(args);
return key;
}
int ui_browser__help_window(struct ui_browser *browser, const char *text)
{
int key;
while ((key = ui__help_window(text)) == K_RESIZE)
ui_browser__handle_resize(browser);
return key;
}
bool ui_browser__dialog_yesno(struct ui_browser *browser, const char *text)
{
int key;
while ((key = ui__dialog_yesno(text)) == K_RESIZE)
ui_browser__handle_resize(browser);
return key == K_ENTER || toupper(key) == 'Y';
}
void ui_browser__reset_index(struct ui_browser *self) void ui_browser__reset_index(struct ui_browser *self)
{ {
self->index = self->top_idx = 0; self->index = self->top_idx = 0;
......
...@@ -43,6 +43,11 @@ void ui_browser__hide(struct ui_browser *self); ...@@ -43,6 +43,11 @@ void ui_browser__hide(struct ui_browser *self);
int ui_browser__refresh(struct ui_browser *self); int ui_browser__refresh(struct ui_browser *self);
int ui_browser__run(struct ui_browser *browser, int delay_secs); int ui_browser__run(struct ui_browser *browser, int delay_secs);
void ui_browser__update_nr_entries(struct ui_browser *browser, u32 nr_entries); void ui_browser__update_nr_entries(struct ui_browser *browser, u32 nr_entries);
void ui_browser__handle_resize(struct ui_browser *browser);
int ui_browser__warning(struct ui_browser *browser, const char *format, ...);
int ui_browser__help_window(struct ui_browser *browser, const char *text);
bool ui_browser__dialog_yesno(struct ui_browser *browser, const char *text);
void ui_browser__argv_seek(struct ui_browser *browser, off_t offset, int whence); void ui_browser__argv_seek(struct ui_browser *browser, off_t offset, int whence);
unsigned int ui_browser__argv_refresh(struct ui_browser *browser); unsigned int ui_browser__argv_refresh(struct ui_browser *browser);
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include "../browser.h" #include "../browser.h"
#include "../helpline.h" #include "../helpline.h"
#include "../util.h" #include "../util.h"
#include "../ui.h"
#include "map.h" #include "map.h"
struct hist_browser { struct hist_browser {
...@@ -882,7 +883,7 @@ static int perf_evsel__hists_browse(struct perf_evsel *evsel, int nr_events, ...@@ -882,7 +883,7 @@ static int perf_evsel__hists_browse(struct perf_evsel *evsel, int nr_events,
goto out_free_stack; goto out_free_stack;
case 'a': case 'a':
if (!browser->has_symbols) { if (!browser->has_symbols) {
ui__warning( ui_browser__warning(&browser->b,
"Annotation is only available for symbolic views, " "Annotation is only available for symbolic views, "
"include \"sym\" in --sort to use it."); "include \"sym\" in --sort to use it.");
continue; continue;
...@@ -900,7 +901,8 @@ static int perf_evsel__hists_browse(struct perf_evsel *evsel, int nr_events, ...@@ -900,7 +901,8 @@ static int perf_evsel__hists_browse(struct perf_evsel *evsel, int nr_events,
case K_F1: case K_F1:
case 'h': case 'h':
case '?': case '?':
ui__help_window("h/?/F1 Show this window\n" ui_browser__help_window(&browser->b,
"h/?/F1 Show this window\n"
"UP/DOWN/PGUP\n" "UP/DOWN/PGUP\n"
"PGDN/SPACE Navigate\n" "PGDN/SPACE Navigate\n"
"q/ESC/CTRL+C Exit browser\n\n" "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,7 +941,8 @@ static int perf_evsel__hists_browse(struct perf_evsel *evsel, int nr_events,
} }
case K_ESC: case K_ESC:
if (!left_exits && if (!left_exits &&
!ui__dialog_yesno("Do you really want to exit?")) !ui_browser__dialog_yesno(&browser->b,
"Do you really want to exit?"))
continue; continue;
/* Fall thru */ /* Fall thru */
case 'q': case 'q':
...@@ -992,6 +995,7 @@ static int perf_evsel__hists_browse(struct perf_evsel *evsel, int nr_events, ...@@ -992,6 +995,7 @@ static int perf_evsel__hists_browse(struct perf_evsel *evsel, int nr_events,
if (choice == annotate) { if (choice == annotate) {
struct hist_entry *he; struct hist_entry *he;
int err;
do_annotate: do_annotate:
he = hist_browser__selected_entry(browser); he = hist_browser__selected_entry(browser);
if (he == NULL) if (he == NULL)
...@@ -1000,10 +1004,12 @@ static int perf_evsel__hists_browse(struct perf_evsel *evsel, int nr_events, ...@@ -1000,10 +1004,12 @@ static int perf_evsel__hists_browse(struct perf_evsel *evsel, int nr_events,
* Don't let this be freed, say, by hists__decay_entry. * Don't let this be freed, say, by hists__decay_entry.
*/ */
he->used = true; he->used = true;
hist_entry__tui_annotate(he, evsel->idx, nr_events, err = hist_entry__tui_annotate(he, evsel->idx, nr_events,
timer, arg, delay_secs); timer, arg, delay_secs);
he->used = false; he->used = false;
ui_browser__update_nr_entries(&browser->b, browser->hists->nr_entries); ui_browser__update_nr_entries(&browser->b, browser->hists->nr_entries);
if (err)
ui_browser__handle_resize(&browser->b);
} else if (choice == browse_map) } else if (choice == browse_map)
map__browse(browser->selection->map); map__browse(browser->selection->map);
else if (choice == zoom_dso) { else if (choice == zoom_dso) {
...@@ -1132,7 +1138,8 @@ static int perf_evsel_menu__run(struct perf_evsel_menu *menu, ...@@ -1132,7 +1138,8 @@ static int perf_evsel_menu__run(struct perf_evsel_menu *menu,
pos = list_entry(pos->node.prev, struct perf_evsel, node); pos = list_entry(pos->node.prev, struct perf_evsel, node);
goto browse_hists; goto browse_hists;
case K_ESC: case K_ESC:
if (!ui__dialog_yesno("Do you really want to exit?")) if (!ui_browser__dialog_yesno(&menu->b,
"Do you really want to exit?"))
continue; continue;
/* Fall thru */ /* Fall thru */
case 'q': case 'q':
...@@ -1144,7 +1151,8 @@ static int perf_evsel_menu__run(struct perf_evsel_menu *menu, ...@@ -1144,7 +1151,8 @@ static int perf_evsel_menu__run(struct perf_evsel_menu *menu,
case K_LEFT: case K_LEFT:
continue; continue;
case K_ESC: case K_ESC:
if (!ui__dialog_yesno("Do you really want to exit?")) if (!ui_browser__dialog_yesno(&menu->b,
"Do you really want to exit?"))
continue; continue;
/* Fall thru */ /* Fall thru */
case 'q': case 'q':
......
#define _GNU_SOURCE #define _GNU_SOURCE
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h>
#include "../debug.h" #include "../debug.h"
#include "helpline.h" #include "helpline.h"
...@@ -11,12 +12,17 @@ void ui_helpline__pop(void) ...@@ -11,12 +12,17 @@ void ui_helpline__pop(void)
{ {
} }
char ui_helpline__current[512];
void ui_helpline__push(const char *msg) void ui_helpline__push(const char *msg)
{ {
const size_t sz = sizeof(ui_helpline__current);
SLsmg_gotorc(SLtt_Screen_Rows - 1, 0); SLsmg_gotorc(SLtt_Screen_Rows - 1, 0);
SLsmg_set_color(0); SLsmg_set_color(0);
SLsmg_write_nstring((char *)msg, SLtt_Screen_Cols); SLsmg_write_nstring((char *)msg, SLtt_Screen_Cols);
SLsmg_refresh(); SLsmg_refresh();
strncpy(ui_helpline__current, msg, sz)[sz - 1] = '\0';
} }
void ui_helpline__vpush(const char *fmt, va_list ap) void ui_helpline__vpush(const char *fmt, va_list ap)
......
...@@ -11,4 +11,6 @@ void ui_helpline__vpush(const char *fmt, va_list ap); ...@@ -11,4 +11,6 @@ void ui_helpline__vpush(const char *fmt, va_list ap);
void ui_helpline__fpush(const char *fmt, ...); void ui_helpline__fpush(const char *fmt, ...);
void ui_helpline__puts(const char *msg); void ui_helpline__puts(const char *msg);
extern char ui_helpline__current[];
#endif /* _PERF_UI_HELPLINE_H_ */ #endif /* _PERF_UI_HELPLINE_H_ */
...@@ -121,43 +121,48 @@ int ui__help_window(const char *text) ...@@ -121,43 +121,48 @@ int ui__help_window(const char *text)
return ui__question_window("Help", text, "Press any key...", 0); return ui__question_window("Help", text, "Press any key...", 0);
} }
bool ui__dialog_yesno(const char *msg) int ui__dialog_yesno(const char *msg)
{ {
int answer = ui__question_window(NULL, msg, "Enter: Yes, ESC: No", 0); return ui__question_window(NULL, msg, "Enter: Yes, ESC: No", 0);
return answer == K_ENTER;
} }
static void __ui__warning(const char *title, const char *format, va_list args) int __ui__warning(const char *title, const char *format, va_list args)
{ {
char *s; char *s;
if (use_browser > 0 && vasprintf(&s, format, args) > 0) { if (use_browser > 0 && vasprintf(&s, format, args) > 0) {
int key;
pthread_mutex_lock(&ui__lock); pthread_mutex_lock(&ui__lock);
ui__question_window(title, s, "Press any key...", 0); key = ui__question_window(title, s, "Press any key...", 0);
pthread_mutex_unlock(&ui__lock); pthread_mutex_unlock(&ui__lock);
free(s); free(s);
return; return key;
} }
fprintf(stderr, "%s:\n", title); fprintf(stderr, "%s:\n", title);
vfprintf(stderr, format, args); vfprintf(stderr, format, args);
return K_ESC;
} }
void ui__warning(const char *format, ...) int ui__warning(const char *format, ...)
{ {
int key;
va_list args; va_list args;
va_start(args, format); va_start(args, format);
__ui__warning("Warning", format, args); key = __ui__warning("Warning", format, args);
va_end(args); va_end(args);
return key;
} }
void ui__error(const char *format, ...) int ui__error(const char *format, ...)
{ {
int key;
va_list args; va_list args;
va_start(args, format); va_start(args, format);
__ui__warning("Error", format, args); key = __ui__warning("Error", format, args);
va_end(args); va_end(args);
return key;
} }
#ifndef _PERF_UI_UTIL_H_ #ifndef _PERF_UI_UTIL_H_
#define _PERF_UI_UTIL_H_ 1 #define _PERF_UI_UTIL_H_ 1
#include <stdbool.h> #include <stdarg.h>
int ui__getch(int delay_secs); int ui__getch(int delay_secs);
int ui__popup_menu(int argc, char * const argv[]); int ui__popup_menu(int argc, char * const argv[]);
int ui__help_window(const char *text); int ui__help_window(const char *text);
bool ui__dialog_yesno(const char *msg); int ui__dialog_yesno(const char *msg);
int ui__question_window(const char *title, const char *text, int ui__question_window(const char *title, const char *text,
const char *exit_msg, int delay_secs); const char *exit_msg, int delay_secs);
int __ui__warning(const char *title, const char *format, va_list args);
#endif /* _PERF_UI_UTIL_H_ */ #endif /* _PERF_UI_UTIL_H_ */
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment