Skip to content

Commit 0ae0389

Browse files
namhyungacmel
authored andcommitted
perf tools: Pass a fd to perf_file_header__read_pipe()
Currently it unconditionally writes to stdout for repipe. But perf inject can direct its output to a regular file. Then it needs to write the header to the file as well. Signed-off-by: Namhyung Kim <[email protected]> Acked-by: Jiri Olsa <[email protected]> Cc: Adrian Hunter <[email protected]> Cc: Andi Kleen <[email protected]> Cc: Ian Rogers <[email protected]> Cc: Peter Zijlstra <[email protected]> Link: http://lore.kernel.org/lkml/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent 2681bd8 commit 0ae0389

File tree

5 files changed

+15
-14
lines changed

5 files changed

+15
-14
lines changed

tools/perf/builtin-inject.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -992,7 +992,8 @@ int cmd_inject(int argc, const char **argv)
992992
}
993993

994994
data.path = inject.input_name;
995-
inject.session = __perf_session__new(&data, inject.output.is_pipe, &inject.tool);
995+
inject.session = __perf_session__new(&data, inject.output.is_pipe,
996+
perf_data__fd(&inject.output), &inject.tool);
996997
if (IS_ERR(inject.session)) {
997998
ret = PTR_ERR(inject.session);
998999
goto out_close_output;

tools/perf/util/header.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3865,10 +3865,10 @@ static int perf_file_section__process(struct perf_file_section *section,
38653865
static int perf_file_header__read_pipe(struct perf_pipe_file_header *header,
38663866
struct perf_header *ph,
38673867
struct perf_data* data,
3868-
bool repipe)
3868+
bool repipe, int repipe_fd)
38693869
{
38703870
struct feat_fd ff = {
3871-
.fd = STDOUT_FILENO,
3871+
.fd = repipe_fd,
38723872
.ph = ph,
38733873
};
38743874
ssize_t ret;
@@ -3891,13 +3891,13 @@ static int perf_file_header__read_pipe(struct perf_pipe_file_header *header,
38913891
return 0;
38923892
}
38933893

3894-
static int perf_header__read_pipe(struct perf_session *session)
3894+
static int perf_header__read_pipe(struct perf_session *session, int repipe_fd)
38953895
{
38963896
struct perf_header *header = &session->header;
38973897
struct perf_pipe_file_header f_header;
38983898

38993899
if (perf_file_header__read_pipe(&f_header, header, session->data,
3900-
session->repipe) < 0) {
3900+
session->repipe, repipe_fd) < 0) {
39013901
pr_debug("incompatible file format\n");
39023902
return -EINVAL;
39033903
}
@@ -3995,7 +3995,7 @@ static int evlist__prepare_tracepoint_events(struct evlist *evlist, struct tep_h
39953995
return 0;
39963996
}
39973997

3998-
int perf_session__read_header(struct perf_session *session)
3998+
int perf_session__read_header(struct perf_session *session, int repipe_fd)
39993999
{
40004000
struct perf_data *data = session->data;
40014001
struct perf_header *header = &session->header;
@@ -4016,7 +4016,7 @@ int perf_session__read_header(struct perf_session *session)
40164016
* We can read 'pipe' data event from regular file,
40174017
* check for the pipe header regardless of source.
40184018
*/
4019-
err = perf_header__read_pipe(session);
4019+
err = perf_header__read_pipe(session, repipe_fd);
40204020
if (!err || perf_data__is_pipe(data)) {
40214021
data->is_pipe = true;
40224022
return err;

tools/perf/util/header.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ struct perf_session;
115115
struct perf_tool;
116116
union perf_event;
117117

118-
int perf_session__read_header(struct perf_session *session);
118+
int perf_session__read_header(struct perf_session *session, int repipe_fd);
119119
int perf_session__write_header(struct perf_session *session,
120120
struct evlist *evlist,
121121
int fd, bool at_exit);

tools/perf/util/session.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,11 @@ static int perf_session__deliver_event(struct perf_session *session,
102102
struct perf_tool *tool,
103103
u64 file_offset);
104104

105-
static int perf_session__open(struct perf_session *session)
105+
static int perf_session__open(struct perf_session *session, int repipe_fd)
106106
{
107107
struct perf_data *data = session->data;
108108

109-
if (perf_session__read_header(session) < 0) {
109+
if (perf_session__read_header(session, repipe_fd) < 0) {
110110
pr_err("incompatible file format (rerun with -v to learn more)\n");
111111
return -1;
112112
}
@@ -186,7 +186,7 @@ static int ordered_events__deliver_event(struct ordered_events *oe,
186186
}
187187

188188
struct perf_session *__perf_session__new(struct perf_data *data,
189-
bool repipe,
189+
bool repipe, int repipe_fd,
190190
struct perf_tool *tool)
191191
{
192192
int ret = -ENOMEM;
@@ -211,7 +211,7 @@ struct perf_session *__perf_session__new(struct perf_data *data,
211211
session->data = data;
212212

213213
if (perf_data__is_read(data)) {
214-
ret = perf_session__open(session);
214+
ret = perf_session__open(session, repipe_fd);
215215
if (ret < 0)
216216
goto out_delete;
217217

tools/perf/util/session.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,13 @@ struct decomp {
5555
struct perf_tool;
5656

5757
struct perf_session *__perf_session__new(struct perf_data *data,
58-
bool repipe,
58+
bool repipe, int repipe_fd,
5959
struct perf_tool *tool);
6060

6161
static inline struct perf_session *perf_session__new(struct perf_data *data,
6262
struct perf_tool *tool)
6363
{
64-
return __perf_session__new(data, false, tool);
64+
return __perf_session__new(data, false, -1, tool);
6565
}
6666

6767
void perf_session__delete(struct perf_session *session);

0 commit comments

Comments
 (0)