Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Jiri Olsa and committed by
Arnaldo Carvalho de Melo
eae8ad80 8ceb41d7

+127 -97
+2 -2
tools/perf/builtin-annotate.c
··· 356 356 } 357 357 358 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 360 goto out; 361 361 } 362 362 ··· 482 482 if (quiet) 483 483 perf_quiet_option(); 484 484 485 - data.path = input_name; 485 + data.file.path = input_name; 486 486 487 487 annotate.session = perf_session__new(&data, false, &annotate.tool); 488 488 if (annotate.session == NULL)
+2 -2
tools/perf/builtin-buildid-cache.c
··· 352 352 nsi = nsinfo__new(ns_id); 353 353 354 354 if (missing_filename) { 355 - data.path = missing_filename; 356 - data.force = force; 355 + data.file.path = missing_filename; 356 + data.force = force; 357 357 358 358 session = perf_session__new(&data, false, NULL); 359 359 if (session == NULL)
+5 -3
tools/perf/builtin-buildid-list.c
··· 51 51 { 52 52 struct perf_session *session; 53 53 struct perf_data data = { 54 - .path = input_name, 55 - .mode = PERF_DATA_MODE_READ, 56 - .force = force, 54 + .file = { 55 + .path = input_name, 56 + }, 57 + .mode = PERF_DATA_MODE_READ, 58 + .force = force, 57 59 }; 58 60 59 61 symbol__elf_init();
+2 -2
tools/perf/builtin-c2c.c
··· 2572 2572 if (!input_name || !strlen(input_name)) 2573 2573 input_name = "perf.data"; 2574 2574 2575 - data.path = input_name; 2576 - data.force = symbol_conf.force; 2575 + data.file.path = input_name; 2576 + data.force = symbol_conf.force; 2577 2577 2578 2578 err = setup_display(display); 2579 2579 if (err)
+6 -6
tools/perf/builtin-diff.c
··· 707 707 708 708 data__for_each_file(i, d) 709 709 fprintf(stdout, "# [%d] %s %s\n", 710 - d->idx, d->data.path, 710 + d->idx, d->data.file.path, 711 711 !d->idx ? "(Baseline)" : ""); 712 712 713 713 fprintf(stdout, "#\n"); ··· 778 778 data__for_each_file(i, d) { 779 779 d->session = perf_session__new(&d->data, false, &tool); 780 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 782 ret = -1; 783 783 goto out_delete; 784 784 } 785 785 786 786 ret = perf_session__process_events(d->session); 787 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 789 goto out_delete; 790 790 } 791 791 ··· 1288 1288 data__for_each_file(i, d) { 1289 1289 struct perf_data *data = &d->data; 1290 1290 1291 - data->path = use_default ? defaults[i] : argv[i]; 1292 - data->mode = PERF_DATA_MODE_READ, 1293 - data->force = force, 1291 + data->file.path = use_default ? defaults[i] : argv[i]; 1292 + data->mode = PERF_DATA_MODE_READ, 1293 + data->force = force, 1294 1294 1295 1295 d->idx = i; 1296 1296 }
+5 -3
tools/perf/builtin-evlist.c
··· 22 22 struct perf_session *session; 23 23 struct perf_evsel *pos; 24 24 struct perf_data data = { 25 - .path = file_name, 26 - .mode = PERF_DATA_MODE_READ, 27 - .force = details->force, 25 + .file = { 26 + .path = file_name, 27 + }, 28 + .mode = PERF_DATA_MODE_READ, 29 + .force = details->force, 28 30 }; 29 31 bool has_tracepoint = false; 30 32
+7 -5
tools/perf/builtin-inject.c
··· 145 145 if (!inject->output.is_pipe) { 146 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 149 if (offset == -1) 150 150 return -errno; 151 151 ret = auxtrace_index__auxtrace_event(&session->auxtrace_index, ··· 775 775 .input_name = "-", 776 776 .samples = LIST_HEAD_INIT(inject.samples), 777 777 .output = { 778 - .path = "-", 779 - .mode = PERF_DATA_MODE_WRITE, 778 + .file = { 779 + .path = "-", 780 + }, 781 + .mode = PERF_DATA_MODE_WRITE, 780 782 }, 781 783 }; 782 784 struct perf_data data = { ··· 791 789 "Inject build-ids into the output stream"), 792 790 OPT_STRING('i', "input", &inject.input_name, "file", 793 791 "input file name"), 794 - OPT_STRING('o', "output", &inject.output.path, "file", 792 + OPT_STRING('o', "output", &inject.output.file.path, "file", 795 793 "output file name"), 796 794 OPT_BOOLEAN('s', "sched-stat", &inject.sched_stat, 797 795 "Merge sched-stat and sched-switch for getting events " ··· 838 836 839 837 inject.tool.ordered_events = inject.sched_stat; 840 838 841 - data.path = inject.input_name; 839 + data.file.path = inject.input_name; 842 840 inject.session = perf_session__new(&data, true, &inject.tool); 843 841 if (inject.session == NULL) 844 842 return -1;
+1 -1
tools/perf/builtin-kmem.c
··· 1949 1949 return __cmd_record(argc, argv); 1950 1950 } 1951 1951 1952 - data.path = input_name; 1952 + data.file.path = input_name; 1953 1953 1954 1954 kmem_session = session = perf_session__new(&data, false, &perf_kmem); 1955 1955 if (session == NULL)
+5 -3
tools/perf/builtin-kvm.c
··· 1068 1068 .ordered_events = true, 1069 1069 }; 1070 1070 struct perf_data file = { 1071 - .path = kvm->file_name, 1072 - .mode = PERF_DATA_MODE_READ, 1073 - .force = kvm->force, 1071 + .file = { 1072 + .path = kvm->file_name, 1073 + }, 1074 + .mode = PERF_DATA_MODE_READ, 1075 + .force = kvm->force, 1074 1076 }; 1075 1077 1076 1078 kvm->tool = eops;
+5 -3
tools/perf/builtin-lock.c
··· 865 865 .ordered_events = true, 866 866 }; 867 867 struct perf_data data = { 868 - .path = input_name, 869 - .mode = PERF_DATA_MODE_READ, 870 - .force = force, 868 + .file = { 869 + .path = input_name, 870 + }, 871 + .mode = PERF_DATA_MODE_READ, 872 + .force = force, 871 873 }; 872 874 873 875 session = perf_session__new(&data, false, &eops);
+5 -3
tools/perf/builtin-mem.c
··· 237 237 static int report_raw_events(struct perf_mem *mem) 238 238 { 239 239 struct perf_data data = { 240 - .path = input_name, 241 - .mode = PERF_DATA_MODE_READ, 242 - .force = mem->force, 240 + .file = { 241 + .path = input_name, 242 + }, 243 + .mode = PERF_DATA_MODE_READ, 244 + .force = mem->force, 243 245 }; 244 246 int ret; 245 247 struct perf_session *session = perf_session__new(&data, false,
+3 -3
tools/perf/builtin-record.c
··· 618 618 619 619 if (!quiet) 620 620 fprintf(stderr, "[ perf record: Dump %s.%s ]\n", 621 - data->path, timestamp); 621 + data->file.path, timestamp); 622 622 623 623 /* Output tracking events */ 624 624 if (!at_exit) { ··· 1118 1118 1119 1119 fprintf(stderr, "[ perf record: Captured and wrote %.3f MB %s%s%s ]\n", 1120 1120 perf_data__size(data) / 1024.0 / 1024.0, 1121 - data->path, postfix, samples); 1121 + data->file.path, postfix, samples); 1122 1122 } 1123 1123 1124 1124 out_delete_session: ··· 1482 1482 OPT_STRING('C', "cpu", &record.opts.target.cpu_list, "cpu", 1483 1483 "list of cpus to monitor"), 1484 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 1486 "output file name"), 1487 1487 OPT_BOOLEAN_SET('i', "no-inherit", &record.opts.no_inherit, 1488 1488 &record.opts.no_inherit_set,
+3 -3
tools/perf/builtin-report.c
··· 637 637 rep->nr_entries += evsel__hists(pos)->nr_entries; 638 638 639 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 641 return 0; 642 642 } 643 643 ··· 940 940 input_name = "perf.data"; 941 941 } 942 942 943 - data.path = input_name; 944 - data.force = symbol_conf.force; 943 + data.file.path = input_name; 944 + data.force = symbol_conf.force; 945 945 946 946 repeat: 947 947 session = perf_session__new(&data, false, &report.tool);
+10 -6
tools/perf/builtin-sched.c
··· 1701 1701 }; 1702 1702 struct perf_session *session; 1703 1703 struct perf_data data = { 1704 - .path = input_name, 1705 - .mode = PERF_DATA_MODE_READ, 1706 - .force = sched->force, 1704 + .file = { 1705 + .path = input_name, 1706 + }, 1707 + .mode = PERF_DATA_MODE_READ, 1708 + .force = sched->force, 1707 1709 }; 1708 1710 int rc = -1; 1709 1711 ··· 2905 2903 { "sched:sched_migrate_task", timehist_migrate_task_event, }, 2906 2904 }; 2907 2905 struct perf_data data = { 2908 - .path = input_name, 2909 - .mode = PERF_DATA_MODE_READ, 2910 - .force = sched->force, 2906 + .file = { 2907 + .path = input_name, 2908 + }, 2909 + .mode = PERF_DATA_MODE_READ, 2910 + .force = sched->force, 2911 2911 }; 2912 2912 2913 2913 struct perf_session *session;
+8 -6
tools/perf/builtin-script.c
··· 222 222 struct perf_evsel_script *es = malloc(sizeof(*es)); 223 223 224 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 226 goto out_free; 227 227 es->fp = fopen(es->filename, "w"); 228 228 if (es->fp == NULL) ··· 2591 2591 DIR *scripts_dir, *lang_dir; 2592 2592 struct perf_session *session; 2593 2593 struct perf_data data = { 2594 - .path = input_name, 2595 - .mode = PERF_DATA_MODE_READ, 2594 + .file = { 2595 + .path = input_name, 2596 + }, 2597 + .mode = PERF_DATA_MODE_READ, 2596 2598 }; 2597 2599 char *temp; 2598 2600 int i = 0; ··· 2984 2982 argc = parse_options_subcommand(argc, argv, options, script_subcommands, script_usage, 2985 2983 PARSE_OPT_STOP_AT_NON_OPTION); 2986 2984 2987 - data.path = input_name; 2988 - data.force = symbol_conf.force; 2985 + data.file.path = input_name; 2986 + data.force = symbol_conf.force; 2989 2987 2990 2988 if (argc > 1 && !strncmp(argv[0], "rec", strlen("rec"))) { 2991 2989 rec_script_path = get_script_path(argv[1], RECORD_SUFFIX); ··· 3208 3206 goto out_delete; 3209 3207 } 3210 3208 3211 - input = open(data.path, O_RDONLY); /* input_name */ 3209 + input = open(data.file.path, O_RDONLY); /* input_name */ 3212 3210 if (input < 0) { 3213 3211 err = -errno; 3214 3212 perror("failed to open file");
+3 -3
tools/perf/builtin-stat.c
··· 2412 2412 PARSE_OPT_STOP_AT_NON_OPTION); 2413 2413 2414 2414 if (output_name) 2415 - data->path = output_name; 2415 + data->file.path = output_name; 2416 2416 2417 2417 if (run_count != 1 || forever) { 2418 2418 pr_err("Cannot use -r option with perf stat record.\n"); ··· 2585 2585 input_name = "perf.data"; 2586 2586 } 2587 2587 2588 - perf_stat.data.path = input_name; 2589 - perf_stat.data.mode = PERF_DATA_MODE_READ; 2588 + perf_stat.data.file.path = input_name; 2589 + perf_stat.data.mode = PERF_DATA_MODE_READ; 2590 2590 2591 2591 session = perf_session__new(&perf_stat.data, false, &perf_stat.tool); 2592 2592 if (session == NULL)
+5 -3
tools/perf/builtin-timechart.c
··· 1602 1602 { "syscalls:sys_exit_select", process_exit_poll }, 1603 1603 }; 1604 1604 struct perf_data data = { 1605 - .path = input_name, 1606 - .mode = PERF_DATA_MODE_READ, 1607 - .force = tchart->force, 1605 + .file = { 1606 + .path = input_name, 1607 + }, 1608 + .mode = PERF_DATA_MODE_READ, 1609 + .force = tchart->force, 1608 1610 }; 1609 1611 1610 1612 struct perf_session *session = perf_session__new(&data, false,
+5 -3
tools/perf/builtin-trace.c
··· 2533 2533 { "probe:vfs_getname", trace__vfs_getname, }, 2534 2534 }; 2535 2535 struct perf_data data = { 2536 - .path = input_name, 2537 - .mode = PERF_DATA_MODE_READ, 2538 - .force = trace->force, 2536 + .file = { 2537 + .path = input_name, 2538 + }, 2539 + .mode = PERF_DATA_MODE_READ, 2540 + .force = trace->force, 2539 2541 }; 2540 2542 struct perf_session *session; 2541 2543 struct perf_evsel *evsel;
+9 -5
tools/perf/tests/topology.c
··· 30 30 { 31 31 struct perf_session *session; 32 32 struct perf_data data = { 33 - .path = path, 34 - .mode = PERF_DATA_MODE_WRITE, 33 + .file = { 34 + .path = path, 35 + }, 36 + .mode = PERF_DATA_MODE_WRITE, 35 37 }; 36 38 37 39 session = perf_session__new(&data, false, NULL); ··· 48 46 session->header.data_size += DATA_SIZE; 49 47 50 48 TEST_ASSERT_VAL("failed to write header", 51 - !perf_session__write_header(session, session->evlist, data.fd, true)); 49 + !perf_session__write_header(session, session->evlist, data.file.fd, true)); 52 50 53 51 perf_session__delete(session); 54 52 ··· 59 57 { 60 58 struct perf_session *session; 61 59 struct perf_data data = { 62 - .path = path, 63 - .mode = PERF_DATA_MODE_READ, 60 + .file = { 61 + .path = path, 62 + }, 63 + .mode = PERF_DATA_MODE_READ, 64 64 }; 65 65 int i; 66 66
+4 -4
tools/perf/util/data-convert-bt.c
··· 1578 1578 { 1579 1579 struct perf_session *session; 1580 1580 struct perf_data data = { 1581 - .path = input, 1582 - .mode = PERF_DATA_MODE_READ, 1583 - .force = opts->force, 1581 + .file.path = input, 1582 + .mode = PERF_DATA_MODE_READ, 1583 + .force = opts->force, 1584 1584 }; 1585 1585 struct convert c = { 1586 1586 .tool = { ··· 1650 1650 1651 1651 fprintf(stderr, 1652 1652 "[ perf data convert: Converted '%s' into CTF data '%s' ]\n", 1653 - data.path, path); 1653 + data.file.path, path); 1654 1654 1655 1655 fprintf(stderr, 1656 1656 "[ perf data convert: Converted and wrote %.3f MB (%" PRIu64 " samples",
+24 -24
tools/perf/util/data.c
··· 28 28 int fd = perf_data__is_read(data) ? 29 29 STDIN_FILENO : STDOUT_FILENO; 30 30 31 - if (!data->path) { 31 + if (!data->file.path) { 32 32 if (!fstat(fd, &st) && S_ISFIFO(st.st_mode)) 33 33 is_pipe = true; 34 34 } else { 35 - if (!strcmp(data->path, "-")) 35 + if (!strcmp(data->file.path, "-")) 36 36 is_pipe = true; 37 37 } 38 38 39 39 if (is_pipe) 40 - data->fd = fd; 40 + data->file.fd = fd; 41 41 42 42 return data->is_pipe = is_pipe; 43 43 } ··· 46 46 { 47 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 50 /* TODO check errors properly */ 51 51 char oldname[PATH_MAX]; 52 52 snprintf(oldname, sizeof(oldname), "%s.old", 53 - data->path); 53 + data->file.path); 54 54 unlink(oldname); 55 - rename(data->path, oldname); 55 + rename(data->file.path, oldname); 56 56 } 57 57 58 58 return 0; ··· 64 64 int fd; 65 65 char sbuf[STRERR_BUFSIZE]; 66 66 67 - fd = open(data->path, O_RDONLY); 67 + fd = open(data->file.path, O_RDONLY); 68 68 if (fd < 0) { 69 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 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 74 pr_err(" (try 'perf record' first)"); 75 75 pr_err("\n"); 76 76 return -err; ··· 81 81 82 82 if (!data->force && st.st_uid && (st.st_uid != geteuid())) { 83 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 85 goto out_close; 86 86 } 87 87 88 88 if (!st.st_size) { 89 89 pr_info("zero-sized data (%s), nothing to do!\n", 90 - data->path); 90 + data->file.path); 91 91 goto out_close; 92 92 } 93 93 ··· 107 107 if (check_backup(data)) 108 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 111 S_IRUSR|S_IWUSR); 112 112 113 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 115 str_error_r(errno, sbuf, sizeof(sbuf))); 116 116 117 117 return fd; ··· 124 124 fd = perf_data__is_read(data) ? 125 125 open_file_read(data) : open_file_write(data); 126 126 127 - data->fd = fd; 127 + data->file.fd = fd; 128 128 return fd < 0 ? -1 : 0; 129 129 } 130 130 ··· 133 133 if (check_pipe(data)) 134 134 return 0; 135 135 136 - if (!data->path) 137 - data->path = "perf.data"; 136 + if (!data->file.path) 137 + data->file.path = "perf.data"; 138 138 139 139 return open_file(data); 140 140 } 141 141 142 142 void perf_data__close(struct perf_data *data) 143 143 { 144 - close(data->fd); 144 + close(data->file.fd); 145 145 } 146 146 147 147 ssize_t perf_data__write(struct perf_data *data, 148 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 153 153 int perf_data__switch(struct perf_data *data, ··· 162 162 if (perf_data__is_read(data)) 163 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 166 return -ENOMEM; 167 167 168 168 /* 169 169 * Only fire a warning, don't return error, continue fill 170 170 * original file. 171 171 */ 172 - if (rename(data->path, new_filepath)) 173 - pr_warning("Failed to rename %s to %s\n", data->path, new_filepath); 172 + if (rename(data->file.path, new_filepath)) 173 + pr_warning("Failed to rename %s to %s\n", data->file.path, new_filepath); 174 174 175 175 if (!at_exit) { 176 - close(data->fd); 176 + close(data->file.fd); 177 177 ret = perf_data__open(data); 178 178 if (ret < 0) 179 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 182 ret = -errno; 183 183 pr_debug("Failed to lseek to %zu: %s", 184 184 pos, strerror(errno)); 185 185 goto out; 186 186 } 187 187 } 188 - ret = data->fd; 188 + ret = data->file.fd; 189 189 out: 190 190 free(new_filepath); 191 191 return ret;
+7 -3
tools/perf/util/data.h
··· 8 8 PERF_DATA_MODE_READ, 9 9 }; 10 10 11 + struct perf_data_file { 12 + const char *path; 13 + int fd; 14 + }; 15 + 11 16 struct perf_data { 12 - const char *path; 13 - int fd; 17 + struct perf_data_file file; 14 18 bool is_pipe; 15 19 bool force; 16 20 unsigned long size; ··· 38 34 39 35 static inline int perf_data__fd(struct perf_data *data) 40 36 { 41 - return data->fd; 37 + return data->file.fd; 42 38 } 43 39 44 40 static inline unsigned long perf_data__size(struct perf_data *data)
+1 -1
tools/perf/util/header.c
··· 2889 2889 if (f_header.data.size == 0) { 2890 2890 pr_warning("WARNING: The %s file's data size field is 0 which is unexpected.\n" 2891 2891 "Was the 'perf record' command properly terminated?\n", 2892 - data->path); 2892 + data->file.path); 2893 2893 } 2894 2894 2895 2895 nr_attrs = f_header.attrs.size / f_header.attr_size;