perf inject: Fix broken data with mixed input/output
Namhyung Kim
maintainercover perf inject: Fix broken data with mixed input/output
Hello,
The perf inject processes the input data and produces an output with injected data according to the given options. During the work, it assumes the input and output files have the same format - either a regular file or a pipe. This works for the obvious cases, but sometimes makes a trouble when input and output have different formats (like for debugging).
For example, this patchset fixed the following cases
1. input: pipe, output: file
# perf record -a -o - sleep 1 | perf inject -b -o perf-pipe.data # perf report -i perf-pipe.data
2. input: file, output: pipe
# perf record -a -B sleep 1 # perf inject -b -i perf.data | perf report -i -
Thanks,
Namhyung
Namhyung Kim (4):
perf tools: Remove repipe argument from perf_session__new() perf tools: Pass a fd to perf_file_header__read_pipe() perf inject: Fix output from a pipe to a file perf inject: Fix output from a file to a pipe
tools/perf/bench/synthesize.c | 4 +- tools/perf/builtin-annotate.c | 2 +- tools/perf/builtin-buildid-cache.c | 2 +- tools/perf/builtin-buildid-list.c | 2 +- tools/perf/builtin-c2c.c | 2 +- tools/perf/builtin-diff.c | 4 +- tools/perf/builtin-evlist.c | 2 +- tools/perf/builtin-inject.c | 67 +++++++++++++++++++++++++++-- tools/perf/builtin-kmem.c | 2 +- tools/perf/builtin-kvm.c | 4 +- tools/perf/builtin-lock.c | 2 +- tools/perf/builtin-mem.c | 3 +- tools/perf/builtin-record.c | 2 +- tools/perf/builtin-report.c | 2 +- tools/perf/builtin-sched.c | 4 +- tools/perf/builtin-script.c | 4 +- tools/perf/builtin-stat.c | 4 +- tools/perf/builtin-timechart.c | 3 +- tools/perf/builtin-top.c | 2 +- tools/perf/builtin-trace.c | 2 +- tools/perf/tests/topology.c | 4 +- tools/perf/util/data-convert-bt.c | 2 +- tools/perf/util/data-convert-json.c | 2 +- tools/perf/util/header.c | 12 +++--- tools/perf/util/header.h | 2 +- tools/perf/util/session.c | 11 ++--- tools/perf/util/session.h | 12 +++++- 27 files changed, 115 insertions(+), 49 deletions(-)
Signature · 1 line
2.32.0.93.g670b81a890-goog
Namhyung Kim
maintainerPATCH 1/4 perf tools: Remove repipe argument from perf_session__new()
The repipe argument is only used by perf inject and the all others passes 'false'. Let's remove it from the function signature and add __perf_session__new() to be called from perf inject directly.
This is a preparation of the change the pipe input/output.
--- tools/perf/bench/synthesize.c | 4 ++-- tools/perf/builtin-annotate.c | 2 +- tools/perf/builtin-buildid-cache.c | 2 +- tools/perf/builtin-buildid-list.c | 2 +- tools/perf/builtin-c2c.c | 2 +- tools/perf/builtin-diff.c | 4 ++-- tools/perf/builtin-evlist.c | 2 +- tools/perf/builtin-inject.c | 3 ++- tools/perf/builtin-kmem.c | 2 +- tools/perf/builtin-kvm.c | 4 ++-- tools/perf/builtin-lock.c | 2 +- tools/perf/builtin-mem.c | 3 +-- tools/perf/builtin-record.c | 2 +- tools/perf/builtin-report.c | 2 +- tools/perf/builtin-sched.c | 4 ++-- tools/perf/builtin-script.c | 4 ++-- tools/perf/builtin-stat.c | 4 ++-- tools/perf/builtin-timechart.c | 3 +-- tools/perf/builtin-top.c | 2 +- tools/perf/builtin-trace.c | 2 +- tools/perf/tests/topology.c | 4 ++-- tools/perf/util/data-convert-bt.c | 2 +- tools/perf/util/data-convert-json.c | 2 +- tools/perf/util/session.c | 5 +++-- tools/perf/util/session.h | 12 ++++++++++-- 25 files changed, 44 insertions(+), 36 deletions(-)
tools/perf/bench/synthesize.c +2 -2
@@ -117,7 +117,7 @@ static int run_single_threaded(void)int err;perf_set_singlethreaded (); - session =perf_session__new (NULL , false,NULL ); + session =perf_session__new (NULL ,NULL );if (IS_ERR (session)) {pr_err ("Session creation failed.\n" );return PTR_ERR (session);
@@ -161,7 +161,7 @@ static int do_run_multi_threaded(struct target *target,init_stats (&time_stats);init_stats (&event_stats);for (i =0 ; i < multi_iterations; i++) { - session =perf_session__new (NULL , false,NULL ); + session =perf_session__new (NULL ,NULL );if (IS_ERR (session))return PTR_ERR (session);
tools/perf/builtin-annotate.c +1 -1
@@ -596,7 +596,7 @@ int cmd_annotate(int argc, const char **argv) data.path = input_name; - annotate.session =perf_session__new (&data, false, &annotate.tool); + annotate.session =perf_session__new (&data, &annotate.tool);if (IS_ERR (annotate.session))return PTR_ERR (annotate.session);
tools/perf/builtin-buildid-cache.c +1 -1
@@ -443,7 +443,7 @@ int cmd_buildid_cache(int argc, const char **argv) data.path = missing_filename; data.force = force; - session =perf_session__new (&data, false,NULL ); + session =perf_session__new (&data,NULL );if (IS_ERR (session))return PTR_ERR (session); }
tools/perf/builtin-buildid-list.c +1 -1
@@ -65,7 +65,7 @@ static int perf_session__list_build_ids(bool force, bool with_hits)if (filename__fprintf_build_id (input_name, stdout) >0 ) goto out; - session =perf_session__new (&data, false, &build_id__mark_dso_hit_ops); + session =perf_session__new (&data, &build_id__mark_dso_hit_ops);if (IS_ERR (session))return PTR_ERR (session);
tools/perf/builtin-c2c.c +1 -1
@@ -2790,7 +2790,7 @@ static int perf_c2c__report(int argc, const char **argv) goto out; } - session =perf_session__new (&data,0 , &c2c.tool); + session =perf_session__new (&data, &c2c.tool);if (IS_ERR (session)) { err =PTR_ERR (session);pr_debug ("Error creating perf session\n" );
tools/perf/builtin-diff.c +2 -2
@@ -1156,7 +1156,7 @@ static int check_file_brstack(void)int i;data__for_each_file (i, d) { - d->session =perf_session__new (&d->data, false, &pdiff.tool); + d->session =perf_session__new (&d->data, &pdiff.tool);if (IS_ERR (d->session)) {pr_err ("Failed to open %s\n" , d->data.path);return PTR_ERR (d->session);
@@ -1188,7 +1188,7 @@ static int __cmd_diff(void) ret = -EINVAL ;data__for_each_file (i, d) { - d->session =perf_session__new (&d->data, false, &pdiff.tool); + d->session =perf_session__new (&d->data, &pdiff.tool);if (IS_ERR (d->session)) { ret =PTR_ERR (d->session);pr_err ("Failed to open %s\n" , d->data.path);
tools/perf/builtin-evlist.c +1 -1
@@ -42,7 +42,7 @@ static int __cmd_evlist(const char *file_name, struct perf_attr_details *details };bool has_tracepoint = false; - session =perf_session__new (&data,0 , &tool); + session =perf_session__new (&data, &tool);if (IS_ERR (session))return PTR_ERR (session);
tools/perf/builtin-inject.c +2 -1
@@ -991,7 +991,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, + &inject.tool);if (IS_ERR (inject.session))return PTR_ERR (inject.session);
tools/perf/builtin-kmem.c +1 -1
@@ -1953,7 +1953,7 @@ int cmd_kmem(int argc, const char **argv) data.path = input_name; - kmem_session = session =perf_session__new (&data, false, &perf_kmem); + kmem_session = session =perf_session__new (&data, &perf_kmem);if (IS_ERR (session))return PTR_ERR (session);
tools/perf/builtin-kvm.c +2 -2
@@ -1093,7 +1093,7 @@ static int read_events(struct perf_kvm_stat *kvm) }; kvm->tool = eops; - kvm->session =perf_session__new (&file, false, &kvm->tool); + kvm->session =perf_session__new (&file, &kvm->tool);if (IS_ERR (kvm->session)) {pr_err ("Initializing perf session failed\n" );return PTR_ERR (kvm->session);
@@ -1447,7 +1447,7 @@ static int kvm_events_live(struct perf_kvm_stat *kvm,/* * perf session */ - kvm->session =perf_session__new (&data, false, &kvm->tool); + kvm->session =perf_session__new (&data, &kvm->tool);if (IS_ERR (kvm->session)) { err =PTR_ERR (kvm->session); goto out;
tools/perf/builtin-lock.c +1 -1
@@ -868,7 +868,7 @@ static int __cmd_report(bool display_info) .force = force, }; - session =perf_session__new (&data, false, &eops); + session =perf_session__new (&data, &eops);if (IS_ERR (session)) {pr_err ("Initializing perf session failed\n" );return PTR_ERR (session);
tools/perf/builtin-mem.c +1 -2
@@ -271,8 +271,7 @@ static int report_raw_events(struct perf_mem *mem) .force = mem->force, };int ret; -struct perf_session *session =perf_session__new (&data, false, - &mem->tool); +struct perf_session *session =perf_session__new (&data, &mem->tool);if (IS_ERR (session))return PTR_ERR (session);
tools/perf/builtin-record.c +1 -1
@@ -1680,7 +1680,7 @@ static int __cmd_record(struct record *rec, int argc, const char **argv)signal (SIGUSR2 ,SIG_IGN ); } - session =perf_session__new (data, false, tool); + session =perf_session__new (data, tool);if (IS_ERR (session)) {pr_err ("Perf session creation failed.\n" );return PTR_ERR (session);
tools/perf/builtin-report.c +1 -1
@@ -1405,7 +1405,7 @@ int cmd_report(int argc, const char **argv) data.force = symbol_conf.force; repeat: - session =perf_session__new (&data, false, &report.tool); + session =perf_session__new (&data, &report.tool);if (IS_ERR (session))return PTR_ERR (session);
tools/perf/builtin-sched.c +2 -2
@@ -1804,7 +1804,7 @@ static int perf_sched__read_events(struct perf_sched *sched) };int rc =-1 ; - session =perf_session__new (&data, false, &sched->tool); + session =perf_session__new (&data, &sched->tool);if (IS_ERR (session)) {pr_debug ("Error creating perf session" );return PTR_ERR (session);
@@ -3011,7 +3011,7 @@ static int perf_sched__timehist(struct perf_sched *sched) symbol_conf.use_callchain = sched->show_callchain; - session =perf_session__new (&data, false, &sched->tool); + session =perf_session__new (&data, &sched->tool);if (IS_ERR (session))return PTR_ERR (session);
tools/perf/builtin-script.c +2 -2
@@ -3287,7 +3287,7 @@ int find_scripts(char **scripts_array, char **scripts_path_array, int num,char *temp;int i =0 ; - session =perf_session__new (&data, false,NULL ); + session =perf_session__new (&data,NULL );if (IS_ERR (session))return PTR_ERR (session);
@@ -4000,7 +4000,7 @@ int cmd_script(int argc, const char **argv) use_browser =0 ; } - session =perf_session__new (&data, false, &script.tool); + session =perf_session__new (&data, &script.tool);if (IS_ERR (session))return PTR_ERR (session);
tools/perf/builtin-stat.c +2 -2
@@ -1993,7 +1993,7 @@ static int __cmd_record(int argc, const char **argv)return -1 ; } - session =perf_session__new (data, false,NULL ); + session =perf_session__new (data,NULL );if (IS_ERR (session)) {pr_err ("Perf session creation failed\n" );return PTR_ERR (session);
@@ -2165,7 +2165,7 @@ static int __cmd_report(int argc, const char **argv) perf_stat.data.path = input_name; perf_stat.data.mode =PERF_DATA_MODE_READ ; - session =perf_session__new (&perf_stat.data, false, &perf_stat.tool); + session =perf_session__new (&perf_stat.data, &perf_stat.tool);if (IS_ERR (session))return PTR_ERR (session);
tools/perf/builtin-timechart.c +1 -2
@@ -1598,8 +1598,7 @@ static int __cmd_timechart(struct timechart *tchart, const char *output_name) .force = tchart->force, }; -struct perf_session *session =perf_session__new (&data, false, - &tchart->tool); +struct perf_session *session =perf_session__new (&data, &tchart->tool);int ret = -EINVAL ;if (IS_ERR (session))
tools/perf/builtin-top.c +1 -1
@@ -1740,7 +1740,7 @@ int cmd_top(int argc, const char **argv)signal (SIGWINCH , winch_sig); } - top.session =perf_session__new (NULL , false,NULL ); + top.session =perf_session__new (NULL ,NULL );if (IS_ERR (top.session)) { status =PTR_ERR (top.session); goto out_delete_evlist;
tools/perf/builtin-trace.c +1 -1
@@ -4205,7 +4205,7 @@ static int trace__replay(struct trace *trace)/* add tid to output */ trace->multiple_threads = true; - session =perf_session__new (&data, false, &trace->tool); + session =perf_session__new (&data, &trace->tool);if (IS_ERR (session))return PTR_ERR (session);
tools/perf/tests/topology.c +2 -2
@@ -38,7 +38,7 @@ static int session_write_header(char *path) .mode = PERF_DATA_MODE_WRITE, }; - session =perf_session__new (&data, false,NULL ); + session =perf_session__new (&data,NULL );TEST_ASSERT_VAL ("can't get session" , !IS_ERR (session));if (!perf_pmu__has_hybrid ()) {
@@ -76,7 +76,7 @@ static int check_cpu_topology(char *path, struct perf_cpu_map *map)int i;struct aggr_cpu_id id; - session =perf_session__new (&data, false,NULL ); + session =perf_session__new (&data,NULL );TEST_ASSERT_VAL ("can't get session" , !IS_ERR (session));cpu__setup_cpunode_map ();
tools/perf/util/data-convert-bt.c +1 -1
@@ -1634,7 +1634,7 @@ int bt_convert__perf2ctf(const char *input, const char *path, err =-1 ;/* perf.data session */ - session =perf_session__new (&data,0 , &c.tool); + session =perf_session__new (&data, &c.tool);if (IS_ERR (session))return PTR_ERR (session);
tools/perf/util/data-convert-json.c +1 -1
@@ -334,7 +334,7 @@ int bt_convert__perf2json(const char *input_name, const char *output_name, goto err; } - session =perf_session__new (&data, false, &c.tool); + session =perf_session__new (&data, &c.tool);if (IS_ERR (session)) {fprintf (stderr,"Error creating perf session!\n" ); goto err_fclose;
tools/perf/util/session.c +3 -2
@@ -185,8 +185,9 @@ static int ordered_events__deliver_event(struct ordered_events *oe, session->tool, event->file_offset); } -struct perf_session *perf_session__new (struct perf_data *data, -bool repipe,struct perf_tool *tool) +struct perf_session *__perf_session__new (struct perf_data *data, +bool repipe, +struct perf_tool *tool) {int ret = -ENOMEM ;struct perf_session *session =zalloc (sizeof (*session));
tools/perf/util/session.h +10 -2
@@ -54,8 +54,16 @@ struct decomp {struct perf_tool ; -struct perf_session *perf_session__new (struct perf_data *data, -bool repipe,struct perf_tool *tool); +struct perf_session *__perf_session__new (struct perf_data *data, +bool repipe, +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); +} +void perf_session__delete (struct perf_session *session);void perf_event_header__bswap (struct perf_event_header *hdr);
Signature · 1 line
2.32.0.93.g670b81a890-goog
Namhyung Kim
maintainerPATCH 2/4 perf tools: Pass a fd to perf_file_header__read_pipe()
In reply to Namhyung KimCurrently 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.
--- tools/perf/builtin-inject.c | 1 + tools/perf/util/header.c | 12 ++++++------ tools/perf/util/header.h | 2 +- tools/perf/util/session.c | 8 ++++---- tools/perf/util/session.h | 4 ++-- 5 files changed, 14 insertions(+), 13 deletions(-)
tools/perf/builtin-inject.c +1 -0
@@ -992,6 +992,7 @@ int cmd_inject(int argc, const char **argv) data.path = inject.input_name; inject.session =__perf_session__new (&data, inject.output.is_pipe, +perf_data__fd (&inject.output), &inject.tool);if (IS_ERR (inject.session))return PTR_ERR (inject.session);
tools/perf/util/header.c +6 -6
@@ -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_hreturn 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;
tools/perf/util/header.h +1 -1
@@ -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);
tools/perf/util/session.c +4 -4
@@ -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;
tools/perf/util/session.h +2 -2
@@ -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);
Signature · 1 line
2.32.0.93.g670b81a890-goog
Namhyung Kim
maintainerPATCH 3/4 perf inject: Fix output from a pipe to a file
In reply to Namhyung KimSometimes it needs to save the perf inject data to a file for debugging. But normally it assumes the same format for input and output, so the end result cannot be used due to a broken format.
# perf record -a -o - sleep 1 | perf inject -b -o my.data
# perf report -i my.data --stdio 0x208 [0]: failed to process type: 0 [Invalid argument] Error: failed to process sample # To display the perf.data header info, please use --header/--header-only options. #
In this case, it thought the data has a regular file header since the output is not a pipe. But actually it doesn't have one and has a pipe file header. At the end of the session, it tries to rewrite the regular file header with updated features and it overwrites the data just follows the pipe header.
Fix it by checking either the input and the output is a pipe.
--- tools/perf/builtin-inject.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-)
tools/perf/builtin-inject.c +8 -4
@@ -46,6 +46,7 @@ struct perf_inject {bool jit_mode;bool in_place_update;bool in_place_update_dry_run; +bool is_pipe;const char *input_name;struct perf_data output;u64 bytes_written;
@@ -126,7 +127,7 @@ static int perf_event__repipe_attr(struct perf_tool *tool,if (ret)return ret; -if (!inject->output.is_pipe) +if (!inject->is_pipe)return 0 ;return perf_event__repipe_synth (tool, event);
@@ -825,14 +826,14 @@ static int __cmd_inject(struct perf_inject *inject)if (!inject->itrace_synth_opts.set)auxtrace_index__free (&session->auxtrace_index); -if (!data_out->is_pipe && !inject->in_place_update) +if (!inject->is_pipe && !inject->in_place_update)lseek (fd, output_data_offset,SEEK_SET ); ret =perf_session__process_events (session);if (ret)return ret; -if (!data_out->is_pipe && !inject->in_place_update) { +if (!inject->is_pipe && !inject->in_place_update) {if (inject->build_ids)perf_header__set_feat (&session->header,HEADER_BUILD_ID );
@@ -991,7 +992,10 @@ int cmd_inject(int argc, const char **argv) } data.path = inject.input_name; - inject.session =__perf_session__new (&data, inject.output.is_pipe, +if (!strcmp (inject.input_name,"-" ) || inject.output.is_pipe) + inject.is_pipe = true; + + inject.session =__perf_session__new (&data, inject.is_pipe,perf_data__fd (&inject.output), &inject.tool);if (IS_ERR (inject.session))
Signature · 1 line
2.32.0.93.g670b81a890-goog
Namhyung Kim
maintainerPATCH 4/4 perf inject: Fix output from a file to a pipe
In reply to Namhyung KimWhen the input is a regular file but the output is a pipe, it should write a pipe header. But just repiping would write a portion of the existing header which is different in 'size' value. So we need to prevent it and write a new pipe header along with other information like event attributes and features.
This can handle something like this:
# perf record -a -B sleep 1
# perf inject -b -i perf.data | perf report -i -
--- tools/perf/builtin-inject.c | 57 +++++++++++++++++++++++++++++++++++-- 1 file changed, 55 insertions(+), 2 deletions(-)
tools/perf/builtin-inject.c +55 -2
@@ -918,6 +918,7 @@ int cmd_inject(int argc, const char **argv) .use_stdio = true, };int ret; +bool repipe = true;struct option options[] = { OPT_BOOLEAN('b', "build-ids", &inject.build_ids,
@@ -992,10 +993,18 @@ int cmd_inject(int argc, const char **argv) } data.path = inject.input_name; -if (!strcmp (inject.input_name,"-" ) || inject.output.is_pipe) +if (!strcmp (inject.input_name,"-" ) || inject.output.is_pipe) { inject.is_pipe = true; +/* +* Do not repipe header when input is a regular file +* since either it can rewrite the header at the end +* or write a new pipe header. +*/ +if (strcmp (inject.input_name,"-" )) + repipe = false; + } - inject.session =__perf_session__new (&data, inject.is_pipe, + inject.session =__perf_session__new (&data, repipe,perf_data__fd (&inject.output), &inject.tool);if (IS_ERR (inject.session))
@@ -1004,6 +1013,50 @@ int cmd_inject(int argc, const char **argv)if (zstd_init (&(inject.session->zstd_data),0 ) <0 )pr_warning ("Decompression initialization failed.\n" ); +if (!data.is_pipe && inject.output.is_pipe) { + ret =perf_header__write_pipe (perf_data__fd (&inject.output)); +if (ret <0 ) { +pr_err ("Couldn't write a new pipe header.\n" ); + goto out_delete; + } + + ret =perf_event__synthesize_attrs (&inject.tool, + inject.session->evlist, + perf_event__repipe); +if (ret <0 ) { +pr_err ("Couldn't inject synthesized attrs.\n" ); + goto out_delete; + } + + ret =perf_event__synthesize_features (&inject.tool, + inject.session, + inject.session->evlist, + perf_event__repipe); +if (ret <0 ) { +pr_err ("Couldn't inject synthesized features.\n" ); + goto out_delete; + } + +if (have_tracepoints (&inject.session->evlist->core.entries)) { +/* +* FIXME err <= 0 here actually means that +* there were no tracepoints so its not really +* an error, just that we don't need to +* synthesize anything. We really have to +* return this more properly and also +* propagate errors that now are calling die() +*/ + ret =perf_event__synthesize_tracing_data (&inject.tool, +perf_data__fd (&inject.output), + inject.session->evlist, + perf_event__repipe); +if (ret <=0 ) { +pr_err ("Couldn't inject tracing data.\n" ); + goto out_delete; + } + } + } +if (inject.build_ids && !inject.build_id_all) {/* * to make sure the mmap records are ordered correctly
Signature · 1 line
2.32.0.93.g670b81a890-goog
Re: [PATCH 4/4] perf inject: Fix output from a file to a pipe
On Wed, Jul 07, 2021 at 11:05:36AM -0700, Namhyung Kim wrote:
SNIP
Quoted 33 lines
tools/perf/builtin-inject.c +33
-0+if (!data.is_pipe && inject.output.is_pipe) { + ret =perf_header__write_pipe (perf_data__fd (&inject.output)); +if (ret <0 ) { +pr_err ("Couldn't write a new pipe header.\n" ); + goto out_delete; + } + + ret =perf_event__synthesize_attrs (&inject.tool, + inject.session->evlist, + perf_event__repipe); +if (ret <0 ) { +pr_err ("Couldn't inject synthesized attrs.\n" ); + goto out_delete; + } + + ret =perf_event__synthesize_features (&inject.tool, + inject.session, + inject.session->evlist, + perf_event__repipe); +if (ret <0 ) { +pr_err ("Couldn't inject synthesized features.\n" ); + goto out_delete; + } + +if (have_tracepoints (&inject.session->evlist->core.entries)) { +/* +* FIXME err <= 0 here actually means that +* there were no tracepoints so its not really +* an error, just that we don't need to +* synthesize anything. We really have to +* return this more properly and also +* propagate errors that now are calling die() +*/
tools/perf/builtin-inject.c int cmd_inject(int argc, const char **argv) · line 1058
Quoted 10 lines
tools/perf/builtin-inject.c +10
-0+ ret =perf_event__synthesize_tracing_data (&inject.tool, +perf_data__fd (&inject.output), + inject.session->evlist, + perf_event__repipe); +if (ret <=0 ) { +pr_err ("Couldn't inject tracing data.\n" ); + goto out_delete; + } + } + }
hum.. how bad (too many args?) would be to put this to some function in util/record.c, because it's copied directly from builtin-record.c
jirka
Quoted 7 lines
tools/perf/builtin-inject.c +1
-0+if (inject.build_ids && !inject.build_id_all) {/* * to make sure the mmap records are ordered correctly Signature · 1 line
2.32.0.93.g670b81a890-goog
Namhyung Kim
maintainerRe: [PATCH 4/4] perf inject: Fix output from a file to a pipe
Hi Jiri,
Quoted 43 lines · Jiri Olsa
On Wed, Jul 07, 2021 at 11:05:36AM -0700, Namhyung Kim wrote:
SNIP
Quoted 38 lines
tools/perf/builtin-inject.c +38
-0+if (!data.is_pipe && inject.output.is_pipe) { + ret =perf_header__write_pipe (perf_data__fd (&inject.output)); +if (ret <0 ) { +pr_err ("Couldn't write a new pipe header.\n" ); + goto out_delete; + } + + ret =perf_event__synthesize_attrs (&inject.tool, + inject.session->evlist, + perf_event__repipe); +if (ret <0 ) { +pr_err ("Couldn't inject synthesized attrs.\n" ); + goto out_delete; + } + + ret =perf_event__synthesize_features (&inject.tool, + inject.session, + inject.session->evlist, + perf_event__repipe); +if (ret <0 ) { +pr_err ("Couldn't inject synthesized features.\n" ); + goto out_delete; + } + +if (have_tracepoints (&inject.session->evlist->core.entries)) { +/* +* FIXME err <= 0 here actually means that +* there were no tracepoints so its not really +* an error, just that we don't need to +* synthesize anything. We really have to +* return this more properly and also +* propagate errors that now are calling die() +*/ + ret =perf_event__synthesize_tracing_data (&inject.tool, +perf_data__fd (&inject.output), + inject.session->evlist, + perf_event__repipe); +if (ret <=0 ) {
Quoted 8 lines
tools/perf/builtin-inject.c int cmd_inject(int argc, const char **argv) · line 1058
Quoted 5 lines
tools/perf/builtin-inject.c +5
-0+pr_err ("Couldn't inject tracing data.\n" ); + goto out_delete; + } + } + }hum.. how bad (too many args?) would be to put this to some function in
util/record.c, because it's copied directly frombuiltin-record.c
I don't think they're too many. Will try to factor it out.
Thanks,
Namhyung