linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/5] perf ui: Introduce struct perf_helpline
@ 2012-08-15 14:57 Namhyung Kim
  2012-08-15 14:57 ` [PATCH 2/5] perf ui/tui: Add tui.h header Namhyung Kim
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Namhyung Kim @ 2012-08-15 14:57 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo; +Cc: Ingo Molnar, Peter Zijlstra, Pekka Enberg, LKML

Add struct perf_helpline in order to provide flexible implementation
of helpline APIs. And convert existing TUI implementation to use it.

Signed-off-by: Namhyung Kim <namhyung@kernel.org>
---
 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

diff --git a/tools/perf/Makefile b/tools/perf/Makefile
index e457afa04b59..483fb69fa4ae 100644
--- a/tools/perf/Makefile
+++ b/tools/perf/Makefile
@@ -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
diff --git a/tools/perf/ui/helpline.c b/tools/perf/ui/helpline.c
index 2f950c2641c8..ac52dd0af49e 100644
--- a/tools/perf/ui/helpline.c
+++ b/tools/perf/ui/helpline.c
@@ -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;
-}
diff --git a/tools/perf/ui/helpline.h b/tools/perf/ui/helpline.h
index 7bab6b34e35e..eee8e2ff51d8 100644
--- a/tools/perf/ui/helpline.h
+++ b/tools/perf/ui/helpline.h
@@ -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_ */
diff --git a/tools/perf/ui/tui/helpline.c b/tools/perf/ui/tui/helpline.c
new file mode 100644
index 000000000000..b63a9326d06b
--- /dev/null
+++ b/tools/perf/ui/tui/helpline.c
@@ -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;
+}
-- 
1.7.9.2


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 2/5] perf ui/tui: Add tui.h header
  2012-08-15 14:57 [PATCH 1/5] perf ui: Introduce struct perf_helpline Namhyung Kim
@ 2012-08-15 14:57 ` Namhyung Kim
  2012-08-15 14:57 ` [PATCH 3/5] perf ui/gtk: Implement helpline_fns Namhyung Kim
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Namhyung Kim @ 2012-08-15 14:57 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo; +Cc: Ingo Molnar, Peter Zijlstra, Pekka Enberg, LKML

Consolidate TUI-relate header files and declarations into tui.h.

Signed-off-by: Namhyung Kim <namhyung@kernel.org>
---
 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

diff --git a/tools/perf/Makefile b/tools/perf/Makefile
index 483fb69fa4ae..14c0b744d98e 100644
--- a/tools/perf/Makefile
+++ b/tools/perf/Makefile
@@ -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
 
diff --git a/tools/perf/ui/helpline.h b/tools/perf/ui/helpline.h
index eee8e2ff51d8..7e2d4fb10ebd 100644
--- a/tools/perf/ui/helpline.h
+++ b/tools/perf/ui/helpline.h
@@ -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);
diff --git a/tools/perf/ui/tui/helpline.c b/tools/perf/ui/tui/helpline.c
index b63a9326d06b..a8e67e4a84ea 100644
--- a/tools/perf/ui/tui/helpline.c
+++ b/tools/perf/ui/tui/helpline.c
@@ -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)
diff --git a/tools/perf/ui/tui/setup.c b/tools/perf/ui/tui/setup.c
index e813c1d17346..e247bf51d247 100644
--- a/tools/perf/ui/tui/setup.c
+++ b/tools/perf/ui/tui/setup.c
@@ -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) {
diff --git a/tools/perf/ui/tui/tui.h b/tools/perf/ui/tui/tui.h
new file mode 100644
index 000000000000..17da45ed8ca4
--- /dev/null
+++ b/tools/perf/ui/tui/tui.h
@@ -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 */
diff --git a/tools/perf/ui/tui/util.c b/tools/perf/ui/tui/util.c
index 092902e30cee..b555ae839b2a 100644
--- a/tools/perf/ui/tui/util.c
+++ b/tools/perf/ui/tui/util.c
@@ -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)
-- 
1.7.9.2


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 3/5] perf ui/gtk: Implement helpline_fns
  2012-08-15 14:57 [PATCH 1/5] perf ui: Introduce struct perf_helpline Namhyung Kim
  2012-08-15 14:57 ` [PATCH 2/5] perf ui/tui: Add tui.h header Namhyung Kim
