[PATCH 12/22] perf tools: Add header callback to hist browser

From: Jiri Olsa
Date: Sun Feb 02 2014 - 16:40:20 EST


Adding header callback for hist browser to display
the column headers.

Signed-off-by: Jiri Olsa <jolsa@xxxxxxxxxx>
Cc: Corey Ashford <cjashfor@xxxxxxxxxxxxxxxxxx>
Cc: Frederic Weisbecker <fweisbec@xxxxxxxxx>
Cc: Ingo Molnar <mingo@xxxxxxx>
Cc: Namhyung Kim <namhyung@xxxxxxxxxx>
Cc: Paul Mackerras <paulus@xxxxxxxxx>
Cc: Peter Zijlstra <a.p.zijlstra@xxxxxxxxx>
Cc: Arnaldo Carvalho de Melo <acme@xxxxxxxxxx>
Cc: David Ahern <dsahern@xxxxxxxxx>
---
tools/perf/ui/browser.c | 46 ++++++++++++++++++++++++++++++++----------
tools/perf/ui/browser.h | 2 ++
tools/perf/ui/browsers/hists.c | 25 +++++++++++++++--------
3 files changed, 54 insertions(+), 19 deletions(-)

diff --git a/tools/perf/ui/browser.c b/tools/perf/ui/browser.c
index 31bd6e8..3f8a758 100644
--- a/tools/perf/ui/browser.c
+++ b/tools/perf/ui/browser.c
@@ -250,26 +250,49 @@ void ui_browser__show_title(struct ui_browser *browser, const char *title)
pthread_mutex_unlock(&ui__lock);
}

-int ui_browser__show(struct ui_browser *browser, const char *title,
- const char *helpline, ...)
+static int ui_browser__show_va(struct ui_browser *browser, const char *title,
+ const char *helpline, va_list args)
{
int err;
- va_list ap;
-
- ui_browser__refresh_dimensions(browser);

- pthread_mutex_lock(&ui__lock);
__ui_browser__show_title(browser, title);

browser->title = title;
zfree(&browser->helpline);

- va_start(ap, helpline);
- err = vasprintf(&browser->helpline, helpline, ap);
- va_end(ap);
+ err = vasprintf(&browser->helpline, helpline, args);
if (err > 0)
ui_helpline__push(browser->helpline);
+
+ return err;
+}
+
+int __ui_browser__show(struct ui_browser *browser, const char *title,
+ const char *helpline, ...)
+{
+ va_list args;
+ int err;
+
+ va_start(args, helpline);
+ err = ui_browser__show_va(browser, title, helpline, args);
+ va_end(args);
+
+ return err ? 0 : -1;
+}
+
+int ui_browser__show(struct ui_browser *browser, const char *title,
+ const char *helpline, ...)
+{
+ va_list args;
+ int err;
+
+ pthread_mutex_lock(&ui__lock);
+ ui_browser__refresh_dimensions(browser);
+ va_start(args, helpline);
+ err = ui_browser__show_va(browser, title, helpline, args);
+ va_end(args);
pthread_mutex_unlock(&ui__lock);
+
return err ? 0 : -1;
}

@@ -311,14 +334,15 @@ static void __ui_browser__header(struct ui_browser *browser)

static int __ui_browser__refresh(struct ui_browser *browser)
{
- int row;
- int width = browser->width;
+ int row, width;

__ui_browser__header(browser);

row = browser->ops.refresh(browser);
ui_browser__set_color(browser, HE_COLORSET_NORMAL);

+ width = browser->width;
+
if (!browser->use_navkeypressed || browser->navkeypressed)
ui_browser__scrollbar_set(browser);
else
diff --git a/tools/perf/ui/browser.h b/tools/perf/ui/browser.h
index 73b17b7..7231f39 100644
--- a/tools/perf/ui/browser.h
+++ b/tools/perf/ui/browser.h
@@ -50,6 +50,8 @@ void __ui_browser__line_arrow(struct ui_browser *browser, unsigned int column,
u64 start, u64 end);
void __ui_browser__show_title(struct ui_browser *browser, const char *title);
void ui_browser__show_title(struct ui_browser *browser, const char *title);
+int __ui_browser__show(struct ui_browser *browser, const char *title,
+ const char *helpline, ...);
int ui_browser__show(struct ui_browser *browser, const char *title,
const char *helpline, ...);
void ui_browser__hide(struct ui_browser *browser);
diff --git a/tools/perf/ui/browsers/hists.c b/tools/perf/ui/browsers/hists.c
index b4e789b..9a95fdc 100644
--- a/tools/perf/ui/browsers/hists.c
+++ b/tools/perf/ui/browsers/hists.c
@@ -316,7 +316,6 @@ static int hist_browser__run(struct hist_browser *browser,
struct hist_browser_timer *hbt)
{
int key;
- char title[160];
int delay_secs = hbt ? hbt->refresh : 0;

browser->b.entries = &browser->hists->entries;
@@ -325,11 +324,6 @@ static int hist_browser__run(struct hist_browser *browser,
browser->b.nr_entries = browser->nr_pcnt_entries;

hist_browser__refresh_dimensions(browser);
- hists__browser_title(browser->hists, title, sizeof(title));
-
- if (ui_browser__show(&browser->b, title,
- "Press '?' for help on key bindings") < 0)
- return -1;

while (1) {
key = ui_browser__run(&browser->b, delay_secs);
@@ -355,8 +349,6 @@ static int hist_browser__run(struct hist_browser *browser,
ui_browser__warn_lost_events(&browser->b);
}

- hists__browser_title(browser->hists, title, sizeof(title));
- ui_browser__show_title(&browser->b, title);
continue;
}
case 'D': { /* Debug */
@@ -1209,12 +1201,29 @@ static int hist_browser__dump(struct hist_browser *browser)
return 0;
}

+static unsigned int hist_browser__header(struct ui_browser *b)
+{
+ struct hist_browser *browser;
+ char title[160];
+
+ browser = container_of(b, struct hist_browser, b);
+ ui_browser__refresh_dimensions(b);
+ hists__browser_title(browser->hists, title, sizeof(title));
+
+ if (__ui_browser__show(b, title,
+ "Press '?' for help on key bindings") < 0)
+ return -1;
+
+ return 0;
+}
+
static struct hist_browser *hist_browser__new(struct hists *hists)
{
struct hist_browser *browser = zalloc(sizeof(*browser));

if (browser) {
browser->hists = hists;
+ browser->b.ops.header = hist_browser__header;
browser->b.ops.refresh = hist_browser__refresh;
browser->b.ops.seek = ui_browser__hists_seek;
browser->b.use_navkeypressed = true;
--
1.8.3.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/