diff options
author | Steven Rostedt <srostedt@redhat.com> | 2010-01-11 21:14:21 -0500 |
---|---|---|
committer | Steven Rostedt <rostedt@goodmis.org> | 2010-01-11 21:23:28 -0500 |
commit | bb8ee16b5b83366458bb23f5479bc6ea96cfa3e8 (patch) | |
tree | a0ce96815e4bf2ca8fe34071c4ca1a6a3a2e780e | |
parent | aa893539b357eaffe97bd78afb40166c1a10329e (diff) | |
parent | 021ca6ab5c2dc9307ef7d413bc6fbce86de871fa (diff) |
Merge branch 'trace-cmd' into trace-view
Updated to handle the API change to tracecmd_open().
modified: kernel-shark.c
modified: trace-cmd.h
modified: trace-graph-main.c
modified: trace-graph.c
modified: trace-input.c
modified: trace-read.c
modified: trace-view-main.c
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
-rw-r--r-- | kernel-shark.c | 6 | ||||
-rw-r--r-- | trace-cmd.h | 3 | ||||
-rw-r--r-- | trace-graph-main.c | 41 | ||||
-rw-r--r-- | trace-graph.c | 1 | ||||
-rw-r--r-- | trace-input.c | 97 | ||||
-rw-r--r-- | trace-read.c | 2 | ||||
-rw-r--r-- | trace-view-main.c | 6 |
7 files changed, 110 insertions, 46 deletions
diff --git a/kernel-shark.c b/kernel-shark.c index 8820109..6742da9 100644 --- a/kernel-shark.c +++ b/kernel-shark.c | |||
@@ -548,12 +548,6 @@ void kernel_shark(int argc, char **argv) | |||
548 | die("error reading header"); | 548 | die("error reading header"); |
549 | info->handle = handle; | 549 | info->handle = handle; |
550 | 550 | ||
551 | if (tracecmd_read_headers(handle) < 0) | ||
552 | return; | ||
553 | |||
554 | if (tracecmd_init_data(handle) < 0) | ||
555 | die("failed to init data"); | ||
556 | |||
557 | gtk_init(&argc, &argv); | 551 | gtk_init(&argc, &argv); |
558 | 552 | ||
559 | /* --- Main window --- */ | 553 | /* --- Main window --- */ |
diff --git a/trace-cmd.h b/trace-cmd.h index 2c46ac8..3639fdd 100644 --- a/trace-cmd.h +++ b/trace-cmd.h | |||
@@ -39,8 +39,11 @@ char *tracecmd_find_tracing_dir(void); | |||
39 | 39 | ||
40 | /* --- Opening and Reading the trace.dat file --- */ | 40 | /* --- Opening and Reading the trace.dat file --- */ |
41 | 41 | ||
42 | struct tracecmd_input *tracecmd_alloc(const char *file); | ||
43 | struct tracecmd_input *tracecmd_alloc_fd(int fd); | ||
42 | struct tracecmd_input *tracecmd_open(const char *file); | 44 | struct tracecmd_input *tracecmd_open(const char *file); |
43 | struct tracecmd_input *tracecmd_open_fd(int fd); | 45 | struct tracecmd_input *tracecmd_open_fd(int fd); |
46 | void tracecmd_ref(struct tracecmd_input *handle); | ||
44 | void tracecmd_close(struct tracecmd_input *handle); | 47 | void tracecmd_close(struct tracecmd_input *handle); |
45 | int tracecmd_read_headers(struct tracecmd_input *handle); | 48 | int tracecmd_read_headers(struct tracecmd_input *handle); |
46 | int tracecmd_long_size(struct tracecmd_input *handle); | 49 | int tracecmd_long_size(struct tracecmd_input *handle); |
diff --git a/trace-graph-main.c b/trace-graph-main.c index fdf73fa..93b7c3c 100644 --- a/trace-graph-main.c +++ b/trace-graph-main.c | |||
@@ -26,34 +26,6 @@ void usage(char *prog) | |||
26 | printf(" -i input_file, default is %s\n", default_input_file); | 26 | printf(" -i input_file, default is %s\n", default_input_file); |
27 | } | 27 | } |
28 | 28 | ||
29 | static struct tracecmd_input *read_tracecmd(gchar *filename) | ||
30 | { | ||
31 | struct tracecmd_input *handle; | ||
32 | |||
33 | handle = tracecmd_open(filename); | ||
34 | |||
35 | if (!handle) { | ||
36 | warning("can not load %s", filename); | ||
37 | return NULL; | ||
38 | } | ||
39 | |||
40 | if (tracecmd_read_headers(handle) < 0) { | ||
41 | warning("can not read %s headers", filename); | ||
42 | goto failed; | ||
43 | } | ||
44 | |||
45 | if (tracecmd_init_data(handle) < 0) { | ||
46 | warning("can not init %s", filename); | ||
47 | goto failed; | ||
48 | } | ||
49 | |||
50 | return handle; | ||
51 | |||
52 | failed: | ||
53 | tracecmd_close(handle); | ||
54 | return NULL; | ||
55 | } | ||
56 | |||
57 | /* Callback for the clicked signal of the Load button */ | 29 | /* Callback for the clicked signal of the Load button */ |
58 | static void | 30 | static void |
59 | load_clicked (gpointer data) | 31 | load_clicked (gpointer data) |
@@ -71,9 +43,12 @@ load_clicked (gpointer data) | |||
71 | NULL); | 43 | NULL); |
72 | if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) { | 44 | if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) { |
73 | filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog)); | 45 | filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog)); |
74 | handle = read_tracecmd(filename); | 46 | handle = tracecmd_open(filename); |
75 | if (handle) | 47 | if (handle) { |
76 | trace_graph_load_handle(ginfo, handle); | 48 | trace_graph_load_handle(ginfo, handle); |
49 | /* Free handle when freeing graph */ | ||
50 | tracecmd_close(handle); | ||
51 | } | ||
77 | g_free(filename); | 52 | g_free(filename); |
78 | } | 53 | } |
79 | gtk_widget_destroy(dialog); | 54 | gtk_widget_destroy(dialog); |
@@ -155,13 +130,17 @@ void trace_graph(int argc, char **argv) | |||
155 | } | 130 | } |
156 | 131 | ||
157 | if (input_file) | 132 | if (input_file) |
158 | handle = read_tracecmd(input_file); | 133 | handle = tracecmd_open(input_file); |
159 | 134 | ||
160 | gtk_init(&argc, &argv); | 135 | gtk_init(&argc, &argv); |
161 | 136 | ||
162 | /* graph struct is used by handlers */ | 137 | /* graph struct is used by handlers */ |
163 | ginfo = trace_graph_create(handle); | 138 | ginfo = trace_graph_create(handle); |
164 | 139 | ||
140 | /* Free handle when freeing graph */ | ||
141 | if (handle) | ||
142 | tracecmd_close(handle); | ||
143 | |||
165 | /* --- Main window --- */ | 144 | /* --- Main window --- */ |
166 | 145 | ||
167 | window = gtk_window_new(GTK_WINDOW_TOPLEVEL); | 146 | window = gtk_window_new(GTK_WINDOW_TOPLEVEL); |
diff --git a/trace-graph.c b/trace-graph.c index d31f7a5..6e67bd7 100644 --- a/trace-graph.c +++ b/trace-graph.c | |||
@@ -2033,6 +2033,7 @@ static int load_handle(struct graph_info *ginfo, | |||
2033 | trace_graph_free_info(ginfo); | 2033 | trace_graph_free_info(ginfo); |
2034 | 2034 | ||
2035 | ginfo->handle = handle; | 2035 | ginfo->handle = handle; |
2036 | tracecmd_ref(handle); | ||
2036 | 2037 | ||
2037 | ginfo->pevent = tracecmd_get_pevent(handle); | 2038 | ginfo->pevent = tracecmd_get_pevent(handle); |
2038 | ginfo->cpus = tracecmd_cpus(handle); | 2039 | ginfo->cpus = tracecmd_cpus(handle); |
diff --git a/trace-input.c b/trace-input.c index 1462b4b..dc1167a 100644 --- a/trace-input.c +++ b/trace-input.c | |||
@@ -52,6 +52,7 @@ struct tracecmd_input { | |||
52 | int page_size; | 52 | int page_size; |
53 | int read_page; | 53 | int read_page; |
54 | int cpus; | 54 | int cpus; |
55 | int ref; | ||
55 | struct cpu_data *cpu_data; | 56 | struct cpu_data *cpu_data; |
56 | 57 | ||
57 | /* file information */ | 58 | /* file information */ |
@@ -1470,10 +1471,20 @@ void tracecmd_print_events(struct tracecmd_input *handle) | |||
1470 | } | 1471 | } |
1471 | 1472 | ||
1472 | /** | 1473 | /** |
1473 | * tracecmd_open_fd - create a tracecmd_handle from the trace.dat file descriptor | 1474 | * tracecmd_alloc_fd - create a tracecmd_input handle from a file descriptor |
1474 | * @fd: the file descriptor for the trace.dat file | 1475 | * @fd: the file descriptor for the trace.dat file |
1476 | * | ||
1477 | * Allocate a tracecmd_input handle from a file descriptor and open the | ||
1478 | * file. This tests if the file is of trace-cmd format and allocates | ||
1479 | * a parse event descriptor. | ||
1480 | * | ||
1481 | * The returned pointer is not ready to be read yet. A tracecmd_read_headers() | ||
1482 | * and tracecmd_init_data() still need to be called on the descriptor. | ||
1483 | * | ||
1484 | * Unless you know what you are doing with this, you want to use | ||
1485 | * tracecmd_open_fd() instead. | ||
1475 | */ | 1486 | */ |
1476 | struct tracecmd_input *tracecmd_open_fd(int fd) | 1487 | struct tracecmd_input *tracecmd_alloc_fd(int fd) |
1477 | { | 1488 | { |
1478 | struct tracecmd_input *handle; | 1489 | struct tracecmd_input *handle; |
1479 | char test[] = { 23, 8, 68 }; | 1490 | char test[] = { 23, 8, 68 }; |
@@ -1486,6 +1497,7 @@ struct tracecmd_input *tracecmd_open_fd(int fd) | |||
1486 | memset(handle, 0, sizeof(*handle)); | 1497 | memset(handle, 0, sizeof(*handle)); |
1487 | 1498 | ||
1488 | handle->fd = fd; | 1499 | handle->fd = fd; |
1500 | handle->ref = 1; | ||
1489 | 1501 | ||
1490 | if (do_read_check(handle, buf, 3)) | 1502 | if (do_read_check(handle, buf, 3)) |
1491 | goto failed_read; | 1503 | goto failed_read; |
@@ -1531,6 +1543,56 @@ struct tracecmd_input *tracecmd_open_fd(int fd) | |||
1531 | } | 1543 | } |
1532 | 1544 | ||
1533 | /** | 1545 | /** |
1546 | * tracecmd_alloc_fd - create a tracecmd_input handle from a file name | ||
1547 | * @file: the file name of the file that is of tracecmd data type. | ||
1548 | * | ||
1549 | * Allocate a tracecmd_input handle from a given file name and open the | ||
1550 | * file. This tests if the file is of trace-cmd format and allocates | ||
1551 | * a parse event descriptor. | ||
1552 | * | ||
1553 | * The returned pointer is not ready to be read yet. A tracecmd_read_headers() | ||
1554 | * and tracecmd_init_data() still need to be called on the descriptor. | ||
1555 | * | ||
1556 | * Unless you know what you are doing with this, you want to use | ||
1557 | * tracecmd_open() instead. | ||
1558 | */ | ||
1559 | struct tracecmd_input *tracecmd_alloc(const char *file) | ||
1560 | { | ||
1561 | int fd; | ||
1562 | |||
1563 | fd = open(file, O_RDONLY); | ||
1564 | if (fd < 0) | ||
1565 | return NULL; | ||
1566 | |||
1567 | return tracecmd_alloc_fd(fd); | ||
1568 | } | ||
1569 | |||
1570 | /** | ||
1571 | * tracecmd_open_fd - create a tracecmd_handle from the trace.dat file descriptor | ||
1572 | * @fd: the file descriptor for the trace.dat file | ||
1573 | */ | ||
1574 | struct tracecmd_input *tracecmd_open_fd(int fd) | ||
1575 | { | ||
1576 | struct tracecmd_input *handle; | ||
1577 | |||
1578 | handle = tracecmd_alloc_fd(fd); | ||
1579 | if (!handle) | ||
1580 | return NULL; | ||
1581 | |||
1582 | if (tracecmd_read_headers(handle) < 0) | ||
1583 | goto fail; | ||
1584 | |||
1585 | if (tracecmd_init_data(handle) < 0) | ||
1586 | goto fail; | ||
1587 | |||
1588 | return handle; | ||
1589 | |||
1590 | fail: | ||
1591 | tracecmd_close(handle); | ||
1592 | return NULL; | ||
1593 | } | ||
1594 | |||
1595 | /** | ||
1534 | * tracecmd_open - create a tracecmd_handle from a given file | 1596 | * tracecmd_open - create a tracecmd_handle from a given file |
1535 | * @file: the file name of the file that is of tracecmd data type. | 1597 | * @file: the file name of the file that is of tracecmd data type. |
1536 | */ | 1598 | */ |
@@ -1545,6 +1607,29 @@ struct tracecmd_input *tracecmd_open(const char *file) | |||
1545 | return tracecmd_open_fd(fd); | 1607 | return tracecmd_open_fd(fd); |
1546 | } | 1608 | } |
1547 | 1609 | ||
1610 | /** | ||
1611 | * tracecmd_ref - add a reference to the handle | ||
1612 | * @handle: input handle for the trace.dat file | ||
1613 | * | ||
1614 | * Some applications may share a handle between parts of | ||
1615 | * the application. Let those parts add reference counters | ||
1616 | * to the handle, and the last one to close it will free it. | ||
1617 | */ | ||
1618 | void tracecmd_ref(struct tracecmd_input *handle) | ||
1619 | { | ||
1620 | if (!handle) | ||
1621 | return; | ||
1622 | |||
1623 | handle->ref++; | ||
1624 | } | ||
1625 | |||
1626 | /** | ||
1627 | * tracecmd_close - close and free the trace.dat handle | ||
1628 | * @handle: input handle for the trace.dat file | ||
1629 | * | ||
1630 | * Close the file descriptor of the handle and frees | ||
1631 | * the resources allocated by the handle. | ||
1632 | */ | ||
1548 | void tracecmd_close(struct tracecmd_input *handle) | 1633 | void tracecmd_close(struct tracecmd_input *handle) |
1549 | { | 1634 | { |
1550 | int cpu; | 1635 | int cpu; |
@@ -1552,6 +1637,14 @@ void tracecmd_close(struct tracecmd_input *handle) | |||
1552 | if (!handle) | 1637 | if (!handle) |
1553 | return; | 1638 | return; |
1554 | 1639 | ||
1640 | if (handle->ref <= 0) { | ||
1641 | warning("tracecmd: bad ref count on handle\n"); | ||
1642 | return; | ||
1643 | } | ||
1644 | |||
1645 | if (--handle->ref) | ||
1646 | return; | ||
1647 | |||
1555 | for (cpu = 0; cpu < handle->cpus; cpu++) { | 1648 | for (cpu = 0; cpu < handle->cpus; cpu++) { |
1556 | struct record *rec; | 1649 | struct record *rec; |
1557 | /* | 1650 | /* |
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 | ||
282 | void trace_report (int argc, char **argv) | 282 | void trace_report (int argc, char **argv) |
diff --git a/trace-view-main.c b/trace-view-main.c index c728646..d98ddb7 100644 --- a/trace-view-main.c +++ b/trace-view-main.c | |||
@@ -136,12 +136,6 @@ void trace_view(int argc, char **argv) | |||
136 | if (!handle) | 136 | if (!handle) |
137 | die("error reading header"); | 137 | die("error reading header"); |
138 | 138 | ||
139 | if (tracecmd_read_headers(handle) < 0) | ||
140 | return; | ||
141 | |||
142 | if (tracecmd_init_data(handle) < 0) | ||
143 | die("failed to init data"); | ||
144 | |||
145 | gtk_init(&argc, &argv); | 139 | gtk_init(&argc, &argv); |
146 | 140 | ||
147 | /* --- Main window --- */ | 141 | /* --- Main window --- */ |