@ 2012-08-15 14:57 ` Namhyung Kim
  2012-08-15 14:57 ` [PATCH 4/5] perf ui/gtk: Use helpline API in browser Namhyung Kim
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Namhyung Kim @ 2012-08-15 14:57 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo; +Cc: Ingo Molnar, Peter Zijlstra, Pekka Enberg, LKML

Add helpline API implementation to GTK front-end.

Cc: Pekka Enberg <penberg@kernel.org>
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
---
 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

diff --git a/tools/perf/Makefile b/tools/perf/Makefile
index 14c0b744d98e..91f16e26fd0d 100644
--- a/tools/perf/Makefile
+++ b/tools/perf/Makefile
@@ -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
diff --git a/tools/perf/ui/gtk/gtk.h b/tools/perf/ui/gtk/gtk.h
index a4d0f2b4a2dc..793cb6116ddf 100644
--- a/tools/perf/ui/gtk/gtk.h
+++ b/tools/perf/ui/gtk/gtk.h
@@ -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)
 {
diff --git a/tools/perf/ui/gtk/helpline.c b/tools/perf/ui/gtk/helpline.c
new file mode 100644
index 000000000000..c02cb4a54939
--- /dev/null
+++ b/tools/perf/ui/gtk/helpline.c
@@ -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 = &gtk_helpline_fns;
+}
diff --git a/tools/perf/ui/gtk/setup.c b/tools/perf/ui/gtk/setup.c
index 92879ce61e2f..ad40b3626fdb 100644
--- a/tools/perf/ui/gtk/setup.c
+++ b/tools/perf/ui/gtk/setup.c
@@ -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;
 }
 
-- 
1.7.9.2


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 4/5] perf ui/gtk: Use helpline API in browser
  2012-08-15 14:57 [PATCH 1/5] perf ui: Introduce struct perf_helpline Namhyung Kim
  2012-08-15 14:57 ` [PATCH 2/5] perf ui/tui: Add tui.h header Namhyung Kim
  2012-08-15 14:57 ` [PATCH 3/5] perf ui/gtk: Implement helpline_fns Namhyung Kim
@ 2012-08-15 14:57 ` Namhyung Kim
  2012-08-15 14:57 ` [PATCH 5/5] perf ui/gtk: Add perf_gtk__show_helpline() for pr_* Namhyung Kim
  2012-08-15 16:34 ` [PATCH 1/5] perf ui: Introduce struct perf_helpline Arnaldo Carvalho de Melo
  4 siblings, 0 replies; 6+ messages in thread
From: Namhyung Kim @ 2012-08-15 14:57 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo; +Cc: Ingo Molnar, Peter Zijlstra, Pekka Enberg, LKML

As we now have a helpline implementation, use it for displaying help
messages.

Cc: Pekka Enberg <penberg@kernel.org>
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
---
 tools/perf/ui/gtk/browser.c |    5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/tools/perf/ui/gtk/browser.c b/tools/perf/ui/gtk/browser.c
index ec12e0b4ded6..26b5b652a8cd 100644
--- a/tools/perf/ui/gtk/browser.c
+++ b/tools/perf/ui/gtk/browser.c
@@ -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);
-- 
1.7.9.2


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 5/5] perf ui/gtk: Add perf_gtk__show_helpline() for pr_*
  2012-08-15 14:57 [PATCH 1/5] perf ui: Introduce struct perf_helpline Namhyung Kim
                   ` (2 preceding siblings ...)
  2012-08-15 14:57 ` [PATCH 4/5] perf ui/gtk: Use helpline API in browser Namhyung Kim
@ 2012-08-15 14:57 ` Namhyung Kim
  2012-08-15 16:34 ` [PATCH 1/5] perf ui: Introduce struct perf_helpline Arnaldo Carvalho de Melo
  4 siblings, 0 replies; 6+ messages in thread
From: Namhyung Kim @ 2012-08-15 14:57 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo; +Cc: Ingo Molnar, Peter Zijlstra, Pekka Enberg, LKML

Use helpline for printing error/debug messages. The code resembles a
TUI counter part and only print the first line of the message.

Cc: Pekka Enberg <penberg@kernel.org>
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
---
 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(-)

diff --git a/tools/perf/ui/gtk/helpline.c b/tools/perf/ui/gtk/helpline.c
index c02cb4a54939..b4f498efdb1e 100644
--- a/tools/perf/ui/gtk/helpline.c
+++ b/tools/perf/ui/gtk/helpline.c
@@ -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 = &gtk_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;
+}
diff --git a/tools/perf/ui/gtk/util.c b/tools/perf/ui/gtk/util.c
index 0ead373c0dfb..b8efb966f94c 100644
--- a/tools/perf/ui/gtk/util.c
+++ b/tools/perf/ui/gtk/util.c
@@ -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)
 {
diff --git a/tools/perf/ui/helpline.h b/tools/perf/ui/helpline.h
index 7e2d4fb10ebd..8d5a8ba3a122 100644
--- a/tools/perf/ui/helpline.h
+++ b/tools/perf/ui/helpline.h
@@ -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_ */
diff --git a/tools/perf/ui/setup.c b/tools/perf/ui/setup.c
index 791fb15ce350..c7820e569660 100644
--- a/tools/perf/ui/setup.c
+++ b/tools/perf/ui/setup.c
@@ -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)
diff --git a/tools/perf/ui/tui/setup.c b/tools/perf/ui/tui/setup.c
index e247bf51d247..009c962fae85 100644
--- a/tools/perf/ui/tui/setup.c
+++ b/tools/perf/ui/tui/setup.c
@@ -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)
diff --git a/tools/perf/util/debug.c b/tools/perf/util/debug.c
index 4dfe0bb3c322..66eb3828ceb5 100644
--- a/tools/perf/util/debug.c
+++ b/tools/perf/util/debug.c
@@ -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);
diff --git a/tools/perf/util/debug.h b/tools/perf/util/debug.h
index 015c91dbc096..05e660cbf7e2 100644
--- a/tools/perf/util/debug.h
+++ b/tools/perf/util/debug.h
@@ -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"
-- 
1.7.9.2


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/5] perf ui: Introduce struct perf_helpline
  2012-08-15 14:57 [PATCH 1/5] perf ui: Introduce struct perf_helpline Namhyung Kim
                   ` (3 preceding siblings ...)
  2012-08-15 14:57 ` [PATCH 5/5] perf ui/gtk: Add perf_gtk__show_helpline() for pr_* Namhyung Kim
@ 2012-08-15 16:34 ` Arnaldo Carvalho de Melo
  4 siblings, 0 replies; 6+ messages in thread
