public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [RFC 1/4] perf ui progress: Add size info into progress bar
@ 2017-09-08 12:05 Jiri Olsa
  2017-09-08 12:05 ` [PATCH 1/4] perf ui progress: Make sure we always define step value Jiri Olsa
                   ` (4 more replies)
  0 siblings, 5 replies; 13+ messages in thread
From: Jiri Olsa @ 2017-09-08 12:05 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: lkml, Ingo Molnar, Namhyung Kim, David Ahern, Peter Zijlstra

hi,
sending some progress bar fixes.

thanks,
jirka

---
 tools/perf/ui/progress.c     | 15 ++++++++++++---
 tools/perf/ui/progress.h     | 12 +++++++++++-
 tools/perf/ui/tui/progress.c | 32 +++++++++++++++++++++++++++++---
 tools/perf/util/session.c    |  2 +-
 4 files changed, 53 insertions(+), 8 deletions(-)

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH 1/4] perf ui progress: Make sure we always define step value
  2017-09-08 12:05 [RFC 1/4] perf ui progress: Add size info into progress bar Jiri Olsa
@ 2017-09-08 12:05 ` Jiri Olsa
  2017-09-08 13:16   ` Milian Wolff
  2017-09-13  7:44   ` [tip:perf/urgent] " tip-bot for Jiri Olsa
  2017-09-08 12:05 ` [PATCH 2/4] perf ui progress: Fix progress update Jiri Olsa
                   ` (3 subsequent siblings)
  4 siblings, 2 replies; 13+ messages in thread
From: Jiri Olsa @ 2017-09-08 12:05 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: lkml, Ingo Molnar, Namhyung Kim, David Ahern, Peter Zijlstra

Unlikely, but we could have ui_progress__init being called
with total < 16, which would set the next and step variables
to 0. That would force unnecessary ui_progress__ops->update
calls because 'next' would never raise.

Forcing the next and step values to be always > 0.

Link: http://lkml.kernel.org/n/tip-0zcvhmsmbhkfgoi7c670rq2x@git.kernel.org
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
 tools/perf/ui/progress.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/perf/ui/progress.c b/tools/perf/ui/progress.c
index a0f24c7115c5..a9c15804b1f6 100644
--- a/tools/perf/ui/progress.c
+++ b/tools/perf/ui/progress.c
@@ -25,7 +25,7 @@ void ui_progress__update(struct ui_progress *p, u64 adv)
 void ui_progress__init(struct ui_progress *p, u64 total, const char *title)
 {
 	p->curr = 0;
-	p->next = p->step = total / 16;
+	p->next = p->step = total / 16 ?: 1;
 	p->total = total;
 	p->title = title;
 
-- 
2.9.5

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH 2/4] perf ui progress: Fix progress update
  2017-09-08 12:05 [RFC 1/4] perf ui progress: Add size info into progress bar Jiri Olsa
  2017-09-08 12:05 ` [PATCH 1/4] perf ui progress: Make sure we always define step value Jiri Olsa
