diff options
| author | Arnaldo Carvalho de Melo <acme@redhat.com> | 2013-10-23 14:40:38 -0400 |
|---|---|---|
| committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2013-10-23 14:40:38 -0400 |
| commit | 4d3001fdfdfacd2b35ee74ff0f037274eeebd3f6 (patch) | |
| tree | 20634d8528fe514298163af38a66b37447503926 | |
| parent | 4779a2e99af80e133ee1c70c7093dc6cc13429a1 (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>
| -rw-r--r-- | tools/perf/ui/gtk/progress.c | 8 | ||||
| -rw-r--r-- | tools/perf/ui/progress.c | 22 | ||||
| -rw-r--r-- | tools/perf/ui/progress.h | 15 | ||||
| -rw-r--r-- | tools/perf/ui/tui/progress.c | 8 | ||||
| -rw-r--r-- | tools/perf/util/session.c | 24 |
5 files changed, 47 insertions, 30 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 @@ | |||
| 7 | static GtkWidget *dialog; | 7 | static GtkWidget *dialog; |
| 8 | static GtkWidget *progress; | 8 | static GtkWidget *progress; |
| 9 | 9 | ||
| 10 | static void gtk_ui_progress__update(u64 curr, u64 total, const char *title) | 10 | static 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 | ||
| 4 | static void null_progress__update(u64 curr __maybe_unused, | 4 | static 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 | ||
| 15 | struct ui_progress_ops *ui_progress__ops = &null_progress__ops; | 13 | struct ui_progress_ops *ui_progress__ops = &null_progress__ops; |
| 16 | 14 | ||
| 17 | void ui_progress__update(u64 curr, u64 total, const char *title) | 15 | void 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 | |||
| 25 | void 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 | ||
| 22 | void ui_progress__finish(void) | 34 | void 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 | ||
| 6 | void ui_progress__finish(void); | ||
| 7 | |||
| 8 | struct ui_progress { | ||
| 9 | const char *title; | ||
| 10 | u64 curr, next, step, total; | ||
| 11 | }; | ||
| 12 | |||
| 13 | void ui_progress__init(struct ui_progress *p, u64 total, const char *title); | ||
| 14 | void ui_progress__update(struct ui_progress *p, u64 adv); | ||
| 15 | |||
| 6 | struct ui_progress_ops { | 16 | struct 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 | ||
| 11 | extern struct ui_progress_ops *ui_progress__ops; | 21 | extern struct ui_progress_ops *ui_progress__ops; |
| 12 | 22 | ||
| 13 | void ui_progress__update(u64 curr, u64 total, const char *title); | ||
| 14 | void 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 | ||
| 8 | static void tui_progress__update(u64 curr, u64 total, const char *title) | 8 | static 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); |
diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c index 854c5aa4db0d..4ba7b548e055 100644 --- a/tools/perf/util/session.c +++ b/tools/perf/util/session.c | |||
| @@ -503,13 +503,16 @@ static int flush_sample_queue(struct perf_session *s, | |||
| 503 | struct perf_sample sample; | 503 | struct perf_sample sample; |
| 504 | u64 limit = os->next_flush; | 504 | u64 limit = os->next_flush; |
| 505 | u64 last_ts = os->last_sample ? os->last_sample->timestamp : 0ULL; | 505 | u64 last_ts = os->last_sample ? os->last_sample->timestamp : 0ULL; |
| 506 | unsigned idx = 0, progress_next = os->nr_samples / 16; | ||
| 507 | bool show_progress = limit == ULLONG_MAX; | 506 | bool show_progress = limit == ULLONG_MAX; |
| 507 | struct ui_progress prog; | ||
| 508 | int ret; | 508 | int ret; |
| 509 | 509 | ||
| 510 | if (!tool->ordered_samples || !limit) | 510 | if (!tool->ordered_samples || !limit) |
| 511 | return 0; | 511 | return 0; |
| 512 | 512 | ||
| 513 | if (show_progress) | ||
| 514 | ui_progress__init(&prog, os->nr_samples, "Processing time ordered events..."); | ||
| 515 | |||
| 513 | list_for_each_entry_safe(iter, tmp, head, list) { | 516 | list_for_each_entry_safe(iter, tmp, head, list) { |
| 514 | if (session_done()) | 517 | if (session_done()) |
| 515 | return 0; | 518 | return 0; |
| @@ -530,11 +533,9 @@ static int flush_sample_queue(struct perf_session *s, | |||
| 530 | os->last_flush = iter->timestamp; | 533 | os->last_flush = iter->timestamp; |
| 531 | list_del(&iter->list); | 534 | list_del(&iter->list); |
| 532 | list_add(&iter->list, &os->sample_cache); | 535 | list_add(&iter->list, &os->sample_cache); |
| 533 | if (show_progress && (++idx >= progress_next)) { | 536 | |
| 534 | progress_next += os->nr_samples / 16; | 537 | if (show_progress) |
| 535 | ui_progress__update(idx, os->nr_samples, | 538 | ui_progress__update(&prog, 1); |
| 536 | "Processing time ordered events..."); | ||
| 537 | } | ||
| 538 | } | 539 | } |
| 539 | 540 | ||
| 540 | if (list_empty(head)) { | 541 | if (list_empty(head)) { |
| @@ -1285,12 +1286,13 @@ int __perf_session__process_events(struct perf_session *session, | |||
| 1285 | u64 file_size, struct perf_tool *tool) | 1286 | u64 file_size, struct perf_tool *tool) |
| 1286 | { | 1287 | { |
| 1287 | int fd = perf_data_file__fd(session->file); | 1288 | int fd = perf_data_file__fd(session->file); |
| 1288 | u64 head, page_offset, file_offset, file_pos, progress_next; | 1289 | u64 head, page_offset, file_offset, file_pos; |
| 1289 | int err, mmap_prot, mmap_flags, map_idx = 0; | 1290 | int err, mmap_prot, mmap_flags, map_idx = 0; |
| 1290 | size_t mmap_size; | 1291 | size_t mmap_size; |
| 1291 | char *buf, *mmaps[NUM_MMAPS]; | 1292 | char *buf, *mmaps[NUM_MMAPS]; |
| 1292 | union perf_event *event; | 1293 | union perf_event *event; |
| 1293 | uint32_t size; | 1294 | uint32_t size; |
| 1295 | struct ui_progress prog; | ||
| 1294 | 1296 | ||
| 1295 | perf_tool__fill_defaults(tool); | 1297 | perf_tool__fill_defaults(tool); |
| 1296 | 1298 | ||
| @@ -1301,7 +1303,7 @@ int __perf_session__process_events(struct perf_session *session, | |||
| 1301 | if (data_size && (data_offset + data_size < file_size)) | 1303 | if (data_size && (data_offset + data_size < file_size)) |
| 1302 | file_size = data_offset + data_size; | 1304 | file_size = data_offset + data_size; |
| 1303 | 1305 | ||
| 1304 | progress_next = file_size / 16; | 1306 | ui_progress__init(&prog, file_size, "Processing events..."); |
| 1305 | 1307 | ||
| 1306 | mmap_size = MMAP_SIZE; | 1308 | mmap_size = MMAP_SIZE; |
| 1307 | if (mmap_size > file_size) | 1309 | if (mmap_size > file_size) |
| @@ -1356,11 +1358,7 @@ more: | |||
| 1356 | head += size; | 1358 | head += size; |
| 1357 | file_pos += size; | 1359 | file_pos += size; |
| 1358 | 1360 | ||
| 1359 | if (file_pos >= progress_next) { | 1361 | ui_progress__update(&prog, size); |
| 1360 | progress_next += file_size / 16; | ||
| 1361 | ui_progress__update(file_pos, file_size, | ||
| 1362 | "Processing events..."); | ||
| 1363 | } | ||
| 1364 | 1362 | ||
| 1365 | if (session_done()) | 1363 | if (session_done()) |
| 1366 | goto out; | 1364 | goto out; |