From: Arnaldo Carvalho de Melo @ 2012-08-15 16:34 UTC (permalink / raw)
  To: Namhyung Kim; +Cc: Ingo Molnar, Peter Zijlstra, Pekka Enberg, LKML

Em Wed, Aug 15, 2012 at 11:57:31PM +0900, Namhyung Kim escreveu:
> Add struct perf_helpline in 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
 
> Signed-off-by: Namhyung Kim <namhyung@kernel.org>
> ---
>  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
> 
> diff --git a/tools/perf/Makefile b/tools/perf/Makefile
> index e457afa04b59..483fb69fa4ae 100644
> --- a/tools/perf/Makefile
> +++ b/tools/perf/Makefile
> @@ -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
> diff --git a/tools/perf/ui/helpline.c b/tools/perf/ui/helpline.c
> index 2f950c2641c8..ac52dd0af49e 100644
> --- a/tools/perf/ui/helpline.c
> +++ b/tools/perf/ui/helpline.c
> @@ -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;
> -}
> diff --git a/tools/perf/ui/helpline.h b/tools/perf/ui/helpline.h
> index 7bab6b34e35e..eee8e2ff51d8 100644
> --- a/tools/perf/ui/helpline.h
> +++ b/tools/perf/ui/helpline.h
> @@ -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_ */
> diff --git a/tools/perf/ui/tui/helpline.c b/tools/perf/ui/tui/helpline.c
> new file mode 100644
> index 000000000000..b63a9326d06b
> --- /dev/null
> +++ b/tools/perf/ui/tui/helpline.c
> @@ -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;
> +}
> -- 
> 1.7.9.2

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2012-08-15 16:34 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-08-15 14:57 [PATCH 1/5] perf ui: Introduce struct perf_helpline Namhyung Kim
2012-08-15 14:57 ` [PATCH 2/5] perf ui/tui: Add tui.h header Namhyung Kim
2012-08-15 14:57 ` [PATCH 3/5] perf ui/gtk: Implement helpline_fns Namhyung Kim
2012-08-15 14:57 ` [PATCH 4/5] perf ui/gtk: Use helpline API in browser Namhyung Kim
2012-08-15 14:57 ` [PATCH 5/5] perf ui/gtk: Add perf_gtk__show_helpline() for pr_* Namhyung Kim
2012-08-15 16:34 ` [PATCH 1/5] perf ui: Introduce struct perf_helpline Arnaldo Carvalho de Melo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).