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>
This commit is contained in:
		
					parent
					
						
							
								1056d3dd94
							
						
					
				
			
			
				commit
				
					
						ae55795ef2
					
				
			
		
					 6 changed files with 76 additions and 66 deletions
				
			
		| 
						 | 
					@ -310,9 +310,12 @@ fallback:
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		err = -ENOENT;
 | 
							err = -ENOENT;
 | 
				
			||||||
		dso->annotate_warned = 1;
 | 
							dso->annotate_warned = 1;
 | 
				
			||||||
		pr_err("Can't annotate %s: No vmlinux file%s was found in the "
 | 
							pr_err("Can't annotate %s:\n\n"
 | 
				
			||||||
		       "path.\nPlease use 'perf buildid-cache -av vmlinux' or "
 | 
							       "No vmlinux file%s\nwas found in the path.\n\n"
 | 
				
			||||||
		       "--vmlinux vmlinux.\n",
 | 
							       "Please use:\n\n"
 | 
				
			||||||
 | 
							       "  perf buildid-cache -av vmlinux\n\n"
 | 
				
			||||||
 | 
							       "or:\n\n"
 | 
				
			||||||
 | 
							       "  --vmlinux vmlinux",
 | 
				
			||||||
		       sym->name, build_id_msg ?: "");
 | 
							       sym->name, build_id_msg ?: "");
 | 
				
			||||||
		goto out_free_filename;
 | 
							goto out_free_filename;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -29,5 +29,6 @@ int ui_helpline__show_help(const char *format, va_list ap);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void ui__warning(const char *format, ...) __attribute__((format(printf, 1, 2)));
 | 
					void ui__warning(const char *format, ...) __attribute__((format(printf, 1, 2)));
 | 
				
			||||||
void ui__warning_paranoid(void);
 | 
					void ui__warning_paranoid(void);
 | 
				
			||||||
 | 
					void ui__error(const char *format, ...) __attribute__((format(printf, 1, 2)));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#endif	/* __PERF_DEBUG_H */
 | 
					#endif	/* __PERF_DEBUG_H */
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,6 +1,9 @@
 | 
				
			||||||
 | 
					#include "../../util.h"
 | 
				
			||||||
#include "../browser.h"
 | 
					#include "../browser.h"
 | 
				
			||||||
#include "../helpline.h"
 | 
					#include "../helpline.h"
 | 
				
			||||||
#include "../libslang.h"
 | 
					#include "../libslang.h"
 | 
				
			||||||
 | 
					#include "../ui.h"
 | 
				
			||||||
 | 
					#include "../util.h"
 | 
				
			||||||
#include "../../annotate.h"
 | 
					#include "../../annotate.h"
 | 
				
			||||||
#include "../../hist.h"
 | 
					#include "../../hist.h"
 | 
				
			||||||
#include "../../sort.h"
 | 
					#include "../../sort.h"
 | 
				
			||||||
| 
						 | 
					@ -8,15 +11,6 @@
 | 
				
			||||||
#include <pthread.h>
 | 
					#include <pthread.h>
 | 
				
			||||||
#include <newt.h>
 | 
					#include <newt.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void ui__error_window(const char *fmt, ...)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
	va_list ap;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	va_start(ap, fmt);
 | 
					 | 
				
			||||||
	newtWinMessagev((char *)"Error", (char *)"Ok", (char *)fmt, ap);
 | 
					 | 
				
			||||||
	va_end(ap);
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
struct annotate_browser {
 | 
					struct annotate_browser {
 | 
				
			||||||
	struct ui_browser b;
 | 
						struct ui_browser b;
 | 
				
			||||||
	struct rb_root	  entries;
 | 
						struct rb_root	  entries;
 | 
				
