2012-08-16 08:21:45

by Namhyung Kim

[permalink] [raw]
Subject: [PATCH 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.

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.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..78ba28ac7a2c 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 nop_helpline__pop(void)
{
}

-char ui_helpline__current[512];
+static void nop_helpline__push(const char *msg __used)
+{
+}

-void ui_helpline__push(const char *msg)
+static struct ui_helpline default_helpline_fns = {
+ .pop = nop_helpline__pop,
+ .push = nop_helpline__push,
+};
+
+struct ui_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..61118b2bc242 100644
--- a/tools/perf/ui/helpline.h
+++ b/tools/perf/ui/helpline.h
@@ -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_ */
diff --git a/tools/perf/ui/tui/helpline.c b/tools/perf/ui/tui/helpline.c
new file mode 100644
index 000000000000..b4e521ef2170
--- /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 ui_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.11.2


2012-08-16 08:21:46

by Namhyung Kim

[permalink] [raw]
Subject: [PATCH v2 2/5] perf ui/tui: Add tui.h header

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

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.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 61118b2bc242..d9e97f771245 100644
--- a/tools/perf/ui/helpline.h
+++ b/tools/perf/ui/helpline.h
@@ -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);
diff --git a/tools/perf/ui/tui/helpline.c b/tools/perf/ui/tui/helpline.c
index b4e521ef2170..62bd9432f12a 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..51e8cb527fcc
--- /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 ui_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.11.2

2012-08-16 08:23:08

by Namhyung Kim

[permalink] [raw]
Subject: [PATCH v2 5/5] 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.

Cc: Pekka Enberg <[email protected]>
Signed-off-by: Namhyung Kim <[email protected]>
---
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 9180fea920d5..28c6d33177a7 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 d9e97f771245..6d49f932ddcc 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 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_ */
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.11.2

2012-08-16 08:23:33

by Namhyung Kim

[permalink] [raw]
Subject: [PATCH v2 4/5] perf ui/gtk: Use helpline API in browser

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

Cc: Pekka Enberg <[email protected]>
Signed-off-by: Namhyung Kim <[email protected]>
---
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.11.2

2012-08-16 08:23:55

by Namhyung Kim

[permalink] [raw]
Subject: [PATCH v2 3/5] perf ui/gtk: Implement helpline_fns

Add helpline API implementation to GTK front-end.

Cc: Pekka Enberg <[email protected]>
Signed-off-by: Namhyung Kim <[email protected]>
---
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..9180fea920d5
--- /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 ui_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.11.2

2012-08-16 19:37:22

by Arnaldo Carvalho de Melo

[permalink] [raw]
Subject: Re: [PATCH v2 2/5] perf ui/tui: Add tui.h header

Em Thu, Aug 16, 2012 at 05:14:51PM +0900, Namhyung Kim escreveu:
> 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

> 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.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 61118b2bc242..d9e97f771245 100644
> --- a/tools/perf/ui/helpline.h
> +++ b/tools/perf/ui/helpline.h
> @@ -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);
> diff --git a/tools/perf/ui/tui/helpline.c b/tools/perf/ui/tui/helpline.c
> index b4e521ef2170..62bd9432f12a 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..51e8cb527fcc
> --- /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 ui_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.11.2

2012-08-16 19:42:19

by Arnaldo Carvalho de Melo

[permalink] [raw]
Subject: 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:
> Em Thu, Aug 16, 2012 at 05:14:51PM +0900, Namhyung Kim escreveu:
> > 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.

Applied all the others too, testing now, should go to my perf/core
branch soon,

Thanks,

- Arnaldo

2012-08-17 11:28:27

by Pekka Enberg

[permalink] [raw]
Subject: Re: [PATCH v2 3/5] perf ui/gtk: Implement helpline_fns

On Thu, 16 Aug 2012, Namhyung Kim wrote:
> Add helpline API implementation to GTK front-end.

For all three:

Acked-by: Pekka Enberg <[email protected]>

2012-08-17 16:04:00

by Namhyung Kim

[permalink] [raw]
Subject: Re: [PATCH v2 2/5] perf ui/tui: Add tui.h header

Hi Arnaldo,

2012-08-16 (목), 16:37 -0300, Arnaldo Carvalho de Melo:
> Em Thu, Aug 16, 2012 at 05:14:51PM +0900, Namhyung Kim escreveu:
> > 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?

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.


> I applied the first patch, looking at the others now.

Thanks! :)
Namhyung


>
> > 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.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 61118b2bc242..d9e97f771245 100644
> > --- a/tools/perf/ui/helpline.h
> > +++ b/tools/perf/ui/helpline.h
> > @@ -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);
> > diff --git a/tools/perf/ui/tui/helpline.c b/tools/perf/ui/tui/helpline.c
> > index b4e521ef2170..62bd9432f12a 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..51e8cb527fcc
> > --- /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 ui_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.11.2


--
Regards,
Namhyung Kim

2012-08-17 16:42:04

by Namhyung Kim

[permalink] [raw]
Subject: [PATCH v3 5/5] 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.

Acked-by: Pekka Enberg <[email protected]>
Signed-off-by: Namhyung Kim <[email protected]>
---
* 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(-)

diff --git a/tools/perf/ui/gtk/helpline.c b/tools/perf/ui/gtk/helpline.c
index c02cb4a54939..efd36719e0a6 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,26 @@ 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;
+
+ 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;
+}
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

