diff options
Diffstat (limited to 'tools/perf/ui/gtk/progress.c')
-rw-r--r-- | tools/perf/ui/gtk/progress.c | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/tools/perf/ui/gtk/progress.c b/tools/perf/ui/gtk/progress.c new file mode 100644 index 000000000000..903426fe27cf --- /dev/null +++ b/tools/perf/ui/gtk/progress.c | |||
@@ -0,0 +1,50 @@ | |||
1 | #include <inttypes.h> | ||
2 | |||
3 | #include "gtk.h" | ||
4 | #include "../progress.h" | ||
5 | #include "util.h" | ||
6 | |||
7 | static GtkWidget *dialog; | ||
8 | static GtkWidget *progress; | ||
9 | |||
10 | static void gtk_progress_update(u64 curr, u64 total, const char *title) | ||
11 | { | ||
12 | double fraction = total ? 1.0 * curr / total : 0.0; | ||
13 | char buf[1024]; | ||
14 | |||
15 | if (dialog == NULL) { | ||
16 | GtkWidget *vbox = gtk_vbox_new(TRUE, 5); | ||
17 | GtkWidget *label = gtk_label_new(title); | ||
18 | |||
19 | dialog = gtk_window_new(GTK_WINDOW_TOPLEVEL); | ||
20 | progress = gtk_progress_bar_new(); | ||
21 | |||
22 | gtk_box_pack_start(GTK_BOX(vbox), label, TRUE, FALSE, 3); | ||
23 | gtk_box_pack_start(GTK_BOX(vbox), progress, TRUE, TRUE, 3); | ||
24 | |||
25 | gtk_container_add(GTK_CONTAINER(dialog), vbox); | ||
26 | |||
27 | gtk_window_set_title(GTK_WINDOW(dialog), "perf"); | ||
28 | gtk_window_resize(GTK_WINDOW(dialog), 300, 80); | ||
29 | gtk_window_set_position(GTK_WINDOW(dialog), GTK_WIN_POS_CENTER); | ||
30 | |||
31 | gtk_widget_show_all(dialog); | ||
32 | } | ||
33 | |||
34 | gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(progress), fraction); | ||
35 | snprintf(buf, sizeof(buf), "%"PRIu64" / %"PRIu64, curr, total); | ||
36 | gtk_progress_bar_set_text(GTK_PROGRESS_BAR(progress), buf); | ||
37 | |||
38 | /* we didn't call gtk_main yet, so do it manually */ | ||
39 | while (gtk_events_pending()) | ||
40 | gtk_main_iteration(); | ||
41 | } | ||
42 | |||
43 | static struct ui_progress gtk_progress_fns = { | ||
44 | .update = gtk_progress_update, | ||
45 | }; | ||
46 | |||
47 | void perf_gtk__init_progress(void) | ||
48 | { | ||
49 | progress_fns = >k_progress_fns; | ||
50 | } | ||