From 9df63eaa95d85d86e540b4181bee460cbd7bb535 Mon Sep 17 00:00:00 2001 From: Steven Rostedt Date: Mon, 11 Jan 2010 17:02:40 -0500 Subject: trace-cmd: Rename tracecmd_open to tracecmd_alloc The tracecmd_open() currently returns a tracecmd_input descriptor that is not finished. The headers still need to be read and data needs to be initialized. Rename tracecmd_open and tracecmd_open_fd to tracecmd_alloc and tracecmd_alloc_fd respectively, and create a new tracecmd_open() and tracecmd_open_fd() that returns a usable descriptor. Signed-off-by: Steven Rostedt --- trace-cmd.h | 2 ++ trace-input.c | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- trace-read.c | 2 +- 3 files changed, 65 insertions(+), 3 deletions(-) diff --git a/trace-cmd.h b/trace-cmd.h index d0b5c92..18d615c 100644 --- a/trace-cmd.h +++ b/trace-cmd.h @@ -41,6 +41,8 @@ char *tracecmd_find_tracing_dir(void); /* --- Opening and Reading the trace.dat file --- */ +struct tracecmd_input *tracecmd_alloc(const char *file); +struct tracecmd_input *tracecmd_alloc_fd(int fd); struct tracecmd_input *tracecmd_open(const char *file); struct tracecmd_input *tracecmd_open_fd(int fd); void tracecmd_close(struct tracecmd_input *handle); diff --git a/trace-input.c b/trace-input.c index 1462b4b..13896eb 100644 --- a/trace-input.c +++ b/trace-input.c @@ -1470,10 +1470,20 @@ void tracecmd_print_events(struct tracecmd_input *handle) } /** - * tracecmd_open_fd - create a tracecmd_handle from the trace.dat file descriptor + * tracecmd_alloc_fd - create a tracecmd_input handle from a file descriptor * @fd: the file descriptor for the trace.dat file + * + * Allocate a tracecmd_input handle from a file descriptor and open the + * file. This tests if the file is of trace-cmd format and allocates + * a parse event descriptor. + * + * The returned pointer is not ready to be read yet. A tracecmd_read_headers() + * and tracecmd_init_data() still need to be called on the descriptor. + * + * Unless you know what you are doing with this, you want to use + * tracecmd_open_fd() instead. */ -struct tracecmd_input *tracecmd_open_fd(int fd) +struct tracecmd_input *tracecmd_alloc_fd(int fd) { struct tracecmd_input *handle; char test[] = { 23, 8, 68 }; @@ -1530,6 +1540,56 @@ struct tracecmd_input *tracecmd_open_fd(int fd) return NULL; } +/** + * tracecmd_alloc_fd - create a tracecmd_input handle from a file name + * @file: the file name of the file that is of tracecmd data type. + * + * Allocate a tracecmd_input handle from a given file name and open the + * file. This tests if the file is of trace-cmd format and allocates + * a parse event descriptor. + * + * The returned pointer is not ready to be read yet. A tracecmd_read_headers() + * and tracecmd_init_data() still need to be called on the descriptor. + * + * Unless you know what you are doing with this, you want to use + * tracecmd_open() instead. + */ +struct tracecmd_input *tracecmd_alloc(const char *file) +{ + int fd; + + fd = open(file, O_RDONLY); + if (fd < 0) + return NULL; + + return tracecmd_open_fd(fd); +} + +/** + * tracecmd_open_fd - create a tracecmd_handle from the trace.dat file descriptor + * @fd: the file descriptor for the trace.dat file + */ +struct tracecmd_input *tracecmd_open_fd(int fd) +{ + struct tracecmd_input *handle; + + handle = tracecmd_alloc_fd(fd); + if (!handle) + return NULL; + + if (tracecmd_read_headers(handle) < 0) + goto fail; + + if (tracecmd_init_data(handle) < 0) + goto fail; + + return handle; + +fail: + tracecmd_close(handle); + return NULL; +} + /** * tracecmd_open - create a tracecmd_handle from a given file * @file: the file name of the file that is of tracecmd data type. diff --git a/trace-read.c b/trace-read.c index f2c7de2..306fa3a 100644 --- a/trace-read.c +++ b/trace-read.c @@ -276,7 +276,7 @@ struct tracecmd_input *read_trace_header(void) if (input_fd < 0) die("opening '%s'\n", input_file); - return tracecmd_open_fd(input_fd); + return tracecmd_alloc_fd(input_fd); } void trace_report (int argc, char **argv) -- cgit v1.2.2