Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

+47 -30
+4 -4
tools/perf/ui/gtk/progress.c
··· 7 7 static GtkWidget *dialog; 8 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 13 char buf[1024]; 14 14 15 15 if (dialog == NULL) { 16 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 19 dialog = gtk_window_new(GTK_WINDOW_TOPLEVEL); 20 20 progress = gtk_progress_bar_new(); ··· 32 32 } 33 33 34 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 36 gtk_progress_bar_set_text(GTK_PROGRESS_BAR(progress), buf); 37 37 38 38 /* we didn't call gtk_main yet, so do it manually */
+17 -5
tools/perf/ui/progress.c
··· 1 1 #include "../cache.h" 2 2 #include "progress.h" 3 3 4 - static void null_progress__update(u64 curr __maybe_unused, 5 - u64 total __maybe_unused, 6 - const char *title __maybe_unused) 4 + static void null_progress__update(struct ui_progress *p __maybe_unused) 7 5 { 8 6 } 9 7 ··· 12 14 13 15 struct ui_progress_ops *ui_progress__ops = &null_progress__ops; 14 16 15 - void ui_progress__update(u64 curr, u64 total, const char *title) 17 + void ui_progress__update(struct ui_progress *p, u64 adv) 16 18 { 17 - return ui_progress__ops->update(curr, total, title); 19 + p->curr += adv; 20 + 21 + if (p->curr >= p->next) { 22 + p->next += p->step; 23 + ui_progress__ops->update(p); 24 + } 25 + } 26 + 27 + void ui_progress__init(struct ui_progress *p, u64 total, const char *title) 28 + { 29 + p->curr = 0; 30 + p->next = p->step = total / 16; 31 + p->total = total; 32 + p->title = title; 33 + 18 34 } 19 35 20 36 void ui_progress__finish(void)
+11 -4
tools/perf/ui/progress.h
··· 3 3 4 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 16 struct ui_progress_ops { 7 - void (*update)(u64, u64, const char *); 17 + void (*update)(struct ui_progress *p); 8 18 void (*finish)(void); 9 19 }; 10 20 11 21 extern struct ui_progress_ops *ui_progress__ops; 12 - 13 - void ui_progress__update(u64 curr, u64 total, const char *title); 14 - void ui_progress__finish(void); 15 22 16 23 #endif
+4 -4
tools/perf/ui/tui/progress.c
··· 5 5 #include "tui.h" 6 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 10 int bar, y; 11 11 /* ··· 15 15 if (use_browser <= 0) 16 16 return; 17 17 18 - if (total == 0) 18 + if (p->total == 0) 19 19 return; 20 20 21 21 ui__refresh_dimensions(true); ··· 24 24 SLsmg_set_color(0); 25 25 SLsmg_draw_box(y, 0, 3, SLtt_Screen_Cols); 26 26 SLsmg_gotorc(y++, 1); 27 - SLsmg_write_string((char *)title); 27 + SLsmg_write_string((char *)p->title); 28 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 30 SLsmg_fill_region(y, 1, 1, bar, ' '); 31 31 SLsmg_refresh(); 32 32 pthread_mutex_unlock(&ui__lock);
+11 -13
tools/perf/util/session.c
··· 503 503 struct perf_sample sample; 504 504 u64 limit = os->next_flush; 505 505 u64 last_ts = os->last_sample ? os->last_sample->timestamp : 0ULL; 506 - unsigned idx = 0, progress_next = os->nr_samples / 16; 507 506 bool show_progress = limit == ULLONG_MAX; 507 + struct ui_progress prog; 508 508 int ret; 509 509 510 510 if (!tool->ordered_samples || !limit) 511 511 return 0; 512 + 513 + if (show_progress) 514 + ui_progress__init(&prog, os->nr_samples, "Processing time ordered events..."); 512 515 513 516 list_for_each_entry_safe(iter, tmp, head, list) { 514 517 if (session_done()) ··· 533 530 os->last_flush = iter->timestamp; 534 531 list_del(&iter->list); 535 532 list_add(&iter->list, &os->sample_cache); 536 - if (show_progress && (++idx >= progress_next)) { 537 - progress_next += os->nr_samples / 16; 538 - ui_progress__update(idx, os->nr_samples, 539 - "Processing time ordered events..."); 540 - } 533 + 534 + if (show_progress) 535 + ui_progress__update(&prog, 1); 541 536 } 542 537 543 538 if (list_empty(head)) { ··· 1286 1285 u64 file_size, struct perf_tool *tool) 1287 1286 { 1288 1287 int fd = perf_data_file__fd(session->file); 1289 - u64 head, page_offset, file_offset, file_pos, progress_next; 1288 + u64 head, page_offset, file_offset, file_pos; 1290 1289 int err, mmap_prot, mmap_flags, map_idx = 0; 1291 1290 size_t mmap_size; 1292 1291 char *buf, *mmaps[NUM_MMAPS]; 1293 1292 union perf_event *event; 1294 1293 uint32_t size; 1294 + struct ui_progress prog; 1295 1295 1296 1296 perf_tool__fill_defaults(tool); 1297 1297 ··· 1303 1301 if (data_size && (data_offset + data_size < file_size)) 1304 1302 file_size = data_offset + data_size; 1305 1303 1306 - progress_next = file_size / 16; 1304 + ui_progress__init(&prog, file_size, "Processing events..."); 1307 1305 1308 1306 mmap_size = MMAP_SIZE; 1309 1307 if (mmap_size > file_size) ··· 1358 1356 head += size; 1359 1357 file_pos += size; 1360 1358 1361 - if (file_pos >= progress_next) { 1362 - progress_next += file_size / 16; 1363 - ui_progress__update(file_pos, file_size, 1364 - "Processing events..."); 1365 - } 1359 + ui_progress__update(&prog, size); 1366 1360 1367 1361 if (session_done()) 1368 1362 goto out;