aboutsummaryrefslogtreecommitdiffstats
path: root/trace-input.c
diff options
context:
space:
mode:
Diffstat (limited to 'trace-input.c')
-rw-r--r--trace-input.c64
1 files changed, 62 insertions, 2 deletions
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 */