@ 2017-09-08 12:05 ` Jiri Olsa
  2017-09-13  7:45   ` [tip:perf/urgent] " tip-bot for Jiri Olsa
  2017-09-08 12:05 ` [PATCH 3/4] perf ui progress: Add ui specific init function Jiri Olsa
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 13+ messages in thread
From: Jiri Olsa @ 2017-09-08 12:05 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: lkml, Ingo Molnar, Namhyung Kim, David Ahern, Peter Zijlstra

We currently update the 'next' variable only with a single
step value. But it's possible the 'adv' update is bigger
than single 'step' value. This would leave 'next' value
under counted and force unnecessary ui_progress__ops->update
calls.

Calculate the amount of steps we need for 'adv' update
and increase the 'next' with that amounts of steps.

Link: http://lkml.kernel.org/n/tip-4xtvcl0ykeg3ndg2gg46kvyn@git.kernel.org
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
 tools/perf/ui/progress.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/tools/perf/ui/progress.c b/tools/perf/ui/progress.c
index a9c15804b1f6..ae91c8148edf 100644
--- a/tools/perf/ui/progress.c
+++ b/tools/perf/ui/progress.c
@@ -1,3 +1,4 @@
+#include <linux/kernel.h>
 #include "../cache.h"
 #include "progress.h"
 
@@ -14,10 +15,14 @@ struct ui_progress_ops *ui_progress__ops = &null_progress__ops;
 
 void ui_progress__update(struct ui_progress *p, u64 adv)
 {
+	u64 last = p->curr;
+
 	p->curr += adv;
 
 	if (p->curr >= p->next) {
-		p->next += p->step;
+		u64 nr = DIV_ROUND_UP(p->curr - last, p->step);
+
+		p->next += nr * p->step;
 		ui_progress__ops->update(p);
 	}
 }
-- 
2.9.5

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH 3/4] perf ui progress: Add ui specific init function
  2017-09-08 12:05 [RFC 1/4] perf ui progress: Add size info into progress bar Jiri Olsa
  2017-09-08 12:05 ` [PATCH 1/4] perf ui progress: Make sure we always define step value Jiri Olsa
  2017-09-08 12:05 ` [PATCH 2/4] perf ui progress: Fix progress update Jiri Olsa
@ 2017-09-08 12:05 ` Jiri Olsa
  2017-09-22 16:34   ` [tip:perf/core] " tip-bot for Jiri Olsa
  2017-09-08 12:05 ` [PATCH 4/4] perf ui progress: Add size info into progress bar Jiri Olsa
  2017-09-08 13:45 ` [RFC 1/4] " Arnaldo Carvalho de Melo
  4 siblings, 1 reply; 13+ messages in thread
From: Jiri Olsa @ 2017-09-08 12:05 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: lkml, Ingo Molnar, Namhyung Kim, David Ahern, Peter Zijlstra

Adding ui specific init function allowing to setup the
progress bar width based on current screen scales.

Adding TUI init function to get more grained update
of the progress bar.

Link: http://lkml.kernel.org/n/tip-tiuspugnjv3o3qbuugsvkgf3@git.kernel.org
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
 tools/perf/ui/progress.c     | 2 ++
 tools/perf/ui/progress.h     | 1 +
 tools/perf/ui/tui/progress.c | 9 +++++++--
 3 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/tools/perf/ui/progress.c b/tools/perf/ui/progress.c
index ae91c8148edf..3e2b5d64c55e 100644
--- a/tools/perf/ui/progress.c
+++ b/tools/perf/ui/progress.c
@@ -34,6 +34,8 @@ void ui_progress__init(struct ui_progress *p, u64 total, const char *title)
 	p->total = total;
 	p->title = title;
 
+	if (ui_progress__ops->init)
+		ui_progress__ops->init(p);
 }
 
 void ui_progress__finish(void)
diff --git a/tools/perf/ui/progress.h b/tools/perf/ui/progress.h
index 717d39d3052b..e5f434a2070b 100644
--- a/tools/perf/ui/progress.h
+++ b/tools/perf/ui/progress.h
@@ -14,6 +14,7 @@ void ui_progress__init(struct ui_progress *p, u64 total, const char *title);
 void ui_progress__update(struct ui_progress *p, u64 adv);
 
 struct ui_progress_ops {
+	void (*init)(struct ui_progress *p);
 	void (*update)(struct ui_progress *p);
 	void (*finish)(void);
 };
diff --git a/tools/perf/ui/tui/progress.c b/tools/perf/ui/tui/progress.c
index c4b99008e2c9..f6b8f52aad7e 100644
--- a/tools/perf/ui/tui/progress.c
+++ b/tools/perf/ui/tui/progress.c
@@ -5,6 +5,11 @@
 #include "tui.h"
 #include "../browser.h"
 
+static void __tui_progress__init(struct ui_progress *p)
+{
+	p->next = p->step = p->total / (SLtt_Screen_Cols - 2) ?: 1;
+}
+
 static void tui_progress__update(struct ui_progress *p)
 {
 	int bar, y;
@@ -49,8 +54,8 @@ static void tui_progress__finish(void)
 	pthread_mutex_unlock(&ui__lock);
 }
 
-static struct ui_progress_ops tui_progress__ops =
-{
+static struct ui_progress_ops tui_progress__ops = {
+	.init   = __tui_progress__init,
 	.update = tui_progress__update,
 	.finish = tui_progress__finish,
 };
-- 
2.9.5

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH 4/4] perf ui progress: Add size info into progress bar
  2017-09-08 12:05 [RFC 1/4] perf ui progress: Add size info into progress bar Jiri Olsa
                   ` (2 preceding siblings ...)
  2017-09-08 12:05 ` [PATCH 3/4] perf ui progress: Add ui specific init function Jiri Olsa
@ 2017-09-08 12:05 ` Jiri Olsa
  2017-09-22 16:35   ` [tip:perf/core] " tip-bot for Jiri Olsa
  2017-09-08 13:45 ` [RFC 1/4] " Arnaldo Carvalho de Melo
  4 siblings, 1 reply; 13+ messages in thread
From: Jiri Olsa @ 2017-09-08 12:05 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: lkml, Ingo Molnar, Namhyung Kim, David Ahern, Peter Zijlstra

Adding the size values '[current/total]' into progress bar,
to show more detailed progress of data reading.

Adding new ui_progress__init_size function to specify we
want to display the size.

Link: http://lkml.kernel.org/n/tip-39wn4d77phel3dgkzo3lyan0@git.kernel.org
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
 tools/perf/ui/progress.c     |  4 +++-
 tools/perf/ui/progress.h     | 11 ++++++++++-
 tools/perf/ui/tui/progress.c | 23 ++++++++++++++++++++++-
 tools/perf/util/session.c    |  2 +-
 4 files changed, 36 insertions(+), 4 deletions(-)

