[PATCH 7/8] perf tools: Introduce hist_browser__init

From: Jiri Olsa
Date: Mon Jun 20 2016 - 17:59:23 EST


Factoring out the hist_browser initialization code,
so it could be used from other parts in following
patches.

Link: http://lkml.kernel.org/n/tip-wpnz9geiwesk0stkiumwc904@xxxxxxxxxxxxxx
Signed-off-by: Jiri Olsa <jolsa@xxxxxxxxxx>
---
tools/perf/ui/browsers/hists.c | 35 ++++++++++++++++++++---------------
tools/perf/ui/browsers/hists.h | 2 ++
2 files changed, 22 insertions(+), 15 deletions(-)

diff --git a/tools/perf/ui/browsers/hists.c b/tools/perf/ui/browsers/hists.c
index fcb06b413325..196e2a87765a 100644
--- a/tools/perf/ui/browsers/hists.c
+++ b/tools/perf/ui/browsers/hists.c
@@ -2042,25 +2042,30 @@ static int hist_browser__dump(struct hist_browser *browser)
return 0;
}

+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) {
- 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;
- }
- }
+ if (browser)
+ hist_browser__init(browser, hists);

return browser;
}
diff --git a/tools/perf/ui/browsers/hists.h b/tools/perf/ui/browsers/hists.h
index ec55a511d910..39bd0f28f211 100644
--- a/tools/perf/ui/browsers/hists.h
+++ b/tools/perf/ui/browsers/hists.h
@@ -27,4 +27,6 @@ struct hist_browser {
struct hist_browser *hist_browser__new(struct hists *hists);
void hist_browser__delete(struct hist_browser *browser);
int hist_browser__run(struct hist_browser *browser, const char *help);
+void hist_browser__init(struct hist_browser *browser,
+ struct hists *hists);
#endif /* _PERF_UI_BROWSER_HISTS_H_ */
--
2.4.11