Merge branch 'perf/urgent' into perf/core, to pick up fixes before merging new changes
[cascardo/linux.git] / tools / perf / ui / browsers / hists.c
index b1b6054..e08b8f7 100644 (file)
 #include "../../util/top.h"
 #include "../../arch/common.h"
 
-#include "../browser.h"
+#include "../browsers/hists.h"
 #include "../helpline.h"
 #include "../util.h"
 #include "../ui.h"
 #include "map.h"
 #include "annotate.h"
 
-struct hist_browser {
-       struct ui_browser   b;
-       struct hists        *hists;
-       struct hist_entry   *he_selection;
-       struct map_symbol   *selection;
-       struct hist_browser_timer *hbt;
-       struct pstack       *pstack;
-       struct perf_env *env;
-       int                  print_seq;
-       bool                 show_dso;
-       bool                 show_headers;
-       float                min_pcnt;
-       u64                  nr_non_filtered_entries;
-       u64                  nr_hierarchy_entries;
-       u64                  nr_callchain_rows;
-};
-
 extern void hist_browser__init_hpp(void);
 
-static int hists__browser_title(struct hists *hists,
-                               struct hist_browser_timer *hbt,
-                               char *bf, size_t size);
+static int perf_evsel_browser_title(struct hist_browser *browser,
+                                   char *bf, size_t size);
 static void hist_browser__update_nr_entries(struct hist_browser *hb);
 
 static struct rb_node *hists__filter_entries(struct rb_node *nd,
@@ -585,7 +567,12 @@ static void ui_browser__warn_lost_events(struct ui_browser *browser)
                "Or reduce the sampling frequency.");
 }
 
-static int hist_browser__run(struct hist_browser *browser, const char *help)
+static int hist_browser__title(struct hist_browser *browser, char *bf, size_t size)
+{
+       return browser->title ? browser->title(browser, bf, size) : 0;
+}
+
+int hist_browser__run(struct hist_browser *browser, const char *help)
 {
        int key;
        char title[160];
@@ -595,7 +582,7 @@ static int hist_browser__run(struct hist_browser *browser, const char *help)
        browser->b.entries = &browser->hists->entries;
        browser->b.nr_entries = hist_browser__nr_entries(browser);
 
-       hists__browser_title(browser->hists, hbt, title, sizeof(title));
+       hist_browser__title(browser, title, sizeof(title));
 
        if (ui_browser__show(&browser->b, title, "%s", help) < 0)
                return -1;
@@ -621,8 +608,7 @@ static int hist_browser__run(struct hist_browser *browser, const char *help)
                                ui_browser__warn_lost_events(&browser->b);
                        }
 
-                       hists__browser_title(browser->hists,
-                                            hbt, title, sizeof(title));
+                       hist_browser__title(browser, title, sizeof(title));
                        ui_browser__show_title(&browser->b, title);
                        continue;
                }
@@ -2056,27 +2042,50 @@ static int hist_browser__dump(struct hist_browser *browser)
        return 0;
 }
 
-static struct hist_browser *hist_browser__new(struct hists *hists,
-                                             struct hist_browser_timer *hbt,
-                                             struct perf_env *env)
+void hist_browser__init(struct hist_browser *browser,
+                       struct hists *hists)
+{
+       struct perf_hpp_fmt *fmt;
+
+       browser->hists                  = hists;
+       browser->b.refresh              = hist_browser__refresh;
+       browser->b.refresh_dimensions   = hist_browser__refresh_dimensions;
+       browser->b.seek                 = ui_browser__hists_seek;
+       browser->b.use_navkeypressed    = true;
+       browser->show_headers           = symbol_conf.show_hist_headers;
+
+       hists__for_each_format(hists, fmt) {
+               perf_hpp__reset_width(fmt, hists);
+               ++browser->b.columns;
+       }
+}
+
+struct hist_browser *hist_browser__new(struct hists *hists)
 {
        struct hist_browser *browser = zalloc(sizeof(*browser));
 
+       if (browser)
+               hist_browser__init(browser, hists);
+
+       return browser;
+}
+
+static struct hist_browser *
+perf_evsel_browser__new(struct perf_evsel *evsel,
+                       struct hist_browser_timer *hbt,
+                       struct perf_env *env)
+{
+       struct hist_browser *browser = hist_browser__new(evsel__hists(evsel));
+
        if (browser) {
-               browser->hists = hists;
-               browser->b.refresh = hist_browser__refresh;
-               browser->b.refresh_dimensions = hist_browser__refresh_dimensions;
-               browser->b.seek = ui_browser__hists_seek;
-               browser->b.use_navkeypressed = true;
-               browser->show_headers = symbol_conf.show_hist_headers;
-               browser->hbt = hbt;
-               browser->env = env;
+               browser->hbt   = hbt;
+               browser->env   = env;
+               browser->title = perf_evsel_browser_title;
        }
-
        return browser;
 }
 
