2014-01-15 05:08:49

by Namhyung Kim

[permalink] [raw]
Subject: [PATCH/RFC] perf ui/tui: Show column header in hist browser

Add a line for showing column headers like --stdio.

Signed-off-by: Namhyung Kim <[email protected]>
---
tools/perf/ui/browser.c | 4 +--
tools/perf/ui/browsers/hists.c | 55 ++++++++++++++++++++++++++++++++++++++++++
2 files changed, 57 insertions(+), 2 deletions(-)

diff --git a/tools/perf/ui/browser.c b/tools/perf/ui/browser.c
index d11541d4d7d7..441470ba8d2c 100644
--- a/tools/perf/ui/browser.c
+++ b/tools/perf/ui/browser.c
@@ -278,8 +278,8 @@ void ui_browser__hide(struct ui_browser *browser)
static void ui_browser__scrollbar_set(struct ui_browser *browser)
{
int height = browser->height, h = 0, pct = 0,
- col = browser->width,
- row = browser->y - 1;
+ col = browser->width, row = 0;
+

if (browser->nr_entries > 1) {
pct = ((browser->index * (browser->height - 1)) /
diff --git a/tools/perf/ui/browsers/hists.c b/tools/perf/ui/browsers/hists.c
index e0ab399d431d..5b94de48f23c 100644
--- a/tools/perf/ui/browsers/hists.c
+++ b/tools/perf/ui/browsers/hists.c
@@ -25,6 +25,7 @@ struct hist_browser {
struct map_symbol *selection;
int print_seq;
bool show_dso;
+ bool show_column_header;
float min_pcnt;
u64 nr_pcnt_entries;
};
@@ -312,6 +313,57 @@ static void ui_browser__warn_lost_events(struct ui_browser *browser)

static void hist_browser__update_pcnt_entries(struct hist_browser *hb);

+static void hist_browser__column_header(struct hist_browser *browser)
+{
+ struct perf_hpp_fmt *fmt;
+ struct sort_entry *se;
+ struct hists *hists = browser->hists;
+ bool show = browser->show_column_header;
+ unsigned int width;
+
+ pthread_mutex_lock(&ui__lock);
+
+ if (!show)
+ goto out;
+
+ ui_browser__gotorc(&browser->b, 0, 0);
+
+ perf_hpp__for_each_format(fmt) {
+ char buf[128];
+ struct perf_hpp hpp = {
+ .buf = buf,
+ .size = sizeof(buf),
+ .ptr = hists_to_evsel(hists),
+ };
+
+ width = fmt->width(fmt, &hpp);
+ fmt->header(fmt, &hpp);
+
+ slsmg_printf(" %-*s", width, hpp.buf);
+ }
+
+ list_for_each_entry(se, &hist_entry__sort_list, list) {
+ if (se->elide)
+ continue;
+
+ width = strlen(se->se_header);
+ if (!hists__new_col_len(hists, se->se_width_idx, width))
+ width = hists__col_len(hists, se->se_width_idx);
+
+ slsmg_printf(" %-*s", width, se->se_header);
+ }
+
+ /*
+ * We just called ui_browser__refresh_dimensions().
+ * Update it to honor a new column header line.
+ */
+ browser->b.y++;
+ browser->b.height--;
+
+out:
+ pthread_mutex_unlock(&ui__lock);
+}
+
static int hist_browser__run(struct hist_browser *browser, const char *ev_name,
struct hist_browser_timer *hbt)
{
@@ -331,6 +383,8 @@ static int hist_browser__run(struct hist_browser *browser, const char *ev_name,
"Press '?' for help on key bindings") < 0)
return -1;

+ hist_browser__column_header(browser);
+
while (1) {
key = ui_browser__run(&browser->b, delay_secs);

@@ -1198,6 +1252,7 @@ static struct hist_browser *hist_browser__new(struct hists *hists)
browser->b.refresh = hist_browser__refresh;
browser->b.seek = ui_browser__hists_seek;
browser->b.use_navkeypressed = true;
+ browser->show_column_header = true;
}

return browser;
--
1.7.11.7


2014-01-15 12:11:31

by Jiri Olsa

[permalink] [raw]
Subject: Re: [PATCH/RFC] perf ui/tui: Show column header in hist browser

On Wed, Jan 15, 2014 at 02:08:45PM +0900, Namhyung Kim wrote:
> Add a line for showing column headers like --stdio.

https://git.kernel.org/cgit/linux/kernel/git/jolsa/perf.git/commit/?h=perf/lock12&id=1a06d77629cb8870838132688f443b9ca1436026

;-) I'll check your change

jirka

>
> Signed-off-by: Namhyung Kim <[email protected]>
> ---
> tools/perf/ui/browser.c | 4 +--
> tools/perf/ui/browsers/hists.c | 55 ++++++++++++++++++++++++++++++++++++++++++
> 2 files changed, 57 insertions(+), 2 deletions(-)
>
> diff --git a/tools/perf/ui/browser.c b/tools/perf/ui/browser.c
> index d11541d4d7d7..441470ba8d2c 100644
> --- a/tools/perf/ui/browser.c
> +++ b/tools/perf/ui/browser.c
> @@ -278,8 +278,8 @@ void ui_browser__hide(struct ui_browser *browser)
> static void ui_browser__scrollbar_set(struct ui_browser *browser)
> {
> int height = browser->height, h = 0, pct = 0,
> - col = browser->width,
> - row = browser->y - 1;
> + col = browser->width, row = 0;
> +
>
> if (browser->nr_entries > 1) {
> pct = ((browser->index * (browser->height - 1)) /
> diff --git a/tools/perf/ui/browsers/hists.c b/tools/perf/ui/browsers/hists.c
> index e0ab399d431d..5b94de48f23c 100644
> --- a/tools/perf/ui/browsers/hists.c
> +++ b/tools/perf/ui/browsers/hists.c
> @@ -25,6 +25,7 @@ struct hist_browser {
> struct map_symbol *selection;
> int print_seq;
> bool show_dso;
> + bool show_column_header;
> float min_pcnt;
> u64 nr_pcnt_entries;
> };
> @@ -312,6 +313,57 @@ static void ui_browser__warn_lost_events(struct ui_browser *browser)
>
> static void hist_browser__update_pcnt_entries(struct hist_browser *hb);
>
> +static void hist_browser__column_header(struct hist_browser *browser)
> +{
> + struct perf_hpp_fmt *fmt;
> + struct sort_entry *se;
> + struct hists *hists = browser->hists;
> + bool show = browser->show_column_header;
> + unsigned int width;
> +
> + pthread_mutex_lock(&ui__lock);
> +
> + if (!show)
> + goto out;
> +
> + ui_browser__gotorc(&browser->b, 0, 0);
> +
> + perf_hpp__for_each_format(fmt) {
> + char buf[128];
> + struct perf_hpp hpp = {
> + .buf = buf,
> + .size = sizeof(buf),
> + .ptr = hists_to_evsel(hists),
> + };
> +
> + width = fmt->width(fmt, &hpp);
> + fmt->header(fmt, &hpp);
> +
> + slsmg_printf(" %-*s", width, hpp.buf);
> + }
> +
> + list_for_each_entry(se, &hist_entry__sort_list, list) {
> + if (se->elide)
> + continue;
> +
> + width = strlen(se->se_header);
> + if (!hists__new_col_len(hists, se->se_width_idx, width))
> + width = hists__col_len(hists, se->se_width_idx);
> +
> + slsmg_printf(" %-*s", width, se->se_header);
> + }
> +
> + /*
> + * We just called ui_browser__refresh_dimensions().
> + * Update it to honor a new column header line.
> + */
> + browser->b.y++;
> + browser->b.height--;
> +
> +out:
> + pthread_mutex_unlock(&ui__lock);
> +}
> +
> static int hist_browser__run(struct hist_browser *browser, const char *ev_name,
> struct hist_browser_timer *hbt)
> {
> @@ -331,6 +383,8 @@ static int hist_browser__run(struct hist_browser *browser, const char *ev_name,
> "Press '?' for help on key bindings") < 0)
> return -1;
>
> + hist_browser__column_header(browser);
> +
> while (1) {
> key = ui_browser__run(&browser->b, delay_secs);
>
> @@ -1198,6 +1252,7 @@ static struct hist_browser *hist_browser__new(struct hists *hists)
> browser->b.refresh = hist_browser__refresh;
> browser->b.seek = ui_browser__hists_seek;
> browser->b.use_navkeypressed = true;
> + browser->show_column_header = true;
> }
>
> return browser;
> --
> 1.7.11.7
>

2014-01-15 14:21:34

by Arnaldo Carvalho de Melo

[permalink] [raw]
Subject: Re: [PATCH/RFC] perf ui/tui: Show column header in hist browser

Em Wed, Jan 15, 2014 at 01:10:44PM +0100, Jiri Olsa escreveu:
> On Wed, Jan 15, 2014 at 02:08:45PM +0900, Namhyung Kim wrote:
> > Add a line for showing column headers like --stdio.
>
> https://git.kernel.org/cgit/linux/kernel/git/jolsa/perf.git/commit/?h=perf/lock12&id=1a06d77629cb8870838132688f443b9ca1436026
>
> ;-) I'll check your change

>From a quick view, your change looks better, i.e. being able to toggle
the header line.

Please let me know what you guys end up agreeing is best.

- Arnaldo

> jirka
>
> >
> > Signed-off-by: Namhyung Kim <[email protected]>
> > ---
> > tools/perf/ui/browser.c | 4 +--
> > tools/perf/ui/browsers/hists.c | 55 ++++++++++++++++++++++++++++++++++++++++++
> > 2 files changed, 57 insertions(+), 2 deletions(-)
> >
> > diff --git a/tools/perf/ui/browser.c b/tools/perf/ui/browser.c
> > index d11541d4d7d7..441470ba8d2c 100644
> > --- a/tools/perf/ui/browser.c
> > +++ b/tools/perf/ui/browser.c
> > @@ -278,8 +278,8 @@ void ui_browser__hide(struct ui_browser *browser)
> > static void ui_browser__scrollbar_set(struct ui_browser *browser)
> > {
> > int height = browser->height, h = 0, pct = 0,
> > - col = browser->width,
> > - row = browser->y - 1;
> > + col = browser->width, row = 0;
> > +
> >
> > if (browser->nr_entries > 1) {
> > pct = ((browser->index * (browser->height - 1)) /
> > diff --git a/tools/perf/ui/browsers/hists.c b/tools/perf/ui/browsers/hists.c
> > index e0ab399d431d..5b94de48f23c 100644
> > --- a/tools/perf/ui/browsers/hists.c
> > +++ b/tools/perf/ui/browsers/hists.c
> > @@ -25,6 +25,7 @@ struct hist_browser {
> > struct map_symbol *selection;
> > int print_seq;
> > bool show_dso;
> > + bool show_column_header;
> > float min_pcnt;
> > u64 nr_pcnt_entries;
> > };
> > @@ -312,6 +313,57 @@ static void ui_browser__warn_lost_events(struct ui_browser *browser)
> >
> > static void hist_browser__update_pcnt_entries(struct hist_browser *hb);
> >
> > +static void hist_browser__column_header(struct hist_browser *browser)
> > +{
> > + struct perf_hpp_fmt *fmt;
> > + struct sort_entry *se;
> > + struct hists *hists = browser->hists;
> > + bool show = browser->show_column_header;
> > + unsigned int width;
> > +
> > + pthread_mutex_lock(&ui__lock);
> > +
> > + if (!show)
> > + goto out;
> > +
> > + ui_browser__gotorc(&browser->b, 0, 0);
> > +
> > + perf_hpp__for_each_format(fmt) {
> > + char buf[128];
> > + struct perf_hpp hpp = {
> > + .buf = buf,
> > + .size = sizeof(buf),
> > + .ptr = hists_to_evsel(hists),
> > + };
> > +
> > + width = fmt->width(fmt, &hpp);
> > + fmt->header(fmt, &hpp);
> > +
> > + slsmg_printf(" %-*s", width, hpp.buf);
> > + }
> > +
> > + list_for_each_entry(se, &hist_entry__sort_list, list) {
> > + if (se->elide)
> > + continue;
> > +
> > + width = strlen(se->se_header);
> > + if (!hists__new_col_len(hists, se->se_width_idx, width))
> > + width = hists__col_len(hists, se->se_width_idx);
> > +
> > + slsmg_printf(" %-*s", width, se->se_header);
> > + }
> > +
> > + /*
> > + * We just called ui_browser__refresh_dimensions().
> > + * Update it to honor a new column header line.
> > + */
> > + browser->b.y++;
> > + browser->b.height--;
> > +
> > +out:
> > + pthread_mutex_unlock(&ui__lock);
> > +}
> > +
> > static int hist_browser__run(struct hist_browser *browser, const char *ev_name,
> > struct hist_browser_timer *hbt)
> > {
> > @@ -331,6 +383,8 @@ static int hist_browser__run(struct hist_browser *browser, const char *ev_name,
> > "Press '?' for help on key bindings") < 0)
> > return -1;
> >
> > + hist_browser__column_header(browser);
> > +
> > while (1) {
> > key = ui_browser__run(&browser->b, delay_secs);
> >
> > @@ -1198,6 +1252,7 @@ static struct hist_browser *hist_browser__new(struct hists *hists)
> > browser->b.refresh = hist_browser__refresh;
> > browser->b.seek = ui_browser__hists_seek;
> > browser->b.use_navkeypressed = true;
> > + browser->show_column_header = true;
> > }
> >
> > return browser;
> > --
> > 1.7.11.7
> >

2014-01-16 00:42:28

by Namhyung Kim

[permalink] [raw]
Subject: Re: [PATCH/RFC] perf ui/tui: Show column header in hist browser

Hi Arnaldo and Jiri,

On Wed, 15 Jan 2014 11:13:14 -0300, Arnaldo Carvalho de Melo wrote:
> Em Wed, Jan 15, 2014 at 01:10:44PM +0100, Jiri Olsa escreveu:
>> On Wed, Jan 15, 2014 at 02:08:45PM +0900, Namhyung Kim wrote:
>> > Add a line for showing column headers like --stdio.
>>
>> https://git.kernel.org/cgit/linux/kernel/git/jolsa/perf.git/commit/?h=perf/lock12&id=1a06d77629cb8870838132688f443b9ca1436026
>>
>> ;-) I'll check your change
>
> From a quick view, your change looks better, i.e. being able to toggle
> the header line.
>
> Please let me know what you guys end up agreeing is best.

Yes, looking at the source, Jiri's version looks much better. I was
lazy for sorting column width and supporting a hotkey for toggling. :)
I just wanted to see how you guys think, so the rfc.

Thanks,
Namhyung

2014-01-16 08:25:17

by Jiri Olsa

[permalink] [raw]
Subject: Re: [PATCH/RFC] perf ui/tui: Show column header in hist browser

On Thu, Jan 16, 2014 at 09:42:23AM +0900, Namhyung Kim wrote:
> Hi Arnaldo and Jiri,
>
> On Wed, 15 Jan 2014 11:13:14 -0300, Arnaldo Carvalho de Melo wrote:
> > Em Wed, Jan 15, 2014 at 01:10:44PM +0100, Jiri Olsa escreveu:
> >> On Wed, Jan 15, 2014 at 02:08:45PM +0900, Namhyung Kim wrote:
> >> > Add a line for showing column headers like --stdio.
> >>
> >> https://git.kernel.org/cgit/linux/kernel/git/jolsa/perf.git/commit/?h=perf/lock12&id=1a06d77629cb8870838132688f443b9ca1436026
> >>
> >> ;-) I'll check your change
> >
> > From a quick view, your change looks better, i.e. being able to toggle
> > the header line.
> >
> > Please let me know what you guys end up agreeing is best.
>
> Yes, looking at the source, Jiri's version looks much better. I was
> lazy for sorting column width and supporting a hotkey for toggling. :)
> I just wanted to see how you guys think, so the rfc.

ok, I'll send it out soon with my other changes

thanks,
jirka