diff options
| author | Steven Rostedt <srostedt@redhat.com> | 2010-03-31 05:32:43 -0400 |
|---|---|---|
| committer | Steven Rostedt <rostedt@goodmis.org> | 2010-04-09 11:56:17 -0400 |
| commit | 3f1e092ed414ab2a9f73eafe87f35e868030463c (patch) | |
| tree | f829402e08e1ba314e5e4c1fb5b6fc38ffc910a2 | |
| parent | 810abc5b84f2855cc328cb709e75046a646be463 (diff) | |
trace-view: Added saving of filters
Add "Save filters" to "File" menu, where it will allow the user to save
the filters to a file in XML format.
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
| -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 | |
