perf ui: Introduce struct ui_helpline
Namhyung Kim
maintainerPATCH v2 1/5 perf ui: Introduce struct ui_helpline
Add struct ui_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 ui_helpline { +void (*pop)(void ); +void (*push)(const char *msg); +}; + +extern struct ui_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.11.2
Namhyung Kim
maintainerPATCH v2 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 ui_helpline {extern struct ui_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 ui_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.11.2
Namhyung Kim
maintainerPATCH v2 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 ui_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.11.2
Namhyung Kim
maintainerPATCH v2 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.11.2
Namhyung Kim
maintainerPATCH v2 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 ui_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.11.2
Re: [PATCH v2 2/5] perf ui/tui: Add tui.h header
In reply to Namhyung KimEm Thu, Aug 16, 2012 at 05:14:51PM +0900, Namhyung Kim escreveu:
Quoted 1 line
Consolidate TUI-relate header files and declarations into
tui.h.
What for?
#include directives should be used where they are needed, and in this new tui.h only the definitions of those two structs are needed, right?
I applied the first patch, looking at the others now.
- Arnaldo
Quoted 132 lines
Signed-off-by Namhyung Kim <[email protected]>--- 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.htools/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 endiftools/perf/ui/helpline.h +0
-2@@ -11,8 +11,6 @@ struct ui_helpline {extern struct ui_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 ui_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.11.2
Re: [PATCH v2 2/5] perf ui/tui: Add tui.h header
Em Thu, Aug 16, 2012 at 04:37:11PM -0300, Arnaldo Carvalho de Melo escreveu:
Quoted 9 lines
Em Thu, Aug 16, 2012 at 05:14:51PM +0900, Namhyung Kim escreveu:
Quoted 1 line
Consolidate TUI-relate header files and declarations into
tui.h.What for?
#include directives should be used where they are needed, and in this new
tui.honly the definitions of those two structs are needed, right?I applied the first patch, looking at the others now.
Applied all the others too, testing now, should go to my perf/core branch soon,
Thanks,
- Arnaldo
Re: [PATCH v2 3/5] perf ui/gtk: Implement helpline_fns
In reply to Namhyung KimQuoted 1 line · Namhyung Kim
Add helpline API implementation to GTK front-end.
For all three:
Re: [PATCH v2 2/5] perf ui/tui: Add tui.h header
In reply to Arnaldo Carvalho de MeloHi Arnaldo,
2012-08-16 (목), 16:37 -0300, Arnaldo Carvalho de Melo:
Quoted 7 lines
Em Thu, Aug 16, 2012 at 05:14:51PM +0900, Namhyung Kim escreveu:
Quoted 1 line
Consolidate TUI-relate header files and declarations into
tui.h.What for?
#include directives should be used where they are needed, and in this new
tui.honly the definitions of those two structs are needed, right?
Right. But I just thought as more UI stuff is added, the more will be needed. At least I'll add two more - hist, progress - in the near future.
Quoted 1 line
I applied the first patch, looking at the others now.
Thanks! :)
Namhyung
Quoted 133 lines
Quoted 133 lines
Signed-off-by Namhyung Kim <[email protected]>--- 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.htools/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 endiftools/perf/ui/helpline.h +0
-2@@ -11,8 +11,6 @@ struct ui_helpline {extern struct ui_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 ui_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.11.2
Signature · 2 lines
Regards, Namhyung Kim
Namhyung Kim
maintainerPATCH v3 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.
---
* protect the function from concurrent access using ui__lock
* use memchr instead of strchr since there's no guarantee that the ui_helpline__current is NULL-terminated.
tools/perf/ui/gtk/helpline.c | 28 ++++++++++++++++++++++++++++ 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, 59 insertions(+), 15 deletions(-)
tools/perf/ui/gtk/helpline.c +28 -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,26 @@ 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; + +pthread_mutex_lock (&ui__lock); + ret =vscnprintf (ui_helpline__current + backlog, +sizeof (ui_helpline__current) - backlog, fmt, ap); + backlog += ret; + +/* only first line can be displayed */ + ptr =memchr (ui_helpline__current,'\n' ,sizeof (ui_helpline__current)); +if (ptr && (ptr - ui_helpline__current) <= backlog) { + *ptr ='\0' ; +ui_helpline__puts (ui_helpline__current); + backlog =0 ; + } +pthread_mutex_unlock (&ui__lock); + +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
tip-bot for Namhyung Kim
maintainerCommit-ID: e6e9046879493d8bf8f44ac1f2718c4a5628aa52 Gitweb: http://git.kernel.org/tip/e6e9046879493d8bf8f44ac1f2718c4a5628aa52 Author: Namhyung Kim <[email protected]> AuthorDate: Thu, 16 Aug 2012 17:14:50 +0900 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Thu, 16 Aug 2012 14:17:01 -0300
perf ui: Introduce struct ui_helpline
Add struct ui_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 | 46 ++++++++----------------------
4 files changed, 43 insertions(+), 74 deletions(-)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 ui_helpline { +void (*pop)(void ); +void (*push)(const char *msg); +}; + +extern struct ui_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 renamed from tools/perf/ui/helpline.c +12 -34
66 lines not on this page · raw message
tip-bot for Namhyung Kim
maintainer[tip:perf/core] perf ui gtk: Implement helpline_fns
In reply to Namhyung KimCommit-ID: 4bb1646a80db65bb45c0a1bffb2435c6690c392e Gitweb: http://git.kernel.org/tip/4bb1646a80db65bb45c0a1bffb2435c6690c392e Author: Namhyung Kim <[email protected]> AuthorDate: Thu, 16 Aug 2012 17:14:52 +0900 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Fri, 17 Aug 2012 12:37:11 -0300
perf ui gtk: Implement helpline_fns
Add helpline API implementation to GTK front-end.
--- tools/perf/Makefile | 1 + tools/perf/ui/gtk/gtk.h | 2 ++ tools/perf/ui/gtk/helpline.c | 30 ++++++++++++++++++++++++++++++ tools/perf/ui/gtk/setup.c | 1 + 4 files changed, 34 insertions(+), 0 deletions(-)
tools/perf/Makefile +1 -0
@@ -600,6 +600,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 +30 -0
@@ -0,0 +1,30 @@ +#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 ui_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 ; }
tip-bot for Namhyung Kim
maintainer[tip:perf/core] perf ui/gtk: Use helpline API in browser
In reply to Namhyung KimCommit-ID: ed70c609ae92e0cb03b746ab566c3cf8f2aaede4 Gitweb: http://git.kernel.org/tip/ed70c609ae92e0cb03b746ab566c3cf8f2aaede4 Author: Namhyung Kim <[email protected]> AuthorDate: Thu, 16 Aug 2012 17:14:53 +0900 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Fri, 17 Aug 2012 12:37:36 -0300
perf ui/gtk: Use helpline API in browser
As we now have a helpline implementation, use it for displaying help messages.
--- tools/perf/ui/gtk/browser.c | 5 ++++- 1 files changed, 4 insertions(+), 1 deletions(-)
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);
tip-bot for Namhyung Kim
maintainer[tip:perf/core] perf ui gtk: Add perf_gtk__show_helpline() for pr_*
In reply to Namhyung KimCommit-ID: 0985a94891c73740dea1e2697f9d598a4a7810ab Gitweb: http://git.kernel.org/tip/0985a94891c73740dea1e2697f9d598a4a7810ab Author: Namhyung Kim <[email protected]> AuthorDate: Thu, 16 Aug 2012 17:14:54 +0900 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Fri, 17 Aug 2012 12:37:56 -0300
perf ui gtk: Add perf_gtk__show_helpline() for pr_*
Use 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 ) {
@@ -28,3 +33,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 ui_helpline {void (*pop)(void );void (*push)(const char *msg);
@@ -21,4 +23,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
@@ -11,8 +11,6 @@#include "../libslang.h" #include "../keysyms.h" -pthread_mutex_t ui__lock =PTHREAD_MUTEX_INITIALIZER ; -static volatile int ui__need_resize;extern struct perf_error_ops perf_tui_eops;
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"