			||||||
| 
						 | 
					@ -400,7 +394,7 @@ int symbol__tui_annotate(struct symbol *sym, struct map *map, int evidx,
 | 
				
			||||||
		return -1;
 | 
							return -1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (symbol__annotate(sym, map, sizeof(struct objdump_line_rb_node)) < 0) {
 | 
						if (symbol__annotate(sym, map, sizeof(struct objdump_line_rb_node)) < 0) {
 | 
				
			||||||
		ui__error_window(ui_helpline__last_msg);
 | 
							ui__error("%s", ui_helpline__last_msg);
 | 
				
			||||||
		return -1;
 | 
							return -1;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -146,10 +146,10 @@ void setup_browser(bool fallback_to_pager)
 | 
				
			||||||
void exit_browser(bool wait_for_ok)
 | 
					void exit_browser(bool wait_for_ok)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	if (use_browser > 0) {
 | 
						if (use_browser > 0) {
 | 
				
			||||||
		if (wait_for_ok) {
 | 
							if (wait_for_ok)
 | 
				
			||||||
			char title[] = "Fatal Error", ok[] = "Ok";
 | 
								ui__question_window("Fatal Error",
 | 
				
			||||||
			newtWinMessage(title, ok, ui_helpline__last_msg);
 | 
										    ui_helpline__last_msg,
 | 
				
			||||||
		}
 | 
										    "Press any key...", 0);
 | 
				
			||||||
		ui__exit();
 | 
							ui__exit();
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,6 +1,5 @@
 | 
				
			||||||
#include <newt.h>
 | 
					#include "../util.h"
 | 
				
			||||||
#include <signal.h>
 | 
					#include <signal.h>
 | 
				
			||||||
#include <stdio.h>
 | 
					 | 
				
			||||||
#include <stdbool.h>
 | 
					#include <stdbool.h>
 | 
				
			||||||
#include <string.h>
 | 
					#include <string.h>
 | 
				
			||||||
#include <sys/ttydefaults.h>
 | 
					#include <sys/ttydefaults.h>
 | 
				
			||||||
| 
						 | 
					@ -12,6 +11,7 @@
 | 
				
			||||||
#include "helpline.h"
 | 
					#include "helpline.h"
 | 
				
			||||||
#include "ui.h"
 | 
					#include "ui.h"
 | 
				
			||||||
#include "util.h"
 | 
					#include "util.h"
 | 
				
			||||||
 | 
					#include "libslang.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void ui_browser__argv_write(struct ui_browser *browser,
 | 
					static void ui_browser__argv_write(struct ui_browser *browser,
 | 
				
			||||||
				   void *entry, int row)
 | 
									   void *entry, int row)
 | 
				
			||||||
| 
						 | 
					@ -56,23 +56,6 @@ static int popup_menu__run(struct ui_browser *menu)
 | 
				
			||||||
	return key;
 | 
						return key;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void newt_form__set_exit_keys(newtComponent self)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
	newtFormAddHotKey(self, NEWT_KEY_LEFT);
 | 
					 | 
				
			||||||
	newtFormAddHotKey(self, NEWT_KEY_ESCAPE);
 | 
					 | 
				
			||||||
	newtFormAddHotKey(self, 'Q');
 | 
					 | 
				
			||||||
	newtFormAddHotKey(self, 'q');
 | 
					 | 
				
			||||||
	newtFormAddHotKey(self, CTRL('c'));
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
static newtComponent newt_form__new(void)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
	newtComponent self = newtForm(NULL, NULL, 0);
 | 
					 | 
				
			||||||
	if (self)
 | 
					 | 
				
			||||||
		newt_form__set_exit_keys(self);
 | 
					 | 
				
			||||||
	return self;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
int ui__popup_menu(int argc, char * const argv[])
 | 
					int ui__popup_menu(int argc, char * const argv[])
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	struct ui_browser menu = {
 | 
						struct ui_browser menu = {
 | 
				
			||||||
| 
						 | 
					@ -86,17 +69,13 @@ int ui__popup_menu(int argc, char * const argv[])
 | 
				
			||||||
	return popup_menu__run(&menu);
 | 
						return popup_menu__run(&menu);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int ui__help_window(const char *text)
 | 
					int ui__question_window(const char *title, const char *text,
 | 
				
			||||||
 | 
								const char *exit_msg, int delay_secs)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	struct newtExitStruct es;
 | 
						int x, y;
 | 
				
			||||||
	newtComponent tb, form = newt_form__new();
 | 
					 | 
				
			||||||
	int rc = -1;
 | 
					 | 
				
			||||||
	int max_len = 0, nr_lines = 0;
 | 
						int max_len = 0, nr_lines = 0;
 | 
				
			||||||
	const char *t;
 | 
						const char *t;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (form == NULL)
 | 
					 | 
				
			||||||
		return -1;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	t = text;
 | 
						t = text;
 | 
				
			||||||
	while (1) {
 | 
						while (1) {
 | 
				
			||||||
		const char *sep = strchr(t, '\n');
 | 
							const char *sep = strchr(t, '\n');
 | 
				
			||||||
| 
						 | 
					@ -113,28 +92,56 @@ int ui__help_window(const char *text)
 | 
				
			||||||
		t = sep + 1;
 | 
							t = sep + 1;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	tb = newtTextbox(0, 0, max_len, nr_lines, 0);
 | 
						max_len += 2;
 | 
				
			||||||
	if (tb == NULL)
 | 
						nr_lines += 4;
 | 
				
			||||||
		goto out_destroy_form;
 | 
						y = SLtt_Screen_Rows / 2 - nr_lines / 2,
 | 
				
			||||||
 | 
						x = SLtt_Screen_Cols / 2 - max_len / 2;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	newtTextboxSetText(tb, text);
 | 
						SLsmg_set_color(0);
 | 
				
			||||||
	newtFormAddComponent(form, tb);
 | 
						SLsmg_draw_box(y, x++, nr_lines, max_len);
 | 
				
			||||||
	newtCenteredWindow(max_len, nr_lines, NULL);
 | 
						if (title) {
 | 
				
			||||||
	newtFormRun(form, &es);
 | 
							SLsmg_gotorc(y, x + 1);
 | 
				
			||||||
	newtPopWindow();
 | 
							SLsmg_write_string((char *)title);
 | 
				
			||||||
	rc = 0;
 | 
						}
 | 
				
			||||||
out_destroy_form:
 | 
						SLsmg_gotorc(++y, x);
 | 
				
			||||||
	newtFormDestroy(form);
 | 
						nr_lines -= 2;
 | 
				
			||||||
	return rc;
 | 
						max_len -= 2;
 | 
				
			||||||
 | 
						SLsmg_write_wrapped_string((unsigned char *)text, y, x,
 | 
				
			||||||
 | 
									   nr_lines, max_len, 1);
 | 
				
			||||||
 | 
						SLsmg_gotorc(y + nr_lines - 2, x);
 | 
				
			||||||
 | 
						SLsmg_write_nstring((char *)" ", max_len);
 | 
				
			||||||
 | 
						SLsmg_gotorc(y + nr_lines - 1, x);
 | 
				
			||||||
 | 
						SLsmg_write_nstring((char *)exit_msg, max_len);
 | 
				
			||||||
 | 
						SLsmg_refresh();
 | 
				
			||||||
 | 
						return ui__getch(delay_secs);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static const char yes[] = "Yes", no[] = "No",
 | 
					int ui__help_window(const char *text)
 | 
				
			||||||
		  warning_str[] = "Warning!", ok[] = "Ok";
 | 
					{
 | 
				
			||||||
 | 
						return ui__question_window("Help", text, "Press any key...", 0);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
bool ui__dialog_yesno(const char *msg)
 | 
					bool ui__dialog_yesno(const char *msg)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	/* newtWinChoice should really be accepting const char pointers... */
 | 
						int answer = ui__question_window(NULL, msg, "Enter: Yes, ESC: No", 0);
 | 
				
			||||||
	return newtWinChoice(NULL, (char *)yes, (char *)no, (char *)msg) == 1;
 | 
					
 | 
				
			||||||
 | 
						return answer == K_ENTER;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static void __ui__warning(const char *title, const char *format, va_list args)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						char *s;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (use_browser > 0 && vasprintf(&s, format, args) > 0) {
 | 
				
			||||||
 | 
							pthread_mutex_lock(&ui__lock);
 | 
				
			||||||
 | 
							ui__question_window(title, s, "Press any key...", 0);
 | 
				
			||||||
 | 
							pthread_mutex_unlock(&ui__lock);
 | 
				
			||||||
 | 
							free(s);
 | 
				
			||||||
 | 
							return;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						fprintf(stderr, "%s:\n", title);
 | 
				
			||||||
 | 
						vfprintf(stderr, format, args);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void ui__warning(const char *format, ...)
 | 
					void ui__warning(const char *format, ...)
 | 
				
			||||||
| 
						 | 
					@ -142,12 +149,15 @@ void ui__warning(const char *format, ...)
 | 
				
			||||||
	va_list args;
 | 
						va_list args;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	va_start(args, format);
 | 
						va_start(args, format);
 | 
				
			||||||
	if (use_browser > 0) {
 | 
						__ui__warning("Warning", format, args);
 | 
				
			||||||
		pthread_mutex_lock(&ui__lock);
 | 
						va_end(args);
 | 
				
			||||||
		newtWinMessagev((char *)warning_str, (char *)ok,
 | 
					}
 | 
				
			||||||
				(char *)format, args);
 | 
					
 | 
				
			||||||
		pthread_mutex_unlock(&ui__lock);
 | 
					void ui__error(const char *format, ...)
 | 
				
			||||||
	} else
 | 
					{
 | 
				
			||||||
		vfprintf(stderr, format, args);
 | 
						va_list args;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						va_start(args, format);
 | 
				
			||||||
 | 
						__ui__warning("Error", format, args);
 | 
				
			||||||
	va_end(args);
 | 
						va_end(args);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -7,5 +7,7 @@ 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);
 | 
					bool ui__dialog_yesno(const char *msg);
 | 
				
			||||||
 | 
					int ui__question_window(const char *title, const char *text,
 | 
				
			||||||
 | 
								const char *exit_msg, int delay_secs);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#endif /* _PERF_UI_UTIL_H_ */
 | 
					#endif /* _PERF_UI_UTIL_H_ */
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue