aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf
diff options
context:
space:
mode:
authorArnaldo Carvalho de Melo <acme@redhat.com>2010-08-10 14:58:50 -0400
committerArnaldo Carvalho de Melo <acme@redhat.com>2010-08-10 15:11:38 -0400
commit1e6dd077a880ba5570beb690523b7a78a91a7615 (patch)
tree979b2006c8c1b93dfe1f4e2152af5c5c4c7c6531 /tools/perf
parentd1b4f2491c3341c61c752049f73ba12553f978d8 (diff)
perf ui: Complete the breakdown of util/newt.c
LKML-Reference: <new-submission> Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf')
-rw-r--r--tools/perf/Makefile7
-rw-r--r--tools/perf/util/debug.c2
-rw-r--r--tools/perf/util/debug.h6
-rw-r--r--tools/perf/util/ui/browsers/annotate.c2
-rw-r--r--tools/perf/util/ui/browsers/hists.c8
-rw-r--r--tools/perf/util/ui/helpline.c26
-rw-r--r--tools/perf/util/ui/helpline.h1
-rw-r--r--tools/perf/util/ui/setup.c42
-rw-r--r--tools/perf/util/ui/util.c (renamed from tools/perf/util/newt.c)70
-rw-r--r--tools/perf/util/ui/util.h10
10 files changed, 96 insertions, 78 deletions
diff --git a/tools/perf/Makefile b/tools/perf/Makefile
index 62e4d6f0dc85..41abb90df50d 100644
--- a/tools/perf/Makefile
+++ b/tools/perf/Makefile
@@ -567,18 +567,20 @@ else
567 # Fedora has /usr/include/slang/slang.h, but ubuntu /usr/include/slang.h 567 # Fedora has /usr/include/slang/slang.h, but ubuntu /usr/include/slang.h
568 BASIC_CFLAGS += -I/usr/include/slang 568 BASIC_CFLAGS += -I/usr/include/slang
569 EXTLIBS += -lnewt -lslang 569 EXTLIBS += -lnewt -lslang
570 LIB_OBJS += $(OUTPUT)util/newt.o 570 LIB_OBJS += $(OUTPUT)util/ui/setup.o
571 LIB_OBJS += $(OUTPUT)util/ui/browser.o 571 LIB_OBJS += $(OUTPUT)util/ui/browser.o
572 LIB_OBJS += $(OUTPUT)util/ui/browsers/annotate.o 572 LIB_OBJS += $(OUTPUT)util/ui/browsers/annotate.o
573 LIB_OBJS += $(OUTPUT)util/ui/browsers/hists.o 573 LIB_OBJS += $(OUTPUT)util/ui/browsers/hists.o
574 LIB_OBJS += $(OUTPUT)util/ui/browsers/map.o 574 LIB_OBJS += $(OUTPUT)util/ui/browsers/map.o
575 LIB_OBJS += $(OUTPUT)util/ui/helpline.o 575 LIB_OBJS += $(OUTPUT)util/ui/helpline.o
576 LIB_OBJS += $(OUTPUT)util/ui/progress.o 576 LIB_OBJS += $(OUTPUT)util/ui/progress.o
577 LIB_OBJS += $(OUTPUT)util/ui/util.o
577 LIB_H += util/ui/browser.h 578 LIB_H += util/ui/browser.h
578 LIB_H += util/ui/browsers/map.h 579 LIB_H += util/ui/browsers/map.h
579 LIB_H += util/ui/helpline.h 580 LIB_H += util/ui/helpline.h
580 LIB_H += util/ui/libslang.h 581 LIB_H += util/ui/libslang.h
581 LIB_H += util/ui/progress.h 582 LIB_H += util/ui/progress.h
583 LIB_H += util/ui/util.h
582 endif 584 endif
583endif 585endif
584 586
@@ -976,9 +978,6 @@ $(OUTPUT)builtin-init-db.o: builtin-init-db.c $(OUTPUT)PERF-CFLAGS
976$(OUTPUT)util/config.o: util/config.c $(OUTPUT)PERF-CFLAGS 978$(OUTPUT)util/config.o: util/config.c $(OUTPUT)PERF-CFLAGS
977 $(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) -DETC_PERFCONFIG='"$(ETC_PERFCONFIG_SQ)"' $< 979 $(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) -DETC_PERFCONFIG='"$(ETC_PERFCONFIG_SQ)"' $<
978 980
979$(OUTPUT)util/newt.o: util/newt.c $(OUTPUT)PERF-CFLAGS
980 $(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) -DENABLE_SLFUTURE_CONST $<
981
982$(OUTPUT)util/ui/browser.o: util/ui/browser.c $(OUTPUT)PERF-CFLAGS 981$(OUTPUT)util/ui/browser.o: util/ui/browser.c $(OUTPUT)PERF-CFLAGS
983 $(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) -DENABLE_SLFUTURE_CONST $< 982 $(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) -DENABLE_SLFUTURE_CONST $<
984 983
diff --git a/tools/perf/util/debug.c b/tools/perf/util/debug.c
index 318dab15d177..f9c7e3ad1aa7 100644
--- a/tools/perf/util/debug.c
+++ b/tools/perf/util/debug.c
@@ -23,7 +23,7 @@ int eprintf(int level, const char *fmt, ...)
23 if (verbose >= level) { 23 if (verbose >= level) {
24 va_start(args, fmt); 24 va_start(args, fmt);
25 if (use_browser > 0) 25 if (use_browser > 0)
26 ret = browser__show_help(fmt, args); 26 ret = ui_helpline__show_help(fmt, args);
27 else 27 else
28 ret = vfprintf(stderr, fmt, args); 28 ret = vfprintf(stderr, fmt, args);
29 va_end(args); 29 va_end(args);
diff --git a/tools/perf/util/debug.h b/tools/perf/util/debug.h
index ba4892e49be2..7a17ee061bcb 100644
--- a/tools/perf/util/debug.h
+++ b/tools/perf/util/debug.h
@@ -14,7 +14,7 @@ void trace_event(event_t *event);
14struct ui_progress; 14struct ui_progress;
15 15
16#ifdef NO_NEWT_SUPPORT 16#ifdef NO_NEWT_SUPPORT
17static inline int browser__show_help(const char *format __used, va_list ap __used) 17static inline int ui_helpline__show_help(const char *format __used, va_list ap __used)
18{ 18{
19 return 0; 19 return 0;
20} 20}
@@ -30,8 +30,8 @@ static inline void ui_progress__update(struct ui_progress *self __used,
30 30
31static inline void ui_progress__delete(struct ui_progress *self __used) {} 31static inline void ui_progress__delete(struct ui_progress *self __used) {}
32#else 32#else
33extern char browser__last_msg[]; 33extern char ui_helpline__last_msg[];
34int browser__show_help(const char *format, va_list ap); 34int ui_helpline__show_help(const char *format, va_list ap);
35#include "ui/progress.h" 35#include "ui/progress.h"
36#endif 36#endif
37 37
diff --git a/tools/perf/util/ui/browsers/annotate.c b/tools/perf/util/ui/browsers/annotate.c
index 783d277f2190..5b01df633f9a 100644
--- a/tools/perf/util/ui/browsers/annotate.c
+++ b/tools/perf/util/ui/browsers/annotate.c
@@ -86,7 +86,7 @@ int hist_entry__tui_annotate(struct hist_entry *self)
86 return -1; 86 return -1;
87 87
88 if (hist_entry__annotate(self, &head) < 0) { 88 if (hist_entry__annotate(self, &head) < 0) {
89 ui__error_window(browser__last_msg); 89 ui__error_window(ui_helpline__last_msg);
90 return -1; 90 return -1;
91 } 91 }
92 92
diff --git a/tools/perf/util/ui/browsers/hists.c b/tools/perf/util/ui/browsers/hists.c
index 9d32a4149ab3..cee7998f1c33 100644
--- a/tools/perf/util/ui/browsers/hists.c
+++ b/tools/perf/util/ui/browsers/hists.c
@@ -17,10 +17,6 @@
17#include "../util.h" 17#include "../util.h"
18#include "map.h" 18#include "map.h"
19 19
20int ui__help_window(const char *text);
21bool dialog_yesno(const char *msg);
22int popup_menu(int argc, char * const argv[]);
23
24struct hist_browser { 20struct hist_browser {
25 struct ui_browser b; 21 struct ui_browser b;
26 struct hists *hists; 22 struct hists *hists;
@@ -798,7 +794,7 @@ do_help:
798 } 794 }
799 if (is_exit_key(key)) { 795 if (is_exit_key(key)) {
800 if (key == NEWT_KEY_ESCAPE && 796 if (key == NEWT_KEY_ESCAPE &&
801 !dialog_yesno("Do you really want to exit?")) 797 !ui__dialog_yesno("Do you really want to exit?"))
802 continue; 798 continue;
803 break; 799 break;
804 } 800 }
@@ -842,7 +838,7 @@ do_help:
842 838
843 options[nr_options++] = (char *)"Exit"; 839 options[nr_options++] = (char *)"Exit";
844 840
845 choice = popup_menu(nr_options, options); 841 choice = ui__popup_menu(nr_options, options);
846 842
847 for (i = 0; i < nr_options - 1; ++i) 843 for (i = 0; i < nr_options - 1; ++i)
848 free(options[i]); 844 free(options[i]);
diff --git a/tools/perf/util/ui/helpline.c b/tools/perf/util/ui/helpline.c
index 6a11e1301559..ff584606a4dc 100644
--- a/tools/perf/util/ui/helpline.c
+++ b/tools/perf/util/ui/helpline.c
@@ -3,6 +3,7 @@
3#include <stdlib.h> 3#include <stdlib.h>
4#include <newt.h> 4#include <newt.h>
5 5
6#include "../debug.h"
6#include "helpline.h" 7#include "helpline.h"
7 8
8void ui_helpline__pop(void) 9void ui_helpline__pop(void)
@@ -41,3 +42,28 @@ void ui_helpline__puts(const char *msg)
41 ui_helpline__pop(); 42 ui_helpline__pop();
42 ui_helpline__push(msg); 43 ui_helpline__push(msg);
43} 44}
45
46void ui_helpline__init(void)
47{
48 ui_helpline__puts(" ");
49}
50
51char ui_helpline__last_msg[1024];
52
53int ui_helpline__show_help(const char *format, va_list ap)
54{
55 int ret;
56 static int backlog;
57
58 ret = vsnprintf(ui_helpline__last_msg + backlog,
59 sizeof(ui_helpline__last_msg) - backlog, format, ap);
60 backlog += ret;
61
62 if (ui_helpline__last_msg[backlog - 1] == '\n') {
63 ui_helpline__puts(ui_helpline__last_msg);
64 newtRefresh();
65 backlog = 0;
66 }
67
68 return ret;
69}
diff --git a/tools/perf/util/ui/helpline.h b/tools/perf/util/ui/helpline.h
index 56d8c1d8ffc8..5d1e5e72ffb5 100644
--- a/tools/perf/util/ui/helpline.h
+++ b/tools/perf/util/ui/helpline.h
@@ -1,6 +1,7 @@
1#ifndef _PERF_UI_HELPLINE_H_ 1#ifndef _PERF_UI_HELPLINE_H_
2#define _PERF_UI_HELPLINE_H_ 1 2#define _PERF_UI_HELPLINE_H_ 1
3 3
4void ui_helpline__init(void);
4void ui_helpline__pop(void); 5void ui_helpline__pop(void);
5void ui_helpline__push(const char *msg); 6void ui_helpline__push(const char *msg);
6void ui_helpline__fpush(const char *fmt, ...); 7void ui_helpline__fpush(const char *fmt, ...);
diff --git a/tools/perf/util/ui/setup.c b/tools/perf/util/ui/setup.c
new file mode 100644
index 000000000000..662085032eb7
--- /dev/null
+++ b/tools/perf/util/ui/setup.c
@@ -0,0 +1,42 @@
1#include <newt.h>
2#include <signal.h>
3#include <stdbool.h>
4
5#include "../cache.h"
6#include "../debug.h"
7#include "browser.h"
8#include "helpline.h"
9
10static void newt_suspend(void *d __used)
11{
12 newtSuspend();
13 raise(SIGTSTP);
14 newtResume();
15}
16
17void setup_browser(void)
18{
19 if (!isatty(1) || !use_browser || dump_trace) {
20 use_browser = 0;
21 setup_pager();
22 return;
23 }
24
25 use_browser = 1;
26 newtInit();
27 newtCls();
28 newtSetSuspendCallback(newt_suspend, NULL);
29 ui_helpline__init();
30 ui_browser__init();
31}
32
33void exit_browser(bool wait_for_ok)
34{
35 if (use_browser > 0) {
36 if (wait_for_ok) {
37 char title[] = "Fatal Error", ok[] = "Ok";
38 newtWinMessage(title, ok, ui_helpline__last_msg);
39 }
40 newtFinished();
41 }
42}
diff --git a/tools/perf/util/newt.c b/tools/perf/util/ui/util.c
index 6bccdaa159aa..04600e26ceea 100644
--- a/tools/perf/util/newt.c
+++ b/tools/perf/util/ui/util.c
@@ -5,35 +5,13 @@
5#include <string.h> 5#include <string.h>
6#include <sys/ttydefaults.h> 6#include <sys/ttydefaults.h>
7 7
8#include "cache.h" 8#include "../cache.h"
9#include "debug.h" 9#include "../debug.h"
10#include "ui/browser.h" 10#include "browser.h"
11#include "ui/helpline.h" 11#include "helpline.h"
12#include "util.h"
12 13
13newtComponent newt_form__new(void); 14newtComponent newt_form__new(void);
14int popup_menu(int argc, char * const argv[]);
15int ui__help_window(const char *text);
16bool dialog_yesno(const char *msg);
17
18char browser__last_msg[1024];
19
20int browser__show_help(const char *format, va_list ap)
21{
22 int ret;
23 static int backlog;
24
25 ret = vsnprintf(browser__last_msg + backlog,
26 sizeof(browser__last_msg) - backlog, format, ap);
27 backlog += ret;
28
29 if (browser__last_msg[backlog - 1] == '\n') {
30 ui_helpline__puts(browser__last_msg);
31 newtRefresh();
32 backlog = 0;
33 }
34
35 return ret;
36}
37 15
38static void newt_form__set_exit_keys(newtComponent self) 16static void newt_form__set_exit_keys(newtComponent self)
39{ 17{
@@ -52,7 +30,7 @@ newtComponent newt_form__new(void)
52 return self; 30 return self;
53} 31}
54 32
55int popup_menu(int argc, char * const argv[]) 33int ui__popup_menu(int argc, char * const argv[])
56{ 34{
57 struct newtExitStruct es; 35 struct newtExitStruct es;
58 int i, rc = -1, max_len = 5; 36 int i, rc = -1, max_len = 5;
@@ -128,43 +106,9 @@ out_destroy_form:
128 return rc; 106 return rc;
129} 107}
130 108
131bool dialog_yesno(const char *msg) 109bool ui__dialog_yesno(const char *msg)
132{ 110{
133 /* newtWinChoice should really be accepting const char pointers... */ 111 /* newtWinChoice should really be accepting const char pointers... */
134 char yes[] = "Yes", no[] = "No"; 112 char yes[] = "Yes", no[] = "No";
135 return newtWinChoice(NULL, yes, no, (char *)msg) == 1; 113 return newtWinChoice(NULL, yes, no, (char *)msg) == 1;
136} 114}
137
138static void newt_suspend(void *d __used)
139{
140 newtSuspend();
141 raise(SIGTSTP);
142 newtResume();
143}
144
145void setup_browser(void)
146{
147 if (!isatty(1) || !use_browser || dump_trace) {
148 use_browser = 0;
149 setup_pager();
150 return;
151 }
152
153 use_browser = 1;
154 newtInit();
155 newtCls();
156 newtSetSuspendCallback(newt_suspend, NULL);
157 ui_helpline__puts(" ");
158 ui_browser__init();
159}
160
161void exit_browser(bool wait_for_ok)
162{
163 if (use_browser > 0) {
164 if (wait_for_ok) {
165 char title[] = "Fatal Error", ok[] = "Ok";
166 newtWinMessage(title, ok, browser__last_msg);
167 }
168 newtFinished();
169 }
170}
diff --git a/tools/perf/util/ui/util.h b/tools/perf/util/ui/util.h
new file mode 100644
index 000000000000..afcbc1d99531
--- /dev/null
+++ b/tools/perf/util/ui/util.h
@@ -0,0 +1,10 @@
1#ifndef _PERF_UI_UTIL_H_
2#define _PERF_UI_UTIL_H_ 1
3
4#include <stdbool.h>
5
6int ui__popup_menu(int argc, char * const argv[]);
7int ui__help_window(const char *text);
8bool ui__dialog_yesno(const char *msg);
9
10#endif /* _PERF_UI_UTIL_H_ */