2012-08-21 16:21:20

by Namhyung Kim

[permalink] [raw]
Subject: [tip:perf/core] perf ui: Introduce struct ui_helpline

Commit-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.

Signed-off-by: Namhyung Kim <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: Paul Mackerras <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
---
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(-)

diff --git a/tools/perf/Makefile b/tools/perf/Makefile
index e457afa..483fb69 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 2f950c2..78ba28a 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 nop_helpline__pop(void)
{
}

-char ui_helpline__current[512];
+static void nop_helpline__push(const char *msg __used)
+{
+}

-void ui_helpline__push(const char *msg)
+static struct ui_helpline default_helpline_fns = {
+ .pop = nop_helpline__pop,
+ .push = nop_helpline__push,
+};
+
+struct ui_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 7bab6b3..61118b2 100644
--- a/tools/perf/ui/helpline.h
+++ b/tools/perf/ui/helpline.h
@@ -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_ */
diff --git a/tools/perf/ui/helpline.c b/tools/perf/ui/tui/helpline.c
similarity index 59%
copy from tools/perf/ui/helpline.c
copy to tools/perf/ui/tui/helpline.c
index 2f950c2..2884d2f 100644
--- a/tools/perf/ui/helpline.c
+++ b/tools/perf/ui/tui/helpline.c
@@ -1,19 +1,18 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <pthread.h>

-#include "../debug.h"
-#include "helpline.h"
-#include "ui.h"
-#include "libslang.h"
+#include "../../util/debug.h"
+#include "../helpline.h"
+#include "../ui.h"
+#include "../libslang.h"

-void ui_helpline__pop(void)
+static void tui_helpline__pop(void)
{
}

-char ui_helpline__current[512];
-
-void ui_helpline__push(const char *msg)
+static void tui_helpline__push(const char *msg)
{
const size_t sz = sizeof(ui_helpline__current);

@@ -24,35 +23,14 @@ void ui_helpline__push(const char *msg)
strncpy(ui_helpline__current, msg, sz)[sz - 1] = '\0';
}

-void ui_helpline__vpush(const char *fmt, va_list ap)
-{
- char *s;
-
- if (vasprintf(&s, fmt, ap) < 0)
- vfprintf(stderr, fmt, ap);
- else {
- ui_helpline__push(s);
- free(s);
- }
-}
-
-void ui_helpline__fpush(const char *fmt, ...)
-{
- va_list ap;
-
- va_start(ap, fmt);
- ui_helpline__vpush(fmt, ap);
- va_end(ap);
-}
-
-void ui_helpline__puts(const char *msg)
-{
- ui_helpline__pop();
- ui_helpline__push(msg);
-}
+struct ui_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(" ");
}

2012-08-21 16:22:14

by Namhyung Kim

[permalink] [raw]
Subject: [tip:perf/core] perf ui gtk: Implement helpline_fns

Commit-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.

Signed-off-by: Namhyung Kim <[email protected]>
Acked-by: Pekka Enberg <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: Paul Mackerras <[email protected]>
Cc: Pekka Enberg <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
---
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(-)

diff --git a/tools/perf/Makefile b/tools/perf/Makefile
index 483fb69..75af93d 100644
--- a/tools/perf/Makefile
+++ b/tools/perf/Makefile
@@ -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
diff --git a/tools/perf/ui/gtk/gtk.h b/tools/perf/ui/gtk/gtk.h
index a4d0f2b..793cb61 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 0000000..2511b37
--- /dev/null
+++ b/tools/perf/ui/gtk/helpline.c
@@ -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 = &gtk_helpline_fns;
+}
diff --git a/tools/perf/ui/gtk/setup.c b/tools/perf/ui/gtk/setup.c
index 92879ce..ad40b36 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;
}

2012-08-21 16:23:09

by Namhyung Kim

[permalink] [raw]
Subject: [tip:perf/core] perf ui/gtk: Use helpline API in browser

Commit-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.

Signed-off-by: Namhyung Kim <[email protected]>
Acked-by: Pekka Enberg <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: Paul Mackerras <[email protected]>
Cc: Pekka Enberg <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
---
tools/perf/ui/gtk/browser.c | 5 ++++-
1 files changed, 4 insertions(+), 1 deletions(-)

diff --git a/tools/perf/ui/gtk/browser.c b/tools/perf/ui/gtk/browser.c
index ec12e0b..26b5b65 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);

2012-08-21 16:24:07

by Namhyung Kim

[permalink] [raw]
Subject: [tip:perf/core] perf ui gtk: Add perf_gtk__show_helpline() for pr_*

Commit-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.

Signed-off-by: Namhyung Kim <[email protected]>
Acked-by: Pekka Enberg <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: Paul Mackerras <[email protected]>
Cc: Pekka Enberg <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
---
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 2511b37..5db4432 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)
{
@@ -28,3 +33,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 0ead373..b8efb96 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 61118b2..a2487f9 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 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_ */
diff --git a/tools/perf/ui/setup.c b/tools/perf/ui/setup.c
index 791fb15..c7820e5 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 e813c1d..4c936e0 100644
--- a/tools/perf/ui/tui/setup.c
+++ b/tools/perf/ui/tui/setup.c
@@ -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;
diff --git a/tools/perf/util/debug.c b/tools/perf/util/debug.c
index 4dfe0bb..66eb382 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 015c91d..05e660c 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"