diff options
author | Arnaldo Carvalho de Melo <acme@redhat.com> | 2010-08-08 18:56:47 -0400 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2010-08-10 15:09:14 -0400 |
commit | 34cea7f7c0620c964676eece258ef431a6608bce (patch) | |
tree | 48b85557823fc63939dad71cb14d6c75b96a11b9 /tools/perf/util | |
parent | 5575536fc7ad7577a4e687a13e2f49acebc519f3 (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/perf/util')
-rw-r--r-- | tools/perf/util/debug.h | 4 | ||||
-rw-r--r-- | tools/perf/util/newt.c | 56 | ||||
-rw-r--r-- | tools/perf/util/ui/progress.c | 60 | ||||
-rw-r--r-- | tools/perf/util/ui/progress.h | 11 |
4 files changed, 72 insertions, 59 deletions
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, | |||
31 | static inline void ui_progress__delete(struct ui_progress *self __used) {} | 31 | static inline void ui_progress__delete(struct ui_progress *self __used) {} |
32 | #else | 32 | #else |
33 | int browser__show_help(const char *format, va_list ap); | 33 | int browser__show_help(const char *format, va_list ap); |
34 | struct ui_progress *ui_progress__new(const char *title, u64 total); | 34 | #include "ui/progress.h" |
35 | void ui_progress__update(struct ui_progress *self, u64 curr); | ||
36 | void 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 | ||
40 | newtComponent newt_form__new(void); | 40 | newtComponent newt_form__new(void); |
41 | 41 | ||
42 | struct ui_progress { | ||
43 | newtComponent form, scale; | ||
44 | }; | ||
45 | |||
46 | struct 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 | |||
70 | out_free_form: | ||
71 | newtFormDestroy(self->form); | ||
72 | out_free_self: | ||
73 | free(self); | ||
74 | return NULL; | ||
75 | } | ||
76 | |||
77 | void 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 | |||
89 | void 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 | |||
98 | static int ui_entry__read(const char *title, char *bf, size_t size, int width) | 42 | static 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 | |||
6 | struct ui_progress { | ||
7 | newtComponent form, scale; | ||
8 | }; | ||
9 | |||
10 | struct 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 | |||
34 | out_free_form: | ||
35 | newtFormDestroy(self->form); | ||
36 | out_free_self: | ||
37 | free(self); | ||
38 | return NULL; | ||
39 | } | ||
40 | |||
41 | void 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 | |||
53 | void 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 | |||
4 | struct ui_progress; | ||
5 | |||
6 | struct ui_progress *ui_progress__new(const char *title, u64 total); | ||
7 | void ui_progress__delete(struct ui_progress *self); | ||
8 | |||
9 | void ui_progress__update(struct ui_progress *self, u64 curr); | ||
10 | |||
11 | #endif | ||