forked from mirrors/linux
		
	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 <namhyung@kernel.org> Acked-by: Jiri Olsa <jolsa@redhat.com> Cc: Adrian Hunter <adrian.hunter@intel.com> Cc: Andi Kleen <ak@linux.intel.com> Cc: Ian Rogers <irogers@google.com> Cc: Peter Zijlstra <peterz@infradead.org> Link: http://lore.kernel.org/lkml/20210719223153.1618812-3-namhyung@kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
This commit is contained in:
		
							parent
							
								
									2681bd85a4
								
							
						
					
					
						commit
						0ae0389362
					
				
					 5 changed files with 15 additions and 14 deletions
				
			
		| 
						 | 
				
			
			@ -992,7 +992,8 @@ int cmd_inject(int argc, const char **argv)
 | 
			
		|||
	}
 | 
			
		||||
 | 
			
		||||
	data.path = inject.input_name;
 | 
			
		||||
	inject.session = __perf_session__new(&data, inject.output.is_pipe, &inject.tool);
 | 
			
		||||
	inject.session = __perf_session__new(&data, inject.output.is_pipe,
 | 
			
		||||
					     perf_data__fd(&inject.output), &inject.tool);
 | 
			
		||||
	if (IS_ERR(inject.session)) {
 | 
			
		||||
		ret = PTR_ERR(inject.session);
 | 
			
		||||
		goto out_close_output;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -3865,10 +3865,10 @@ static int perf_file_section__process(struct perf_file_section *section,
 | 
			
		|||
static int perf_file_header__read_pipe(struct perf_pipe_file_header *header,
 | 
			
		||||
				       struct perf_header *ph,
 | 
			
		||||
				       struct perf_data* data,
 | 
			
		||||
				       bool repipe)
 | 
			
		||||
				       bool repipe, int repipe_fd)
 | 
			
		||||
{
 | 
			
		||||
	struct feat_fd ff = {
 | 
			
		||||
		.fd = STDOUT_FILENO,
 | 
			
		||||
		.fd = repipe_fd,
 | 
			
		||||
		.ph = ph,
 | 
			
		||||
	};
 | 
			
		||||
	ssize_t ret;
 | 
			
		||||
| 
						 | 
				
			
			@ -3891,13 +3891,13 @@ static int perf_file_header__read_pipe(struct perf_pipe_file_header *header,
 | 
			
		|||
	return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static int perf_header__read_pipe(struct perf_session *session)
 | 
			
		||||
static int perf_header__read_pipe(struct perf_session *session, int repipe_fd)
 | 
			
		||||
{
 | 
			
		||||
	struct perf_header *header = &session->header;
 | 
			
		||||
	struct perf_pipe_file_header f_header;
 | 
			
		||||
 | 
			
		||||
	if (perf_file_header__read_pipe(&f_header, header, session->data,
 | 
			
		||||
					session->repipe) < 0) {
 | 
			
		||||
					session->repipe, repipe_fd) < 0) {
 | 
			
		||||
		pr_debug("incompatible file format\n");
 | 
			
		||||
		return -EINVAL;
 | 
			
		||||
	}
 | 
			
		||||
| 
						 | 
				
			
			@ -3995,7 +3995,7 @@ static int evlist__prepare_tracepoint_events(struct evlist *evlist, struct tep_h
 | 
			
		|||
	return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int perf_session__read_header(struct perf_session *session)
 | 
			
		||||
int perf_session__read_header(struct perf_session *session, int repipe_fd)
 | 
			
		||||
{
 | 
			
		||||
	struct perf_data *data = session->data;
 | 
			
		||||
	struct perf_header *header = &session->header;
 | 
			
		||||
| 
						 | 
				
			
			@ -4016,7 +4016,7 @@ int perf_session__read_header(struct perf_session *session)
 | 
			
		|||
	 * We can read 'pipe' data event from regular file,
 | 
			
		||||
	 * check for the pipe header regardless of source.
 | 
			
		||||
	 */
 | 
			
		||||
	err = perf_header__read_pipe(session);
 | 
			
		||||
	err = perf_header__read_pipe(session, repipe_fd);
 | 
			
		||||
	if (!err || perf_data__is_pipe(data)) {
 | 
			
		||||
		data->is_pipe = true;
 | 
			
		||||
		return err;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -115,7 +115,7 @@ struct perf_session;
 | 
			
		|||
struct perf_tool;
 | 
			
		||||
union perf_event;
 | 
			
		||||
 | 
			
		||||
int perf_session__read_header(struct perf_session *session);
 | 
			
		||||
int perf_session__read_header(struct perf_session *session, int repipe_fd);
 | 
			
		||||
int perf_session__write_header(struct perf_session *session,
 | 
			
		||||
			       struct evlist *evlist,
 | 
			
		||||
			       int fd, bool at_exit);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -102,11 +102,11 @@ static int perf_session__deliver_event(struct perf_session *session,
 | 
			
		|||
				       struct perf_tool *tool,
 | 
			
		||||
				       u64 file_offset);
 | 
			
		||||
 | 
			
		||||
static int perf_session__open(struct perf_session *session)
 | 
			
		||||
static int perf_session__open(struct perf_session *session, int repipe_fd)
 | 
			
		||||
{
 | 
			
		||||
	struct perf_data *data = session->data;
 | 
			
		||||
 | 
			
		||||
	if (perf_session__read_header(session) < 0) {
 | 
			
		||||
	if (perf_session__read_header(session, repipe_fd) < 0) {
 | 
			
		||||
		pr_err("incompatible file format (rerun with -v to learn more)\n");
 | 
			
		||||
		return -1;
 | 
			
		||||
	}
 | 
			
		||||
| 
						 | 
				
			
			@ -186,7 +186,7 @@ static int ordered_events__deliver_event(struct ordered_events *oe,
 | 
			
		|||
}
 | 
			
		||||
 | 
			
		||||
struct perf_session *__perf_session__new(struct perf_data *data,
 | 
			
		||||
					 bool repipe,
 | 
			
		||||
					 bool repipe, int repipe_fd,
 | 
			
		||||
					 struct perf_tool *tool)
 | 
			
		||||
{
 | 
			
		||||
	int ret = -ENOMEM;
 | 
			
		||||
| 
						 | 
				
			
			@ -211,7 +211,7 @@ struct perf_session *__perf_session__new(struct perf_data *data,
 | 
			
		|||
		session->data = data;
 | 
			
		||||
 | 
			
		||||
		if (perf_data__is_read(data)) {
 | 
			
		||||
			ret = perf_session__open(session);
 | 
			
		||||
			ret = perf_session__open(session, repipe_fd);
 | 
			
		||||
			if (ret < 0)
 | 
			
		||||
				goto out_delete;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -55,13 +55,13 @@ struct decomp {
 | 
			
		|||
struct perf_tool;
 | 
			
		||||
 | 
			
		||||
struct perf_session *__perf_session__new(struct perf_data *data,
 | 
			
		||||
					 bool repipe,
 | 
			
		||||
					 bool repipe, int repipe_fd,
 | 
			
		||||
					 struct perf_tool *tool);
 | 
			
		||||
 | 
			
		||||
static inline struct perf_session *perf_session__new(struct perf_data *data,
 | 
			
		||||
						     struct perf_tool *tool)
 | 
			
		||||
{
 | 
			
		||||
	return __perf_session__new(data, false, tool);
 | 
			
		||||
	return __perf_session__new(data, false, -1, tool);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void perf_session__delete(struct perf_session *session);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in a new issue