aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorArnaldo Carvalho de Melo <acme@redhat.com>2010-08-08 18:56:47 -0400
committerArnaldo Carvalho de Melo <acme@redhat.com>2010-08-10 15:09:14 -0400
commit34cea7f7c0620c964676eece258ef431a6608bce (patch)
tree48b85557823fc63939dad71cb14d6c75b96a11b9 /tools
parent5575536fc7ad7577a4e687a13e2f49acebc519f3 (diff)
perf ui: Move ui_progress routines to separate file in util/ui/
LKML-Reference: <new-submission> Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools')
-rw-r--r--tools/perf/Makefile2
-rw-r--r--tools/perf/util/debug.h4
-rw-r--r--tools/perf/util/newt.c56
-rw-r--r--tools/perf/util/ui/progress.c60
-rw-r--r--tools/perf/util/ui/progress.h11
5 files changed, 74 insertions, 59 deletions
diff --git a/tools/perf/Makefile b/tools/perf/Makefile
index d77a101ab7dd..528c91469c0d 100644
--- a/tools/perf/Makefile
+++ b/tools/perf/Makefile
@@ -570,8 +570,10 @@ else
570 LIB_OBJS += $(OUTPUT)util/newt.o 570 LIB_OBJS += $(OUTPUT)util/newt.o
571 LIB_OBJS += $(OUTPUT)util/ui/browser.o 571 LIB_OBJS += $(OUTPUT)util/ui/browser.o
572 LIB_OBJS += $(OUTPUT)util/ui/helpline.o 572 LIB_OBJS += $(OUTPUT)util/ui/helpline.o
573 LIB_OBJS += $(OUTPUT)util/ui/progress.o
573 LIB_H += util/ui/browser.h 574 LIB_H += util/ui/browser.h
574 LIB_H += util/ui/helpline.h 575 LIB_H += util/ui/helpline.h
576 LIB_H += util/ui/progress.h
575 endif 577 endif
576endif 578endif
577 579
diff --git a/tools/perf/util/debug.h b/tools/perf/util/debug.h
index 047ac3324ebe..a929b06cfc0a 100644
--- a/tools/perf/util/debug.h
+++ b/tools/perf/util/debug.h
@@ -31,9 +31,7 @@ static inline void ui_progress__update(struct ui_progress *self __used,
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
33int browser__show_help(const char *format, va_list ap); 33int browser__show_help(const char *format, va_list ap);
34struct ui_progress *ui_progress__new(const char *title, u64 total); 34#include "ui/progress.h"
35void ui_progress__update(struct ui_progress *self, u64 curr);
36void ui_progress__delete(struct ui_progress *self);
37#endif 35#endif
38 36
39#endif /* __PERF_DEBUG_H */ 37#endif /* __PERF_DEBUG_H */
diff --git a/tools/perf/util/newt.c b/tools/perf/util/newt.c
index 23f3b7d31bff..c0986d342954 100644
--- a/tools/perf/util/newt.c
+++ b/tools/perf/util/newt.c
@@ -39,62 +39,6 @@
39 39
40newtComponent newt_form__new(void); 40newtComponent newt_form__new(void);
41 41
42struct ui_progress {
43 newtComponent form, scale;
44};
45
46struct ui_progress *ui_progress__new(const char *title, u64 total)
47{
48 struct ui_progress *self = malloc(sizeof(*self));
49
50 if (self != NULL) {
51 int cols;
52
53 if (use_browser <= 0)
54 return self;
55 newtGetScreenSize(&cols, NULL);
56 cols -= 4;
57 newtCenteredWindow(cols, 1, title);
58 self->form = newtForm(NULL, NULL, 0);
59 if (self->form == NULL)
60 goto out_free_self;
61 self->scale = newtScale(0, 0, cols, total);
62 if (self->scale == NULL)
63 goto out_free_form;
64 newtFormAddComponent(self->form, self->scale);
65 newtRefresh();
66 }
67
68 return self;
69
70out_free_form:
71 newtFormDestroy(self->form);
72out_free_self:
73 free(self);
74 return NULL;
75}
76
77void ui_progress__update(struct ui_progress *self, u64 curr)
78{
79 /*
80 * FIXME: We should have a per UI backend way of showing progress,
81 * stdio will just show a percentage as NN%, etc.
82 */
83 if (use_browser <= 0)
84 return;
85 newtScaleSet(self->scale, curr);
86 newtRefresh();
87}
88
89void ui_progress__delete(struct ui_progress *self)
90{
91 if (use_browser > 0) {
92 newtFormDestroy(self->form);
93 newtPopWindow();
94 }
95 free(self);
96}
97
98static int ui_entry__read(const char *title, char *bf, size_t size, int width) 42static int ui_entry__read(const char *title, char *bf, size_t size, int width)
99{ 43{
100 struct newtExitStruct es; 44 struct newtExitStruct es;
diff --git a/tools/perf/util/ui/progress.c b/tools/perf/util/ui/progress.c
new file mode 100644
index 000000000000..d7fc399d36b3
--- /dev/null
+++ b/tools/perf/util/ui/progress.c
@@ -0,0 +1,60 @@
1#include <stdlib.h>
2#include <newt.h>
3#include "../cache.h"
4#include "progress.h"
5
6struct ui_progress {
7 newtComponent form, scale;
8};
9
10struct ui_progress *ui_progress__new(const char *title, u64 total)
11{
12 struct ui_progress *self = malloc(sizeof(*self));
13
14 if (self != NULL) {
15 int cols;
16
17 if (use_browser <= 0)
18 return self;
19 newtGetScreenSize(&cols, NULL);
20 cols -= 4;
21 newtCenteredWindow(cols, 1, title);
22 self->form = newtForm(NULL, NULL, 0);
23 if (self->form == NULL)
24 goto out_free_self;
25 self->scale = newtScale(0, 0, cols, total);
26 if (self->scale == NULL)
27 goto out_free_form;
28 newtFormAddComponent(self->form, self->scale);
29 newtRefresh();
30 }
31
32 return self;
33
34out_free_form:
35 newtFormDestroy(self->form);
36out_free_self:
37 free(self);
38 return NULL;
39}
40
41void ui_progress__update(struct ui_progress *self, u64 curr)
42{
43 /*
44 * FIXME: We should have a per UI backend way of showing progress,
45 * stdio will just show a percentage as NN%, etc.
46 */
47 if (use_browser <= 0)
48 return;
49 newtScaleSet(self->scale, curr);
50 newtRefresh();
51}
52
53void ui_progress__delete(struct ui_progress *self)
54{
55 if (use_browser > 0) {
56 newtFormDestroy(self->form);
57 newtPopWindow();
58 }
59 free(self);
60}
diff --git a/tools/perf/util/ui/progress.h b/tools/perf/util/ui/progress.h
new file mode 100644
index 000000000000..a3820a0beb5b
--- /dev/null
+++ b/tools/perf/util/ui/progress.h
@@ -0,0 +1,11 @@
1#ifndef _PERF_UI_PROGRESS_H_
2#define _PERF_UI_PROGRESS_H_ 1
3
4struct ui_progress;
5
6struct ui_progress *ui_progress__new(const char *title, u64 total);
7void ui_progress__delete(struct ui_progress *self);
8
9void ui_progress__update(struct ui_progress *self, u64 curr);
10
11#endif