Skip to content

Commit

Permalink
perf ui: Complete the breakdown of util/newt.c
Browse files Browse the repository at this point in the history
LKML-Reference: <new-submission>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
  • Loading branch information
Arnaldo Carvalho de Melo committed Aug 10, 2010
1 parent d1b4f24 commit 1e6dd07
Show file tree
Hide file tree
Showing 10 changed files with 96 additions and 78 deletions.
7 changes: 3 additions & 4 deletions tools/perf/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -567,18 +567,20 @@ else
# Fedora has /usr/include/slang/slang.h, but ubuntu /usr/include/slang.h
BASIC_CFLAGS += -I/usr/include/slang
EXTLIBS += -lnewt -lslang
LIB_OBJS += $(OUTPUT)util/newt.o
LIB_OBJS += $(OUTPUT)util/ui/setup.o
LIB_OBJS += $(OUTPUT)util/ui/browser.o
LIB_OBJS += $(OUTPUT)util/ui/browsers/annotate.o
LIB_OBJS += $(OUTPUT)util/ui/browsers/hists.o
LIB_OBJS += $(OUTPUT)util/ui/browsers/map.o
LIB_OBJS += $(OUTPUT)util/ui/helpline.o
LIB_OBJS += $(OUTPUT)util/ui/progress.o
LIB_OBJS += $(OUTPUT)util/ui/util.o
LIB_H += util/ui/browser.h
LIB_H += util/ui/browsers/map.h
LIB_H += util/ui/helpline.h
LIB_H += util/ui/libslang.h
LIB_H += util/ui/progress.h
LIB_H += util/ui/util.h
endif
endif

Expand Down Expand Up @@ -976,9 +978,6 @@ $(OUTPUT)builtin-init-db.o: builtin-init-db.c $(OUTPUT)PERF-CFLAGS
$(OUTPUT)util/config.o: util/config.c $(OUTPUT)PERF-CFLAGS
$(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) -DETC_PERFCONFIG='"$(ETC_PERFCONFIG_SQ)"' $<

$(OUTPUT)util/newt.o: util/newt.c $(OUTPUT)PERF-CFLAGS
$(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) -DENABLE_SLFUTURE_CONST $<

$(OUTPUT)util/ui/browser.o: util/ui/browser.c $(OUTPUT)PERF-CFLAGS
$(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) -DENABLE_SLFUTURE_CONST $<

Expand Down
2 changes: 1 addition & 1 deletion tools/perf/util/debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ int eprintf(int level, const char *fmt, ...)
if (verbose >= level) {
va_start(args, fmt);
if (use_browser > 0)
ret = browser__show_help(fmt, args);
ret = ui_helpline__show_help(fmt, args);
else
ret = vfprintf(stderr, fmt, args);
va_end(args);
Expand Down
6 changes: 3 additions & 3 deletions tools/perf/util/debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ void trace_event(event_t *event);
struct ui_progress;

#ifdef NO_NEWT_SUPPORT
static inline int browser__show_help(const char *format __used, va_list ap __used)
static inline int ui_helpline__show_help(const char *format __used, va_list ap __used)
{
return 0;
}
Expand All @@ -30,8 +30,8 @@ static inline void ui_progress__update(struct ui_progress *self __used,

static inline void ui_progress__delete(struct ui_progress *self __used) {}
#else
extern char browser__last_msg[];
int browser__show_help(const char *format, va_list ap);
extern char ui_helpline__last_msg[];
int ui_helpline__show_help(const char *format, va_list ap);
#include "ui/progress.h"
#endif

Expand Down
2 changes: 1 addition & 1 deletion tools/perf/util/ui/browsers/annotate.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ int hist_entry__tui_annotate(struct hist_entry *self)
return -1;

if (hist_entry__annotate(self, &head) < 0) {
ui__error_window(browser__last_msg);
ui__error_window(ui_helpline__last_msg);
return -1;
}

Expand Down
8 changes: 2 additions & 6 deletions tools/perf/util/ui/browsers/hists.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@
#include "../util.h"
#include "map.h"

int ui__help_window(const char *text);
bool dialog_yesno(const char *msg);
int popup_menu(int argc, char * const argv[]);

struct hist_browser {
struct ui_browser b;
struct hists *hists;
Expand Down Expand Up @@ -798,7 +794,7 @@ int hists__browse(struct hists *self, const char *helpline, const char *ev_name)
}
if (is_exit_key(key)) {
if (key == NEWT_KEY_ESCAPE &&
!dialog_yesno("Do you really want to exit?"))
!ui__dialog_yesno("Do you really want to exit?"))
continue;
break;
}
Expand Down Expand Up @@ -842,7 +838,7 @@ int hists__browse(struct hists *self, const char *helpline, const char *ev_name)

options[nr_options++] = (char *)"Exit";

choice = popup_menu(nr_options, options);
choice = ui__popup_menu(nr_options, options);

for (i = 0; i < nr_options - 1; ++i)
free(options[i]);
Expand Down
26 changes: 26 additions & 0 deletions tools/perf/util/ui/helpline.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <stdlib.h>
#include <newt.h>

#include "../debug.h"
#include "helpline.h"

void ui_helpline__pop(void)
Expand Down Expand Up @@ -41,3 +42,28 @@ 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;

ret = vsnprintf(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);
newtRefresh();
backlog = 0;
}

