perf report: Add progress bars
authorArnaldo Carvalho de Melo <acme@redhat.com>
Sat, 27 Mar 2010 00:16:22 +0000 (21:16 -0300)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Fri, 2 Apr 2010 19:27:55 +0000 (16:27 -0300)
For when we are processing the events and inserting the entries in the
browser.

Experimentation here: naming "ui_something" we may be treading into
creating a TUI/GUI set of routines that can then be implemented in terms
of multiple backends.

Also the time it takes for adding things to the "browser" takes, visually
(I guess I should do some profiling here ;-) ), more time than for
processing the events...

That means we probably need to create a custom hist_entry browser, so
that we reuse the structures we have in place instead of duplicating
them in newt.

But progress was made and at least we can see something while long files
are being loaded, that must be one of UI 101 bullet points :-)

Cc: Frédéric Weisbecker <fweisbec@gmail.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Paul Mackerras <paulus@samba.org>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/builtin-report.c
tools/perf/util/debug.h
tools/perf/util/hist.c
tools/perf/util/hist.h
tools/perf/util/newt.c
tools/perf/util/session.c
tools/perf/util/session.h

index 6ab16980dd6611842c15529c56d4c953b83aae36..381918515a5c555dee83131ebb26040d77e6a5f4 100644 (file)
@@ -303,13 +303,14 @@ static int __cmd_report(void)
        next = rb_first(&session->stats_by_id);
        while (next) {
                struct event_stat_id *stats;
+               u64 nr_hists;
 
                stats = rb_entry(next, struct event_stat_id, rb_node);
                perf_session__collapse_resort(&stats->hists);
-               perf_session__output_resort(&stats->hists, stats->stats.total);
-
+               nr_hists = perf_session__output_resort(&stats->hists,
+                                                      stats->stats.total);
                if (use_browser)
-                       perf_session__browse_hists(&stats->hists,
+                       perf_session__browse_hists(&stats->hists, nr_hists,
                                                   stats->stats.total, help);
                else {
                        if (rb_first(&session->stats_by_id) ==
index 0172edf3f1533bf4f33991dedda6fcf435edba14..5cb0a1b1401a86db13c35ba822698aa3756fe7e7 100644 (file)
@@ -10,13 +10,29 @@ extern int dump_trace;
 int dump_printf(const char *fmt, ...) __attribute__((format(printf, 1, 2)));
 void trace_event(event_t *event);
 
+struct ui_progress;
+
 #ifdef NO_NEWT_SUPPORT
 static inline int browser__show_help(const char *format __used, va_list ap __used)
 {
        return 0;
 }
+
+static inline struct ui_progress *ui_progress__new(const char *title __used,
+                                                  u64 total __used)
+{
+       return (struct ui_progress *)1;
+}
+
+static inline void ui_progress__update(struct ui_progress *self __used,
+                                      u64 curr __used) {}
+
+static inline void ui_progress__delete(struct ui_progress *self __used) {}
 #else
 int browser__show_help(const char *format, va_list ap);
+struct ui_progress *ui_progress__new(const char *title, u64 total);
+void ui_progress__update(struct ui_progress *self, u64 curr);
+void ui_progress__delete(struct ui_progress *self);
 #endif
 
 #endif /* __PERF_DEBUG_H */
index de3190102cc88065ccd5fc3778fea0fd69cd38b5..a46d093324623007b482d215819c98858f1e5d38 100644 (file)
@@ -185,12 +185,13 @@ static void perf_session__insert_output_hist_entry(struct rb_root *root,
        rb_insert_color(&he->rb_node, root);
 }
 
-void perf_session__output_resort(struct rb_root *hists, u64 total_samples)
+u64 perf_session__output_resort(struct rb_root *hists, u64 total_samples)
 {
        struct rb_root tmp;
        struct rb_node *next;
        struct hist_entry *n;
        u64 min_callchain_hits;
+       u64 nr_hists = 0;
 
        min_callchain_hits =
                total_samples * (callchain_param.min_percent / 100);
@@ -205,9 +206,11 @@ void perf_session__output_resort(struct rb_root *hists, u64 total_samples)
                rb_erase(&n->rb_node, hists);
                perf_session__insert_output_hist_entry(&tmp, n,
                                                       min_callchain_hits);
+               ++nr_hists;
        }
 
        *hists = tmp;
+       return nr_hists;
 }
 
 static size_t callchain__fprintf_left_margin(FILE *fp, int left_margin)
index fe366ce5db453ba2a153374b82de4a055d98ff64..da6a8c1320fa4741dc4f00d44c326874f722441c 100644 (file)
@@ -25,7 +25,7 @@ size_t hist_entry__fprintf(struct hist_entry *self,
                           u64 session_total);
 void hist_entry__free(struct hist_entry *);
 
-void perf_session__output_resort(struct rb_root *hists, u64 total_samples);
+u64 perf_session__output_resort(struct rb_root *hists, u64 total_samples);
 void perf_session__collapse_resort(struct rb_root *hists);
 size_t perf_session__fprintf_hists(struct rb_root *hists,
                                   struct perf_session *pair,
index e99bcc8d193909d3ab97766d6132b6567d7a9c9d..b0210ae5b93c73fc4a81f5a8b9510266c5f8e02f 100644 (file)
 #include "sort.h"
 #include "symbol.h"
 
+struct ui_progress {
+       newtComponent form, scale;
+};
+
+struct ui_progress *ui_progress__new(const char *title, u64 total)
+{
+       struct ui_progress *self = malloc(sizeof(*self));
+
+       if (self != NULL) {
+               int cols;
+               newtGetScreenSize(&cols, NULL);
+               cols -= 4;
+               newtCenteredWindow(cols, 1, title);
+               self->form  = newtForm(NULL, NULL, 0);
+               if (self->form == NULL)
+                       goto out_free_self;
+               self->scale = newtScale(0, 0, cols, total);
+               if (self->scale == NULL)
+                       goto out_free_form;
+               newtFormAddComponents(self->form, self->scale, NULL);
+               newtRefresh();
+       }
+
+       return self;
+
+out_free_form:
+       newtFormDestroy(self->form);
+out_free_self:
+       free(self);
+       return NULL;
+}
+
+void ui_progress__update(struct ui_progress *self, u64 curr)
+{
+       newtScaleSet(self->scale, curr);
+       newtRefresh();
+}
+
+void ui_progress__delete(struct ui_progress *self)
+{
+       newtFormDestroy(self->form);
+       newtPopWindow();
+       free(self);
+}
+
+static char browser__last_msg[1024];
+
+int browser__show_help(const char *format, va_list ap)
+{
+       int ret;
+       static int backlog;
+
+        ret = vsnprintf(browser__last_msg + backlog,
+                       sizeof(browser__last_msg) - backlog, format, ap);
+       backlog += ret;
+
+       if (browser__last_msg[backlog - 1] == '\n') {
+               newtPopHelpLine();
+               newtPushHelpLine(browser__last_msg);
+               newtRefresh();
+               backlog = 0;
+       }
+
+       return ret;
+}
+
 static void newt_form__set_exit_keys(newtComponent self)
 {
        newtFormAddHotKey(self, NEWT_KEY_ESCAPE);
@@ -364,8 +430,8 @@ static void perf_session__selection(newtComponent self, void *data)
        *symbol_ptr = newt__symbol_tree_get_current(self);
 }
 
-void perf_session__browse_hists(struct rb_root *hists, u64 session_total,
-                               const char *helpline)
+int perf_session__browse_hists(struct rb_root *hists, u64 nr_hists,
+                              u64 session_total, const char *helpline)
 {
        struct sort_entry *se;
        struct rb_node *nd;
@@ -378,6 +444,12 @@ void perf_session__browse_hists(struct rb_root *hists, u64 session_total,
        newtComponent form, tree;
        struct newtExitStruct es;
        const struct map_symbol *selection;
+       u64 curr_hist = 0;
+       struct ui_progress *progress;
+
+       progress = ui_progress__new("Adding entries to the browser...", nr_hists);
+       if (progress == NULL)
+               return -1;
 
        snprintf(str, sizeof(str), "Samples: %Ld", session_total);
        newtDrawRootText(0, 0, str);
@@ -419,8 +491,13 @@ void perf_session__browse_hists(struct rb_root *hists, u64 session_total,
                        max_len = len;
                if (symbol_conf.use_callchain)
                        hist_entry__append_callchain_browser(h, tree, session_total, idx++);
+               ++curr_hist;
+               if (curr_hist % 5)
+                       ui_progress__update(progress, curr_hist);
        }
 
+       ui_progress__delete(progress);
+
        if (max_len > cols)
                max_len = cols - 3;
 
@@ -480,27 +557,7 @@ do_annotate:
 
        newtFormDestroy(form);
        newtPopWindow();
-}
-
-static char browser__last_msg[1024];
-
-int browser__show_help(const char *format, va_list ap)
-{
-       int ret;
-       static int backlog;
-
-        ret = vsnprintf(browser__last_msg + backlog,
-                       sizeof(browser__last_msg) - backlog, format, ap);
-       backlog += ret;
-
-       if (browser__last_msg[backlog - 1] == '\n') {
-               newtPopHelpLine();
-               newtPushHelpLine(browser__last_msg);
-               newtRefresh();
-               backlog = 0;
-       }
-
-       return ret;
+       return 0;
 }
 
 void setup_browser(void)
index 76b4ac689df90e762029f2800691782b6b19f79c..32765cdca058a6b7bdb541b7ec475a2bcea7ebbf 100644 (file)
@@ -397,6 +397,10 @@ int __perf_session__process_events(struct perf_session *self,
        event_t *event;
        uint32_t size;
        char *buf;
+       struct ui_progress *progress = ui_progress__new("Processing events...",
+                                                       self->size);
+       if (progress == NULL)
+               return -1;
 
        perf_event_ops__fill_defaults(ops);
 
@@ -425,6 +429,7 @@ remap:
 
 more:
        event = (event_t *)(buf + head);
+       ui_progress__update(progress, offset);
 
        if (self->header.needs_swap)
                perf_event_header__bswap(&event->header);
@@ -475,6 +480,7 @@ more:
 done:
        err = 0;
 out_err:
+       ui_progress__delete(progress);
        return err;
 }
 
index 631f8157fc17dab9505726569c33a9df9499d99d..6a15daeda57781facecc4c9039a2ab44a6868eee 100644 (file)
@@ -88,11 +88,15 @@ static inline struct map *
 }
 
 #ifdef NO_NEWT_SUPPORT
-static inline void perf_session__browse_hists(struct rb_root *hists __used,
+static inline int perf_session__browse_hists(struct rb_root *hists __used,
+                                             u64 nr_hists __used,
                                              u64 session_total __used,
-                                             const char *helpline __used) {}
+                                             const char *helpline __used)
+{
+       return 0;
+}
 #else
-void perf_session__browse_hists(struct rb_root *hists, u64 session_total,
-                               const char *helpline);
+int perf_session__browse_hists(struct rb_root *hists, u64 nr_hists,
+                               u64 session_total, const char *helpline);
 #endif
 #endif /* __PERF_SESSION_H */