-static void hist_browser__delete(struct hist_browser *browser)
+void hist_browser__delete(struct hist_browser *browser)
 {
        free(browser);
 }
@@ -2097,10 +2106,11 @@ static inline bool is_report_browser(void *timer)
        return timer == NULL;
 }
 
-static int hists__browser_title(struct hists *hists,
-                               struct hist_browser_timer *hbt,
+static int perf_evsel_browser_title(struct hist_browser *browser,
                                char *bf, size_t size)
 {
+       struct hist_browser_timer *hbt = browser->hbt;
+       struct hists *hists = browser->hists;
        char unit;
        int printed;
        const struct dso *dso = hists->dso_filter;
@@ -2657,7 +2667,7 @@ static int perf_evsel__hists_browse(struct perf_evsel *evsel, int nr_events,
                                    struct perf_env *env)
 {
        struct hists *hists = evsel__hists(evsel);
-       struct hist_browser *browser = hist_browser__new(hists, hbt, env);
+       struct hist_browser *browser = perf_evsel_browser__new(evsel, hbt, env);
        struct branch_info *bi;
 #define MAX_OPTIONS  16
        char *options[MAX_OPTIONS];
@@ -2666,7 +2676,6 @@ static int perf_evsel__hists_browse(struct perf_evsel *evsel, int nr_events,
        int key = -1;
        char buf[64];
        int delay_secs = hbt ? hbt->refresh : 0;
-       struct perf_hpp_fmt *fmt;
 
 #define HIST_BROWSER_HELP_COMMON                                       \
        "h/?/F1        Show this window\n"                              \
@@ -2725,18 +2734,6 @@ static int perf_evsel__hists_browse(struct perf_evsel *evsel, int nr_events,
        memset(options, 0, sizeof(options));
        memset(actions, 0, sizeof(actions));
 
-       hists__for_each_format(browser->hists, fmt) {
-               perf_hpp__reset_width(fmt, hists);
-               /*
-                * This is done just once, and activates the horizontal scrolling
-                * code in the ui_browser code, it would be better to have a the
-                * counter in the perf_hpp code, but I couldn't find doing it here
-                * works, FIXME by setting this in hist_browser__new, for now, be
-                * clever 8-)
-                */
-               ++browser->b.columns;
-       }
-
        if (symbol_conf.col_width_list_str)
                perf_hpp__set_user_width(symbol_conf.col_width_list_str);
 
@@ -3202,7 +3199,7 @@ static int __perf_evlist__tui_browse_hists(struct perf_evlist *evlist,
 
        ui_helpline__push("Press ESC to exit");
 
-       evlist__for_each(evlist, pos) {
+       evlist__for_each_entry(evlist, pos) {
                const char *ev_name = perf_evsel__name(pos);
                size_t line_len = strlen(ev_name) + 7;
 
@@ -3233,7 +3230,7 @@ single_entry:
                struct perf_evsel *pos;
 
                nr_entries = 0;
-               evlist__for_each(evlist, pos) {
+               evlist__for_each_entry(evlist, pos) {
                        if (perf_evsel__is_group_leader(pos))
                                nr_entries++;
                }