return ret;
}
1 change: 1 addition & 0 deletions tools/perf/util/ui/helpline.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#ifndef _PERF_UI_HELPLINE_H_
#define _PERF_UI_HELPLINE_H_ 1

void ui_helpline__init(void);
void ui_helpline__pop(void);
void ui_helpline__push(const char *msg);
void ui_helpline__fpush(const char *fmt, ...);
Expand Down
42 changes: 42 additions & 0 deletions tools/perf/util/ui/setup.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#include <newt.h>
#include <signal.h>
#include <stdbool.h>

#include "../cache.h"
#include "../debug.h"
#include "browser.h"
#include "helpline.h"

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

void setup_browser(void)
{
if (!isatty(1) || !use_browser || dump_trace) {
use_browser = 0;
setup_pager();
return;
}

use_browser = 1;
newtInit();
newtCls();
newtSetSuspendCallback(newt_suspend, NULL);
ui_helpline__init();
ui_browser__init();
}

void exit_browser(bool wait_for_ok)
{
if (use_browser > 0) {
if (wait_for_ok) {
char title[] = "Fatal Error", ok[] = "Ok";
newtWinMessage(title, ok, ui_helpline__last_msg);
}
newtFinished();
}
}
70 changes: 7 additions & 63 deletions tools/perf/util/newt.c → tools/perf/util/ui/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,35 +5,13 @@
#include <string.h>
#include <sys/ttydefaults.h>

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

newtComponent newt_form__new(void);
int popup_menu(int argc, char * const argv[]);
int ui__help_window(const char *text);
bool dialog_yesno(const char *msg);

char browser__last_msg[1024];

int browser__show_help(const char *format, va_list ap)
{
int ret;
static int backlog;

ret = vsnprintf(browser__last_msg + backlog,
sizeof(browser__last_msg) - backlog, format, ap);
backlog += ret;

if (browser__last_msg[backlog - 1] == '\n') {
ui_helpline__puts(browser__last_msg);
newtRefresh();
backlog = 0;
}

return ret;
}

static void newt_form__set_exit_keys(newtComponent self)
{
Expand All @@ -52,7 +30,7 @@ newtComponent newt_form__new(void)
return self;
}

int popup_menu(int argc, char * const argv[])
int ui__popup_menu(int argc, char * const argv[])
{
struct newtExitStruct es;
int i, rc = -1, max_len = 5;
Expand Down Expand Up @@ -128,43 +106,9 @@ int ui__help_window(const char *text)
return rc;
}

bool dialog_yesno(const char *msg)
bool ui__dialog_yesno(const char *msg)
{
/* newtWinChoice should really be accepting const char pointers... */
char yes[] = "Yes", no[] = "No";
return newtWinChoice(NULL, yes, no, (char *)msg) == 1;
}

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

void setup_browser(void)
{
if (!isatty(1) || !use_browser || dump_trace) {
use_browser = 0;
setup_pager();
return;
}

use_browser = 1;
newtInit();
newtCls();
newtSetSuspendCallback(newt_suspend, NULL);
ui_helpline__puts(" ");
ui_browser__init();
}

void exit_browser(bool wait_for_ok)
{
if (use_browser > 0) {
if (wait_for_ok) {
char title[] = "Fatal Error", ok[] = "Ok";
newtWinMessage(title, ok, browser__last_msg);
}
newtFinished();
}
}
10 changes: 10 additions & 0 deletions tools/perf/util/ui/util.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#ifndef _PERF_UI_UTIL_H_
#define _PERF_UI_UTIL_H_ 1

#include <stdbool.h>

int ui__popup_menu(int argc, char * const argv[]);
int ui__help_window(const char *text);
bool ui__dialog_yesno(const char *msg);

#endif /* _PERF_UI_UTIL_H_ */

0 comments on commit 1e6dd07

Please sign in to comment.