diff options
author | Jiri Olsa <jolsa@kernel.org> | 2019-02-21 04:41:30 -0500 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2019-02-22 14:52:07 -0500 |
commit | 2d4f27999b8877409f326682fd8cc40c52f47cea (patch) | |
tree | 33c3e619718d0c75bee39957f6ca4ed70ac59c0d | |
parent | 45112e89a8b2b4c9a004147cbfb448b1200cfbf7 (diff) |
perf data: Add global path holder
Add a 'path' member to 'struct perf_data'. It will keep the configured
path for the data (const char *). The path in struct perf_data_file is
now dynamically allocated (duped) from it.
This scheme is useful/used in following patches where struct
perf_data::path holds the 'configure' directory path and struct
perf_data_file::path holds the allocated path for specific files.
Also it actually makes the code little simpler.
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Alexey Budankov <alexey.budankov@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/r/20190221094145.9151-3-jolsa@kernel.org
[ Fixup data-convert-bt.c missing conversion ]
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
-rw-r--r-- | tools/perf/builtin-annotate.c | 4 | ||||
-rw-r--r-- | tools/perf/builtin-buildid-cache.c | 4 | ||||
-rw-r--r-- | tools/perf/builtin-buildid-list.c | 8 | ||||
-rw-r--r-- | tools/perf/builtin-c2c.c | 4 | ||||
-rw-r--r-- | tools/perf/builtin-diff.c | 12 | ||||
-rw-r--r-- | tools/perf/builtin-evlist.c | 4 | ||||
-rw-r--r-- | tools/perf/builtin-inject.c | 10 | ||||
-rw-r--r-- | tools/perf/builtin-kmem.c | 2 | ||||
-rw-r--r-- | tools/perf/builtin-kvm.c | 8 | ||||
-rw-r--r-- | tools/perf/builtin-lock.c | 8 | ||||
-rw-r--r-- | tools/perf/builtin-mem.c | 8 | ||||
-rw-r--r-- | tools/perf/builtin-record.c | 6 | ||||
-rw-r--r-- | tools/perf/builtin-report.c | 6 | ||||
-rw-r--r-- | tools/perf/builtin-sched.c | 16 | ||||
-rw-r--r-- | tools/perf/builtin-script.c | 12 | ||||
-rw-r--r-- | tools/perf/builtin-stat.c | 6 | ||||
-rw-r--r-- | tools/perf/builtin-timechart.c | 8 | ||||
-rw-r--r-- | tools/perf/builtin-trace.c | 8 | ||||
-rw-r--r-- | tools/perf/util/data-convert-bt.c | 4 | ||||
-rw-r--r-- | tools/perf/util/data.c | 39 | ||||
-rw-r--r-- | tools/perf/util/data.h | 3 |
21 files changed, 87 insertions, 93 deletions
diff --git a/tools/perf/builtin-annotate.c b/tools/perf/builtin-annotate.c index 7f3c3fea67b4..67f9d9ffacfb 100644 --- a/tools/perf/builtin-annotate.c +++ b/tools/perf/builtin-annotate.c | |||
@@ -441,7 +441,7 @@ static int __cmd_annotate(struct perf_annotate *ann) | |||
441 | } | 441 | } |
442 | 442 | ||
443 | if (total_nr_samples == 0) { | 443 | if (total_nr_samples == 0) { |
444 | ui__error("The %s file has no samples!\n", session->data->file.path); | 444 | ui__error("The %s data has no samples!\n", session->data->path); |
445 | goto out; | 445 | goto out; |
446 | } | 446 | } |
447 | 447 | ||
@@ -578,7 +578,7 @@ int cmd_annotate(int argc, const char **argv) | |||
578 | if (quiet) | 578 | if (quiet) |
579 | perf_quiet_option(); | 579 | perf_quiet_option(); |
580 | 580 | ||
581 | data.file.path = input_name; | 581 | data.path = input_name; |
582 | 582 | ||
583 | annotate.session = perf_session__new(&data, false, &annotate.tool); | 583 | annotate.session = perf_session__new(&data, false, &annotate.tool); |
584 | if (annotate.session == NULL) | 584 | if (annotate.session == NULL) |
diff --git a/tools/perf/builtin-buildid-cache.c b/tools/perf/builtin-buildid-cache.c index 115110a4796a..10457b10e568 100644 --- a/tools/perf/builtin-buildid-cache.c +++ b/tools/perf/builtin-buildid-cache.c | |||
@@ -416,8 +416,8 @@ int cmd_buildid_cache(int argc, const char **argv) | |||
416 | nsi = nsinfo__new(ns_id); | 416 | nsi = nsinfo__new(ns_id); |
417 | 417 | ||
418 | if (missing_filename) { | 418 | if (missing_filename) { |
419 | data.file.path = missing_filename; | 419 | data.path = missing_filename; |
420 | data.force = force; | 420 | data.force = force; |
421 | 421 | ||
422 | session = perf_session__new(&data, false, NULL); | 422 | session = perf_session__new(&data, false, NULL); |
423 | if (session == NULL) | 423 | if (session == NULL) |
diff --git a/tools/perf/builtin-buildid-list.c b/tools/perf/builtin-buildid-list.c index 78abbe8d9d5f..f403e19488b5 100644 --- a/tools/perf/builtin-buildid-list.c +++ b/tools/perf/builtin-buildid-list.c | |||
@@ -52,11 +52,9 @@ static int perf_session__list_build_ids(bool force, bool with_hits) | |||
52 | { | 52 | { |
53 | struct perf_session *session; | 53 | struct perf_session *session; |
54 | struct perf_data data = { | 54 | struct perf_data data = { |
55 | .file = { | 55 | .path = input_name, |
56 | .path = input_name, | 56 | .mode = PERF_DATA_MODE_READ, |
57 | }, | 57 | .force = force, |
58 | .mode = PERF_DATA_MODE_READ, | ||
59 | .force = force, | ||
60 | }; | 58 | }; |
61 | 59 | ||
62 | symbol__elf_init(); | 60 | symbol__elf_init(); |
diff --git a/tools/perf/builtin-c2c.c b/tools/perf/builtin-c2c.c index efaaab23c6fd..4272763a5e96 100644 --- a/tools/perf/builtin-c2c.c +++ b/tools/perf/builtin-c2c.c | |||
@@ -2750,8 +2750,8 @@ static int perf_c2c__report(int argc, const char **argv) | |||
2750 | if (!input_name || !strlen(input_name)) | 2750 | if (!input_name || !strlen(input_name)) |
2751 | input_name = "perf.data"; | 2751 | input_name = "perf.data"; |
2752 | 2752 | ||
2753 | data.file.path = input_name; | 2753 | data.path = input_name; |
2754 | data.force = symbol_conf.force; | 2754 | data.force = symbol_conf.force; |
2755 | 2755 | ||
2756 | err = setup_display(display); | 2756 | err = setup_display(display); |
2757 | if (err) | 2757 | if (err) |
diff --git a/tools/perf/builtin-diff.c b/tools/perf/builtin-diff.c index 751e1971456b..58fe0e88215c 100644 --- a/tools/perf/builtin-diff.c +++ b/tools/perf/builtin-diff.c | |||
@@ -708,7 +708,7 @@ static void data__fprintf(void) | |||
708 | 708 | ||
709 | data__for_each_file(i, d) | 709 | data__for_each_file(i, d) |
710 | fprintf(stdout, "# [%d] %s %s\n", | 710 | fprintf(stdout, "# [%d] %s %s\n", |
711 | d->idx, d->data.file.path, | 711 | d->idx, d->data.path, |
712 | !d->idx ? "(Baseline)" : ""); | 712 | !d->idx ? "(Baseline)" : ""); |
713 | 713 | ||
714 | fprintf(stdout, "#\n"); | 714 | fprintf(stdout, "#\n"); |
@@ -779,14 +779,14 @@ static int __cmd_diff(void) | |||
779 | data__for_each_file(i, d) { | 779 | data__for_each_file(i, d) { |
780 | d->session = perf_session__new(&d->data, false, &tool); | 780 | d->session = perf_session__new(&d->data, false, &tool); |
781 | if (!d->session) { | 781 | if (!d->session) { |
782 | pr_err("Failed to open %s\n", d->data.file.path); | 782 | pr_err("Failed to open %s\n", d->data.path); |
783 | ret = -1; | 783 | ret = -1; |
784 | goto out_delete; | 784 | goto out_delete; |
785 | } | 785 | } |
786 | 786 | ||
787 | ret = perf_session__process_events(d->session); | 787 | ret = perf_session__process_events(d->session); |
788 | if (ret) { | 788 | if (ret) { |
789 | pr_err("Failed to process %s\n", d->data.file.path); | 789 | pr_err("Failed to process %s\n", d->data.path); |
790 | goto out_delete; | 790 | goto out_delete; |
791 | } | 791 | } |
792 | 792 | ||
@@ -1289,9 +1289,9 @@ static int data_init(int argc, const char **argv) | |||
1289 | data__for_each_file(i, d) { | 1289 | data__for_each_file(i, d) { |
1290 | struct perf_data *data = &d->data; | 1290 | struct perf_data *data = &d->data; |
1291 | 1291 | ||
1292 | data->file.path = use_default ? defaults[i] : argv[i]; | 1292 | data->path = use_default ? defaults[i] : argv[i]; |
1293 | data->mode = PERF_DATA_MODE_READ, | 1293 | data->mode = PERF_DATA_MODE_READ, |
1294 | data->force = force, | 1294 | data->force = force, |
1295 | 1295 | ||
1296 | d->idx = i; | 1296 | d->idx = i; |
1297 | } | 1297 | } |
diff --git a/tools/perf/builtin-evlist.c b/tools/perf/builtin-evlist.c index e06e822ce634..6e4f63b0da4a 100644 --- a/tools/perf/builtin-evlist.c +++ b/tools/perf/builtin-evlist.c | |||
@@ -23,9 +23,7 @@ static int __cmd_evlist(const char *file_name, struct perf_attr_details *details | |||
23 | struct perf_session *session; | 23 | struct perf_session *session; |
24 | struct perf_evsel *pos; | 24 | struct perf_evsel *pos; |
25 | struct perf_data data = { | 25 | struct perf_data data = { |
26 | .file = { | 26 | .path = file_name, |
27 | .path = file_name, | ||
28 | }, | ||
29 | .mode = PERF_DATA_MODE_READ, | 27 | .mode = PERF_DATA_MODE_READ, |
30 | .force = details->force, | 28 | .force = details->force, |
31 | }; | 29 | }; |
diff --git a/tools/perf/builtin-inject.c b/tools/perf/builtin-inject.c index 9bb1f35d5cb7..24086b7f1b14 100644 --- a/tools/perf/builtin-inject.c +++ b/tools/perf/builtin-inject.c | |||
@@ -770,10 +770,8 @@ int cmd_inject(int argc, const char **argv) | |||
770 | .input_name = "-", | 770 | .input_name = "-", |
771 | .samples = LIST_HEAD_INIT(inject.samples), | 771 | .samples = LIST_HEAD_INIT(inject.samples), |
772 | .output = { | 772 | .output = { |
773 | .file = { | 773 | .path = "-", |
774 | .path = "-", | 774 | .mode = PERF_DATA_MODE_WRITE, |
775 | }, | ||
776 | .mode = PERF_DATA_MODE_WRITE, | ||
777 | }, | 775 | }, |
778 | }; | 776 | }; |
779 | struct perf_data data = { | 777 | struct perf_data data = { |
@@ -786,7 +784,7 @@ int cmd_inject(int argc, const char **argv) | |||
786 | "Inject build-ids into the output stream"), | 784 | "Inject build-ids into the output stream"), |
787 | OPT_STRING('i', "input", &inject.input_name, "file", | 785 | OPT_STRING('i', "input", &inject.input_name, "file", |
788 | "input file name"), | 786 | "input file name"), |
789 | OPT_STRING('o', "output", &inject.output.file.path, "file", | 787 | OPT_STRING('o', "output", &inject.output.path, "file", |
790 | "output file name"), | 788 | "output file name"), |
791 | OPT_BOOLEAN('s', "sched-stat", &inject.sched_stat, | 789 | OPT_BOOLEAN('s', "sched-stat", &inject.sched_stat, |
792 | "Merge sched-stat and sched-switch for getting events " | 790 | "Merge sched-stat and sched-switch for getting events " |
@@ -834,7 +832,7 @@ int cmd_inject(int argc, const char **argv) | |||
834 | 832 | ||
835 | inject.tool.ordered_events = inject.sched_stat; | 833 | inject.tool.ordered_events = inject.sched_stat; |
836 | 834 | ||
837 | data.file.path = inject.input_name; | 835 | data.path = inject.input_name; |
838 | inject.session = perf_session__new(&data, true, &inject.tool); | 836 | inject.session = perf_session__new(&data, true, &inject.tool); |
839 | if (inject.session == NULL) | 837 | if (inject.session == NULL) |
840 | return -1; | 838 | return -1; |
diff --git a/tools/perf/builtin-kmem.c b/tools/perf/builtin-kmem.c index b80ec0883537..fa520f4b8095 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.file.path = input_name; | 1952 | data.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 3d4cbc4e87c7..dbb6f737a3e2 100644 --- a/tools/perf/builtin-kvm.c +++ b/tools/perf/builtin-kvm.c | |||
@@ -1080,11 +1080,9 @@ static int read_events(struct perf_kvm_stat *kvm) | |||
1080 | .ordered_events = true, | 1080 | .ordered_events = true, |
1081 | }; | 1081 | }; |
1082 | struct perf_data file = { | 1082 | struct perf_data file = { |
1083 | .file = { | 1083 | .path = kvm->file_name, |
1084 | .path = kvm->file_name, | 1084 | .mode = PERF_DATA_MODE_READ, |
1085 | }, | 1085 | .force = kvm->force, |
1086 | .mode = PERF_DATA_MODE_READ, | ||
1087 | .force = kvm->force, | ||
1088 | }; | 1086 | }; |
1089 | 1087 | ||
1090 | kvm->tool = eops; | 1088 | kvm->tool = eops; |
diff --git a/tools/perf/builtin-lock.c b/tools/perf/builtin-lock.c index 6e0189df2b3b..b9810a8d350a 100644 --- a/tools/perf/builtin-lock.c +++ b/tools/perf/builtin-lock.c | |||
@@ -866,11 +866,9 @@ static int __cmd_report(bool display_info) | |||
866 | .ordered_events = true, | 866 | .ordered_events = true, |
867 | }; | 867 | }; |
868 | struct perf_data data = { | 868 | struct perf_data data = { |
869 | .file = { | 869 | .path = input_name, |
870 | .path = input_name, | 870 | .mode = PERF_DATA_MODE_READ, |
871 | }, | 871 | .force = force, |
872 | .mode = PERF_DATA_MODE_READ, | ||
873 | .force = force, | ||
874 | }; | 872 | }; |
875 | 873 | ||
876 | session = perf_session__new(&data, false, &eops); | 874 | session = perf_session__new(&data, false, &eops); |
diff --git a/tools/perf/builtin-mem.c b/tools/perf/builtin-mem.c index ba7e8d87dec3..f45c8b502f63 100644 --- a/tools/perf/builtin-mem.c +++ b/tools/perf/builtin-mem.c | |||
@@ -239,11 +239,9 @@ static int process_sample_event(struct perf_tool *tool, | |||
239 | static int report_raw_events(struct perf_mem *mem) | 239 | static int report_raw_events(struct perf_mem *mem) |
240 | { | 240 | { |
241 | struct perf_data data = { | 241 | struct perf_data data = { |
242 | .file = { | 242 | .path = input_name, |
243 | .path = input_name, | 243 | .mode = PERF_DATA_MODE_READ, |
244 | }, | 244 | .force = mem->force, |
245 | .mode = PERF_DATA_MODE_READ, | ||
246 | .force = mem->force, | ||
247 | }; | 245 | }; |
248 | int ret; | 246 | int ret; |
249 | 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 e5e9900c9039..f3f7f3100336 100644 --- a/tools/perf/builtin-record.c +++ b/tools/perf/builtin-record.c | |||
@@ -918,7 +918,7 @@ record__switch_output(struct record *rec, bool at_exit) | |||
918 | 918 | ||
919 | if (!quiet) | 919 | if (!quiet) |
920 | fprintf(stderr, "[ perf record: Dump %s.%s ]\n", | 920 | fprintf(stderr, "[ perf record: Dump %s.%s ]\n", |
921 | data->file.path, timestamp); | 921 | data->path, timestamp); |
922 | 922 | ||
923 | /* Output tracking events */ | 923 | /* Output tracking events */ |
924 | if (!at_exit) { | 924 | if (!at_exit) { |
@@ -1461,7 +1461,7 @@ out_child: | |||
1461 | 1461 | ||
1462 | fprintf(stderr, "[ perf record: Captured and wrote %.3f MB %s%s%s ]\n", | 1462 | fprintf(stderr, "[ perf record: Captured and wrote %.3f MB %s%s%s ]\n", |
1463 | perf_data__size(data) / 1024.0 / 1024.0, | 1463 | perf_data__size(data) / 1024.0 / 1024.0, |
1464 | data->file.path, postfix, samples); | 1464 | data->path, postfix, samples); |
1465 | } | 1465 | } |
1466 | 1466 | ||
1467 | out_delete_session: | 1467 | out_delete_session: |
@@ -1862,7 +1862,7 @@ static struct option __record_options[] = { | |||
1862 | OPT_STRING('C', "cpu", &record.opts.target.cpu_list, "cpu", | 1862 | OPT_STRING('C', "cpu", &record.opts.target.cpu_list, "cpu", |
1863 | "list of cpus to monitor"), | 1863 | "list of cpus to monitor"), |
1864 | OPT_U64('c', "count", &record.opts.user_interval, "event period to sample"), | 1864 | OPT_U64('c', "count", &record.opts.user_interval, "event period to sample"), |
1865 | OPT_STRING('o', "output", &record.data.file.path, "file", | 1865 | OPT_STRING('o', "output", &record.data.path, "file", |
1866 | "output file name"), | 1866 | "output file name"), |
1867 | OPT_BOOLEAN_SET('i', "no-inherit", &record.opts.no_inherit, | 1867 | OPT_BOOLEAN_SET('i', "no-inherit", &record.opts.no_inherit, |
1868 | &record.opts.no_inherit_set, | 1868 | &record.opts.no_inherit_set, |
diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c index 2e8c74d6430c..1532ebde6c4b 100644 --- a/tools/perf/builtin-report.c +++ b/tools/perf/builtin-report.c | |||
@@ -899,7 +899,7 @@ static int __cmd_report(struct report *rep) | |||
899 | rep->nr_entries += evsel__hists(pos)->nr_entries; | 899 | rep->nr_entries += evsel__hists(pos)->nr_entries; |
900 | 900 | ||
901 | if (rep->nr_entries == 0) { | 901 | if (rep->nr_entries == 0) { |
902 | ui__error("The %s file has no samples!\n", data->file.path); | 902 | ui__error("The %s data has no samples!\n", data->path); |
903 | return 0; | 903 | return 0; |
904 | } | 904 | } |
905 | 905 | ||
@@ -1207,8 +1207,8 @@ int cmd_report(int argc, const char **argv) | |||
1207 | input_name = "perf.data"; | 1207 | input_name = "perf.data"; |
1208 | } | 1208 | } |
1209 | 1209 | ||
1210 | data.file.path = input_name; | 1210 | data.path = input_name; |
1211 | data.force = symbol_conf.force; | 1211 | data.force = symbol_conf.force; |
1212 | 1212 | ||
1213 | repeat: | 1213 | repeat: |
1214 | session = perf_session__new(&data, false, &report.tool); | 1214 | session = perf_session__new(&data, false, &report.tool); |
diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c index 640558e9352e..275f2d92a7bf 100644 --- a/tools/perf/builtin-sched.c +++ b/tools/perf/builtin-sched.c | |||
@@ -1785,11 +1785,9 @@ static int perf_sched__read_events(struct perf_sched *sched) | |||
1785 | }; | 1785 | }; |
1786 | struct perf_session *session; | 1786 | struct perf_session *session; |
1787 | struct perf_data data = { | 1787 | struct perf_data data = { |
1788 | .file = { | 1788 | .path = input_name, |
1789 | .path = input_name, | 1789 | .mode = PERF_DATA_MODE_READ, |
1790 | }, | 1790 | .force = sched->force, |
1791 | .mode = PERF_DATA_MODE_READ, | ||
1792 | .force = sched->force, | ||
1793 | }; | 1791 | }; |
1794 | int rc = -1; | 1792 | int rc = -1; |
1795 | 1793 | ||
@@ -2958,11 +2956,9 @@ static int perf_sched__timehist(struct perf_sched *sched) | |||
2958 | { "sched:sched_migrate_task", timehist_migrate_task_event, }, | 2956 | { "sched:sched_migrate_task", timehist_migrate_task_event, }, |
2959 | }; | 2957 | }; |
2960 | struct perf_data data = { | 2958 | struct perf_data data = { |
2961 | .file = { | 2959 | .path = input_name, |
2962 | .path = input_name, | 2960 | .mode = PERF_DATA_MODE_READ, |
2963 | }, | 2961 | .force = sched->force, |
2964 | .mode = PERF_DATA_MODE_READ, | ||
2965 | .force = sched->force, | ||
2966 | }; | 2962 | }; |
2967 | 2963 | ||
2968 | struct perf_session *session; | 2964 | struct perf_session *session; |
diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c index 373ea151dc60..5b1543f42290 100644 --- a/tools/perf/builtin-script.c +++ b/tools/perf/builtin-script.c | |||
@@ -2951,10 +2951,8 @@ int find_scripts(char **scripts_array, char **scripts_path_array) | |||
2951 | DIR *scripts_dir, *lang_dir; | 2951 | DIR *scripts_dir, *lang_dir; |
2952 | struct perf_session *session; | 2952 | struct perf_session *session; |
2953 | struct perf_data data = { | 2953 | struct perf_data data = { |
2954 | .file = { | 2954 | .path = input_name, |
2955 | .path = input_name, | 2955 | .mode = PERF_DATA_MODE_READ, |
2956 | }, | ||
2957 | .mode = PERF_DATA_MODE_READ, | ||
2958 | }; | 2956 | }; |
2959 | char *temp; | 2957 | char *temp; |
2960 | int i = 0; | 2958 | int i = 0; |
@@ -3427,8 +3425,8 @@ int cmd_script(int argc, const char **argv) | |||
3427 | argc = parse_options_subcommand(argc, argv, options, script_subcommands, script_usage, | 3425 | argc = parse_options_subcommand(argc, argv, options, script_subcommands, script_usage, |
3428 | PARSE_OPT_STOP_AT_NON_OPTION); | 3426 | PARSE_OPT_STOP_AT_NON_OPTION); |
3429 | 3427 | ||
3430 | data.file.path = input_name; | 3428 | data.path = input_name; |
3431 | data.force = symbol_conf.force; | 3429 | data.force = symbol_conf.force; |
3432 | 3430 | ||
3433 | if (argc > 1 && !strncmp(argv[0], "rec", strlen("rec"))) { | 3431 | if (argc > 1 && !strncmp(argv[0], "rec", strlen("rec"))) { |
3434 | rec_script_path = get_script_path(argv[1], RECORD_SUFFIX); | 3432 | rec_script_path = get_script_path(argv[1], RECORD_SUFFIX); |
@@ -3654,7 +3652,7 @@ int cmd_script(int argc, const char **argv) | |||
3654 | goto out_delete; | 3652 | goto out_delete; |
3655 | } | 3653 | } |
3656 | 3654 | ||
3657 | input = open(data.file.path, O_RDONLY); /* input_name */ | 3655 | input = open(data.path, O_RDONLY); /* input_name */ |
3658 | if (input < 0) { | 3656 | if (input < 0) { |
3659 | err = -errno; | 3657 | err = -errno; |
3660 | perror("failed to open file"); | 3658 | perror("failed to open file"); |
diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index bb24f9c17f9a..7b8f09b0b8bf 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c | |||
@@ -1322,7 +1322,7 @@ static int __cmd_record(int argc, const char **argv) | |||
1322 | PARSE_OPT_STOP_AT_NON_OPTION); | 1322 | PARSE_OPT_STOP_AT_NON_OPTION); |
1323 | 1323 | ||
1324 | if (output_name) | 1324 | if (output_name) |
1325 | data->file.path = output_name; | 1325 | data->path = output_name; |
1326 | 1326 | ||
1327 | if (stat_config.run_count != 1 || forever) { | 1327 | if (stat_config.run_count != 1 || forever) { |
1328 | pr_err("Cannot use -r option with perf stat record.\n"); | 1328 | pr_err("Cannot use -r option with perf stat record.\n"); |
@@ -1523,8 +1523,8 @@ static int __cmd_report(int argc, const char **argv) | |||
1523 | input_name = "perf.data"; | 1523 | input_name = "perf.data"; |
1524 | } | 1524 | } |
1525 | 1525 | ||
1526 | perf_stat.data.file.path = input_name; | 1526 | perf_stat.data.path = input_name; |
1527 | perf_stat.data.mode = PERF_DATA_MODE_READ; | 1527 | perf_stat.data.mode = PERF_DATA_MODE_READ; |
1528 | 1528 | ||
1529 | session = perf_session__new(&perf_stat.data, false, &perf_stat.tool); | 1529 | session = perf_session__new(&perf_stat.data, false, &perf_stat.tool); |
1530 | if (session == NULL) | 1530 | if (session == NULL) |
diff --git a/tools/perf/builtin-timechart.c b/tools/perf/builtin-timechart.c index 775b99833e51..9b98687a27b9 100644 --- a/tools/perf/builtin-timechart.c +++ b/tools/perf/builtin-timechart.c | |||
@@ -1602,11 +1602,9 @@ 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 | .file = { | 1605 | .path = input_name, |
1606 | .path = input_name, | 1606 | .mode = PERF_DATA_MODE_READ, |
1607 | }, | 1607 | .force = tchart->force, |
1608 | .mode = PERF_DATA_MODE_READ, | ||
1609 | .force = tchart->force, | ||
1610 | }; | 1608 | }; |
1611 | 1609 | ||
1612 | struct perf_session *session = perf_session__new(&data, false, | 1610 | struct perf_session *session = perf_session__new(&data, false, |
diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c index 1a11fe656afc..f5b3a1e9c1dd 100644 --- a/tools/perf/builtin-trace.c +++ b/tools/perf/builtin-trace.c | |||
@@ -3154,11 +3154,9 @@ static int trace__replay(struct trace *trace) | |||
3154 | { "probe:vfs_getname", trace__vfs_getname, }, | 3154 | { "probe:vfs_getname", trace__vfs_getname, }, |
3155 | }; | 3155 | }; |
3156 | struct perf_data data = { | 3156 | struct perf_data data = { |
3157 | .file = { | 3157 | .path = input_name, |
3158 | .path = input_name, | 3158 | .mode = PERF_DATA_MODE_READ, |
3159 | }, | 3159 | .force = trace->force, |
3160 | .mode = PERF_DATA_MODE_READ, | ||
3161 | .force = trace->force, | ||
3162 | }; | 3160 | }; |
3163 | struct perf_session *session; | 3161 | struct perf_session *session; |
3164 | struct perf_evsel *evsel; | 3162 | struct perf_evsel *evsel; |
diff --git a/tools/perf/util/data-convert-bt.c b/tools/perf/util/data-convert-bt.c index 2a36fab76994..26af43ad9ddd 100644 --- a/tools/perf/util/data-convert-bt.c +++ b/tools/perf/util/data-convert-bt.c | |||
@@ -1578,7 +1578,7 @@ 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 | .file = { .path = input, .fd = -1 }, | 1581 | .path = input, |
1582 | .mode = PERF_DATA_MODE_READ, | 1582 | .mode = PERF_DATA_MODE_READ, |
1583 | .force = opts->force, | 1583 | .force = opts->force, |
1584 | }; | 1584 | }; |
@@ -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.file.path, path); | 1653 | data.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 09eceda17fc2..e16d06ed1100 100644 --- a/tools/perf/util/data.c +++ b/tools/perf/util/data.c | |||
@@ -19,11 +19,11 @@ static bool check_pipe(struct perf_data *data) | |||
19 | int fd = perf_data__is_read(data) ? | 19 | int fd = perf_data__is_read(data) ? |
20 | STDIN_FILENO : STDOUT_FILENO; | 20 | STDIN_FILENO : STDOUT_FILENO; |
21 | 21 | ||
22 | if (!data->file.path) { | 22 | if (!data->path) { |
23 | if (!fstat(fd, &st) && S_ISFIFO(st.st_mode)) | 23 | if (!fstat(fd, &st) && S_ISFIFO(st.st_mode)) |
24 | is_pipe = true; | 24 | is_pipe = true; |
25 | } else { | 25 | } else { |
26 | if (!strcmp(data->file.path, "-")) | 26 | if (!strcmp(data->path, "-")) |
27 | is_pipe = true; | 27 | is_pipe = true; |
28 | } | 28 | } |
29 | 29 | ||
@@ -37,13 +37,13 @@ static int check_backup(struct perf_data *data) | |||
37 | { | 37 | { |
38 | struct stat st; | 38 | struct stat st; |
39 | 39 | ||
40 | if (!stat(data->file.path, &st) && st.st_size) { | 40 | if (!stat(data->path, &st) && st.st_size) { |
41 | /* TODO check errors properly */ | 41 | /* TODO check errors properly */ |
42 | char oldname[PATH_MAX]; | 42 | char oldname[PATH_MAX]; |
43 | snprintf(oldname, sizeof(oldname), "%s.old", | 43 | snprintf(oldname, sizeof(oldname), "%s.old", |
44 | data->file.path); | 44 | data->path); |
45 | unlink(oldname); | 45 | unlink(oldname); |
46 | rename(data->file.path, oldname); | 46 | rename(data->path, oldname); |
47 | } | 47 | } |
48 | 48 | ||
49 | return 0; | 49 | return 0; |
@@ -115,8 +115,22 @@ static int open_file(struct perf_data *data) | |||
115 | fd = perf_data__is_read(data) ? | 115 | fd = perf_data__is_read(data) ? |
116 | open_file_read(data) : open_file_write(data); | 116 | open_file_read(data) : open_file_write(data); |
117 | 117 | ||
118 | if (fd < 0) { | ||
119 | free(data->file.path); | ||
120 | return -1; | ||
121 | } | ||
122 | |||
118 | data->file.fd = fd; | 123 | data->file.fd = fd; |
119 | return fd < 0 ? -1 : 0; | 124 | return 0; |
125 | } | ||
126 | |||
127 | static int open_file_dup(struct perf_data *data) | ||
128 | { | ||
129 | data->file.path = strdup(data->path); | ||
130 | if (!data->file.path) | ||
131 | return -ENOMEM; | ||
132 | |||
133 | return open_file(data); | ||
120 | } | 134 | } |
121 | 135 | ||
122 | int perf_data__open(struct perf_data *data) | 136 | int perf_data__open(struct perf_data *data) |
@@ -124,14 +138,15 @@ int perf_data__open(struct perf_data *data) | |||
124 | if (check_pipe(data)) | 138 | if (check_pipe(data)) |
125 | return 0; | 139 | return 0; |
126 | 140 | ||
127 | if (!data->file.path) | 141 | if (!data->path) |
128 | data->file.path = "perf.data"; | 142 | data->path = "perf.data"; |
129 | 143 | ||
130 | return open_file(data); | 144 | return open_file_dup(data); |
131 | } | 145 | } |
132 | 146 | ||
133 | void perf_data__close(struct perf_data *data) | 147 | void perf_data__close(struct perf_data *data) |
134 | { | 148 | { |
149 | free(data->file.path); | ||
135 | close(data->file.fd); | 150 | close(data->file.fd); |
136 | } | 151 | } |
137 | 152 | ||
@@ -159,15 +174,15 @@ int perf_data__switch(struct perf_data *data, | |||
159 | if (perf_data__is_read(data)) | 174 | if (perf_data__is_read(data)) |
160 | return -EINVAL; | 175 | return -EINVAL; |
161 | 176 | ||
162 | if (asprintf(&new_filepath, "%s.%s", data->file.path, postfix) < 0) | 177 | if (asprintf(&new_filepath, "%s.%s", data->path, postfix) < 0) |
163 | return -ENOMEM; | 178 | return -ENOMEM; |
164 | 179 | ||
165 | /* | 180 | /* |
166 | * Only fire a warning, don't return error, continue fill | 181 | * Only fire a warning, don't return error, continue fill |
167 | * original file. | 182 | * original file. |
168 | */ | 183 | */ |
169 | if (rename(data->file.path, new_filepath)) | 184 | if (rename(data->path, new_filepath)) |
170 | pr_warning("Failed to rename %s to %s\n", data->file.path, new_filepath); | 185 | pr_warning("Failed to rename %s to %s\n", data->path, new_filepath); |
171 | 186 | ||
172 | if (!at_exit) { | 187 | if (!at_exit) { |
173 | close(data->file.fd); | 188 | close(data->file.fd); |
diff --git a/tools/perf/util/data.h b/tools/perf/util/data.h index 85f9c0dbf982..2bce28117ccf 100644 --- a/tools/perf/util/data.h +++ b/tools/perf/util/data.h | |||
@@ -10,12 +10,13 @@ enum perf_data_mode { | |||
10 | }; | 10 | }; |
11 | 11 | ||
12 | struct perf_data_file { | 12 | struct perf_data_file { |
13 | const char *path; | 13 | char *path; |
14 | int fd; | 14 | int fd; |
15 | unsigned long size; | 15 | unsigned long size; |
16 | }; | 16 | }; |
17 | 17 | ||
18 | struct perf_data { | 18 | struct perf_data { |
19 | const char *path; | ||
19 | struct perf_data_file file; | 20 | struct perf_data_file file; |
20 | bool is_pipe; | 21 | bool is_pipe; |
21 | bool force; | 22 | bool force; |