diff options
-rw-r--r-- | Makefile | 8 | ||||
-rw-r--r-- | trace-filter.c | 51 | ||||
-rw-r--r-- | trace-filter.h | 7 | ||||
-rw-r--r-- | trace-view-main.c | 42 | ||||
-rw-r--r-- | trace-view.c | 48 | ||||
-rw-r--r-- | trace-view.h | 4 | ||||
-rw-r--r-- | trace-xml.c | 127 | ||||
-rw-r--r-- | trace-xml.h | 41 |
8 files changed, 323 insertions, 5 deletions
@@ -96,7 +96,7 @@ plugin_dir_SQ = $(subst ','\'',$(plugin_dir)) | |||
96 | LIBS = -L. -ltracecmd -ldl | 96 | LIBS = -L. -ltracecmd -ldl |
97 | LIB_FILE = libtracecmd.a | 97 | LIB_FILE = libtracecmd.a |
98 | 98 | ||
99 | PACKAGES= gtk+-2.0 | 99 | PACKAGES= gtk+-2.0 libxml-2.0 |
100 | 100 | ||
101 | ifndef BUILDGUI | 101 | ifndef BUILDGUI |
102 | BUILDGUI = 0 | 102 | BUILDGUI = 0 |
@@ -213,13 +213,15 @@ $(obj)/%.o: $(src)/%.c | |||
213 | %.o: $(src)/%.c | 213 | %.o: $(src)/%.c |
214 | $(Q)$(call check_gui) | 214 | $(Q)$(call check_gui) |
215 | 215 | ||
216 | TRACE_GUI_OBJS = trace-filter.o trace-compat.o trace-hash.o trace-dialog.o | 216 | TRACE_GUI_OBJS = trace-filter.o trace-compat.o trace-hash.o trace-dialog.o \ |
217 | trace-xml.o | ||
217 | TRACE_CMD_OBJS = trace-cmd.o trace-usage.o trace-read.o trace-split.o trace-listen.o | 218 | TRACE_CMD_OBJS = trace-cmd.o trace-usage.o trace-read.o trace-split.o trace-listen.o |
218 | TRACE_VIEW_OBJS = trace-view.o trace-view-store.o | 219 | TRACE_VIEW_OBJS = trace-view.o trace-view-store.o |
219 | TRACE_GRAPH_OBJS = trace-graph.o trace-plot.o trace-plot-cpu.o trace-plot-task.o | 220 | TRACE_GRAPH_OBJS = trace-graph.o trace-plot.o trace-plot-cpu.o trace-plot-task.o |
220 | TRACE_VIEW_MAIN_OBJS = trace-view-main.o $(TRACE_VIEW_OBJS) $(TRACE_GUI_OBJS) | 221 | TRACE_VIEW_MAIN_OBJS = trace-view-main.o $(TRACE_VIEW_OBJS) $(TRACE_GUI_OBJS) |
221 | TRACE_GRAPH_MAIN_OBJS = trace-graph-main.o $(TRACE_GRAPH_OBJS) $(TRACE_GUI_OBJS) | 222 | TRACE_GRAPH_MAIN_OBJS = trace-graph-main.o $(TRACE_GRAPH_OBJS) $(TRACE_GUI_OBJS) |
222 | KERNEL_SHARK_OBJS = $(TRACE_VIEW_OBJS) $(TRACE_GRAPH_OBJS) $(TRACE_GUI_OBJS) kernel-shark.o | 223 | KERNEL_SHARK_OBJS = $(TRACE_VIEW_OBJS) $(TRACE_GRAPH_OBJS) $(TRACE_GUI_OBJS) \ |
224 | kernel-shark.o | ||
223 | 225 | ||
224 | PEVENT_LIB_OBJS = parse-events.o trace-seq.o parse-filter.o | 226 | PEVENT_LIB_OBJS = parse-events.o trace-seq.o parse-filter.o |
225 | TCMD_LIB_OBJS = $(PEVENT_LIB_OBJS) trace-util.o trace-input.o trace-ftrace.o \ | 227 | TCMD_LIB_OBJS = $(PEVENT_LIB_OBJS) trace-util.o trace-input.o trace-ftrace.o \ |
diff --git a/trace-filter.c b/trace-filter.c index 15d59c0..904c9cb 100644 --- a/trace-filter.c +++ b/trace-filter.c | |||
@@ -2158,3 +2158,54 @@ void trace_filter_convert_char_to_filter(struct event_filter *filter, | |||
2158 | 2158 | ||
2159 | pevent_filter_free(copy); | 2159 | pevent_filter_free(copy); |
2160 | } | 2160 | } |
2161 | |||
2162 | int trace_filter_save_events(struct tracecmd_xml_handle *handle, | ||
2163 | struct event_filter *filter) | ||
2164 | { | ||
2165 | struct event_format *event; | ||
2166 | char **systems; | ||
2167 | gint *event_ids; | ||
2168 | char *str; | ||
2169 | int i; | ||
2170 | |||
2171 | trace_filter_convert_filter_to_names(filter, &systems, | ||
2172 | &event_ids); | ||
2173 | |||
2174 | for (i = 0; systems && systems[i]; i++) | ||
2175 | tracecmd_xml_write_element(handle, "System", systems[i]); | ||
2176 | |||
2177 | for (i = 0; event_ids && event_ids[i] > 0; i++) { | ||
2178 | str = pevent_filter_make_string(filter, event_ids[i]); | ||
2179 | if (!str) | ||
2180 | continue; | ||
2181 | |||
2182 | event = pevent_find_event(filter->pevent, event_ids[i]); | ||
2183 | if (event) { | ||
2184 | |||
2185 | /* skip not filtered items */ | ||
2186 | if (strcmp(str, "FALSE") == 0) { | ||
2187 | free(str); | ||
2188 | continue; | ||
2189 | } | ||
2190 | |||
2191 | tracecmd_xml_start_sub_system(handle, "Event"); | ||
2192 | tracecmd_xml_write_element(handle, "System", event->system); | ||
2193 | tracecmd_xml_write_element(handle, "Name", event->name); | ||
2194 | /* If this is has an advanced filter, include that too */ | ||
2195 | if (strcmp(str, "TRUE") != 0) { | ||
2196 | tracecmd_xml_write_element(handle, "Advanced", | ||
2197 | str); | ||
2198 | } | ||
2199 | tracecmd_xml_end_sub_system(handle); | ||
2200 | } | ||
2201 | free(str); | ||
2202 | } | ||
2203 | |||
2204 | return 0; | ||
2205 | } | ||
2206 | |||
2207 | int trace_filter_save_tasks(struct tracecmd_xml_handle *handle, | ||
2208 | struct filter_task *filter) | ||
2209 | { | ||
2210 | return 0; | ||
2211 | } | ||
diff --git a/trace-filter.h b/trace-filter.h index c68e8f0..7575244 100644 --- a/trace-filter.h +++ b/trace-filter.h | |||
@@ -23,6 +23,8 @@ | |||
23 | 23 | ||
24 | #include <gtk/gtk.h> | 24 | #include <gtk/gtk.h> |
25 | 25 | ||
26 | #include "trace-xml.h" | ||
27 | |||
26 | struct event_filter_list { | 28 | struct event_filter_list { |
27 | struct event_filter_list *next; | 29 | struct event_filter_list *next; |
28 | struct event *event; | 30 | struct event *event; |
@@ -140,4 +142,9 @@ int id_cmp(const void *a, const void *b); | |||
140 | 142 | ||
141 | void trace_array_add(gint **array, gint *count, gint val); | 143 | void trace_array_add(gint **array, gint *count, gint val); |
142 | 144 | ||
145 | int trace_filter_save_events(struct tracecmd_xml_handle *handle, | ||
146 | struct event_filter *filter); | ||
147 | int trace_filter_save_tasks(struct tracecmd_xml_handle *handle, | ||
148 | struct filter_task *filter); | ||
149 | |||
143 | #endif /* _TRACE_FILTER_H */ | 150 | #endif /* _TRACE_FILTER_H */ |
diff --git a/trace-view-main.c b/trace-view-main.c index 7f1461b..52fb4f8 100644 --- a/trace-view-main.c +++ b/trace-view-main.c | |||
@@ -28,6 +28,7 @@ | |||
28 | 28 | ||
29 | #include "trace-cmd.h" | 29 | #include "trace-cmd.h" |
30 | #include "trace-view.h" | 30 | #include "trace-view.h" |
31 | #include "trace-xml.h" | ||
31 | #include "trace-gui.h" | 32 | #include "trace-gui.h" |
32 | 33 | ||
33 | #define version "0.1.1" | 34 | #define version "0.1.1" |
@@ -71,6 +72,29 @@ load_clicked (gpointer data) | |||
71 | g_free(filename); | 72 | g_free(filename); |
72 | } | 73 | } |
73 | 74 | ||
75 | /* Callback for the clicked signal of the Save State button */ | ||
76 | static void | ||
77 | save_filters_clicked (gpointer data) | ||
78 | { | ||
79 | struct trace_tree_info *info = data; | ||
80 | GtkTreeView *trace_tree = GTK_TREE_VIEW(info->trace_tree); | ||
81 | struct tracecmd_xml_handle *handle; | ||
82 | gchar *filename; | ||
83 | |||
84 | filename = trace_get_file_dialog("Save State"); | ||
85 | if (!filename) | ||
86 | return; | ||
87 | |||
88 | handle = tracecmd_xml_create(filename); | ||
89 | if (!handle) | ||
90 | warning("Could not create save state %s", filename); | ||
91 | g_free(filename); | ||
92 | |||
93 | trace_view_save_filters(handle, trace_tree); | ||
94 | |||
95 | tracecmd_xml_close(handle); | ||
96 | } | ||
97 | |||
74 | /* Callback for the clicked signal of the Exit button */ | 98 | /* Callback for the clicked signal of the Exit button */ |
75 | static void | 99 | static void |
76 | exit_clicked (GtkWidget *widget, gpointer data) | 100 | exit_clicked (GtkWidget *widget, gpointer data) |
@@ -249,12 +273,11 @@ void trace_view(int argc, char **argv) | |||
249 | 273 | ||
250 | /* --- File - Load Option --- */ | 274 | /* --- File - Load Option --- */ |
251 | 275 | ||
252 | sub_item = gtk_menu_item_new_with_label("Load info"); | 276 | sub_item = gtk_menu_item_new_with_label("Load data"); |
253 | 277 | ||
254 | /* Add them to the menu */ | 278 | /* Add them to the menu */ |
255 | gtk_menu_shell_append(GTK_MENU_SHELL (menu), sub_item); | 279 | gtk_menu_shell_append(GTK_MENU_SHELL (menu), sub_item); |
256 | 280 | ||
257 | /* We can attach the Quit menu item to our exit function */ | ||
258 | g_signal_connect_swapped (G_OBJECT (sub_item), "activate", | 281 | g_signal_connect_swapped (G_OBJECT (sub_item), "activate", |
259 | G_CALLBACK (load_clicked), | 282 | G_CALLBACK (load_clicked), |
260 | (gpointer) &tree_info); | 283 | (gpointer) &tree_info); |
@@ -263,6 +286,21 @@ void trace_view(int argc, char **argv) | |||
263 | gtk_widget_show(sub_item); | 286 | gtk_widget_show(sub_item); |
264 | 287 | ||
265 | 288 | ||
289 | /* --- File - Save State Option --- */ | ||
290 | |||
291 | sub_item = gtk_menu_item_new_with_label("Save filters"); | ||
292 | |||
293 | /* Add them to the menu */ | ||
294 | gtk_menu_shell_append(GTK_MENU_SHELL (menu), sub_item); | ||
295 | |||
296 | g_signal_connect_swapped (G_OBJECT (sub_item), "activate", | ||
297 | G_CALLBACK (save_filters_clicked), | ||
298 | (gpointer) &tree_info); | ||
299 | |||
300 | /* We do need to show menu items */ | ||
301 | gtk_widget_show(sub_item); | ||
302 | |||
303 | |||
266 | /* --- File - Quit Option --- */ | 304 | /* --- File - Quit Option --- */ |
267 | 305 | ||
268 | sub_item = gtk_menu_item_new_with_label("Quit"); | 306 | sub_item = gtk_menu_item_new_with_label("Quit"); |
diff --git a/trace-view.c b/trace-view.c index 59e7e1a..c183b19 100644 --- a/trace-view.c +++ b/trace-view.c | |||
@@ -29,6 +29,7 @@ | |||
29 | #include "trace-local.h" | 29 | #include "trace-local.h" |
30 | #include "trace-view.h" | 30 | #include "trace-view.h" |
31 | #include "trace-compat.h" | 31 | #include "trace-compat.h" |
32 | #include "version.h" | ||
32 | #include "cpu.h" | 33 | #include "cpu.h" |
33 | #include "util.h" | 34 | #include "util.h" |
34 | 35 | ||
@@ -870,3 +871,50 @@ void trace_view_search_setup(GtkBox *box, GtkTreeView *treeview) | |||
870 | G_CALLBACK (search_tree), | 871 | G_CALLBACK (search_tree), |
871 | (gpointer) info); | 872 | (gpointer) info); |
872 | } | 873 | } |
874 | |||
875 | int trace_view_save_filters(struct tracecmd_xml_handle *handle, | ||
876 | GtkTreeView *trace_tree) | ||
877 | { | ||
878 | struct event_filter *event_filter; | ||
879 | GtkTreeModel *model; | ||
880 | TraceViewStore *store; | ||
881 | gboolean all_events; | ||
882 | |||
883 | model = gtk_tree_view_get_model(trace_tree); | ||
884 | if (!model) | ||
885 | return -1; | ||
886 | |||
887 | store = TRACE_VIEW_STORE(model); | ||
888 | |||
889 | tracecmd_xml_start_system(handle, "TraceView", VERSION_STRING); | ||
890 | |||
891 | all_events = trace_view_store_get_all_events_enabled(store); | ||
892 | event_filter = trace_view_store_get_event_filter(store); | ||
893 | |||
894 | tracecmd_xml_start_sub_system(handle, "EventFilter"); | ||
895 | |||
896 | if (all_events || !event_filter) | ||
897 | tracecmd_xml_write_element(handle, "FilterType", "all events"); | ||
898 | else { | ||
899 | tracecmd_xml_write_element(handle, "FilterType", "filter"); | ||
900 | trace_filter_save_events(handle, event_filter); | ||
901 | } | ||
902 | |||
903 | tracecmd_xml_end_sub_system(handle); | ||
904 | |||
905 | if (store->task_filter) { | ||
906 | tracecmd_xml_start_sub_system(handle, "TaskFilter"); | ||
907 | trace_filter_save_tasks(handle, store->task_filter); | ||
908 | tracecmd_xml_end_sub_system(handle); | ||
909 | } | ||
910 | |||
911 | if (store->hide_tasks) { | ||
912 | tracecmd_xml_start_sub_system(handle, "HideTasks"); | ||
913 | trace_filter_save_tasks(handle, store->hide_tasks); | ||
914 | tracecmd_xml_end_sub_system(handle); | ||
915 | } | ||
916 | |||
917 | tracecmd_xml_end_system(handle); | ||
918 | |||
919 | return 0; | ||
920 | } | ||
diff --git a/trace-view.h b/trace-view.h index 182b285..5ad33bf 100644 --- a/trace-view.h +++ b/trace-view.h | |||
@@ -23,6 +23,7 @@ | |||
23 | 23 | ||
24 | #include "trace-view-store.h" | 24 | #include "trace-view-store.h" |
25 | #include "trace-filter.h" | 25 | #include "trace-filter.h" |
26 | #include "trace-xml.h" | ||
26 | 27 | ||
27 | void | 28 | void |
28 | trace_view_load(GtkWidget *view, struct tracecmd_input *handle, | 29 | trace_view_load(GtkWidget *view, struct tracecmd_input *handle, |
@@ -65,4 +66,7 @@ void trace_view_search_setup(GtkBox *box, GtkTreeView *treeview); | |||
65 | 66 | ||
66 | gint trace_view_get_selected_row(GtkWidget *treeview); | 67 | gint trace_view_get_selected_row(GtkWidget *treeview); |
67 | 68 | ||
69 | int trace_view_save_filters(struct tracecmd_xml_handle *handle, | ||
70 | GtkTreeView *treeview); | ||
71 | |||
68 | #endif /* _TRACE_VIEW_H */ | 72 | #endif /* _TRACE_VIEW_H */ |
diff --git a/trace-xml.c b/trace-xml.c new file mode 100644 index 0000000..0bc130c --- /dev/null +++ b/trace-xml.c | |||
@@ -0,0 +1,127 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2009, 2010 Red Hat Inc, Steven Rostedt <srostedt@redhat.com> | ||
3 | * | ||
4 | * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
5 | * This program is free software; you can redistribute it and/or | ||
6 | * modify it under the terms of the GNU Lesser General Public | ||
7 | * License as published by the Free Software Foundation; | ||
8 | * version 2.1 of the License (not later!) | ||
9 | * | ||
10 | * This program is distributed in the hope that it will be useful, | ||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | * GNU Lesser General Public License for more details. | ||
14 | * | ||
15 | * You should have received a copy of the GNU Lesser General Public | ||
16 | * License along with this program; if not, write to the Free Software | ||
17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
18 | * | ||
19 | * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
20 | */ | ||
21 | #include <stdio.h> | ||
22 | #include <stdlib.h> | ||
23 | #include <stdarg.h> | ||
24 | #include <string.h> | ||
25 | |||
26 | #include <libxml/xmlwriter.h> | ||
27 | #include <libxml/parser.h> | ||
28 | #include <libxml/encoding.h> | ||
29 | |||
30 | #include "trace-cmd.h" | ||
31 | #include "trace-xml.h" | ||
32 | |||
33 | struct tracecmd_xml_handle { | ||
34 | xmlTextWriterPtr writer; | ||
35 | }; | ||
36 | |||
37 | #define TRACE_ENCODING "UTF-8" | ||
38 | |||
39 | int tracecmd_xml_write_element(struct tracecmd_xml_handle *handle, | ||
40 | const char *obj, | ||
41 | const char *fmt, ...) | ||
42 | { | ||
43 | va_list ap; | ||
44 | int ret; | ||
45 | |||
46 | va_start(ap, fmt); | ||
47 | ret = xmlTextWriterWriteVFormatElement(handle->writer, | ||
48 | BAD_CAST obj, fmt, ap); | ||
49 | va_end(ap); | ||
50 | |||
51 | return ret; | ||
52 | } | ||
53 | |||
54 | struct tracecmd_xml_handle *tracecmd_xml_create(const char *name) | ||
55 | { | ||
56 | struct tracecmd_xml_handle *handle; | ||
57 | int ret; | ||
58 | |||
59 | handle = malloc_or_die(sizeof(*handle)); | ||
60 | memset(handle, 0, sizeof(*handle)); | ||
61 | |||
62 | handle->writer = xmlNewTextWriterFilename(name, 0); | ||
63 | if (!handle->writer) | ||
64 | goto fail_free; | ||
65 | |||
66 | ret = xmlTextWriterStartDocument(handle->writer, NULL, | ||
67 | TRACE_ENCODING, NULL); | ||
68 | if (ret < 0) | ||
69 | goto fail_close; | ||
70 | |||
71 | return handle; | ||
72 | |||
73 | fail_close: | ||
74 | xmlFreeTextWriter(handle->writer); | ||
75 | fail_free: | ||
76 | free(handle); | ||
77 | return NULL; | ||
78 | } | ||
79 | |||
80 | int tracecmd_xml_start_system(struct tracecmd_xml_handle *handle, | ||
81 | const char *system, const char *version) | ||
82 | { | ||
83 | int ret; | ||
84 | |||
85 | ret = xmlTextWriterStartElement(handle->writer, | ||
86 | BAD_CAST system); | ||
87 | |||
88 | if (ret < 0) | ||
89 | return ret; | ||
90 | |||
91 | ret = tracecmd_xml_write_element(handle, "Version", "%s", version); | ||
92 | if (ret < 0) | ||
93 | return ret; | ||
94 | |||
95 | return 0; | ||
96 | } | ||
97 | |||
98 | int tracecmd_xml_start_sub_system(struct tracecmd_xml_handle *handle, | ||
99 | const char *subsystem) | ||
100 | { | ||
101 | int ret; | ||
102 | |||
103 | ret = xmlTextWriterStartElement(handle->writer, | ||
104 | BAD_CAST subsystem); | ||
105 | |||
106 | return ret; | ||
107 | } | ||
108 | |||
109 | void tracecmd_xml_end_system(struct tracecmd_xml_handle *handle) | ||
110 | { | ||
111 | xmlTextWriterEndElement(handle->writer); | ||
112 | } | ||
113 | |||
114 | void tracecmd_xml_end_sub_system(struct tracecmd_xml_handle *handle) | ||
115 | { | ||
116 | xmlTextWriterEndElement(handle->writer); | ||
117 | } | ||
118 | |||
119 | void tracecmd_xml_close(struct tracecmd_xml_handle *handle) | ||
120 | { | ||
121 | if (handle->writer) { | ||
122 | xmlTextWriterEndDocument(handle->writer); | ||
123 | xmlFreeTextWriter(handle->writer); | ||
124 | } | ||
125 | |||
126 | free(handle); | ||
127 | } | ||
diff --git a/trace-xml.h b/trace-xml.h new file mode 100644 index 0000000..41f6193 --- /dev/null +++ b/trace-xml.h | |||
@@ -0,0 +1,41 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2009, 2010 Red Hat Inc, Steven Rostedt <srostedt@redhat.com> | ||
3 | * | ||
4 | * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
5 | * This program is free software; you can redistribute it and/or | ||
6 | * modify it under the terms of the GNU Lesser General Public | ||
7 | * License as published by the Free Software Foundation; | ||
8 | * version 2.1 of the License (not later!) | ||
9 | * | ||
10 | * This program is distributed in the hope that it will be useful, | ||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | * GNU Lesser General Public License for more details. | ||
14 | * | ||
15 | * You should have received a copy of the GNU Lesser General Public | ||
16 | * License along with this program; if not, write to the Free Software | ||
17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
18 | * | ||
19 | * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
20 | */ | ||
21 | #ifndef __TRACE_XML_H | ||
22 | #define __TRACE_XML_H | ||
23 | |||
24 | struct tracecmd_xml_handle; | ||
25 | |||
26 | struct tracecmd_xml_handle *tracecmd_xml_create(const char *name); | ||
27 | void tracecmd_xml_close(struct tracecmd_xml_handle *handle); | ||
28 | |||
29 | int tracecmd_xml_start_system(struct tracecmd_xml_handle *handle, | ||
30 | const char *system, const char *version); | ||
31 | void tracecmd_xml_end_system(struct tracecmd_xml_handle *handle); | ||
32 | |||
33 | int tracecmd_xml_start_sub_system(struct tracecmd_xml_handle *handle, | ||
34 | const char *subsystem); | ||
35 | void tracecmd_xml_end_sub_system(struct tracecmd_xml_handle *handle); | ||
36 | |||
37 | int tracecmd_xml_write_element(struct tracecmd_xml_handle *handle, | ||
38 | const char *obj, | ||
39 | const char *fmt, ...); | ||
40 | |||
41 | #endif /* __TRACE_XML_H */ | ||