linux-perf-users.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] perf report: Display pregress bar on redirected pipe data
@ 2024-06-27 18:19 Namhyung Kim
  2024-06-27 19:41 ` Ian Rogers
  2024-06-28 16:54 ` Namhyung Kim
  0 siblings, 2 replies; 3+ messages in thread
From: Namhyung Kim @ 2024-06-27 18:19 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Ian Rogers, Kan Liang
  Cc: Jiri Olsa, Adrian Hunter, Peter Zijlstra, Ingo Molnar, LKML,
	linux-perf-users

It's possible to save pipe output of perf record into a file.

  $ perf record -o- ... > pipe.data

And you can use the data same as the normal perf data.

  $ perf report -i pipe.data

In that case, perf tools will treat the input as a pipe, but it can get
the total size of the input.  This means it can show the progress bar
unlike the normal pipe input (which doesn't know the total size in
advance).

While at it, fix the string in __perf_session__process_dir_events().

Signed-off-by: Namhyung Kim <namhyung@kernel.org>
---
 tools/perf/util/session.c | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)

diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c
index 0ec92d47373c..5596bed1b8c8 100644
--- a/tools/perf/util/session.c
+++ b/tools/perf/util/session.c
@@ -2050,6 +2050,7 @@ static int __perf_session__process_pipe_events(struct perf_session *session)
 {
 	struct ordered_events *oe = &session->ordered_events;
 	struct perf_tool *tool = session->tool;
+	struct ui_progress prog;
 	union perf_event *event;
 	uint32_t size, cur_size = 0;
 	void *buf = NULL;
@@ -2057,9 +2058,21 @@ static int __perf_session__process_pipe_events(struct perf_session *session)
 	u64 head;
 	ssize_t err;
 	void *p;
+	bool update_prog = false;
 
 	perf_tool__fill_defaults(tool);
 
+	/*
+	 * If it's from a file saving pipe data (by redirection), it would have
+	 * a file name other than "-".  Then we can get the total size and show
+	 * the progress.
+	 */
+	if (strcmp(session->data->path, "-") && session->data->file.size) {
+		ui_progress__init_size(&prog, session->data->file.size,
+				       "Processing events...");
+		update_prog = true;
+	}
+
 	head = 0;
 	cur_size = sizeof(union perf_event);
 
@@ -2131,6 +2144,9 @@ static int __perf_session__process_pipe_events(struct perf_session *session)
 	if (err)
 		goto out_err;
 
+	if (update_prog)
+		ui_progress__update(&prog, size);
+
 	if (!session_done())
 		goto more;
 done:
@@ -2144,6 +2160,8 @@ static int __perf_session__process_pipe_events(struct perf_session *session)
 	err = perf_session__flush_thread_stacks(session);
 out_err:
 	free(buf);
+	if (update_prog)
+		ui_progress__finish();
 	if (!tool->no_warn)
 		perf_session__warn_about_errors(session);
 	ordered_events__free(&session->ordered_events);
@@ -2523,7 +2541,7 @@ static int __perf_session__process_dir_events(struct perf_session *session)
 
 	perf_tool__fill_defaults(tool);
 
-	ui_progress__init_size(&prog, total_size, "Sorting events...");
+	ui_progress__init_size(&prog, total_size, "Processing events...");
 
 	nr_readers = 1;
 	for (i = 0; i < data->dir.nr; i++) {
-- 
2.45.2.803.g4e1b14247a-goog


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

* Re: [PATCH] perf report: Display pregress bar on redirected pipe data
  2024-06-27 18:19 [PATCH] perf report: Display pregress bar on redirected pipe data Namhyung Kim
@ 2024-06-27 19:41 ` Ian Rogers
  2024-06-28 16:54 ` Namhyung Kim
  1 sibling, 0 replies; 3+ messages in thread
From: Ian Rogers @ 2024-06-27 19:41 UTC (permalink / raw)
  To: Namhyung Kim
  Cc: Arnaldo Carvalho de Melo, Kan Liang, Jiri Olsa, Adrian Hunter,
	Peter Zijlstra, Ingo Molnar, LKML, linux-perf-users

On Thu, Jun 27, 2024 at 11:19 AM Namhyung Kim <namhyung@kernel.org> wrote:
>
> It's possible to save pipe output of perf record into a file.
>
>   $ perf record -o- ... > pipe.data
>
> And you can use the data same as the normal perf data.
>
>   $ perf report -i pipe.data
>
> In that case, perf tools will treat the input as a pipe, but it can get
> the total size of the input.  This means it can show the progress bar
> unlike the normal pipe input (which doesn't know the total size in
> advance).
>
> While at it, fix the string in __perf_session__process_dir_events().
>
> Signed-off-by: Namhyung Kim <namhyung@kernel.org>

Reviewed-by: Ian Rogers <irogers@google.com>

Thanks,
Ian

> ---
>  tools/perf/util/session.c | 20 +++++++++++++++++++-
>  1 file changed, 19 insertions(+), 1 deletion(-)
>
> diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c
> index 0ec92d47373c..5596bed1b8c8 100644
> --- a/tools/perf/util/session.c
> +++ b/tools/perf/util/session.c
> @@ -2050,6 +2050,7 @@ static int __perf_session__process_pipe_events(struct perf_session *session)
>  {
>         struct ordered_events *oe = &session->ordered_events;
>         struct perf_tool *tool = session->tool;
> +       struct ui_progress prog;
>         union perf_event *event;
>         uint32_t size, cur_size = 0;
>         void *buf = NULL;
> @@ -2057,9 +2058,21 @@ static int __perf_session__process_pipe_events(struct perf_session *session)
>         u64 head;
>         ssize_t err;
>         void *p;
> +       bool update_prog = false;
>
>         perf_tool__fill_defaults(tool);
>
> +       /*
> +        * If it's from a file saving pipe data (by redirection), it would have
> +        * a file name other than "-".  Then we can get the total size and show
> +        * the progress.
> +        */
> +       if (strcmp(session->data->path, "-") && session->data->file.size) {
> +               ui_progress__init_size(&prog, session->data->file.size,
> +                                      "Processing events...");
> +               update_prog = true;
> +       }
> +
>         head = 0;
>         cur_size = sizeof(union perf_event);
>
> @@ -2131,6 +2144,9 @@ static int __perf_session__process_pipe_events(struct perf_session *session)
>         if (err)
>                 goto out_err;
>
> +       if (update_prog)
> +               ui_progress__update(&prog, size);
> +
>         if (!session_done())
>                 goto more;
>  done:
> @@ -2144,6 +2160,8 @@ static int __perf_session__process_pipe_events(struct perf_session *session)
>         err = perf_session__flush_thread_stacks(session);
>  out_err:
>         free(buf);
> +       if (update_prog)
> +               ui_progress__finish();
>         if (!tool->no_warn)
>                 perf_session__warn_about_errors(session);
>         ordered_events__free(&session->ordered_events);
> @@ -2523,7 +2541,7 @@ static int __perf_session__process_dir_events(struct perf_session *session)
>
>         perf_tool__fill_defaults(tool);
>
> -       ui_progress__init_size(&prog, total_size, "Sorting events...");
> +       ui_progress__init_size(&prog, total_size, "Processing events...");
>
>         nr_readers = 1;
>         for (i = 0; i < data->dir.nr; i++) {
> --
> 2.45.2.803.g4e1b14247a-goog
>

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

* Re: [PATCH] perf report: Display pregress bar on redirected pipe data
  2024-06-27 18:19 [PATCH] perf report: Display pregress bar on redirected pipe data Namhyung Kim
  2024-06-27 19:41 ` Ian Rogers
@ 2024-06-28 16:54 ` Namhyung Kim
  1 sibling, 0 replies; 3+ messages in thread
From: Namhyung Kim @ 2024-06-28 16:54 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Ian Rogers, Kan Liang, Namhyung Kim
  Cc: Jiri Olsa, Adrian Hunter, Peter Zijlstra, Ingo Molnar, LKML,
	linux-perf-users

On Thu, 27 Jun 2024 11:19:16 -0700, Namhyung Kim wrote:

> It's possible to save pipe output of perf record into a file.
> 
>   $ perf record -o- ... > pipe.data
> 
> And you can use the data same as the normal perf data.
> 
>   $ perf report -i pipe.data
> 
> [...]

Applied to perf-tools-next, thanks!

Best regards,
Namhyung

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

end of thread, other threads:[~2024-06-28 16:54 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-06-27 18:19 [PATCH] perf report: Display pregress bar on redirected pipe data Namhyung Kim
2024-06-27 19:41 ` Ian Rogers
2024-06-28 16:54 ` Namhyung Kim

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).