perf tools: Add struct perf_data_file
tip-bot for Jiri Olsa
merge botCommit-ID: eae8ad8042d82775da1ddf3faa915b32854d9cf4 Gitweb: https://git.kernel.org/tip/eae8ad8042d82775da1ddf3faa915b32854d9cf4 Author: Jiri Olsa <[email protected]> AuthorDate: Mon, 23 Jan 2017 22:25:41 +0100 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Mon, 30 Oct 2017 13:37:37 -0300
perf tools: Add struct perf_data_file
Add struct perf_data_file to represent a single file within a perf_data struct.
Signed-off-by Jiri Olsa <[email protected]>
Cc Andi Kleen <[email protected]>
Cc Changbin Du <[email protected]>
Cc David Ahern <[email protected]>
Cc Jin Yao <[email protected]>
Cc Namhyung Kim <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Wang Nan <[email protected]>
[ Fixup recent changes in 'perf script --per-event-dump' ]
Signed-off-by Arnaldo Carvalho de Melo <[email protected]>
--- tools/perf/builtin-annotate.c | 4 ++-- tools/perf/builtin-buildid-cache.c | 4 ++-- tools/perf/builtin-buildid-list.c | 8 ++++--- tools/perf/builtin-c2c.c | 4 ++-- tools/perf/builtin-diff.c | 12 +++++----- tools/perf/builtin-evlist.c | 8 ++++--- tools/perf/builtin-inject.c | 12 ++++++---- tools/perf/builtin-kmem.c | 2 +- tools/perf/builtin-kvm.c | 8 ++++--- tools/perf/builtin-lock.c | 8 ++++--- tools/perf/builtin-mem.c | 8 ++++--- tools/perf/builtin-record.c | 6 ++--- tools/perf/builtin-report.c | 6 ++--- tools/perf/builtin-sched.c | 16 ++++++++----- tools/perf/builtin-script.c | 14 ++++++----- tools/perf/builtin-stat.c | 6 ++--- tools/perf/builtin-timechart.c | 8 ++++--- tools/perf/builtin-trace.c | 8 ++++--- tools/perf/tests/topology.c | 14 +++++++---- tools/perf/util/data-convert-bt.c | 8 +++---- tools/perf/util/data.c | 48 +++++++++++++++++++------------------- tools/perf/util/data.h | 10 +++++--- tools/perf/util/header.c | 2 +- 23 files changed, 127 insertions(+), 97 deletions(-)
tools/perf/builtin-annotate.c +2 -2
@@ -356,7 +356,7 @@ static int __cmd_annotate(struct perf_annotate *ann) }if (total_nr_samples ==0 ) { -ui__error ("The %s file has no samples!\n" , session->data->path); +ui__error ("The %s file has no samples!\n" , session->data->file.path); goto out; }
@@ -482,7 +482,7 @@ int cmd_annotate(int argc, const char **argv)if (quiet)perf_quiet_option (); - data.path = input_name; + data.file.path = input_name; annotate.session =perf_session__new (&data, false, &annotate.tool);if (annotate.session ==NULL )
tools/perf/builtin-buildid-cache.c +2 -2
@@ -352,8 +352,8 @@ int cmd_buildid_cache(int argc, const char **argv) nsi =nsinfo__new (ns_id);if (missing_filename) { - data.path = missing_filename; - data.force = force; + data.file.path = missing_filename; + data.force = force; session =perf_session__new (&data, false,NULL );if (session ==NULL )
tools/perf/builtin-buildid-list.c +5 -3
@@ -51,9 +51,11 @@ static int perf_session__list_build_ids(bool force, bool with_hits) {struct perf_session *session;struct perf_data data = { - .path = input_name, - .mode =PERF_DATA_MODE_READ , - .force = force, + .file = { + .path = input_name, + }, + .mode =PERF_DATA_MODE_READ , + .force = force, };symbol__elf_init ();
tools/perf/builtin-c2c.c +2 -2
@@ -2572,8 +2572,8 @@ static int perf_c2c__report(int argc, const char **argv)if (!input_name || !strlen (input_name)) input_name ="perf.data" ; - data.path = input_name; - data.force = symbol_conf.force; + data.file.path = input_name; + data.force = symbol_conf.force; err =setup_display (display);if (err)
tools/perf/builtin-diff.c +6 -6
@@ -707,7 +707,7 @@ static void data__fprintf(void)data__for_each_file (i, d)fprintf (stdout,"# [%d] %s %s\n" , - d->idx, d->data.path, + d->idx, d->data.file.path, !d->idx ?"(Baseline)" :"" );fprintf (stdout,"#\n" );
@@ -778,14 +778,14 @@ static int __cmd_diff(void)data__for_each_file (i, d) { d->session =perf_session__new (&d->data, false, &tool);if (!d->session) { -pr_err ("Failed to open %s\n" , d->data.path); +pr_err ("Failed to open %s\n" , d->data.file.path); ret =-1 ; goto out_delete; } ret =perf_session__process_events (d->session);if (ret) { -pr_err ("Failed to process %s\n" , d->data.path); +pr_err ("Failed to process %s\n" , d->data.file.path); goto out_delete; }
@@ -1288,9 +1288,9 @@ static int data_init(int argc, const char **argv)data__for_each_file (i, d) {struct perf_data *data = &d->data; - data->path = use_default ? defaults[i] : argv[i]; - data->mode =PERF_DATA_MODE_READ , - data->force = force, + data->file.path = use_default ? defaults[i] : argv[i]; + data->mode =PERF_DATA_MODE_READ , + data->force = force, d->idx = i; }
tools/perf/builtin-evlist.c +5 -3
@@ -22,9 +22,11 @@ static int __cmd_evlist(const char *file_name, struct perf_attr_details *detailsstruct perf_session *session;struct perf_evsel *pos;struct perf_data data = { - .path = file_name, - .mode =PERF_DATA_MODE_READ , - .force = details->force, + .file = { + .path = file_name, + }, + .mode =PERF_DATA_MODE_READ , + .force = details->force, };bool has_tracepoint = false;
tools/perf/builtin-inject.c +7 -5
@@ -145,7 +145,7 @@ static s64 perf_event__repipe_auxtrace(struct perf_tool *tool,if (!inject->output.is_pipe) {off_t offset; - offset =lseek (inject->output.fd,0 ,SEEK_CUR ); + offset =lseek (inject->output.file.fd,0 ,SEEK_CUR );if (offset ==-1 )return -errno; ret = auxtrace_index__auxtrace_event(&session->auxtrace_index,
@@ -775,8 +775,10 @@ int cmd_inject(int argc, const char **argv) .input_name = "-", .samples = LIST_HEAD_INIT(inject.samples), .output = { - .path = "-", - .mode = PERF_DATA_MODE_WRITE, + .file = { + .path = "-", + }, + .mode = PERF_DATA_MODE_WRITE, }, };struct perf_data data = {
@@ -789,7 +791,7 @@ int cmd_inject(int argc, const char **argv) "Inject build-ids into the output stream"),OPT_STRING ('i' ,"input" , &inject.input_name,"file" ,"input file name" ), -OPT_STRING ('o' ,"output" , &inject.output.path,"file" , +OPT_STRING ('o' ,"output" , &inject.output.file.path,"file" ,"output file name" ),OPT_BOOLEAN ('s' ,"sched-stat" , &inject.sched_stat, "Merge sched-stat and sched-switch for getting events "
@@ -836,7 +838,7 @@ int cmd_inject(int argc, const char **argv) inject.tool.ordered_events = inject.sched_stat; - data.path = inject.input_name; + data.file.path = inject.input_name; inject.session =perf_session__new (&data, true, &inject.tool);if (inject.session ==NULL )return -1 ;
tools/perf/builtin-kmem.c +1 -1
@@ -1949,7 +1949,7 @@ int cmd_kmem(int argc, const char **argv)return __cmd_record (argc, argv); } - data.path = input_name; + data.file.path = input_name; kmem_session = session =perf_session__new (&data, false, &perf_kmem);if (session ==NULL )
tools/perf/builtin-kvm.c +5 -3
@@ -1068,9 +1068,11 @@ static int read_events(struct perf_kvm_stat *kvm) .ordered_events = true, };struct perf_data file = { - .path = kvm->file_name, - .mode =PERF_DATA_MODE_READ , - .force = kvm->force, + .file = { + .path = kvm->file_name, + }, + .mode =PERF_DATA_MODE_READ , + .force = kvm->force, }; kvm->tool = eops;
tools/perf/builtin-lock.c +5 -3
@@ -865,9 +865,11 @@ static int __cmd_report(bool display_info) .ordered_events = true, };struct perf_data data = { - .path = input_name, - .mode =PERF_DATA_MODE_READ , - .force = force, + .file = { + .path = input_name, + }, + .mode =PERF_DATA_MODE_READ , + .force = force, }; session =perf_session__new (&data, false, &eops);
tools/perf/builtin-mem.c +5 -3
@@ -237,9 +237,11 @@ static int process_sample_event(struct perf_tool *tool,static int report_raw_events (struct perf_mem *mem) {struct perf_data data = { - .path = input_name, - .mode =PERF_DATA_MODE_READ , - .force = mem->force, + .file = { + .path = input_name, + }, + .mode =PERF_DATA_MODE_READ , + .force = mem->force, };int ret; struct perf_session *session = perf_session__new(&data, false,
tools/perf/builtin-record.c +3 -3
@@ -618,7 +618,7 @@ record__switch_output(struct record *rec, bool at_exit)if (!quiet)fprintf (stderr,"[ perf record: Dump %s.%s ]\n" , - data->path, timestamp); + data->file.path, timestamp);/* Output tracking events */ if (!at_exit) {
@@ -1118,7 +1118,7 @@ out_child:fprintf (stderr,"[ perf record: Captured and wrote %.3f MB %s%s%s ]\n" ,perf_data__size (data) /1024.0 /1024.0 , - data->path, postfix, samples); + data->file.path, postfix, samples); } out_delete_session:
@@ -1482,7 +1482,7 @@ static struct option __record_options[] = {OPT_STRING ('C' ,"cpu" , &record.opts.target.cpu_list,"cpu" ,"list of cpus to monitor" ),OPT_U64 ('c' ,"count" , &record.opts.user_interval,"event period to sample" ), -OPT_STRING ('o' ,"output" , &record.data.path,"file" , +OPT_STRING ('o' ,"output" , &record.data.file.path,"file" ,"output file name" ), OPT_BOOLEAN_SET('i', "no-inherit", &record.opts.no_inherit, &record.opts.no_inherit_set,
tools/perf/builtin-report.c +3 -3
@@ -637,7 +637,7 @@ static int __cmd_report(struct report *rep) rep->nr_entries +=evsel__hists (pos)->nr_entries;if (rep->nr_entries ==0 ) { -ui__error ("The %s file has no samples!\n" , data->path); +ui__error ("The %s file has no samples!\n" , data->file.path);return 0 ; }
@@ -940,8 +940,8 @@ int cmd_report(int argc, const char **argv) input_name ="perf.data" ; } - data.path = input_name; - data.force = symbol_conf.force; + data.file.path = input_name; + data.force = symbol_conf.force; repeat: session =perf_session__new (&data, false, &report.tool);
tools/perf/builtin-sched.c +10 -6
@@ -1701,9 +1701,11 @@ static int perf_sched__read_events(struct perf_sched *sched) };struct perf_session *session;struct perf_data data = { - .path = input_name, - .mode =PERF_DATA_MODE_READ , - .force = sched->force, + .file = { + .path = input_name, + }, + .mode =PERF_DATA_MODE_READ , + .force = sched->force, };int rc =-1 ;
@@ -2903,9 +2905,11 @@ static int perf_sched__timehist(struct perf_sched *sched) { "sched:sched_migrate_task", timehist_migrate_task_event, }, };struct perf_data data = { - .path = input_name, - .mode =PERF_DATA_MODE_READ , - .force = sched->force, + .file = { + .path = input_name, + }, + .mode =PERF_DATA_MODE_READ , + .force = sched->force, };struct perf_session *session;
tools/perf/builtin-script.c +8 -6
@@ -222,7 +222,7 @@ static struct perf_evsel_script *perf_evsel_script__new(struct perf_evsel *evselstruct perf_evsel_script *es =malloc (sizeof (*es));if (es !=NULL ) { -if (asprintf (&es->filename,"%s.%s.dump" , data->path,perf_evsel__name (evsel)) <0 ) +if (asprintf (&es->filename,"%s.%s.dump" , data->file.path,perf_evsel__name (evsel)) <0 ) goto out_free; es->fp =fopen (es->filename,"w" );if (es->fp ==NULL )
@@ -2591,8 +2591,10 @@ int find_scripts(char **scripts_array, char **scripts_path_array)DIR *scripts_dir, *lang_dir;struct perf_session *session;struct perf_data data = { - .path = input_name, - .mode =PERF_DATA_MODE_READ , + .file = { + .path = input_name, + }, + .mode =PERF_DATA_MODE_READ , };char *temp;int i =0 ;
@@ -2982,8 +2984,8 @@ int cmd_script(int argc, const char **argv) argc =parse_options_subcommand (argc, argv, options, script_subcommands, script_usage,PARSE_OPT_STOP_AT_NON_OPTION ); - data.path = input_name; - data.force = symbol_conf.force; + data.file.path = input_name; + data.force = symbol_conf.force;if (argc >1 && !strncmp (argv[0 ],"rec" ,strlen ("rec" ))) { rec_script_path =get_script_path (argv[1 ],RECORD_SUFFIX );
@@ -3206,7 +3208,7 @@ int cmd_script(int argc, const char **argv) goto out_delete; } - input =open (data.path,O_RDONLY );/* input_name */ + input =open (data.file.path,O_RDONLY );/* input_name */ if (input <0 ) { err = -errno;perror ("failed to open file" );
tools/perf/builtin-stat.c +3 -3
@@ -2412,7 +2412,7 @@ static int __cmd_record(int argc, const char **argv) PARSE_OPT_STOP_AT_NON_OPTION);if (output_name) - data->path = output_name; + data->file.path = output_name;if (run_count !=1 || forever) {pr_err ("Cannot use -r option with perf stat record.\n" );
@@ -2585,8 +2585,8 @@ static int __cmd_report(int argc, const char **argv) input_name ="perf.data" ; } - perf_stat.data.path = input_name; - perf_stat.data.mode =PERF_DATA_MODE_READ ; + perf_stat.data.file.path = input_name; + perf_stat.data.mode =PERF_DATA_MODE_READ ; session =perf_session__new (&perf_stat.data, false, &perf_stat.tool);if (session ==NULL )
tools/perf/builtin-timechart.c +5 -3
@@ -1602,9 +1602,11 @@ static int __cmd_timechart(struct timechart *tchart, const char *output_name) { "syscalls:sys_exit_select", process_exit_poll }, };struct perf_data data = { - .path = input_name, - .mode =PERF_DATA_MODE_READ , - .force = tchart->force, + .file = { + .path = input_name, + }, + .mode =PERF_DATA_MODE_READ , + .force = tchart->force, }; struct perf_session *session = perf_session__new(&data, false,
tools/perf/builtin-trace.c +5 -3
@@ -2533,9 +2533,11 @@ static int trace__replay(struct trace *trace) { "probe:vfs_getname", trace__vfs_getname, }, };struct perf_data data = { - .path = input_name, - .mode =PERF_DATA_MODE_READ , - .force = trace->force, + .file = { + .path = input_name, + }, + .mode =PERF_DATA_MODE_READ , + .force = trace->force, };struct perf_session *session;struct perf_evsel *evsel;
tools/perf/tests/topology.c +9 -5
@@ -30,8 +30,10 @@ static int session_write_header(char *path) {struct perf_session *session;struct perf_data data = { - .path = path, - .mode =PERF_DATA_MODE_WRITE , + .file = { + .path = path, + }, + .mode =PERF_DATA_MODE_WRITE , }; session =perf_session__new (&data, false,NULL );
@@ -46,7 +48,7 @@ static int session_write_header(char *path) session->header.data_size +=DATA_SIZE ;TEST_ASSERT_VAL ("failed to write header" , - !perf_session__write_header (session, session->evlist, data.fd, true)); + !perf_session__write_header (session, session->evlist, data.file.fd, true));perf_session__delete (session);
@@ -57,8 +59,10 @@ static int check_cpu_topology(char *path, struct cpu_map *map) {struct perf_session *session;struct perf_data data = { - .path = path, - .mode =PERF_DATA_MODE_READ , + .file = { + .path = path, + }, + .mode =PERF_DATA_MODE_READ , };int i;
tools/perf/util/data-convert-bt.c +4 -4
@@ -1578,9 +1578,9 @@ int bt_convert__perf2ctf(const char *input, const char *path, {struct perf_session *session;struct perf_data data = { - .path = input, - .mode =PERF_DATA_MODE_READ , - .force = opts->force, + .file.path = input, + .mode =PERF_DATA_MODE_READ , + .force = opts->force, };struct convert c = { .tool = {
@@ -1650,7 +1650,7 @@ int bt_convert__perf2ctf(const char *input, const char *path,fprintf (stderr,"[ perf data convert: Converted '%s' into CTF data '%s' ]\n" , - data.path, path); + data.file.path, path); fprintf(stderr, "[ perf data convert: Converted and wrote %.3f MB (%" PRIu64 " samples",
tools/perf/util/data.c +24 -24
148 lines not on this page · raw message
tools/perf/util/data.h +7 -3
@@ -8,9 +8,13 @@ enum perf_data_mode { PERF_DATA_MODE_READ, }; +struct perf_data_file { +const char *path; +int fd; +}; +struct perf_data { -const char *path; -int fd; +struct perf_data_file file;bool is_pipe;bool force;unsigned long size;
@@ -34,7 +38,7 @@ static inline int perf_data__is_pipe(struct perf_data *data)static inline int perf_data__fd (struct perf_data *data) { -return data->fd; +return data->file.fd; }static inline unsigned long perf_data__size (struct perf_data *data)
tools/perf/util/header.c +1 -1
@@ -2889,7 +2889,7 @@ int perf_session__read_header(struct perf_session *session)if (f_header.data.size ==0 ) {pr_warning ("WARNING: The %s file's data size field is 0 which is unexpected.\n" "Was the 'perf record' command properly terminated?\n" , - data->path); + data->file.path); } nr_attrs = f_header.attrs.size / f_header.attr_size;