Skip to content

Commit

Permalink
perf ui: Add gtk2 support into setup_browser()
Browse files Browse the repository at this point in the history
Now setup_browser can handle gtk2 front-end so split the TUI code to
ui/tui/setup.c in order to remove dependency.

To this end, make ui__init/exit global symbols and take an argument.
Also split gtk code to ui/gtk/setup.c.

Signed-off-by: Namhyung Kim <namhyung.kim@lge.com>
Acked-by: Pekka Enberg <penberg@kernel.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Namhyung Kim <namhyung@gmail.com>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Pekka Enberg <penberg@kernel.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: http://lkml.kernel.org/r/1335761711-31403-5-git-send-email-namhyung.kim@lge.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
  • Loading branch information
Namhyung Kim authored and Arnaldo Carvalho de Melo committed May 2, 2012
1 parent 28e62b9 commit 281ef54
Show file tree
Hide file tree
Showing 7 changed files with 205 additions and 165 deletions.
6 changes: 6 additions & 0 deletions tools/perf/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,7 @@ else
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_H += ui/browser.h
LIB_H += ui/browsers/map.h
LIB_H += ui/helpline.h
Expand All @@ -505,6 +506,11 @@ else
BASIC_CFLAGS += $(shell pkg-config --cflags gtk+-2.0)
EXTLIBS += $(shell pkg-config --libs gtk+-2.0)
LIB_OBJS += $(OUTPUT)ui/gtk/browser.o
LIB_OBJS += $(OUTPUT)ui/gtk/setup.o
# Make sure that it'd be included only once.
ifneq ($(findstring -DNO_NEWT_SUPPORT,$(BASIC_CFLAGS)),)
LIB_OBJS += $(OUTPUT)ui/setup.o
endif
endif
endif

Expand Down
10 changes: 3 additions & 7 deletions tools/perf/builtin-report.c
Original file line number Diff line number Diff line change
Expand Up @@ -676,14 +676,10 @@ int cmd_report(int argc, const char **argv, const char *prefix __used)

}

if (strcmp(report.input_name, "-") != 0) {
if (report.use_gtk)
perf_gtk__setup_browser(true);
else
setup_browser(true);
} else {
if (strcmp(report.input_name, "-") != 0)
setup_browser(true);
else
use_browser = 0;
}

/*
* Only in the newt browser we are doing integrated annotation,
Expand Down
10 changes: 0 additions & 10 deletions tools/perf/ui/gtk/browser.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,6 @@

#define MAX_COLUMNS 32

void perf_gtk__setup_browser(bool fallback_to_pager __used)
{
gtk_init(NULL, NULL);
}

void perf_gtk__exit_browser(bool wait_for_ok __used)
{
gtk_main_quit();
}

static void perf_gtk__signal(int sig)
{
psignal(sig, "perf");
Expand Down
12 changes: 12 additions & 0 deletions tools/perf/ui/gtk/setup.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include "gtk.h"
#include "../../util/cache.h"

void perf_gtk__init(bool fallback_to_pager __used)
{
gtk_init(NULL, NULL);
}

void perf_gtk__exit(bool wait_for_ok __used)
{
gtk_main_quit();
}
169 changes: 26 additions & 143 deletions tools/perf/ui/setup.c
Original file line number Diff line number Diff line change
@@ -1,161 +1,44 @@
#include <newt.h>
#include <signal.h>
#include <stdbool.h>

#include "../cache.h"
#include "../debug.h"
#include "browser.h"
#include "helpline.h"
#include "ui.h"
#include "util.h"
#include "libslang.h"
#include "keysyms.h"

pthread_mutex_t ui__lock = PTHREAD_MUTEX_INITIALIZER;

static volatile int ui__need_resize;

void ui__refresh_dimensions(bool force)
{
if (force || ui__need_resize) {
ui__need_resize = 0;
pthread_mutex_lock(&ui__lock);
SLtt_get_screen_size();
SLsmg_reinit_smg();
pthread_mutex_unlock(&ui__lock);
}
}

static void ui__sigwinch(int sig __used)
{
ui__need_resize = 1;
}

static void ui__setup_sigwinch(void)
{
static bool done;

if (done)
return;

done = true;
pthread__unblock_sigwinch();
signal(SIGWINCH, ui__sigwinch);
}

int ui__getch(int delay_secs)
{
struct timeval timeout, *ptimeout = delay_secs ? &timeout : NULL;
fd_set read_set;
int err, key;

ui__setup_sigwinch();

FD_ZERO(&read_set);
FD_SET(0, &read_set);

if (delay_secs) {
timeout.tv_sec = delay_secs;
timeout.tv_usec = 0;
}

err = select(1, &read_set, NULL, NULL, ptimeout);

if (err == 0)
return K_TIMER;

if (err == -1) {
if (errno == EINTR)
return K_RESIZE;
return K_ERROR;
}

key = SLang_getkey();
if (key != K_ESC)
return key;

FD_ZERO(&read_set);
FD_SET(0, &read_set);
timeout.tv_sec = 0;
timeout.tv_usec = 20;
err = select(1, &read_set, NULL, NULL, &timeout);
if (err == 0)
return K_ESC;

SLang_ungetkey(key);
return SLkp_getkey();
}

static void newt_suspend(void *d __used)
{
newtSuspend();
raise(SIGTSTP);
newtResume();
}

static void ui__exit(void);

static void ui__signal(int sig)
{
ui__exit();
psignal(sig, "perf");
exit(0);
}

static int ui__init(void)
void setup_browser(bool fallback_to_pager)
{
int err;

newtInit();
err = SLkp_init();
if (err < 0) {
pr_err("TUI initialization failed.\n");
goto out;
}

SLkp_define_keysym((char *)"^(kB)", SL_KEY_UNTAB);
if (!isatty(1) || dump_trace)
use_browser = 0;

newtSetSuspendCallback(newt_suspend, NULL);
ui_helpline__init();
ui_browser__init();
/* default to TUI */
if (use_browser < 0)
use_browser = 1;

