}
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;
}
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)
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)
{
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();
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)
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");
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;
}
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;
}
struct 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;
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,
.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 = {
"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 "
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;
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)
.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;
.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);
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,
if (!quiet)
fprintf(stderr, "[ perf record: Dump %s.%s ]\n",
- data->path, timestamp);
+ data->file.path, timestamp);
/* Output tracking events */
if (!at_exit) {
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:
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,
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;
}
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);
};
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;
{ "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;
struct 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)
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;
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);
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");
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");
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)
{ "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,
{ "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;
{
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);
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);
{
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;
{
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 = {
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",
int fd = perf_data__is_read(data) ?
STDIN_FILENO : STDOUT_FILENO;
- if (!data->path) {
+ if (!data->file.path) {
if (!fstat(fd, &st) && S_ISFIFO(st.st_mode))
is_pipe = true;
} else {
- if (!strcmp(data->path, "-"))
+ if (!strcmp(data->file.path, "-"))
is_pipe = true;
}
if (is_pipe)
- data->fd = fd;
+ data->file.fd = fd;
return data->is_pipe = is_pipe;
}
{
struct stat st;
- if (!stat(data->path, &st) && st.st_size) {
+ if (!stat(data->file.path, &st) && st.st_size) {
/* TODO check errors properly */
char oldname[PATH_MAX];
snprintf(oldname, sizeof(oldname), "%s.old",
- data->path);
+ data->file.path);
unlink(oldname);
- rename(data->path, oldname);
+ rename(data->file.path, oldname);
}
return 0;
int fd;
char sbuf[STRERR_BUFSIZE];
- fd = open(data->path, O_RDONLY);
+ fd = open(data->file.path, O_RDONLY);
if (fd < 0) {
int err = errno;
- pr_err("failed to open %s: %s", data->path,
+ pr_err("failed to open %s: %s", data->file.path,
str_error_r(err, sbuf, sizeof(sbuf)));
- if (err == ENOENT && !strcmp(data->path, "perf.data"))
+ if (err == ENOENT && !strcmp(data->file.path, "perf.data"))
pr_err(" (try 'perf record' first)");
pr_err("\n");
return -err;
if (!data->force && st.st_uid && (st.st_uid != geteuid())) {
pr_err("File %s not owned by current user or root (use -f to override)\n",
- data->path);
+ data->file.path);
goto out_close;
}
if (!st.st_size) {
pr_info("zero-sized data (%s), nothing to do!\n",
- data->path);
+ data->file.path);
goto out_close;
}
if (check_backup(data))
return -1;
- fd = open(data->path, O_CREAT|O_RDWR|O_TRUNC|O_CLOEXEC,
+ fd = open(data->file.path, O_CREAT|O_RDWR|O_TRUNC|O_CLOEXEC,
S_IRUSR|S_IWUSR);
if (fd < 0)
- pr_err("failed to open %s : %s\n", data->path,
+ pr_err("failed to open %s : %s\n", data->file.path,
str_error_r(errno, sbuf, sizeof(sbuf)));
return fd;
fd = perf_data__is_read(data) ?
open_file_read(data) : open_file_write(data);
- data->fd = fd;
+ data->file.fd = fd;
return fd < 0 ? -1 : 0;
}
if (check_pipe(data))
return 0;
- if (!data->path)
- data->path = "perf.data";
+ if (!data->file.path)
+ data->file.path = "perf.data";
return open_file(data);
}
void perf_data__close(struct perf_data *data)
{
- close(data->fd);
+ close(data->file.fd);
}
ssize_t perf_data__write(struct perf_data *data,
void *buf, size_t size)
{
- return writen(data->fd, buf, size);
+ return writen(data->file.fd, buf, size);
}
int perf_data__switch(struct perf_data *data,
if (perf_data__is_read(data))
return -EINVAL;
- if (asprintf(&new_filepath, "%s.%s", data->path, postfix) < 0)
+ if (asprintf(&new_filepath, "%s.%s", data->file.path, postfix) < 0)
return -ENOMEM;
/*
* Only fire a warning, don't return error, continue fill
* original file.
*/
- if (rename(data->path, new_filepath))
- pr_warning("Failed to rename %s to %s\n", data->path, new_filepath);
+ if (rename(data->file.path, new_filepath))
+ pr_warning("Failed to rename %s to %s\n", data->file.path, new_filepath);
if (!at_exit) {
- close(data->fd);
+ close(data->file.fd);
ret = perf_data__open(data);
if (ret < 0)
goto out;
- if (lseek(data->fd, pos, SEEK_SET) == (off_t)-1) {
+ if (lseek(data->file.fd, pos, SEEK_SET) == (off_t)-1) {
ret = -errno;
pr_debug("Failed to lseek to %zu: %s",
pos, strerror(errno));
goto out;
}
}
- ret = data->fd;
+ ret = data->file.fd;
out:
free(new_filepath);
return ret;
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;
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)
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;