Skip to content

Commit

Permalink
perf report: Display pregress bar on redirected pipe data
Browse files Browse the repository at this point in the history
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().

Reviewed-by: Ian Rogers <irogers@google.com>
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Link: https://lore.kernel.org/r/20240627181916.1202110-1-namhyung@kernel.org
  • Loading branch information
Namhyung Kim committed Jun 28, 2024
1 parent e8b86f0 commit 4553c43
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion tools/perf/util/session.c
Original file line number Diff line number Diff line change
Expand Up @@ -2050,16 +2050,29 @@ 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;
s64 skip = 0;
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);

Expand Down Expand Up @@ -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:
Expand All @@ -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);
Expand Down Expand Up @@ -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++) {
Expand Down

0 comments on commit 4553c43

Please sign in to comment.