aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf/ui
diff options
context:
space:
mode:
authorArnaldo Carvalho de Melo <acme@redhat.com>2013-10-23 14:40:38 -0400
committerArnaldo Carvalho de Melo <acme@redhat.com>2013-10-23 14:40:38 -0400
commit4d3001fdfdfacd2b35ee74ff0f037274eeebd3f6 (patch)
tree20634d8528fe514298163af38a66b37447503926 /tools/perf/ui
parent4779a2e99af80e133ee1c70c7093dc6cc13429a1 (diff)
perf ui progress: Per progress bar state
That will ease using a progress bar across multiple functions, like in the upcoming patches that will present a progress bar when collapsing histograms. Based on a previous patch by Namhyung Kim. Cc: Adrian Hunter <adrian.hunter@intel.com> Cc: David Ahern <dsahern@gmail.com> Cc: Frederic Weisbecker <fweisbec@gmail.com> Cc: Jiri Olsa <jolsa@redhat.com> Cc: Mike Galbraith <efault@gmx.de> Cc: Paul Mackerras <paulus@samba.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Stephane Eranian <eranian@google.com> Link: http://lkml.kernel.org/n/tip-cr7lq7ud9fj21bg7wvq27w1u@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf/ui')
-rw-r--r--tools/perf/ui/gtk/progress.c8
-rw-r--r--tools/perf/ui/progress.c22
-rw-r--r--tools/perf/ui/progress.h15
-rw-r--r--tools/perf/ui/tui/progress.c8
4 files changed, 36 insertions, 17 deletions
diff --git a/tools/perf/ui/gtk/progress.c b/tools/perf/ui/gtk/progress.c
index 195c7f94f98e..b656655fbc39 100644
--- a/tools/perf/ui/gtk/progress.c
+++ b/tools/perf/ui/gtk/progress.c
@@ -7,14 +7,14 @@
7static GtkWidget *dialog; 7static GtkWidget *dialog;
8static GtkWidget *progress; 8static GtkWidget *progress;
9 9
10static void gtk_ui_progress__update(u64 curr, u64 total, const char *title) 10static void gtk_ui_progress__update(struct ui_progress *p)
11{ 11{
12 double fraction = total ? 1.0 * curr / total : 0.0; 12 double fraction = p->total ? 1.0 * p->curr / p->total : 0.0;
13 char buf[1024]; 13 char buf[1024];
14 14
15 if (dialog == NULL) { 15 if (dialog == NULL) {
16 GtkWidget *vbox = gtk_vbox_new(TRUE, 5); 16 GtkWidget *vbox = gtk_vbox_new(TRUE, 5);
17 GtkWidget *label = gtk_label_new(title); 17 GtkWidget *label = gtk_label_new(p->title);
18 18
19 dialog = gtk_window_new(GTK_WINDOW_TOPLEVEL); 19 dialog = gtk_window_new(GTK_WINDOW_TOPLEVEL);
20 progress = gtk_progress_bar_new(); 20 progress = gtk_progress_bar_new();
@@ -32,7 +32,7 @@ static void gtk_ui_progress__update(u64 curr, u64 total, const char *title)
32 } 32 }
33 33
34 gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(progress), fraction); 34 gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(progress), fraction);
35 snprintf(buf, sizeof(buf), "%"PRIu64" / %"PRIu64, curr, total); 35 snprintf(buf, sizeof(buf), "%"PRIu64" / %"PRIu64, p->curr, p->total);
36 gtk_progress_bar_set_text(GTK_PROGRESS_BAR(progress), buf); 36 gtk_progress_bar_set_text(GTK_PROGRESS_BAR(progress), buf);
37 37
38 /* we didn't call gtk_main yet, so do it manually */ 38 /* we didn't call gtk_main yet, so do it manually */
diff --git a/tools/perf/ui/progress.c b/tools/perf/ui/progress.c
index d753821b6e0b..a0f24c7115c5 100644
--- a/tools/perf/ui/progress.c
+++ b/tools/perf/ui/progress.c
@@ -1,9 +1,7 @@
1#include "../cache.h" 1#include "../cache.h"
2#include "progress.h" 2#include "progress.h"
3 3
4static void null_progress__update(u64 curr __maybe_unused, 4static void null_progress__update(struct ui_progress *p __maybe_unused)
5 u64 total __maybe_unused,
6 const char *title __maybe_unused)
7{ 5{
8} 6}
9 7
@@ -14,9 +12,23 @@ static struct ui_progress_ops null_progress__ops =
14 12
15struct ui_progress_ops *ui_progress__ops = &null_progress__ops; 13struct ui_progress_ops *ui_progress__ops = &null_progress__ops;
16 14
17void ui_progress__update(u64 curr, u64 total, const char *title) 15void ui_progress__update(struct ui_progress *p, u64 adv)
18{ 16{
19 return ui_progress__ops->update(curr, total, title); 17 p->curr += adv;
18
19 if (p->curr >= p->next) {
20 p->next += p->step;
21 ui_progress__ops->update(p);
22 }
23}
24
25void ui_progress__init(struct ui_progress *p, u64 total, const char *title)
26{
27 p->curr = 0;
28 p->next = p->step = total / 16;
29 p->total = total;
30 p->title = title;
31
20} 32}
21 33
22void ui_progress__finish(void) 34void ui_progress__finish(void)
diff --git a/tools/perf/ui/progress.h b/tools/perf/ui/progress.h
index d41bde5908a6..29ec8efffefb 100644
--- a/tools/perf/ui/progress.h
+++ b/tools/perf/ui/progress.h
@@ -3,14 +3,21 @@
3 3
4#include <../types.h> 4#include <../types.h>
5 5
6void ui_progress__finish(void);
7
8struct ui_progress {
9 const char *title;
10 u64 curr, next, step, total;
11};
12
13void ui_progress__init(struct ui_progress *p, u64 total, const char *title);
14void ui_progress__update(struct ui_progress *p, u64 adv);
15
6struct ui_progress_ops { 16struct ui_progress_ops {
7 void (*update)(u64, u64, const char *); 17 void (*update)(struct ui_progress *p);
8 void (*finish)(void); 18 void (*finish)(void);
9}; 19};
10 20
11extern struct ui_progress_ops *ui_progress__ops; 21extern struct ui_progress_ops *ui_progress__ops;
12 22
13void ui_progress__update(u64 curr, u64 total, const char *title);
14void ui_progress__finish(void);
15
16#endif 23#endif
diff --git a/tools/perf/ui/tui/progress.c b/tools/perf/ui/tui/progress.c
index 0fcc5a1f525a..3e2d936d7443 100644
--- a/tools/perf/ui/tui/progress.c
+++ b/tools/perf/ui/tui/progress.c
@@ -5,7 +5,7 @@
5#include "tui.h" 5#include "tui.h"
6#include "../browser.h" 6#include "../browser.h"
7 7
8static void tui_progress__update(u64 curr, u64 total, const char *title) 8static void tui_progress__update(struct ui_progress *p)
9{ 9{
10 int bar, y; 10 int bar, y;
11 /* 11 /*
@@ -15,7 +15,7 @@ static void tui_progress__update(u64 curr, u64 total, const char *title)
15 if (use_browser <= 0) 15 if (use_browser <= 0)
16 return; 16 return;
17 17
18 if (total == 0) 18 if (p->total == 0)
19 return; 19 return;
20 20
21 ui__refresh_dimensions(true); 21 ui__refresh_dimensions(true);
@@ -24,9 +24,9 @@ static void tui_progress__update(u64 curr, u64 total, const char *title)
24 SLsmg_set_color(0); 24 SLsmg_set_color(0);
25 SLsmg_draw_box(y, 0, 3, SLtt_Screen_Cols); 25 SLsmg_draw_box(y, 0, 3, SLtt_Screen_Cols);
26 SLsmg_gotorc(y++, 1); 26 SLsmg_gotorc(y++, 1);
27 SLsmg_write_string((char *)title); 27 SLsmg_write_string((char *)p->title);
28 SLsmg_set_color(HE_COLORSET_SELECTED); 28 SLsmg_set_color(HE_COLORSET_SELECTED);
29 bar = ((SLtt_Screen_Cols - 2) * curr) / total; 29 bar = ((SLtt_Screen_Cols - 2) * p->curr) / p->total;
30 SLsmg_fill_region(y, 1, 1, bar, ' '); 30 SLsmg_fill_region(y, 1, 1, bar, ' ');
31 SLsmg_refresh(); 31 SLsmg_refresh();
32 pthread_mutex_unlock(&ui__lock); 32 pthread_mutex_unlock(&ui__lock);