summaryrefslogtreecommitdiff
path: root/tools/perf/util
diff options
context:
space:
mode:
authorJiri Olsa <jolsa@kernel.org>2017-01-23 22:25:41 +0100
committerArnaldo Carvalho de Melo <acme@redhat.com>2017-10-30 13:37:37 -0300
commiteae8ad8042d82775da1ddf3faa915b32854d9cf4 (patch)
treec00e93fe4edcd756a8dec1cf4e86a51473c636fc /tools/perf/util
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/perf/util')
-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
4 files changed, 36 insertions, 32 deletions
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,
{
struct perf_session *session;
struct perf_data data = {
- .path = input,
- .mode = PERF_DATA_MODE_READ,
- .force = opts->force,
+ .file.path = input,
+ .mode = PERF_DATA_MODE_READ,
+ .force = opts->force,
};
struct convert c = {
.tool = {
@@ -1650,7 +1650,7 @@ int bt_convert__perf2ctf(const char *input, const char *path,
fprintf(stderr,
"[ perf data convert: Converted '%s' into CTF data '%s' ]\n",
- data.path, path);
+ data.file.path, path);
fprintf(stderr,
"[ perf data convert: Converted and wrote %.3f MB (%" PRIu64 " samples",
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)
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;
}
@@ -46,13 +46,13 @@ static int check_backup(struct perf_data *data)
{
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;
@@ -64,13 +64,13 @@ static int open_file_read(struct perf_data *data)
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;
@@ -81,13 +81,13 @@ static int open_file_read(struct perf_data *data)
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;
}
@@ -107,11 +107,11 @@ static int open_file_write(struct perf_data *data)
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;
@@ -124,7 +124,7 @@ static int open_file(struct perf_data *data)
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;
}
@@ -133,21 +133,21 @@ int perf_data__open(struct perf_data *data)
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,
@@ -162,30 +162,30 @@ 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;
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 {
PERF_DATA_MODE_READ,
};
+struct perf_data_file {
+ const char *path;
+ int fd;
+};
+
struct perf_data {
- const char *path;
- int fd;
+ struct perf_data_file file;
bool is_pipe;
bool force;
unsigned long size;
@@ -34,7 +38,7 @@ static inline int perf_data__is_pipe(struct perf_data *data)
static inline int perf_data__fd(struct perf_data *data)
{
- return data->fd;
+ return data->file.fd;
}
static inline unsigned long perf_data__size(struct perf_data *data)
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)
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;