aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorJiri Olsa <jolsa@kernel.org>2017-01-23 16:25:41 -0500
committerArnaldo Carvalho de Melo <acme@redhat.com>2017-10-30 12:37:37 -0400
commiteae8ad8042d82775da1ddf3faa915b32854d9cf4 (patch)
treec00e93fe4edcd756a8dec1cf4e86a51473c636fc /tools
parent8ceb41d7e305f186543c58178d2e1fe34f708948 (diff)
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 <jolsa@kernel.org> Cc: Andi Kleen <andi@firstfloor.org> Cc: Changbin Du <changbin.du@intel.com> Cc: David Ahern <dsahern@gmail.com> Cc: Jin Yao <yao.jin@linux.intel.com> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Wang Nan <wangnan0@huawei.com> Link: http://lkml.kernel.org/n/tip-c3f9p4xzykr845ktqcek6p4t@git.kernel.org [ Fixup recent changes in 'perf script --per-event-dump' ] Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools')
-rw-r--r--tools/perf/builtin-annotate.c4
-rw-r--r--tools/perf/builtin-buildid-cache.c4
-rw-r--r--tools/perf/builtin-buildid-list.c8
-rw-r--r--tools/perf/builtin-c2c.c4
-rw-r--r--tools/perf/builtin-diff.c12
-rw-r--r--tools/perf/builtin-evlist.c8
-rw-r--r--tools/perf/builtin-inject.c12
-rw-r--r--tools/perf/builtin-kmem.c2
-rw-r--r--tools/perf/builtin-kvm.c8
-rw-r--r--tools/perf/builtin-lock.c8
-rw-r--r--tools/perf/builtin-mem.c8
-rw-r--r--tools/perf/builtin-record.c6
-rw-r--r--tools/perf/builtin-report.c6
-rw-r--r--tools/perf/builtin-sched.c16
-rw-r--r--tools/perf/builtin-script.c14
-rw-r--r--tools/perf/builtin-stat.c6
-rw-r--r--tools/perf/builtin-timechart.c8
-rw-r--r--tools/perf/builtin-trace.c8
-rw-r--r--tools/perf/tests/topology.c14
-rw-r--r--tools/perf/util/data-convert-bt.c8
-rw-r--r--tools/perf/util/data.c48
-rw-r--r--tools/perf/util/data.h10
-rw-r--r--tools/perf/util/header.c2
23 files changed, 127 insertions, 97 deletions
diff --git a/tools/perf/builtin-annotate.c b/tools/perf/builtin-annotate.c
index 2d06be81a109..2d5c87578f83 100644
--- a/tools/perf/builtin-annotate.c
+++ b/tools/perf/builtin-annotate.c
@@ -356,7 +356,7 @@ static int __cmd_annotate(struct perf_annotate *ann)
356 } 356 }
357 357
358 if (total_nr_samples == 0) { 358 if (total_nr_samples == 0) {
359 ui__error("The %s file has no samples!\n", session->data->path); 359 ui__error("The %s file has no samples!\n", session->data->file.path);
360 goto out; 360 goto out;
361 } 361 }
362 362
@@ -482,7 +482,7 @@ int cmd_annotate(int argc, const char **argv)
482 if (quiet) 482 if (quiet)
483 perf_quiet_option(); 483 perf_quiet_option();
484 484
485 data.path = input_name; 485 data.file.path = input_name;
486 486
487 annotate.session = perf_session__new(&data, false, &annotate.tool); 487 annotate.session = perf_session__new(&data, false, &annotate.tool);
488 if (annotate.session == NULL) 488 if (annotate.session == NULL)
diff --git a/tools/perf/builtin-buildid-cache.c b/tools/perf/builtin-buildid-cache.c
index 9fceae47a02e..cb2453b29365 100644
--- a/tools/perf/builtin-buildid-cache.c
+++ b/tools/perf/builtin-buildid-cache.c
@@ -352,8 +352,8 @@ int cmd_buildid_cache(int argc, const char **argv)
352 nsi = nsinfo__new(ns_id); 352 nsi = nsinfo__new(ns_id);
353 353
354 if (missing_filename) { 354 if (missing_filename) {
355 data.path = missing_filename; 355 data.file.path = missing_filename;
356 data.force = force; 356 data.force = force;
357 357
358 session = perf_session__new(&data, false, NULL); 358 session = perf_session__new(&data, false, NULL);
359 if (session == NULL) 359 if (session == NULL)
diff --git a/tools/perf/builtin-buildid-list.c b/tools/perf/builtin-buildid-list.c
index 72bdc0eba990..00099a830b0d 100644
--- a/tools/perf/builtin-buildid-list.c
+++ b/tools/perf/builtin-buildid-list.c
@@ -51,9 +51,11 @@ static int perf_session__list_build_ids(bool force, bool with_hits)
51{ 51{
52 struct perf_session *session; 52 struct perf_session *session;
53 struct perf_data data = { 53 struct perf_data data = {
54 .path = input_name, 54 .file = {
55 .mode = PERF_DATA_MODE_READ, 55 .path = input_name,
56 .force = force, 56 },
57 .mode = PERF_DATA_MODE_READ,
58 .force = force,
57 }; 59 };
58 60
59 symbol__elf_init(); 61 symbol__elf_init();
diff --git a/tools/perf/builtin-c2c.c b/tools/perf/builtin-c2c.c
index 87a52d09da29..9590fdcc6484 100644
--- a/tools/perf/builtin-c2c.c
+++ b/tools/perf/builtin-c2c.c
@@ -2572,8 +2572,8 @@ static int perf_c2c__report(int argc, const char **argv)
2572 if (!input_name || !strlen(input_name)) 2572 if (!input_name || !strlen(input_name))
2573 input_name = "perf.data"; 2573 input_name = "perf.data";
2574 2574
2575 data.path = input_name; 2575 data.file.path = input_name;
2576 data.force = symbol_conf.force; 2576 data.force = symbol_conf.force;
2577 2577
2578 err = setup_display(display); 2578 err = setup_display(display);
2579 if (err) 2579 if (err)
diff --git a/tools/perf/builtin-diff.c b/tools/perf/builtin-diff.c
index 5292e3d13cec..67570e6417e5 100644
--- a/tools/perf/builtin-diff.c
+++ b/tools/perf/builtin-diff.c
@@ -707,7 +707,7 @@ static void data__fprintf(void)
707 707
708 data__for_each_file(i, d) 708 data__for_each_file(i, d)
709 fprintf(stdout, "# [%d] %s %s\n", 709 fprintf(stdout, "# [%d] %s %s\n",
710 d->idx, d->data.path, 710 d->idx, d->data.file.path,
711 !d->idx ? "(Baseline)" : ""); 711 !d->idx ? "(Baseline)" : "");
712 712
713 fprintf(stdout, "#\n"); 713 fprintf(stdout, "#\n");
@@ -778,14 +778,14 @@ static int __cmd_diff(void)
778 data__for_each_file(i, d) { 778 data__for_each_file(i, d) {
779 d->session = perf_session__new(&d->data, false, &tool); 779 d->session = perf_session__new(&d->data, false, &tool);
780 if (!d->session) { 780 if (!d->session) {
781 pr_err("Failed to open %s\n", d->data.path); 781 pr_err("Failed to open %s\n", d->data.file.path);
782 ret = -1; 782 ret = -1;
783 goto out_delete; 783 goto out_delete;
784 } 784 }
785 785
786 ret = perf_session__process_events(d->session); 786 ret = perf_session__process_events(d->session);
787 if (ret) { 787 if (ret) {
788 pr_err("Failed to process %s\n", d->data.path); 788 pr_err("Failed to process %s\n", d->data.file.path);
789 goto out_delete; 789 goto out_delete;
790 } 790 }
791 791
@@ -1288,9 +1288,9 @@ static int data_init(int argc, const char **argv)
1288 data__for_each_file(i, d) { 1288 data__for_each_file(i, d) {
1289 struct perf_data *data = &d->data; 1289 struct perf_data *data = &d->data;
1290 1290
1291 data->path = use_default ? defaults[i] : argv[i]; 1291 data->file.path = use_default ? defaults[i] : argv[i];
1292 data->mode = PERF_DATA_MODE_READ, 1292 data->mode = PERF_DATA_MODE_READ,
1293 data->force = force, 1293 data->force = force,
1294 1294
1295 d->idx = i; 1295 d->idx = i;
1296 } 1296 }
diff --git a/tools/perf/builtin-evlist.c b/tools/perf/builtin-evlist.c
index cd79c26e16a4..93b85dc857b6 100644
--- a/tools/perf/builtin-evlist.c
+++ b/tools/perf/builtin-evlist.c
@@ -22,9 +22,11 @@ static int __cmd_evlist(const char *file_name, struct perf_attr_details *details
22 struct perf_session *session; 22 struct perf_session *session;
23 struct perf_evsel *pos; 23 struct perf_evsel *pos;
24 struct perf_data data = { 24 struct perf_data data = {
25 .path = file_name, 25 .file = {
26 .mode = PERF_DATA_MODE_READ, 26 .path = file_name,
27 .force = details->force, 27 },
28 .mode = PERF_DATA_MODE_READ,
29 .force = details->force,
28 }; 30 };
29 bool has_tracepoint = false; 31 bool has_tracepoint = false;
30 32
diff --git a/tools/perf/builtin-inject.c b/tools/perf/builtin-inject.c
index ac7486f6c46f..91e65093d3c2 100644
--- a/tools/perf/builtin-inject.c
+++ b/tools/perf/builtin-inject.c
@@ -145,7 +145,7 @@ static s64 perf_event__repipe_auxtrace(struct perf_tool *tool,
145 if (!inject->output.is_pipe) { 145 if (!inject->output.is_pipe) {
146 off_t offset; 146 off_t offset;
147 147
148 offset = lseek(inject->output.fd, 0, SEEK_CUR); 148 offset = lseek(inject->output.file.fd, 0, SEEK_CUR);
149 if (offset == -1) 149 if (offset == -1)
150 return -errno; 150 return -errno;
151 ret = auxtrace_index__auxtrace_event(&session->auxtrace_index, 151 ret = auxtrace_index__auxtrace_event(&session->auxtrace_index,
@@ -775,8 +775,10 @@ int cmd_inject(int argc, const char **argv)
775 .input_name = "-", 775 .input_name = "-",
776 .samples = LIST_HEAD_INIT(inject.samples), 776 .samples = LIST_HEAD_INIT(inject.samples),
777 .output = { 777 .output = {
778 .path = "-", 778 .file = {
779 .mode = PERF_DATA_MODE_WRITE, 779 .path = "-",
780 },
781 .mode = PERF_DATA_MODE_WRITE,
780 }, 782 },
781 }; 783 };
782 struct perf_data data = { 784 struct perf_data data = {
@@ -789,7 +791,7 @@ int cmd_inject(int argc, const char **argv)
789 "Inject build-ids into the output stream"), 791 "Inject build-ids into the output stream"),
790 OPT_STRING('i', "input", &inject.input_name, "file", 792 OPT_STRING('i', "input", &inject.input_name, "file",
791 "input file name"), 793 "input file name"),
792 OPT_STRING('o', "output", &inject.output.path, "file", 794 OPT_STRING('o', "output", &inject.output.file.path, "file",
793 "output file name"), 795 "output file name"),
794 OPT_BOOLEAN('s', "sched-stat", &inject.sched_stat, 796 OPT_BOOLEAN('s', "sched-stat", &inject.sched_stat,
795 "Merge sched-stat and sched-switch for getting events " 797 "Merge sched-stat and sched-switch for getting events "
@@ -836,7 +838,7 @@ int cmd_inject(int argc, const char **argv)
836 838
837 inject.tool.ordered_events = inject.sched_stat; 839 inject.tool.ordered_events = inject.sched_stat;
838 840
839 data.path = inject.input_name; 841 data.file.path = inject.input_name;
840 inject.session = perf_session__new(&data, true, &inject.tool); 842 inject.session = perf_session__new(&data, true, &inject.tool);
841 if (inject.session == NULL) 843 if (inject.session == NULL)
842 return -1; 844 return -1;
diff --git a/tools/perf/builtin-kmem.c b/tools/perf/builtin-kmem.c
index d45740a3e5f1..abcab75cc5b9 100644
--- a/tools/perf/builtin-kmem.c
+++ b/tools/perf/builtin-kmem.c
@@ -1949,7 +1949,7 @@ int cmd_kmem(int argc, const char **argv)
1949 return __cmd_record(argc, argv); 1949 return __cmd_record(argc, argv);
1950 } 1950 }
1951 1951
1952 data.path = input_name; 1952 data.file.path = input_name;
1953 1953
1954 kmem_session = session = perf_session__new(&data, false, &perf_kmem); 1954 kmem_session = session = perf_session__new(&data, false, &perf_kmem);
1955 if (session == NULL) 1955 if (session == NULL)
diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c
index 4301fc34f23c..0af4c092b471 100644
--- a/tools/perf/builtin-kvm.c
+++ b/tools/perf/builtin-kvm.c
@@ -1068,9 +1068,11 @@ static int read_events(struct perf_kvm_stat *kvm)
1068 .ordered_events = true, 1068 .ordered_events = true,
1069 }; 1069 };
1070 struct perf_data file = { 1070 struct perf_data file = {
1071 .path = kvm->file_name, 1071 .file = {
1072 .mode = PERF_DATA_MODE_READ, 1072 .path = kvm->file_name,
1073 .force = kvm->force, 1073 },
1074 .mode = PERF_DATA_MODE_READ,
1075 .force = kvm->force,
1074 }; 1076 };
1075 1077
1076 kvm->tool = eops; 1078 kvm->tool = eops;
diff --git a/tools/perf/builtin-lock.c b/tools/perf/builtin-lock.c
index 2e281f7b0fca..81af29400b64 100644
--- a/tools/perf/builtin-lock.c
+++ b/tools/perf/builtin-lock.c
@@ -865,9 +865,11 @@ static int __cmd_report(bool display_info)
865 .ordered_events = true, 865 .ordered_events = true,
866 }; 866 };
867 struct perf_data data = { 867 struct perf_data data = {
868 .path = input_name, 868 .file = {
869 .mode = PERF_DATA_MODE_READ, 869 .path = input_name,
870 .force = force, 870 },
871 .mode = PERF_DATA_MODE_READ,
872 .force = force,
871 }; 873 };
872 874
873 session = perf_session__new(&data, false, &eops); 875 session = perf_session__new(&data, false, &eops);
diff --git a/tools/perf/builtin-mem.c b/tools/perf/builtin-mem.c
index 5a4a6f8e614d..f09fd1a1b813 100644
--- a/tools/perf/builtin-mem.c
+++ b/tools/perf/builtin-mem.c
@@ -237,9 +237,11 @@ static int process_sample_event(struct perf_tool *tool,
237static int report_raw_events(struct perf_mem *mem) 237static int report_raw_events(struct perf_mem *mem)
238{ 238{
239 struct perf_data data = { 239 struct perf_data data = {
240 .path = input_name, 240 .file = {
241 .mode = PERF_DATA_MODE_READ, 241 .path = input_name,
242 .force = mem->force, 242 },
243 .mode = PERF_DATA_MODE_READ,
244 .force = mem->force,
243 }; 245 };
244 int ret; 246 int ret;
245 struct perf_session *session = perf_session__new(&data, false, 247 struct perf_session *session = perf_session__new(&data, false,
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index 0ab7dd0e4f2b..f4d9fc54b382 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -618,7 +618,7 @@ record__switch_output(struct record *rec, bool at_exit)
618 618
619 if (!quiet) 619 if (!quiet)
620 fprintf(stderr, "[ perf record: Dump %s.%s ]\n", 620 fprintf(stderr, "[ perf record: Dump %s.%s ]\n",
621 data->path, timestamp); 621 data->file.path, timestamp);
622 622
623 /* Output tracking events */ 623 /* Output tracking events */
624 if (!at_exit) { 624 if (!at_exit) {
@@ -1118,7 +1118,7 @@ out_child:
1118 1118
1119 fprintf(stderr, "[ perf record: Captured and wrote %.3f MB %s%s%s ]\n", 1119 fprintf(stderr, "[ perf record: Captured and wrote %.3f MB %s%s%s ]\n",
1120 perf_data__size(data) / 1024.0 / 1024.0, 1120 perf_data__size(data) / 1024.0 / 1024.0,
1121 data->path, postfix, samples); 1121 data->file.path, postfix, samples);
1122 } 1122 }
1123 1123
1124out_delete_session: 1124out_delete_session:
@@ -1482,7 +1482,7 @@ static struct option __record_options[] = {
1482 OPT_STRING('C', "cpu", &record.opts.target.cpu_list, "cpu", 1482 OPT_STRING('C', "cpu", &record.opts.target.cpu_list, "cpu",
1483 "list of cpus to monitor"), 1483 "list of cpus to monitor"),
1484 OPT_U64('c', "count", &record.opts.user_interval, "event period to sample"), 1484 OPT_U64('c', "count", &record.opts.user_interval, "event period to sample"),
1485 OPT_STRING('o', "output", &record.data.path, "file", 1485 OPT_STRING('o', "output", &record.data.file.path, "file",
1486 "output file name"), 1486 "output file name"),
1487 OPT_BOOLEAN_SET('i', "no-inherit", &record.opts.no_inherit, 1487 OPT_BOOLEAN_SET('i', "no-inherit", &record.opts.no_inherit,
1488 &record.opts.no_inherit_set, 1488 &record.opts.no_inherit_set,
diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c
index 0dc323772b5e..3c2d9d4932f3 100644
--- a/tools/perf/builtin-report.c
+++ b/tools/perf/builtin-report.c
@@ -637,7 +637,7 @@ static int __cmd_report(struct report *rep)
637 rep->nr_entries += evsel__hists(pos)->nr_entries; 637 rep->nr_entries += evsel__hists(pos)->nr_entries;
638 638
639 if (rep->nr_entries == 0) { 639 if (rep->nr_entries == 0) {
640 ui__error("The %s file has no samples!\n", data->path); 640 ui__error("The %s file has no samples!\n", data->file.path);
641 return 0; 641 return 0;
642 } 642 }
643 643
@@ -940,8 +940,8 @@ int cmd_report(int argc, const char **argv)
940 input_name = "perf.data"; 940 input_name = "perf.data";
941 } 941 }
942 942
943 data.path = input_name; 943 data.file.path = input_name;
944 data.force = symbol_conf.force; 944 data.force = symbol_conf.force;
945 945
946repeat: 946repeat:
947 session = perf_session__new(&data, false, &report.tool); 947 session = perf_session__new(&data, false, &report.tool);
diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c
index cb5410511f69..47e54348b5ed 100644
--- a/tools/perf/builtin-sched.c
+++ b/tools/perf/builtin-sched.c
@@ -1701,9 +1701,11 @@ static int perf_sched__read_events(struct perf_sched *sched)
1701 }; 1701 };
1702 struct perf_session *session; 1702 struct perf_session *session;
1703 struct perf_data data = { 1703 struct perf_data data = {
1704 .path = input_name, 1704 .file = {
1705 .mode = PERF_DATA_MODE_READ, 1705 .path = input_name,
1706 .force = sched->force, 1706 },
1707 .mode = PERF_DATA_MODE_READ,
1708 .force = sched->force,
1707 }; 1709 };
1708 int rc = -1; 1710 int rc = -1;
1709 1711
@@ -2903,9 +2905,11 @@ static int perf_sched__timehist(struct perf_sched *sched)
2903 { "sched:sched_migrate_task", timehist_migrate_task_event, }, 2905 { "sched:sched_migrate_task", timehist_migrate_task_event, },
2904 }; 2906 };
2905 struct perf_data data = { 2907 struct perf_data data = {
2906 .path = input_name, 2908 .file = {
2907 .mode = PERF_DATA_MODE_READ, 2909 .path = input_name,
2908 .force = sched->force, 2910 },
2911 .mode = PERF_DATA_MODE_READ,
2912 .force = sched->force,
2909 }; 2913 };
2910 2914
2911 struct perf_session *session; 2915 struct perf_session *session;
diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
index 8f8fa952b506..89975e30c0ba 100644
--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -222,7 +222,7 @@ static struct perf_evsel_script *perf_evsel_script__new(struct perf_evsel *evsel
222 struct perf_evsel_script *es = malloc(sizeof(*es)); 222 struct perf_evsel_script *es = malloc(sizeof(*es));
223 223
224 if (es != NULL) { 224 if (es != NULL) {
225 if (asprintf(&es->filename, "%s.%s.dump", data->path, perf_evsel__name(evsel)) < 0) 225 if (asprintf(&es->filename, "%s.%s.dump", data->file.path, perf_evsel__name(evsel)) < 0)
226 goto out_free; 226 goto out_free;
227 es->fp = fopen(es->filename, "w"); 227 es->fp = fopen(es->filename, "w");
228 if (es->fp == NULL) 228 if (es->fp == NULL)
@@ -2591,8 +2591,10 @@ int find_scripts(char **scripts_array, char **scripts_path_array)
2591 DIR *scripts_dir, *lang_dir; 2591 DIR *scripts_dir, *lang_dir;
2592 struct perf_session *session; 2592 struct perf_session *session;
2593 struct perf_data data = { 2593 struct perf_data data = {
2594 .path = input_name, 2594 .file = {
2595 .mode = PERF_DATA_MODE_READ, 2595 .path = input_name,
2596 },
2597 .mode = PERF_DATA_MODE_READ,
2596 }; 2598 };
2597 char *temp; 2599 char *temp;
2598 int i = 0; 2600 int i = 0;
@@ -2982,8 +2984,8 @@ int cmd_script(int argc, const char **argv)
2982 argc = parse_options_subcommand(argc, argv, options, script_subcommands, script_usage, 2984 argc = parse_options_subcommand(argc, argv, options, script_subcommands, script_usage,
2983 PARSE_OPT_STOP_AT_NON_OPTION); 2985 PARSE_OPT_STOP_AT_NON_OPTION);
2984 2986
2985 data.path = input_name; 2987 data.file.path = input_name;
2986 data.force = symbol_conf.force; 2988 data.force = symbol_conf.force;
2987 2989
2988 if (argc > 1 && !strncmp(argv[0], "rec", strlen("rec"))) { 2990 if (argc > 1 && !strncmp(argv[0], "rec", strlen("rec"))) {
2989 rec_script_path = get_script_path(argv[1], RECORD_SUFFIX); 2991 rec_script_path = get_script_path(argv[1], RECORD_SUFFIX);
@@ -3206,7 +3208,7 @@ int cmd_script(int argc, const char **argv)
3206 goto out_delete; 3208 goto out_delete;
3207 } 3209 }
3208 3210
3209 input = open(data.path, O_RDONLY); /* input_name */ 3211 input = open(data.file.path, O_RDONLY); /* input_name */
3210 if (input < 0) { 3212 if (input < 0) {
3211 err = -errno; 3213 err = -errno;
3212 perror("failed to open file"); 3214 perror("failed to open file");
diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
index 85af6d291c06..fa5896270022 100644
--- a/tools/perf/builtin-stat.c
+++ b/tools/perf/builtin-stat.c
@@ -2412,7 +2412,7 @@ static int __cmd_record(int argc, const char **argv)
2412 PARSE_OPT_STOP_AT_NON_OPTION); 2412 PARSE_OPT_STOP_AT_NON_OPTION);
2413 2413
2414 if (output_name) 2414 if (output_name)
2415 data->path = output_name; 2415 data->file.path = output_name;
2416 2416
2417 if (run_count != 1 || forever) { 2417 if (run_count != 1 || forever) {
2418 pr_err("Cannot use -r option with perf stat record.\n"); 2418 pr_err("Cannot use -r option with perf stat record.\n");
@@ -2585,8 +2585,8 @@ static int __cmd_report(int argc, const char **argv)
2585 input_name = "perf.data"; 2585 input_name = "perf.data";
2586 } 2586 }
2587 2587
2588 perf_stat.data.path = input_name; 2588 perf_stat.data.file.path = input_name;
2589 perf_stat.data.mode = PERF_DATA_MODE_READ; 2589 perf_stat.data.mode = PERF_DATA_MODE_READ;
2590 2590
2591 session = perf_session__new(&perf_stat.data, false, &perf_stat.tool); 2591 session = perf_session__new(&perf_stat.data, false, &perf_stat.tool);
2592 if (session == NULL) 2592 if (session == NULL)
diff --git a/tools/perf/builtin-timechart.c b/tools/perf/builtin-timechart.c
index 0f79ea5e2f0f..813698a9b8c7 100644
--- a/tools/perf/builtin-timechart.c
+++ b/tools/perf/builtin-timechart.c
@@ -1602,9 +1602,11 @@ static int __cmd_timechart(struct timechart *tchart, const char *output_name)
1602 { "syscalls:sys_exit_select", process_exit_poll }, 1602 { "syscalls:sys_exit_select", process_exit_poll },
1603 }; 1603 };
1604 struct perf_data data = { 1604 struct perf_data data = {
1605 .path = input_name, 1605 .file = {
1606 .mode = PERF_DATA_MODE_READ, 1606 .path = input_name,
1607 .force = tchart->force, 1607 },
1608 .mode = PERF_DATA_MODE_READ,
1609 .force = tchart->force,
1608 }; 1610 };
1609 1611
1610 struct perf_session *session = perf_session__new(&data, false, 1612 struct perf_session *session = perf_session__new(&data, false,
diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c
index 7def6947ad61..c373f9a3e4a9 100644
--- a/tools/perf/builtin-trace.c
+++ b/tools/perf/builtin-trace.c
@@ -2533,9 +2533,11 @@ static int trace__replay(struct trace *trace)
2533 { "probe:vfs_getname", trace__vfs_getname, }, 2533 { "probe:vfs_getname", trace__vfs_getname, },
2534 }; 2534 };
2535 struct perf_data data = { 2535 struct perf_data data = {
2536 .path = input_name, 2536 .file = {
2537 .mode = PERF_DATA_MODE_READ, 2537 .path = input_name,
2538 .force = trace->force, 2538 },
2539 .mode = PERF_DATA_MODE_READ,
2540 .force = trace->force,
2539 }; 2541 };
2540 struct perf_session *session; 2542 struct perf_session *session;
2541 struct perf_evsel *evsel; 2543 struct perf_evsel *evsel;
diff --git a/tools/perf/tests/topology.c b/tools/perf/tests/topology.c
index 7536782e8495..9bbfed51f1d6 100644
--- a/tools/perf/tests/topology.c
+++ b/tools/perf/tests/topology.c
@@ -30,8 +30,10 @@ static int session_write_header(char *path)
30{ 30{
31 struct perf_session *session; 31 struct perf_session *session;
32 struct perf_data data = { 32 struct perf_data data = {
33 .path = path, 33 .file = {
34 .mode = PERF_DATA_MODE_WRITE, 34 .path = path,
35 },
36 .mode = PERF_DATA_MODE_WRITE,
35 }; 37 };
36 38
37 session = perf_session__new(&data, false, NULL); 39 session = perf_session__new(&data, false, NULL);
@@ -46,7 +48,7 @@ static int session_write_header(char *path)
46 session->header.data_size += DATA_SIZE; 48 session->header.data_size += DATA_SIZE;
47 49
48 TEST_ASSERT_VAL("failed to write header", 50 TEST_ASSERT_VAL("failed to write header",
49 !perf_session__write_header(session, session->evlist, data.fd, true)); 51 !perf_session__write_header(session, session->evlist, data.file.fd, true));
50 52
51 perf_session__delete(session); 53 perf_session__delete(session);
52 54
@@ -57,8 +59,10 @@ static int check_cpu_topology(char *path, struct cpu_map *map)
57{ 59{
58 struct perf_session *session; 60 struct perf_session *session;
59 struct perf_data data = { 61 struct perf_data data = {
60 .path = path, 62 .file = {
61 .mode = PERF_DATA_MODE_READ, 63 .path = path,
64 },
65 .mode = PERF_DATA_MODE_READ,
62 }; 66 };
63 int i; 67 int i;
64 68
diff --git a/tools/perf/util/data-convert-bt.c b/tools/perf/util/data-convert-bt.c
index 9fdae383a58c..5744c12641a5 100644
--- a/tools/perf/util/data-convert-bt.c
+++ b/tools/perf/util/data-convert-bt.c
@@ -1578,9 +1578,9 @@ int bt_convert__perf2ctf(const char *input, const char *path,
1578{ 1578{
1579 struct perf_session *session; 1579 struct perf_session *session;
1580 struct perf_data data = { 1580 struct perf_data data = {
1581 .path = input, 1581 .file.path = input,
1582 .mode = PERF_DATA_MODE_READ, 1582 .mode = PERF_DATA_MODE_READ,
1583 .force = opts->force, 1583 .force = opts->force,
1584 }; 1584 };
1585 struct convert c = { 1585 struct convert c = {
1586 .tool = { 1586 .tool = {
@@ -1650,7 +1650,7 @@ int bt_convert__perf2ctf(const char *input, const char *path,
1650 1650
1651 fprintf(stderr, 1651 fprintf(stderr,
1652 "[ perf data convert: Converted '%s' into CTF data '%s' ]\n", 1652 "[ perf data convert: Converted '%s' into CTF data '%s' ]\n",
1653 data.path, path); 1653 data.file.path, path);
1654 1654
1655 fprintf(stderr, 1655 fprintf(stderr,
1656 "[ perf data convert: Converted and wrote %.3f MB (%" PRIu64 " samples", 1656 "[ perf data convert: Converted and wrote %.3f MB (%" PRIu64 " samples",
diff --git a/tools/perf/util/data.c b/tools/perf/util/data.c
index a6eea3df4c10..07ef56a4123c 100644
--- a/tools/perf/util/data.c
+++ b/tools/perf/util/data.c
@@ -28,16 +28,16 @@ static bool check_pipe(struct perf_data *data)
28 int fd = perf_data__is_read(data) ? 28 int fd = perf_data__is_read(data) ?
29 STDIN_FILENO : STDOUT_FILENO; 29 STDIN_FILENO : STDOUT_FILENO;
30 30
31 if (!data->path) { 31 if (!data->file.path) {
32 if (!fstat(fd, &st) && S_ISFIFO(st.st_mode)) 32 if (!fstat(fd, &st) && S_ISFIFO(st.st_mode))
33 is_pipe = true; 33 is_pipe = true;
34 } else { 34 } else {
35 if (!strcmp(data->path, "-")) 35 if (!strcmp(data->file.path, "-"))
36 is_pipe = true; 36 is_pipe = true;
37 } 37 }
38 38
39 if (is_pipe) 39 if (is_pipe)
40 data->fd = fd; 40 data->file.fd = fd;
41 41
42 return data->is_pipe = is_pipe; 42 return data->is_pipe = is_pipe;
43} 43}
@@ -46,13 +46,13 @@ static int check_backup(struct perf_data *data)
46{ 46{
47 struct stat st; 47 struct stat st;
48 48
49 if (!stat(data->path, &st) && st.st_size) { 49 if (!stat(data->file.path, &st) && st.st_size) {
50 /* TODO check errors properly */ 50 /* TODO check errors properly */
51 char oldname[PATH_MAX]; 51 char oldname[PATH_MAX];
52 snprintf(oldname, sizeof(oldname), "%s.old", 52 snprintf(oldname, sizeof(oldname), "%s.old",
53 data->path); 53 data->file.path);
54 unlink(oldname); 54 unlink(oldname);
55 rename(data->path, oldname); 55 rename(data->file.path, oldname);
56 } 56 }
57 57
58 return 0; 58 return 0;
@@ -64,13 +64,13 @@ static int open_file_read(struct perf_data *data)
64 int fd; 64 int fd;
65 char sbuf[STRERR_BUFSIZE]; 65 char sbuf[STRERR_BUFSIZE];
66 66
67 fd = open(data->path, O_RDONLY); 67 fd = open(data->file.path, O_RDONLY);
68 if (fd < 0) { 68 if (fd < 0) {
69 int err = errno; 69 int err = errno;
70 70
71 pr_err("failed to open %s: %s", data->path, 71 pr_err("failed to open %s: %s", data->file.path,
72 str_error_r(err, sbuf, sizeof(sbuf))); 72 str_error_r(err, sbuf, sizeof(sbuf)));
73 if (err == ENOENT && !strcmp(data->path, "perf.data")) 73 if (err == ENOENT && !strcmp(data->file.path, "perf.data"))
74 pr_err(" (try 'perf record' first)"); 74 pr_err(" (try 'perf record' first)");
75 pr_err("\n"); 75 pr_err("\n");
76 return -err; 76 return -err;
@@ -81,13 +81,13 @@ static int open_file_read(struct perf_data *data)
81 81
82 if (!data->force && st.st_uid && (st.st_uid != geteuid())) { 82 if (!data->force && st.st_uid && (st.st_uid != geteuid())) {
83 pr_err("File %s not owned by current user or root (use -f to override)\n", 83 pr_err("File %s not owned by current user or root (use -f to override)\n",
84 data->path); 84 data->file.path);
85 goto out_close; 85 goto out_close;
86 } 86 }
87 87
88 if (!st.st_size) { 88 if (!st.st_size) {
89 pr_info("zero-sized data (%s), nothing to do!\n", 89 pr_info("zero-sized data (%s), nothing to do!\n",
90 data->path); 90 data->file.path);
91 goto out_close; 91 goto out_close;
92 } 92 }
93 93
@@ -107,11 +107,11 @@ static int open_file_write(struct perf_data *data)
107 if (check_backup(data)) 107 if (check_backup(data))
108 return -1; 108 return -1;
109 109
110 fd = open(data->path, O_CREAT|O_RDWR|O_TRUNC|O_CLOEXEC, 110 fd = open(data->file.path, O_CREAT|O_RDWR|O_TRUNC|O_CLOEXEC,
111 S_IRUSR|S_IWUSR); 111 S_IRUSR|S_IWUSR);
112 112
113 if (fd < 0) 113 if (fd < 0)
114 pr_err("failed to open %s : %s\n", data->path, 114 pr_err("failed to open %s : %s\n", data->file.path,
115 str_error_r(errno, sbuf, sizeof(sbuf))); 115 str_error_r(errno, sbuf, sizeof(sbuf)));
116 116
117 return fd; 117 return fd;
@@ -124,7 +124,7 @@ static int open_file(struct perf_data *data)
124 fd = perf_data__is_read(data) ? 124 fd = perf_data__is_read(data) ?
125 open_file_read(data) : open_file_write(data); 125 open_file_read(data) : open_file_write(data);
126 126
127 data->fd = fd; 127 data->file.fd = fd;
128 return fd < 0 ? -1 : 0; 128 return fd < 0 ? -1 : 0;
129} 129}
130 130
@@ -133,21 +133,21 @@ int perf_data__open(struct perf_data *data)
133 if (check_pipe(data)) 133 if (check_pipe(data))
134 return 0; 134 return 0;
135 135
136 if (!data->path) 136 if (!data->file.path)
137 data->path = "perf.data"; 137 data->file.path = "perf.data";
138 138
139 return open_file(data); 139 return open_file(data);
140} 140}
141 141
142void perf_data__close(struct perf_data *data) 142void perf_data__close(struct perf_data *data)
143{ 143{
144 close(data->fd); 144 close(data->file.fd);
145} 145}
146 146
147ssize_t perf_data__write(struct perf_data *data, 147ssize_t perf_data__write(struct perf_data *data,
148 void *buf, size_t size) 148 void *buf, size_t size)
149{ 149{
150 return writen(data->fd, buf, size); 150 return writen(data->file.fd, buf, size);
151} 151}
152 152
153int perf_data__switch(struct perf_data *data, 153int perf_data__switch(struct perf_data *data,
@@ -162,30 +162,30 @@ int perf_data__switch(struct perf_data *data,
162 if (perf_data__is_read(data)) 162 if (perf_data__is_read(data))
163 return -EINVAL; 163 return -EINVAL;
164 164
165 if (asprintf(&new_filepath, "%s.%s", data->path, postfix) < 0) 165 if (asprintf(&new_filepath, "%s.%s", data->file.path, postfix) < 0)
166 return -ENOMEM; 166 return -ENOMEM;
167 167
168 /* 168 /*
169 * Only fire a warning, don't return error, continue fill 169 * Only fire a warning, don't return error, continue fill
170 * original file. 170 * original file.
171 */ 171 */
172 if (rename(data->path, new_filepath)) 172 if (rename(data->file.path, new_filepath))
173 pr_warning("Failed to rename %s to %s\n", data->path, new_filepath); 173 pr_warning("Failed to rename %s to %s\n", data->file.path, new_filepath);
174 174
175 if (!at_exit) { 175 if (!at_exit) {
176 close(data->fd); 176 close(data->file.fd);
177 ret = perf_data__open(data); 177 ret = perf_data__open(data);
178 if (ret < 0) 178 if (ret < 0)
179 goto out; 179 goto out;
180 180
181 if (lseek(data->fd, pos, SEEK_SET) == (off_t)-1) { 181 if (lseek(data->file.fd, pos, SEEK_SET) == (off_t)-1) {
182 ret = -errno; 182 ret = -errno;
183 pr_debug("Failed to lseek to %zu: %s", 183 pr_debug("Failed to lseek to %zu: %s",
184 pos, strerror(errno)); 184 pos, strerror(errno));
185 goto out; 185 goto out;
186 } 186 }
187 } 187 }
188 ret = data->fd; 188 ret = data->file.fd;
189out: 189out:
190 free(new_filepath); 190 free(new_filepath);
191 return ret; 191 return ret;
diff --git a/tools/perf/util/data.h b/tools/perf/util/data.h
index a1f9d70426b1..1797bed3aa4b 100644
--- a/tools/perf/util/data.h
+++ b/tools/perf/util/data.h
@@ -8,9 +8,13 @@ enum perf_data_mode {
8 PERF_DATA_MODE_READ, 8 PERF_DATA_MODE_READ,
9}; 9};
10 10
11struct perf_data_file {
12 const char *path;
13 int fd;
14};
15
11struct perf_data { 16struct perf_data {
12 const char *path; 17 struct perf_data_file file;
13 int fd;
14 bool is_pipe; 18 bool is_pipe;
15 bool force; 19 bool force;
16 unsigned long size; 20 unsigned long size;
@@ -34,7 +38,7 @@ static inline int perf_data__is_pipe(struct perf_data *data)
34 38
35static inline int perf_data__fd(struct perf_data *data) 39static inline int perf_data__fd(struct perf_data *data)
36{ 40{
37 return data->fd; 41 return data->file.fd;
38} 42}
39 43
40static inline unsigned long perf_data__size(struct perf_data *data) 44static inline unsigned long perf_data__size(struct perf_data *data)
diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c
index d7be552b21c8..6e59dcca9df2 100644
--- a/tools/perf/util/header.c
+++ b/tools/perf/util/header.c
@@ -2889,7 +2889,7 @@ int perf_session__read_header(struct perf_session *session)
2889 if (f_header.data.size == 0) { 2889 if (f_header.data.size == 0) {
2890 pr_warning("WARNING: The %s file's data size field is 0 which is unexpected.\n" 2890 pr_warning("WARNING: The %s file's data size field is 0 which is unexpected.\n"
2891 "Was the 'perf record' command properly terminated?\n", 2891 "Was the 'perf record' command properly terminated?\n",
2892 data->path); 2892 data->file.path);
2893 } 2893 }
2894 2894
2895 nr_attrs = f_header.attrs.size / f_header.attr_size; 2895 nr_attrs = f_header.attrs.size / f_header.attr_size;