diff --git a/tools/perf/ui/progress.c b/tools/perf/ui/progress.c
index 3e2b5d64c55e..7ade387d511c 100644
--- a/tools/perf/ui/progress.c
+++ b/tools/perf/ui/progress.c
@@ -27,12 +27,14 @@ void ui_progress__update(struct ui_progress *p, u64 adv)
 	}
 }
 
-void ui_progress__init(struct ui_progress *p, u64 total, const char *title)
+void __ui_progress__init(struct ui_progress *p, u64 total,
+			 const char *title, bool size)
 {
 	p->curr = 0;
 	p->next = p->step = total / 16 ?: 1;
 	p->total = total;
 	p->title = title;
+	p->size  = size;
 
 	if (ui_progress__ops->init)
 		ui_progress__ops->init(p);
diff --git a/tools/perf/ui/progress.h b/tools/perf/ui/progress.h
index e5f434a2070b..fbaa1507ebfe 100644
--- a/tools/perf/ui/progress.h
+++ b/tools/perf/ui/progress.h
@@ -8,9 +8,18 @@ void ui_progress__finish(void);
 struct ui_progress {
 	const char *title;
 	u64 curr, next, step, total;
+	bool size;
 };
 
-void ui_progress__init(struct ui_progress *p, u64 total, const char *title);
+void __ui_progress__init(struct ui_progress *p, u64 total,
+			 const char *title, bool size);
+
+#define ui_progress__init(p, total, title) \
+	__ui_progress__init(p, total, title, false)
+
+#define ui_progress__init_size(p, total, title) \
+	__ui_progress__init(p, total, title, true)
+
 void ui_progress__update(struct ui_progress *p, u64 adv);
 
 struct ui_progress_ops {
diff --git a/tools/perf/ui/tui/progress.c b/tools/perf/ui/tui/progress.c
index f6b8f52aad7e..68f6144ea603 100644
--- a/tools/perf/ui/tui/progress.c
+++ b/tools/perf/ui/tui/progress.c
@@ -1,8 +1,10 @@
+#include <linux/kernel.h>
 #include "../cache.h"
 #include "../progress.h"
 #include "../libslang.h"
 #include "../ui.h"
 #include "tui.h"
+#include "units.h"
 #include "../browser.h"
 
 static void __tui_progress__init(struct ui_progress *p)
@@ -10,8 +12,22 @@ static void __tui_progress__init(struct ui_progress *p)
 	p->next = p->step = p->total / (SLtt_Screen_Cols - 2) ?: 1;
 }
 
+static int get_title(struct ui_progress *p, char *buf, size_t size)
+{
+	char buf_cur[20];
+	char buf_tot[20];
+	int ret;
+
+	ret  = unit_number__scnprintf(buf_cur, sizeof(buf_cur), p->curr);
+	ret += unit_number__scnprintf(buf_tot, sizeof(buf_tot), p->total);
+
+	return ret + scnprintf(buf, size, "%s [%s/%s]",
+			       p->title, buf_cur, buf_tot);
+}
+
 static void tui_progress__update(struct ui_progress *p)
 {
+	char buf[100], *title = (char *) p->title;
 	int bar, y;
 	/*
 	 * FIXME: We should have a per UI backend way of showing progress,
@@ -23,13 +39,18 @@ static void tui_progress__update(struct ui_progress *p)
 	if (p->total == 0)
 		return;
 
+	if (p->size) {
+		get_title(p, buf, sizeof(buf));
+		title = buf;
+	}
+
 	ui__refresh_dimensions(false);
 	pthread_mutex_lock(&ui__lock);
 	y = SLtt_Screen_Rows / 2 - 2;
 	SLsmg_set_color(0);
 	SLsmg_draw_box(y, 0, 3, SLtt_Screen_Cols);
 	SLsmg_gotorc(y++, 1);
-	SLsmg_write_string((char *)p->title);
+	SLsmg_write_string(title);
 	SLsmg_fill_region(y, 1, 1, SLtt_Screen_Cols - 2, ' ');
 	SLsmg_set_color(HE_COLORSET_SELECTED);
 	bar = ((SLtt_Screen_Cols - 2) * p->curr) / p->total;
diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c
index a7ebd9fe8e40..ceac0848469d 100644
--- a/tools/perf/util/session.c
+++ b/tools/perf/util/session.c
@@ -1847,7 +1847,7 @@ static int __perf_session__process_events(struct perf_session *session,
 	if (data_offset + data_size < file_size)
 		file_size = data_offset + data_size;
 
-	ui_progress__init(&prog, file_size, "Processing events...");
+	ui_progress__init_size(&prog, file_size, "Processing events...");
 
 	mmap_size = MMAP_SIZE;
 	if (mmap_size > file_size) {
-- 
2.9.5

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* Re: [PATCH 1/4] perf ui progress: Make sure we always define step value
  2017-09-08 12:05 ` [PATCH 1/4] perf ui progress: Make sure we always define step value Jiri Olsa
@ 2017-09-08 13:16   ` Milian Wolff
  2017-09-08 13:26     ` Arnaldo Carvalho de Melo
  2017-09-13  7:44   ` [tip:perf/urgent] " tip-bot for Jiri Olsa
  1 sibling, 1 reply; 13+ messages in thread
From: Milian Wolff @ 2017-09-08 13:16 UTC (permalink / raw)
  To: Jiri Olsa
  Cc: Arnaldo Carvalho de Melo, lkml, Ingo Molnar, Namhyung Kim,
	David Ahern, Peter Zijlstra

On Freitag, 8. September 2017 14:05:07 CEST Jiri Olsa wrote:
> Unlikely, but we could have ui_progress__init being called
> with total < 16, which would set the next and step variables
> to 0. That would force unnecessary ui_progress__ops->update
> calls because 'next' would never raise.
> 
> Forcing the next and step values to be always > 0.
> 
> Link: http://lkml.kernel.org/n/tip-0zcvhmsmbhkfgoi7c670rq2x@git.kernel.org
> Signed-off-by: Jiri Olsa <jolsa@kernel.org>
> ---
>  tools/perf/ui/progress.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/tools/perf/ui/progress.c b/tools/perf/ui/progress.c
> index a0f24c7115c5..a9c15804b1f6 100644
> --- a/tools/perf/ui/progress.c
> +++ b/tools/perf/ui/progress.c
> @@ -25,7 +25,7 @@ void ui_progress__update(struct ui_progress *p, u64 adv)
>  void ui_progress__init(struct ui_progress *p, u64 total, const char *title)
> {
>  	p->curr = 0;
> -	p->next = p->step = total / 16;
> +	p->next = p->step = total / 16 ?: 1;
>  	p->total = total;
>  	p->title = title;

This is a GNU extension, does this compile with clang?

Cheers

-- 
Milian Wolff | milian.wolff@kdab.com | Senior Software Engineer
KDAB (Deutschland) GmbH&Co KG, a KDAB Group company
Tel: +49-30-521325470
KDAB - The Qt Experts

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 1/4] perf ui progress: Make sure we always define step value
  2017-09-08 13:16   ` Milian Wolff
@ 2017-09-08 13:26     ` Arnaldo Carvalho de Melo
  2017-09-09 10:09       ` Milian Wolff
  0 siblings, 1 reply; 13+ messages in thread
From: Arnaldo Carvalho de Melo @ 2017-09-08 13:26 UTC (permalink / raw)
  To: Milian Wolff
  Cc: Jiri Olsa, lkml, Ingo Molnar, Namhyung Kim, David Ahern,
	Peter Zijlstra

Em Fri, Sep 08, 2017 at 03:16:37PM +0200, Milian Wolff escreveu:
> On Freitag, 8. September 2017 14:05:07 CEST Jiri Olsa wrote:
> > +++ b/tools/perf/ui/progress.c
> > @@ -25,7 +25,7 @@ void ui_progress__update(struct ui_progress *p, u64 adv)
> >  void ui_progress__init(struct ui_progress *p, u64 total, const char *title)
> > {
> >  	p->curr = 0;
> > -	p->next = p->step = total / 16;
> > +	p->next = p->step = total / 16 ?: 1;
> >  	p->total = total;
> >  	p->title = title;
> 
> This is a GNU extension, does this compile with clang?

Huh?

[acme@jouet linux]$ find tools/ -name "*.[ch]"| xargs grep ?: | wc -l
64
[acme@jouet linux]$ find . -name "*.[ch]"| xargs grep ?: | wc -l
725
[acme@jouet linux]$

And yes, tools/perf/ is built with clang regularly, I use containers to
test build the tools/{perf,lib} codebase with gcc and clang on almost
all distros, things like:

[acme@jouet linux]$ cat ~/git/linux-perf-tools-build/fedora/26/Dockerfile 
# docker.io/acmel/linux-perf-tools-build-fedora:26
FROM docker.io/fedora:26
MAINTAINER Arnaldo Carvalho de Melo <acme@kernel.org>
# The second dnf line is to be able to build a kernel, do a make header_install, etc,
# So that we can build samples/bpf/ and the kernel
RUN dnf -y install make gcc flex bison elfutils-libelf-devel \
		   bc findutils clang llvm openssl git \
		   elfutils-devel libunwind-devel audit-libs-devel \
		   openssl-devel slang-devel gtk2-devel perl-ExtUtils-Embed \
		   python-devel binutils-devel xz-devel numactl-devel systemtap-sdt-devel \
		   redhat-rpm-config && \
    dnf -y clean all && \
    rm -rf /usr/share/doc /usr/share/gtk-doc /usr/share/locale /usr/share/man && \
    mkdir -m 777 -p /tmp/build/perf /tmp/build/objtool /tmp/build/linux && \
    groupadd -r perfbuilder && \
    useradd -m -r -g perfbuilder perfbuilder && \
    chown -R perfbuilder.perfbuilder /tmp/build
USER perfbuilder
ENTRYPOINT make -C /git/linux/tools/perf O=/tmp/build/perf && \
           rm -rf /tmp/build/perf/{.[^.]*,*} && \
           make -C /git/linux/tools/perf O=/tmp/build/perf CC=clang && \
           rm -rf /tmp/build/perf/{.[^.]*,*} && \
           make NO_LIBELF=1 -C /git/linux/tools/perf O=/tmp/build/perf && \
           rm -rf /tmp/build/perf/{.[^.]*,*} && \
           make NO_LIBELF=1 -C /git/linux/tools/perf O=/tmp/build/perf CC=clang && \
           make -C /git/linux/tools/objtool O=/tmp/build/objtool && \
           make -C /git/linux O=/tmp/build/linux defconfig && \
           make -C /git/linux O=/tmp/build/linux headers_install && \
           make -C /git/linux O=/tmp/build/linux samples/bpf/
[acme@jouet linux]$

- Arnaldo

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [RFC 1/4] perf ui progress: Add size info into progress bar
  2017-09-08 12:05 [RFC 1/4] perf ui progress: Add size info into progress bar Jiri Olsa
                   ` (3 preceding siblings ...)
  2017-09-08 12:05 ` [PATCH 4/4] perf ui progress: Add size info into progress bar Jiri Olsa
@ 2017-09-08 13:45 ` Arnaldo Carvalho de Melo
  4 siblings, 0 replies; 13+ messages in thread
From: Arnaldo Carvalho de Melo @ 2017-09-08 13:45 UTC (permalink / raw)
  To: Jiri Olsa; +Cc: lkml, Ingo Molnar, Namhyung Kim, David Ahern, Peter Zijlstra

Em Fri, Sep 08, 2017 at 02:05:06PM +0200, Jiri Olsa escreveu:
> hi,
> sending some progress bar fixes.

Thanks, tested and applied.

- Arnaldo

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 1/4] perf ui progress: Make sure we always define step value
  2017-09-08 13:26     ` Arnaldo Carvalho de Melo
@ 2017-09-09 10:09       ` Milian Wolff
  0 siblings, 0 replies; 13+ messages in thread
From: Milian Wolff @ 2017-09-09 10:09 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: Jiri Olsa, lkml, Ingo Molnar, Namhyung Kim, David Ahern,
	Peter Zijlstra

On Freitag, 8. September 2017 15:26:42 CEST Arnaldo Carvalho de Melo wrote:
> Em Fri, Sep 08, 2017 at 03:16:37PM +0200, Milian Wolff escreveu:
> > On Freitag, 8. September 2017 14:05:07 CEST Jiri Olsa wrote:
> > > +++ b/tools/perf/ui/progress.c
> > > @@ -25,7 +25,7 @@ void ui_progress__update(struct ui_progress *p, u64
> > > adv)
> > > 
> > >  void ui_progress__init(struct ui_progress *p, u64 total, const char
> > >  *title)
> > > 
> > > {
> > > 
> > >  	p->curr = 0;
> > > 
> > > -	p->next = p->step = total / 16;
> > > +	p->next = p->step = total / 16 ?: 1;
> > > 
> > >  	p->total = total;
> > >  	p->title = title;
> > 
> > This is a GNU extension, does this compile with clang?
> 
> Huh?
> 
> [acme@jouet linux]$ find tools/ -name "*.[ch]"| xargs grep ?: | wc -l
> 64
> [acme@jouet linux]$ find . -name "*.[ch]"| xargs grep ?: | wc -l
> 725
> [acme@jouet linux]$
> 
> And yes, tools/perf/ is built with clang regularly, I use containers to
> test build the tools/{perf,lib} codebase with gcc and clang on almost
> all distros, things like:

OK, thanks for the clarification. I was wondering because I didn't know about 
this syntax. Googling I found this: https://en.wikipedia.org/wiki/%3F:#C

Quote:

> A GNU extension to C allows omitting the second operand, and using 
implicitly the first operand as the second also:
>
>     a = x ? : y;

Cheers

-- 
Milian Wolff | milian.wolff@kdab.com | Senior Software Engineer
KDAB (Deutschland) GmbH&Co KG, a KDAB Group company
Tel: +49-30-521325470
KDAB - The Qt Experts

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [tip:perf/urgent] perf ui progress: Make sure we always define step value
  2017-09-08 12:05 ` [PATCH 1/4] perf ui progress: Make sure we always define step value Jiri Olsa
  2017-09-08 13:16   ` Milian Wolff
@ 2017-09-13  7:44   ` tip-bot for Jiri Olsa
  1 sibling, 0 replies; 13+ messages in thread
From: tip-bot for Jiri Olsa @ 2017-09-13  7:44 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: acme, linux-kernel, namhyung, tglx, hpa, mingo, dsahern,
	a.p.zijlstra, jolsa

Commit-ID:  4d286c89e412fc2eaa1b8988481d2f32b5e3826f
Gitweb:     http://git.kernel.org/tip/4d286c89e412fc2eaa1b8988481d2f32b5e3826f
Author:     Jiri Olsa <jolsa@kernel.org>
AuthorDate: Fri, 8 Sep 2017 14:05:07 +0200
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Tue, 12 Sep 2017 12:34:46 -0300

perf ui progress: Make sure we always define step value

Unlikely, but we could have ui_progress__init being called with total <
16, which would set the next and step variables to 0. That would force
unnecessary ui_progress__ops->update calls because 'next' would never
raise.

Forcing the next and step values to be always > 0.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Cc: David Ahern <dsahern@gmail.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: http://lkml.kernel.org/r/20170908120510.22515-2-jolsa@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/ui/progress.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/perf/ui/progress.c b/tools/perf/ui/progress.c
index a0f24c7..a9c1580 100644
--- a/tools/perf/ui/progress.c
+++ b/tools/perf/ui/progress.c
@@ -25,7 +25,7 @@ void ui_progress__update(struct ui_progress *p, u64 adv)
 void ui_progress__init(struct ui_progress *p, u64 total, const char *title)
 {
 	p->curr = 0;
-	p->next = p->step = total / 16;
+	p->next = p->step = total / 16 ?: 1;
 	p->total = total;
 	p->title = title;
 

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [tip:perf/urgent] perf ui progress: Fix progress update
  2017-09-08 12:05 ` [PATCH 2/4] perf ui progress: Fix progress update Jiri Olsa
@ 2017-09-13  7:45   ` tip-bot for Jiri Olsa
  0 siblings, 0 replies; 13+ messages in thread
From: tip-bot for Jiri Olsa @ 2017-09-13  7:45 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: linux-kernel, tglx, a.p.zijlstra, acme, hpa, mingo, dsahern,
	jolsa, namhyung

Commit-ID:  a82bfd041d0ec41861a7adda4c078993f2f9c452
Gitweb:     http://git.kernel.org/tip/a82bfd041d0ec41861a7adda4c078993f2f9c452
Author:     Jiri Olsa <jolsa@kernel.org>
AuthorDate: Fri, 8 Sep 2017 14:05:08 +0200
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Tue, 12 Sep 2017 12:34:54 -0300

perf ui progress: Fix progress update

We currently update the 'next' variable only with a single step value.
But it's possible the 'adv' update is bigger than single 'step' value.
This would leave 'next' value under counted and force unnecessary
ui_progress__ops->update calls.

Calculate the amount of steps we need for 'adv' update and increase the
'next' with that amounts of steps.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Cc: David Ahern <dsahern@gmail.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: http://lkml.kernel.org/r/20170908120510.22515-3-jolsa@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/ui/progress.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/tools/perf/ui/progress.c b/tools/perf/ui/progress.c
index a9c1580..ae91c81 100644
--- a/tools/perf/ui/progress.c
+++ b/tools/perf/ui/progress.c
@@ -1,3 +1,4 @@
+#include <linux/kernel.h>
 #include "../cache.h"
 #include "progress.h"
 
@@ -14,10 +15,14 @@ struct ui_progress_ops *ui_progress__ops = &null_progress__ops;
 
 void ui_progress__update(struct ui_progress *p, u64 adv)
 {
+	u64 last = p->curr;
+
 	p->curr += adv;
 
 	if (p->curr >= p->next) {
-		p->next += p->step;
+		u64 nr = DIV_ROUND_UP(p->curr - last, p->step);
+
+		p->next += nr * p->step;
 		ui_progress__ops->update(p);
 	}
 }

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [tip:perf/core] perf ui progress: Add ui specific init function
  2017-09-08 12:05 ` [PATCH 3/4] perf ui progress: Add ui specific init function Jiri Olsa
@ 2017-09-22 16:34   ` tip-bot for Jiri Olsa
  0 siblings, 0 replies; 13+ messages in thread
From: tip-bot for Jiri Olsa @ 2017-09-22 16:34 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: acme, linux-kernel, dsahern, mingo, jolsa, a.p.zijlstra, hpa,
	namhyung, tglx

Commit-ID:  25cc4eb44b0c840eff0e5a46a85b9ccbde77401b
Gitweb:     http://git.kernel.org/tip/25cc4eb44b0c840eff0e5a46a85b9ccbde77401b
Author:     Jiri Olsa <jolsa@kernel.org>
AuthorDate: Fri, 8 Sep 2017 14:05:09 +0200
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Wed, 13 Sep 2017 09:49:15 -0300

perf ui progress: Add ui specific init function

Adding ui specific init function allowing to setup the progress bar
width based on current screen scales.

Adding TUI init function to get more grained update of the progress bar.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Cc: David Ahern <dsahern@gmail.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: http://lkml.kernel.org/r/20170908120510.22515-4-jolsa@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/ui/progress.c     | 2 ++
 tools/perf/ui/progress.h     | 1 +
 tools/perf/ui/tui/progress.c | 9 +++++++--
 3 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/tools/perf/ui/progress.c b/tools/perf/ui/progress.c
index ae91c81..3e2b5d6 100644
--- a/tools/perf/ui/progress.c
+++ b/tools/perf/ui/progress.c
@@ -34,6 +34,8 @@ void ui_progress__init(struct ui_progress *p, u64 total, const char *title)
 	p->total = total;
 	p->title = title;
 
+	if (ui_progress__ops->init)
+		ui_progress__ops->init(p);
 }
 
 void ui_progress__finish(void)
diff --git a/tools/perf/ui/progress.h b/tools/perf/ui/progress.h
index 717d39d..e5f434a 100644
--- a/tools/perf/ui/progress.h
+++ b/tools/perf/ui/progress.h
@@ -14,6 +14,7 @@ void ui_progress__init(struct ui_progress *p, u64 total, const char *title);
 void ui_progress__update(struct ui_progress *p, u64 adv);
 
 struct ui_progress_ops {
+	void (*init)(struct ui_progress *p);
 	void (*update)(struct ui_progress *p);
 	void (*finish)(void);
 };
diff --git a/tools/perf/ui/tui/progress.c b/tools/perf/ui/tui/progress.c
index c4b9900..f6b8f52 100644
--- a/tools/perf/ui/tui/progress.c
+++ b/tools/perf/ui/tui/progress.c
@@ -5,6 +5,11 @@
 #include "tui.h"
 #include "../browser.h"
 
+static void __tui_progress__init(struct ui_progress *p)
+{
+	p->next = p->step = p->total / (SLtt_Screen_Cols - 2) ?: 1;
+}
+
 static void tui_progress__update(struct ui_progress *p)
 {
 	int bar, y;
@@ -49,8 +54,8 @@ static void tui_progress__finish(void)
 	pthread_mutex_unlock(&ui__lock);
 }
 
-static struct ui_progress_ops tui_progress__ops =
-{
+static struct ui_progress_ops tui_progress__ops = {
+	.init   = __tui_progress__init,
 	.update = tui_progress__update,
 	.finish = tui_progress__finish,
 };

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [tip:perf/core] perf ui progress: Add size info into progress bar
  2017-09-08 12:05 ` [PATCH 4/4] perf ui progress: Add size info into progress bar Jiri Olsa
@ 2017-09-22 16:35   ` tip-bot for Jiri Olsa
  0 siblings, 0 replies; 13+ messages in thread
From: tip-bot for Jiri Olsa @ 2017-09-22 16:35 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: linux-kernel, a.p.zijlstra, namhyung, acme, jolsa, dsahern, hpa,
	tglx, mingo

Commit-ID:  8233822f403b67bbaa1d58e8fa6b8f821fe7626d
Gitweb:     http://git.kernel.org/tip/8233822f403b67bbaa1d58e8fa6b8f821fe7626d
Author:     Jiri Olsa <jolsa@kernel.org>
AuthorDate: Fri, 8 Sep 2017 14:05:10 +0200
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Wed, 13 Sep 2017 09:49:15 -0300

perf ui progress: Add size info into progress bar

Adding the size values '[current/total]' into progress bar, to show more
detailed progress of data reading.

Adding new ui_progress__init_size function to specify we want to display
the size.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: http://lkml.kernel.org/r/20170908120510.22515-5-jolsa@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/ui/progress.c     |  4 +++-
 tools/perf/ui/progress.h     | 11 ++++++++++-
 tools/perf/ui/tui/progress.c | 23 ++++++++++++++++++++++-
 tools/perf/util/session.c    |  2 +-
 4 files changed, 36 insertions(+), 4 deletions(-)

diff --git a/tools/perf/ui/progress.c b/tools/perf/ui/progress.c
index 3e2b5d6..7ade387 100644
--- a/tools/perf/ui/progress.c
+++ b/tools/perf/ui/progress.c
@@ -27,12 +27,14 @@ void ui_progress__update(struct ui_progress *p, u64 adv)
 	}
 }
 
-void ui_progress__init(struct ui_progress *p, u64 total, const char *title)
+void __ui_progress__init(struct ui_progress *p, u64 total,
+			 const char *title, bool size)
 {
 	p->curr = 0;
 	p->next = p->step = total / 16 ?: 1;
 	p->total = total;
 	p->title = title;
+	p->size  = size;
 
 	if (ui_progress__ops->init)
 		ui_progress__ops->init(p);
diff --git a/tools/perf/ui/progress.h b/tools/perf/ui/progress.h
index e5f434a..fbaa150 100644
--- a/tools/perf/ui/progress.h
+++ b/tools/perf/ui/progress.h
@@ -8,9 +8,18 @@ void ui_progress__finish(void);
 struct ui_progress {
 	const char *title;
 	u64 curr, next, step, total;
+	bool size;
 };
 
-void ui_progress__init(struct ui_progress *p, u64 total, const char *title);
+void __ui_progress__init(struct ui_progress *p, u64 total,
+			 const char *title, bool size);
+
+#define ui_progress__init(p, total, title) \
+	__ui_progress__init(p, total, title, false)
+
+#define ui_progress__init_size(p, total, title) \
+	__ui_progress__init(p, total, title, true)
+
 void ui_progress__update(struct ui_progress *p, u64 adv);
 
 struct ui_progress_ops {
diff --git a/tools/perf/ui/tui/progress.c b/tools/perf/ui/tui/progress.c
index f6b8f52..68f6144 100644
--- a/tools/perf/ui/tui/progress.c
+++ b/tools/perf/ui/tui/progress.c
@@ -1,8 +1,10 @@
+#include <linux/kernel.h>
 #include "../cache.h"
 #include "../progress.h"
 #include "../libslang.h"
 #include "../ui.h"
 #include "tui.h"
+#include "units.h"
 #include "../browser.h"
 
 static void __tui_progress__init(struct ui_progress *p)
@@ -10,8 +12,22 @@ static void __tui_progress__init(struct ui_progress *p)
 	p->next = p->step = p->total / (SLtt_Screen_Cols - 2) ?: 1;
 }
 
+static int get_title(struct ui_progress *p, char *buf, size_t size)
+{
+	char buf_cur[20];
+	char buf_tot[20];
+	int ret;
+
+	ret  = unit_number__scnprintf(buf_cur, sizeof(buf_cur), p->curr);
+	ret += unit_number__scnprintf(buf_tot, sizeof(buf_tot), p->total);
+
+	return ret + scnprintf(buf, size, "%s [%s/%s]",
+			       p->title, buf_cur, buf_tot);
+}
+
 static void tui_progress__update(struct ui_progress *p)
 {
+	char buf[100], *title = (char *) p->title;
 	int bar, y;
 	/*
 	 * FIXME: We should have a per UI backend way of showing progress,
@@ -23,13 +39,18 @@ static void tui_progress__update(struct ui_progress *p)
 	if (p->total == 0)
 		return;
 
+	if (p->size) {
+		get_title(p, buf, sizeof(buf));
+		title = buf;
+	}
+
 	ui__refresh_dimensions(false);
 	pthread_mutex_lock(&ui__lock);
 	y = SLtt_Screen_Rows / 2 - 2;
 	SLsmg_set_color(0);
 	SLsmg_draw_box(y, 0, 3, SLtt_Screen_Cols);
 	SLsmg_gotorc(y++, 1);
-	SLsmg_write_string((char *)p->title);
+	SLsmg_write_string(title);
 	SLsmg_fill_region(y, 1, 1, SLtt_Screen_Cols - 2, ' ');
 	SLsmg_set_color(HE_COLORSET_SELECTED);
 	bar = ((SLtt_Screen_Cols - 2) * p->curr) / p->total;
diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c
index a7ebd9f..ceac084 100644
--- a/tools/perf/util/session.c
+++ b/tools/perf/util/session.c
@@ -1847,7 +1847,7 @@ static int __perf_session__process_events(struct perf_session *session,
 	if (data_offset + data_size < file_size)
 		file_size = data_offset + data_size;
 
-	ui_progress__init(&prog, file_size, "Processing events...");
+	ui_progress__init_size(&prog, file_size, "Processing events...");
 
 	mmap_size = MMAP_SIZE;
 	if (mmap_size > file_size) {

^ permalink raw reply related	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2017-09-22 16:37 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-09-08 12:05 [RFC 1/4] perf ui progress: Add size info into progress bar Jiri Olsa
2017-09-08 12:05 ` [PATCH 1/4] perf ui progress: Make sure we always define step value Jiri Olsa
2017-09-08 13:16   ` Milian Wolff
2017-09-08 13:26     ` Arnaldo Carvalho de Melo
2017-09-09 10:09       ` Milian Wolff
2017-09-13  7:44   ` [tip:perf/urgent] " tip-bot for Jiri Olsa
2017-09-08 12:05 ` [PATCH 2/4] perf ui progress: Fix progress update Jiri Olsa
2017-09-13  7:45   ` [tip:perf/urgent] " tip-bot for Jiri Olsa
2017-09-08 12:05 ` [PATCH 3/4] perf ui progress: Add ui specific init function Jiri Olsa
2017-09-22 16:34   ` [tip:perf/core] " tip-bot for Jiri Olsa
2017-09-08 12:05 ` [PATCH 4/4] perf ui progress: Add size info into progress bar Jiri Olsa
2017-09-22 16:35   ` [tip:perf/core] " tip-bot for Jiri Olsa
2017-09-08 13:45 ` [RFC 1/4] " Arnaldo Carvalho de Melo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox