aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSteven Rostedt <srostedt@redhat.com>2010-01-11 17:02:40 -0500
committerSteven Rostedt <rostedt@goodmis.org>2010-01-11 17:11:41 -0500
commit9df63eaa95d85d86e540b4181bee460cbd7bb535 (patch)
tree0ba5208e3252457c75ec8f8e82deadad18fe640d
parente0a752eb3f78c4fd50cbb25236d0601e786b8623 (diff)
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 <rostedt@goodmis.org>
-rw-r--r--trace-cmd.h2
-rw-r--r--trace-input.c64
-rw-r--r--trace-read.c2
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);
41 41
42/* --- Opening and Reading the trace.dat file --- */ 42/* --- Opening and Reading the trace.dat file --- */
43 43
44struct tracecmd_input *tracecmd_alloc(const char *file);
45struct tracecmd_input *tracecmd_alloc_fd(int fd);
44struct tracecmd_input *tracecmd_open(const char *file); 46struct tracecmd_input *tracecmd_open(const char *file);
45struct tracecmd_input *tracecmd_open_fd(int fd); 47struct tracecmd_input *tracecmd_open_fd(int fd);
46void tracecmd_close(struct tracecmd_input *handle); 48void 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)
1470} 1470}
1471 1471
1472/** 1472/**
1473 * tracecmd_open_fd - create a tracecmd_handle from the trace.dat file descriptor 1473 * tracecmd_alloc_fd - create a tracecmd_input handle from a file descriptor
1474 * @fd: the file descriptor for the trace.dat file 1474 * @fd: the file descriptor for the trace.dat file
1475 *
1476 * Allocate a tracecmd_input handle from a file descriptor and open the
1477 * file. This tests if the file is of trace-cmd format and allocates
1478 * a parse event descriptor.
1479 *
1480 * The returned pointer is not ready to be read yet. A tracecmd_read_headers()
1481 * and tracecmd_init_data() still need to be called on the descriptor.
1482 *
1483 * Unless you know what you are doing with this, you want to use
1484 * tracecmd_open_fd() instead.
1475 */ 1485 */
1476struct tracecmd_input *tracecmd_open_fd(int fd) 1486struct tracecmd_input *tracecmd_alloc_fd(int fd)
1477{ 1487{
1478 struct tracecmd_input *handle; 1488 struct tracecmd_input *handle;
1479 char test[] = { 23, 8, 68 }; 1489 char test[] = { 23, 8, 68 };
@@ -1531,6 +1541,56 @@ struct tracecmd_input *tracecmd_open_fd(int fd)
1531} 1541}
1532 1542
1533/** 1543/**
1544 * tracecmd_alloc_fd - create a tracecmd_input handle from a file name
1545 * @file: the file name of the file that is of tracecmd data type.
1546 *
1547 * Allocate a tracecmd_input handle from a given file name and open the
1548 * file. This tests if the file is of trace-cmd format and allocates
1549 * a parse event descriptor.
1550 *
1551 * The returned pointer is not ready to be read yet. A tracecmd_read_headers()
1552 * and tracecmd_init_data() still need to be called on the descriptor.
1553 *
1554 * Unless you know what you are doing with this, you want to use
1555 * tracecmd_open() instead.
1556 */
1557struct tracecmd_input *tracecmd_alloc(const char *file)
1558{
1559 int fd;
1560
1561 fd = open(file, O_RDONLY);
1562 if (fd < 0)
1563 return NULL;
1564
1565 return tracecmd_open_fd(fd);
1566}
1567
1568/**
1569 * tracecmd_open_fd - create a tracecmd_handle from the trace.dat file descriptor
1570 * @fd: the file descriptor for the trace.dat file
1571 */
1572struct tracecmd_input *tracecmd_open_fd(int fd)
1573{
1574 struct tracecmd_input *handle;
1575
1576 handle = tracecmd_alloc_fd(fd);
1577 if (!handle)
1578 return NULL;
1579
1580 if (tracecmd_read_headers(handle) < 0)
1581 goto fail;
1582
1583 if (tracecmd_init_data(handle) < 0)
1584 goto fail;
1585
1586 return handle;
1587
1588fail:
1589 tracecmd_close(handle);
1590 return NULL;
1591}
1592
1593/**
1534 * tracecmd_open - create a tracecmd_handle from a given file 1594 * tracecmd_open - create a tracecmd_handle from a given file
1535 * @file: the file name of the file that is of tracecmd data type. 1595 * @file: the file name of the file that is of tracecmd data type.
1536 */ 1596 */
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)
276 if (input_fd < 0) 276 if (input_fd < 0)
277 die("opening '%s'\n", input_file); 277 die("opening '%s'\n", input_file);
278 278
279 return tracecmd_open_fd(input_fd); 279 return tracecmd_alloc_fd(input_fd);
280} 280}
281 281
282void trace_report (int argc, char **argv) 282void trace_report (int argc, char **argv)