perf ui: Introduce struct perf_helpline
Namhyung Kim
maintainerPATCH 1/5 perf ui: Introduce struct perf_helpline
Add struct perf_helpline in order to provide flexible implementation of helpline APIs. And convert existing TUI implementation to use it.
--- tools/perf/Makefile | 5 ++-- tools/perf/ui/helpline.c | 56 ++++++++++++++-------------------------- tools/perf/ui/helpline.h | 10 +++++++- tools/perf/ui/tui/helpline.c | 58 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 89 insertions(+), 40 deletions(-) create mode 100644 tools/perf/ui/tui/helpline.c
tools/perf/Makefile +3 -2
@@ -335,6 +335,7 @@ LIB_H += util/rblist.h LIB_H += util/intlist.h LIB_H += util/perf_regs.h LIB_H += util/unwind.h +LIB_H += ui/helpline.h LIB_OBJS += $(OUTPUT)util/abspath.o LIB_OBJS += $(OUTPUT)util/alias.o
@@ -402,6 +403,7 @@ LIB_OBJS += $(OUTPUT)util/cgroup.o LIB_OBJS += $(OUTPUT)util/target.o LIB_OBJS += $(OUTPUT)util/rblist.o LIB_OBJS += $(OUTPUT)util/intlist.o +LIB_OBJS += $(OUTPUT)ui/helpline.o BUILTIN_OBJS += $(OUTPUT)builtin-annotate.o
@@ -567,14 +569,13 @@ else LIB_OBJS += $(OUTPUT)ui/browsers/annotate.o LIB_OBJS += $(OUTPUT)ui/browsers/hists.o LIB_OBJS += $(OUTPUT)ui/browsers/map.o - LIB_OBJS += $(OUTPUT)ui/helpline.o LIB_OBJS += $(OUTPUT)ui/progress.o LIB_OBJS += $(OUTPUT)ui/util.o LIB_OBJS += $(OUTPUT)ui/tui/setup.o LIB_OBJS += $(OUTPUT)ui/tui/util.o + LIB_OBJS += $(OUTPUT)ui/tui/helpline.o LIB_H += ui/browser.h LIB_H += ui/browsers/map.h - LIB_H += ui/helpline.h LIB_H += ui/keysyms.h LIB_H += ui/libslang.h LIB_H += ui/progress.h
tools/perf/ui/helpline.c +19 -37
72 lines not on this page · raw message
tools/perf/ui/helpline.h +9 -1
@@ -4,13 +4,21 @@#include <stdio.h> #include <stdarg.h> +struct perf_helpline { +void (*pop)(void ); +void (*push)(const char *msg); +}; + +extern struct perf_helpline *helpline_fns; +void ui_helpline__init (void ); +void ui_helpline__pop (void );void ui_helpline__push (const char *msg);void ui_helpline__vpush (const char *fmt,va_list ap);void ui_helpline__fpush (const char *fmt, ...);void ui_helpline__puts (const char *msg); -extern char ui_helpline__current[]; +extern char ui_helpline__current[512 ];#endif /* _PERF_UI_HELPLINE_H_ */
tools/perf/ui/tui/helpline.c new file +58 -0
58 lines not on this page · raw message
Signature · 1 line
1.7.9.2
Namhyung Kim
maintainerPATCH 2/5 perf ui/tui: Add tui.h header
Consolidate TUI-relate header files and declarations into tui.h.
--- tools/perf/Makefile | 1 + tools/perf/ui/helpline.h | 2 -- tools/perf/ui/tui/helpline.c | 5 +---- tools/perf/ui/tui/setup.c | 12 +----------- tools/perf/ui/tui/tui.h | 21 +++++++++++++++++++++ tools/perf/ui/tui/util.c | 10 +--------- 6 files changed, 25 insertions(+), 26 deletions(-) create mode 100644 tools/perf/ui/tui/tui.h
tools/perf/Makefile +1 -0
@@ -581,6 +581,7 @@ else LIB_H += ui/progress.h LIB_H += ui/util.h LIB_H += ui/ui.h + LIB_H += ui/tui/tui.h endif endif
tools/perf/ui/helpline.h +0 -2
@@ -11,8 +11,6 @@ struct perf_helpline {extern struct perf_helpline *helpline_fns; -void ui_helpline__init (void ); -void ui_helpline__pop (void );void ui_helpline__push (const char *msg);void ui_helpline__vpush (const char *fmt,va_list ap);
tools/perf/ui/tui/helpline.c +1 -4
@@ -3,10 +3,7 @@#include <string.h> #include <pthread.h> -#include "../../util/debug.h" -#include "../helpline.h" -#include "../ui.h" -#include "../libslang.h" +#include "tui.h" static void tui_helpline__pop (void )
tools/perf/ui/tui/setup.c +1 -11
@@ -1,22 +1,12 @@ -#include <newt.h> #include <signal.h> #include <stdbool.h> -#include "../../util/cache.h" -#include "../../util/debug.h" -#include "../browser.h" -#include "../helpline.h" -#include "../ui.h" -#include "../util.h" -#include "../libslang.h" -#include "../keysyms.h" +#include "tui.h" pthread_mutex_t ui__lock =PTHREAD_MUTEX_INITIALIZER ;static volatile int ui__need_resize; -extern struct perf_error_ops perf_tui_eops; -void ui__refresh_dimensions (bool force) {if (force || ui__need_resize) {
tools/perf/ui/tui/tui.h new file +21 -0
@@ -0,0 +1,21 @@ +#ifndef _PERF_TUI_H_ +#define _PERF_TUI_H_ + +#include <newt.h> + +#include "../../util/debug.h" +#include "../../util/cache.h" +#include "../ui.h" +#include "../util.h" +#include "../browser.h" +#include "../helpline.h" +#include "../libslang.h" +#include "../keysyms.h" + +extern struct perf_error_ops perf_tui_eops; + +extern struct perf_helpline tui_helpline_fns; + +void ui_helpline__init (void ); + +#endif /* _PERF_TUI_H */
tools/perf/ui/tui/util.c +1 -9
@@ -1,17 +1,9 @@ -#include "../../util/util.h" #include <signal.h> #include <stdbool.h> #include <string.h> #include <sys/ttydefaults.h> -#include "../../util/cache.h" -#include "../../util/debug.h" -#include "../browser.h" -#include "../keysyms.h" -#include "../helpline.h" -#include "../ui.h" -#include "../util.h" -#include "../libslang.h" +#include "tui.h" static void ui_browser__argv_write (struct ui_browser *browser,void *entry,int row)
Signature · 1 line
1.7.9.2
Namhyung Kim
maintainerPATCH 3/5 perf ui/gtk: Implement helpline_fns
In reply to Namhyung KimAdd helpline API implementation to GTK front-end.
--- tools/perf/Makefile | 1 + tools/perf/ui/gtk/gtk.h | 2 ++ tools/perf/ui/gtk/helpline.c | 31 +++++++++++++++++++++++++++++++ tools/perf/ui/gtk/setup.c | 1 + 4 files changed, 35 insertions(+) create mode 100644 tools/perf/ui/gtk/helpline.c
tools/perf/Makefile +1 -0
@@ -601,6 +601,7 @@ else LIB_OBJS += $(OUTPUT)ui/gtk/browser.o LIB_OBJS += $(OUTPUT)ui/gtk/setup.o LIB_OBJS += $(OUTPUT)ui/gtk/util.o + LIB_OBJS += $(OUTPUT)ui/gtk/helpline.o # Make sure that it'd be included only once. ifneq ($(findstring -DNO_NEWT_SUPPORT,$(BASIC_CFLAGS)),) LIB_OBJS += $(OUTPUT)ui/setup.o
tools/perf/ui/gtk/gtk.h +2 -0
@@ -29,6 +29,8 @@ static inline bool perf_gtk__is_active_context(struct perf_gtk_context *ctx)struct perf_gtk_context *perf_gtk__activate_context (GtkWidget *window);int perf_gtk__deactivate_context (struct perf_gtk_context **ctx); +void perf_gtk__init_helpline (void ); +#ifndef HAVE_GTK_INFO_BAR static inline GtkWidget *perf_gtk__setup_info_bar (void ) {
tools/perf/ui/gtk/helpline.c new file +31 -0
@@ -0,0 +1,31 @@ +#include "gtk.h" +#include "../helpline.h" + + +static void gtk_helpline_pop (void ) +{ +if (!perf_gtk__is_active_context (pgctx)) +return ; + +gtk_statusbar_pop (GTK_STATUSBAR (pgctx->statbar), + pgctx->statbar_ctx_id); +} + +static void gtk_helpline_push (const char *msg) +{ +if (!perf_gtk__is_active_context (pgctx)) +return ; + +gtk_statusbar_push (GTK_STATUSBAR (pgctx->statbar), + pgctx->statbar_ctx_id, msg); +} + +static struct perf_helpline gtk_helpline_fns = { + .pop = gtk_helpline_pop, + .push = gtk_helpline_push, +}; + +void perf_gtk__init_helpline (void ) +{ + helpline_fns = >k_helpline_fns; +}
tools/perf/ui/gtk/setup.c +1 -0
@@ -7,6 +7,7 @@ extern struct perf_error_ops perf_gtk_eops;int perf_gtk__init (void ) {perf_error__register (&perf_gtk_eops); +perf_gtk__init_helpline ();return gtk_init_check (NULL ,NULL ) ?0 :-1 ; }
Signature · 1 line
1.7.9.2
Namhyung Kim
maintainerPATCH 4/5 perf ui/gtk: Use helpline API in browser
In reply to Namhyung KimAs we now have a helpline implementation, use it for displaying help messages.
--- tools/perf/ui/gtk/browser.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
tools/perf/ui/gtk/browser.c +4 -1
@@ -3,6 +3,7 @@#include "../evsel.h" #include "../sort.h" #include "../hist.h" +#include "../helpline.h" #include "gtk.h" #include <signal.h>
@@ -166,7 +167,7 @@ static GtkWidget *perf_gtk__setup_statusbar(void) }int perf_evlist__gtk_browse_hists (struct perf_evlist *evlist, -const char *help__used , +const char *help,void (*timer) (void *arg)__used ,void *arg__used ,int delay_secs__used ) {
@@ -233,6 +234,8 @@ int perf_evlist__gtk_browse_hists(struct perf_evlist *evlist,gtk_window_set_position (GTK_WINDOW (window),GTK_WIN_POS_CENTER ); +ui_helpline__push (help); +gtk_main ();perf_gtk__deactivate_context (&pgctx);
Signature · 1 line
1.7.9.2
Namhyung Kim
maintainerPATCH 5/5 perf ui/gtk: Add perf_gtk__show_helpline() for pr_*
In reply to Namhyung KimUse helpline for printing error/debug messages. The code resembles a TUI counter part and only print the first line of the message.
--- tools/perf/ui/gtk/helpline.c | 26 ++++++++++++++++++++++++++ tools/perf/ui/gtk/util.c | 5 ----- tools/perf/ui/helpline.h | 23 +++++++++++++++++++++++ tools/perf/ui/setup.c | 4 ++++ tools/perf/ui/tui/setup.c | 2 -- tools/perf/util/debug.c | 4 +++- tools/perf/util/debug.h | 8 +------- 7 files changed, 57 insertions(+), 15 deletions(-)
tools/perf/ui/gtk/helpline.c +26 -0
@@ -1,5 +1,10 @@ +#include <stdio.h> +#include <string.h> +#include "gtk.h" +#include "../ui.h" #include "../helpline.h" +#include "../../util/debug.h" static void gtk_helpline_pop (void )
@@ -29,3 +34,24 @@ void perf_gtk__init_helpline(void) { helpline_fns = >k_helpline_fns; } + +int perf_gtk__show_helpline (const char *fmt,va_list ap) +{ +int ret; +char *ptr; +static int backlog; + + ret =vscnprintf (ui_helpline__current + backlog, +sizeof (ui_helpline__current) - backlog, fmt, ap); + backlog += ret; + +/* only first line can be displayed */ + ptr =strchr (ui_helpline__current,'\n' ); +if (ptr && (ptr - ui_helpline__current) <= backlog) { + *ptr ='\0' ; +ui_helpline__puts (ui_helpline__current); + backlog =0 ; + } + +return ret; +}
tools/perf/ui/gtk/util.c +0 -5
@@ -117,11 +117,6 @@ struct perf_error_ops perf_gtk_eops = {* For now, just add stubs for NO_NEWT=1 build. */ #ifdef NO_NEWT_SUPPORT -int ui_helpline__show_help (const char *format__used ,va_list ap__used ) -{ -return 0 ; -} -void ui_progress__update (u64 curr__used ,u64 total__used ,const char *title__used ) {
tools/perf/ui/helpline.h +23 -0
@@ -4,6 +4,8 @@#include <stdio.h> #include <stdarg.h> +#include "../util/cache.h" +struct perf_helpline {void (*pop)(void );void (*push)(const char *msg);
@@ -19,4 +21,25 @@ void ui_helpline__puts(const char *msg);extern char ui_helpline__current[512 ]; +#ifdef NO_NEWT_SUPPORT +static inline int ui_helpline__show_help (const char *format__used , +va_list ap__used ) +{ +return 0 ; +} +#else +extern char ui_helpline__last_msg[]; +int ui_helpline__show_help (const char *format,va_list ap); +#endif /* NO_NEWT_SUPPORT */ + +#ifdef NO_GTK2_SUPPORT +static inline int perf_gtk__show_helpline (const char *format__used , +va_list ap__used ) +{ +return 0 ; +} +#else +int perf_gtk__show_helpline (const char *format,va_list ap); +#endif /* NO_GTK2_SUPPORT */ +#endif /* _PERF_UI_HELPLINE_H_ */
tools/perf/ui/setup.c +4 -0
@@ -1,7 +1,11 @@ +#include <pthread.h> +#include "../cache.h" #include "../debug.h" +pthread_mutex_t ui__lock =PTHREAD_MUTEX_INITIALIZER ; +void setup_browser (bool fallback_to_pager) {if (!isatty (1 ) || dump_trace)
tools/perf/ui/tui/setup.c +0 -2
@@ -3,8 +3,6 @@#include "tui.h" -pthread_mutex_t ui__lock =PTHREAD_MUTEX_INITIALIZER ; -static volatile int ui__need_resize;void ui__refresh_dimensions (bool force)
tools/perf/util/debug.c +3 -1
@@ -23,8 +23,10 @@ int eprintf(int level, const char *fmt, ...)if (verbose >= level) {va_start (args, fmt); -if (use_browser >0 ) +if (use_browser ==1 ) ret =ui_helpline__show_help (fmt, args); +else if (use_browser ==2 ) + ret =perf_gtk__show_helpline (fmt, args);else ret =vfprintf (stderr, fmt, args);va_end (args);
tools/perf/util/debug.h +1 -7
@@ -4,6 +4,7 @@#include <stdbool.h> #include "event.h" +#include "../ui/helpline.h" extern int verbose;extern bool quiet, dump_trace;
@@ -15,11 +16,6 @@ struct ui_progress;struct perf_error_ops ;#if defined(NO_NEWT_SUPPORT ) && defined(NO_GTK2_SUPPORT ) -static inline int ui_helpline__show_help (const char *format__used ,va_list ap__used ) -{ -return 0 ; -} -static inline void ui_progress__update (u64 curr__used ,u64 total__used ,const char *title__used ) {}
@@ -39,8 +35,6 @@ perf_error__unregister(struct perf_error_ops *eops __used)#else /* NO_NEWT_SUPPORT && NO_GTK2_SUPPORT */ -extern char ui_helpline__last_msg[]; -int ui_helpline__show_help (const char *format,va_list ap);#include "../ui/progress.h" int ui__error (const char *format, ...) __attribute__((format (printf,1 ,2 )));#include "../ui/util.h"
Signature · 1 line
1.7.9.2
Em Wed, Aug 15, 2012 at 11:57:31PM +0900, Namhyung Kim escreveu:
Quoted 2 lines
Add struct
perf_helplinein order to provide flexible implementation of helpline APIs. And convert existing TUI implementation to use it.
I advise not to use struct perf_helpline but struct ui_helpline, as it is just user interface, not exactly tied to perf, it is just its first user.
We don't need to bend over backwardws trying to create yet another UI widget set, but there is no need to use the "perf_" namespace on it, I think.
- Arnaldo
Quoted 216 lines
Signed-off-by Namhyung Kim <[email protected]>--- tools/perf/Makefile | 5 ++-- tools/perf/ui/helpline.c | 56 ++++++++++++++-------------------------- tools/perf/ui/helpline.h | 10 +++++++- tools/perf/ui/tui/helpline.c | 58 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 89 insertions(+), 40 deletions(-) create mode 100644 tools/perf/ui/tui/helpline.ctools/perf/Makefile +3
-2@@ -335,6 +335,7 @@ LIB_H += util/rblist.h LIB_H += util/intlist.h LIB_H += util/perf_regs.h LIB_H += util/unwind.h +LIB_H += ui/helpline.h LIB_OBJS += $(OUTPUT)util/abspath.o LIB_OBJS += $(OUTPUT)util/alias.o@@ -402,6 +403,7 @@ LIB_OBJS += $(OUTPUT)util/cgroup.o LIB_OBJS += $(OUTPUT)util/target.o LIB_OBJS += $(OUTPUT)util/rblist.o LIB_OBJS += $(OUTPUT)util/intlist.o +LIB_OBJS += $(OUTPUT)ui/helpline.o BUILTIN_OBJS += $(OUTPUT)builtin-annotate.o@@ -567,14 +569,13 @@ else LIB_OBJS += $(OUTPUT)ui/browsers/annotate.o LIB_OBJS += $(OUTPUT)ui/browsers/hists.o LIB_OBJS += $(OUTPUT)ui/browsers/map.o - LIB_OBJS += $(OUTPUT)ui/helpline.o LIB_OBJS += $(OUTPUT)ui/progress.o LIB_OBJS += $(OUTPUT)ui/util.o LIB_OBJS += $(OUTPUT)ui/tui/setup.o LIB_OBJS += $(OUTPUT)ui/tui/util.o + LIB_OBJS += $(OUTPUT)ui/tui/helpline.o LIB_H += ui/browser.h LIB_H += ui/browsers/map.h - LIB_H += ui/helpline.h LIB_H += ui/keysyms.h LIB_H += ui/libslang.h LIB_H += ui/progress.htools/perf/ui/helpline.c +19
-37@@ -5,23 +5,32 @@#include "../debug.h" #include "helpline.h" #include "ui.h" -#include "libslang.h" -void ui_helpline__pop (void ) +char ui_helpline__current[512 ]; + +static void perf_helpline__pop (void ) { } -char ui_helpline__current[512 ]; +static void perf_helpline__push (const char *msg__used ) +{ +} -void ui_helpline__push (const char *msg) +static struct perf_helpline default_helpline_fns = { + .pop = perf_helpline__pop, + .push = perf_helpline__push, +}; + +struct perf_helpline *helpline_fns = &default_helpline_fns; + +void ui_helpline__pop (void ) { -const size_t sz =sizeof (ui_helpline__current); + helpline_fns->pop (); +} -SLsmg_gotorc (SLtt_Screen_Rows -1 ,0 ); -SLsmg_set_color (0 ); -SLsmg_write_nstring ((char *)msg, SLtt_Screen_Cols); -SLsmg_refresh (); -strncpy (ui_helpline__current, msg, sz)[sz -1 ] ='\0' ; +void ui_helpline__push (const char *msg) +{ + helpline_fns->push (msg); }void ui_helpline__vpush (const char *fmt,va_list ap)@@ -50,30 +59,3 @@ void ui_helpline__puts(const char *msg)ui_helpline__pop ();ui_helpline__push (msg); } - -void ui_helpline__init (void ) -{ -ui_helpline__puts (" " ); -} - -char ui_helpline__last_msg[1024 ]; - -int ui_helpline__show_help (const char *format,va_list ap) -{ -int ret; -static int backlog; - -pthread_mutex_lock (&ui__lock); - ret =vscnprintf (ui_helpline__last_msg + backlog, -sizeof (ui_helpline__last_msg) - backlog, format, ap); - backlog += ret; - -if (ui_helpline__last_msg[backlog -1 ] =='\n' ) { -ui_helpline__puts (ui_helpline__last_msg); -SLsmg_refresh (); - backlog =0 ; - } -pthread_mutex_unlock (&ui__lock); - -return ret; -}tools/perf/ui/helpline.h +9
-1@@ -4,13 +4,21 @@#include <stdio.h> #include <stdarg.h> +struct perf_helpline { +void (*pop)(void ); +void (*push)(const char *msg); +}; + +extern struct perf_helpline *helpline_fns; +void ui_helpline__init (void ); +void ui_helpline__pop (void );void ui_helpline__push (const char *msg);void ui_helpline__vpush (const char *fmt,va_list ap);void ui_helpline__fpush (const char *fmt, ...);void ui_helpline__puts (const char *msg); -extern char ui_helpline__current[]; +extern char ui_helpline__current[512 ];#endif /* _PERF_UI_HELPLINE_H_ */ tools/perf/ui/tui/helpline.c new file +58
-0@@ -0,0 +1,58 @@ +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <pthread.h> + +#include "../../util/debug.h" +#include "../helpline.h" +#include "../ui.h" +#include "../libslang.h" + + +static void tui_helpline__pop (void ) +{ +} + +static void tui_helpline__push (const char *msg) +{ +const size_t sz =sizeof (ui_helpline__current); + +SLsmg_gotorc (SLtt_Screen_Rows -1 ,0 ); +SLsmg_set_color (0 ); +SLsmg_write_nstring ((char *)msg, SLtt_Screen_Cols); +SLsmg_refresh (); +strncpy (ui_helpline__current, msg, sz)[sz -1 ] ='\0' ; +} + +struct perf_helpline tui_helpline_fns = { + .pop = tui_helpline__pop, + .push = tui_helpline__push, +}; + +void ui_helpline__init (void ) +{ + helpline_fns = &tui_helpline_fns; +ui_helpline__puts (" " ); +} + +char ui_helpline__last_msg[1024 ]; + +int ui_helpline__show_help (const char *format,va_list ap) +{ +int ret; +static int backlog; + +pthread_mutex_lock (&ui__lock); + ret =vscnprintf (ui_helpline__last_msg + backlog, +sizeof (ui_helpline__last_msg) - backlog, format, ap); + backlog += ret; + +if (ui_helpline__last_msg[backlog -1 ] =='\n' ) { +ui_helpline__puts (ui_helpline__last_msg); +SLsmg_refresh (); + backlog =0 ; + } +pthread_mutex_unlock (&ui__lock); + +return ret; +}Signature · 1 line
1.7.9.2