Skip to content

Commit 4553c43

Browse files
committed
perf report: Display pregress bar on redirected pipe data
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 <[email protected]> Signed-off-by: Namhyung Kim <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent e8b86f0 commit 4553c43

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

tools/perf/util/session.c

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2050,16 +2050,29 @@ static int __perf_session__process_pipe_events(struct perf_session *session)
20502050
{
20512051
struct ordered_events *oe = &session->ordered_events;
20522052
struct perf_tool *tool = session->tool;
2053+
struct ui_progress prog;
20532054
union perf_event *event;
20542055
uint32_t size, cur_size = 0;
20552056
void *buf = NULL;
20562057
s64 skip = 0;
20572058
u64 head;
20582059
ssize_t err;
20592060
void *p;
2061+
bool update_prog = false;
20602062

20612063
perf_tool__fill_defaults(tool);
20622064

2065+
/*
2066+
* If it's from a file saving pipe data (by redirection), it would have
2067+
* a file name other than "-". Then we can get the total size and show
2068+
* the progress.
2069+
*/
2070+
if (strcmp(session->data->path, "-") && session->data->file.size) {
2071+
ui_progress__init_size(&prog, session->data->file.size,
2072+
"Processing events...");
2073+
update_prog = true;
2074+
}
2075+
20632076
head = 0;
20642077
cur_size = sizeof(union perf_event);
20652078

@@ -2131,6 +2144,9 @@ static int __perf_session__process_pipe_events(struct perf_session *session)
21312144
if (err)
21322145
goto out_err;
21332146

2147+
if (update_prog)
2148+
ui_progress__update(&prog, size);
2149+
21342150
if (!session_done())
21352151
goto more;
21362152
done:
@@ -2144,6 +2160,8 @@ static int __perf_session__process_pipe_events(struct perf_session *session)
21442160
err = perf_session__flush_thread_stacks(session);
21452161
out_err:
21462162
free(buf);
2163+
if (update_prog)
2164+
ui_progress__finish();
21472165
if (!tool->no_warn)
21482166
perf_session__warn_about_errors(session);
21492167
ordered_events__free(&session->ordered_events);
@@ -2523,7 +2541,7 @@ static int __perf_session__process_dir_events(struct perf_session *session)
25232541

25242542
perf_tool__fill_defaults(tool);
25252543

2526-
ui_progress__init_size(&prog, total_size, "Sorting events...");
2544+
ui_progress__init_size(&prog, total_size, "Processing events...");
25272545

25282546
nr_readers = 1;
25292547
for (i = 0; i < data->dir.nr; i++) {

0 commit comments

Comments
 (0)