signal(SIGSEGV, ui__signal);
signal(SIGFPE, ui__signal);
signal(SIGINT, ui__signal);
signal(SIGQUIT, ui__signal);
signal(SIGTERM, ui__signal);
out:
return err;
}
switch (use_browser) {
case 2:
perf_gtk__init(fallback_to_pager);
break;

static void ui__exit(void)
{
SLtt_set_cursor_visibility(1);
SLsmg_refresh();
SLsmg_reset_smg();
SLang_reset_tty();
}
case 1:
ui__init(fallback_to_pager);
break;

void setup_browser(bool fallback_to_pager)
{
if (!isatty(1) || !use_browser || dump_trace) {
use_browser = 0;
default:
if (fallback_to_pager)
setup_pager();
return;
break;
}

use_browser = 1;
ui__init();
}

void exit_browser(bool wait_for_ok)
{
if (use_browser > 0) {
if (wait_for_ok)
ui__question_window("Fatal Error",
ui_helpline__last_msg,
"Press any key...", 0);
ui__exit();
switch (use_browser) {
case 2:
perf_gtk__exit(wait_for_ok);
break;

case 1:
ui__exit(wait_for_ok);
break;

default:
break;
}
}
140 changes: 140 additions & 0 deletions tools/perf/ui/tui/setup.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
#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"

pthread_mutex_t ui__lock = PTHREAD_MUTEX_INITIALIZER;

static volatile int ui__need_resize;

void ui__refresh_dimensions(bool force)
{
if (force || ui__need_resize) {
ui__need_resize = 0;
pthread_mutex_lock(&ui__lock);
SLtt_get_screen_size();
SLsmg_reinit_smg();
pthread_mutex_unlock(&ui__lock);
}
}

static void ui__sigwinch(int sig __used)
{
ui__need_resize = 1;
}

static void ui__setup_sigwinch(void)
{
static bool done;

if (done)
return;

done = true;
pthread__unblock_sigwinch();
signal(SIGWINCH, ui__sigwinch);
}

int ui__getch(int delay_secs)
{
struct timeval timeout, *ptimeout = delay_secs ? &timeout : NULL;
fd_set read_set;
int err, key;

ui__setup_sigwinch();

FD_ZERO(&read_set);
FD_SET(0, &read_set);

if (delay_secs) {
timeout.tv_sec = delay_secs;
timeout.tv_usec = 0;
}

err = select(1, &read_set, NULL, NULL, ptimeout);

if (err == 0)
return K_TIMER;

if (err == -1) {
if (errno == EINTR)
return K_RESIZE;
return K_ERROR;
}

key = SLang_getkey();
if (key != K_ESC)
return key;

FD_ZERO(&read_set);
FD_SET(0, &read_set);
timeout.tv_sec = 0;
timeout.tv_usec = 20;
err = select(1, &read_set, NULL, NULL, &timeout);
if (err == 0)
return K_ESC;

SLang_ungetkey(key);
return SLkp_getkey();
}

static void newt_suspend(void *d __used)
{
newtSuspend();
raise(SIGTSTP);
newtResume();
}

static void ui__signal(int sig)
{
ui__exit(false);
psignal(sig, "perf");
exit(0);
}

int ui__init(bool fallback_to_pager __used)
{
int err;

newtInit();
err = SLkp_init();
if (err < 0) {
pr_err("TUI initialization failed.\n");
goto out;
}

SLkp_define_keysym((char *)"^(kB)", SL_KEY_UNTAB);

newtSetSuspendCallback(newt_suspend, NULL);
ui_helpline__init();
ui_browser__init();

signal(SIGSEGV, ui__signal);
signal(SIGFPE, ui__signal);
signal(SIGINT, ui__signal);
signal(SIGQUIT, ui__signal);
signal(SIGTERM, ui__signal);
out:
return err;
}

void ui__exit(bool wait_for_ok)
{
if (wait_for_ok)
ui__question_window("Fatal Error",
ui_helpline__last_msg,
"Press any key...", 0);

SLtt_set_cursor_visibility(1);
SLsmg_refresh();
SLsmg_reset_smg();
SLang_reset_tty();
}
Loading

0 comments on commit 281ef54

Please sign in to comment.