diff options
author | Steven Rostedt <srostedt@redhat.com> | 2010-04-05 21:30:53 -0400 |
---|---|---|
committer | Steven Rostedt <rostedt@goodmis.org> | 2010-04-09 11:56:18 -0400 |
commit | 38b92d6b993327de864ef7182cebe530abc5f5c7 (patch) | |
tree | bce4bdf49f02e7390beaad0c531714cd370ba1c0 | |
parent | 64be78aa61dfda0c5fdf5c7ccfc2d9a93ba52aa5 (diff) |
trace-graph: Add loading and saving of task and event filters
Add the filter loading and saving to trace-graph. Most of the work
was done already to get trace-view working. This just hooks into
that framework.
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
-rw-r--r-- | trace-graph-main.c | 73 | ||||
-rw-r--r-- | trace-graph.c | 119 | ||||
-rw-r--r-- | trace-graph.h | 6 |
3 files changed, 198 insertions, 0 deletions
diff --git a/trace-graph-main.c b/trace-graph-main.c index 303f342..4a9fed1 100644 --- a/trace-graph-main.c +++ b/trace-graph-main.c | |||
@@ -152,6 +152,50 @@ plot_tasks_clicked (gpointer data) | |||
152 | free(selected); | 152 | free(selected); |
153 | } | 153 | } |
154 | 154 | ||
155 | /* Callback for the clicked signal of the Load Filters button */ | ||
156 | static void | ||
157 | load_filters_clicked (gpointer data) | ||
158 | { | ||
159 | struct graph_info *ginfo = data; | ||
160 | struct tracecmd_xml_handle *handle; | ||
161 | gchar *filename; | ||
162 | |||
163 | filename = trace_get_file_dialog("Load Filters"); | ||
164 | if (!filename) | ||
165 | return; | ||
166 | |||
167 | handle = tracecmd_xml_open(filename); | ||
168 | if (!handle) | ||
169 | warning("Could not open %s", filename); | ||
170 | g_free(filename); | ||
171 | |||
172 | trace_graph_load_filters(ginfo, handle); | ||
173 | |||
174 | tracecmd_xml_close(handle); | ||
175 | } | ||
176 | |||
177 | /* Callback for the clicked signal of the Save Filters button */ | ||
178 | static void | ||
179 | save_filters_clicked (gpointer data) | ||
180 | { | ||
181 | struct graph_info *ginfo = data; | ||
182 | struct tracecmd_xml_handle *handle; | ||
183 | gchar *filename; | ||
184 | |||
185 | filename = trace_get_file_dialog("Save Filters"); | ||
186 | if (!filename) | ||
187 | return; | ||
188 | |||
189 | handle = tracecmd_xml_create(filename); | ||
190 | if (!handle) | ||
191 | warning("Could not create %s", filename); | ||
192 | g_free(filename); | ||
193 | |||
194 | trace_graph_save_filters(ginfo, handle); | ||
195 | |||
196 | tracecmd_xml_close(handle); | ||
197 | } | ||
198 | |||
155 | void trace_graph(int argc, char **argv) | 199 | void trace_graph(int argc, char **argv) |
156 | { | 200 | { |
157 | struct tracecmd_input *handle = NULL; | 201 | struct tracecmd_input *handle = NULL; |
@@ -247,6 +291,35 @@ void trace_graph(int argc, char **argv) | |||
247 | gtk_widget_show(sub_item); | 291 | gtk_widget_show(sub_item); |
248 | 292 | ||
249 | 293 | ||
294 | /* --- File - Load Filter Option --- */ | ||
295 | |||
296 | sub_item = gtk_menu_item_new_with_label("Load filters"); | ||
297 | |||
298 | /* Add them to the menu */ | ||
299 | gtk_menu_shell_append(GTK_MENU_SHELL (menu), sub_item); | ||
300 | |||
301 | g_signal_connect_swapped (G_OBJECT (sub_item), "activate", | ||
302 | G_CALLBACK (load_filters_clicked), | ||
303 | (gpointer) ginfo); | ||
304 | |||
305 | /* We do need to show menu items */ | ||
306 | gtk_widget_show(sub_item); | ||
307 | |||
308 | |||
309 | /* --- File - Save Filter Option --- */ | ||
310 | |||
311 | sub_item = gtk_menu_item_new_with_label("Save filters"); | ||
312 | |||
313 | /* Add them to the menu */ | ||
314 | gtk_menu_shell_append(GTK_MENU_SHELL (menu), sub_item); | ||
315 | |||
316 | g_signal_connect_swapped (G_OBJECT (sub_item), "activate", | ||
317 | G_CALLBACK (save_filters_clicked), | ||
318 | (gpointer) ginfo); | ||
319 | |||
320 | /* We do need to show menu items */ | ||
321 | gtk_widget_show(sub_item); | ||
322 | |||
250 | /* --- File - Quit Option --- */ | 323 | /* --- File - Quit Option --- */ |
251 | 324 | ||
252 | sub_item = gtk_menu_item_new_with_label("Quit"); | 325 | sub_item = gtk_menu_item_new_with_label("Quit"); |
diff --git a/trace-graph.c b/trace-graph.c index 6ed7851..9ec3924 100644 --- a/trace-graph.c +++ b/trace-graph.c | |||
@@ -32,6 +32,8 @@ | |||
32 | #include "trace-hash.h" | 32 | #include "trace-hash.h" |
33 | #include "trace-filter.h" | 33 | #include "trace-filter.h" |
34 | 34 | ||
35 | #include "version.h" | ||
36 | |||
35 | #include "util.h" | 37 | #include "util.h" |
36 | 38 | ||
37 | #define DEBUG_LEVEL 0 | 39 | #define DEBUG_LEVEL 0 |
@@ -2395,6 +2397,123 @@ int trace_graph_load_handle(struct graph_info *ginfo, | |||
2395 | return 0; | 2397 | return 0; |
2396 | } | 2398 | } |
2397 | 2399 | ||
2400 | static int load_event_filter(struct graph_info *ginfo, | ||
2401 | struct tracecmd_xml_handle *handle, | ||
2402 | struct tracecmd_xml_system_node *node) | ||
2403 | { | ||
2404 | struct tracecmd_xml_system_node *child; | ||
2405 | struct event_filter *event_filter; | ||
2406 | const char *name; | ||
2407 | const char *value; | ||
2408 | |||
2409 | event_filter = ginfo->event_filter; | ||
2410 | |||
2411 | child = tracecmd_xml_node_child(node); | ||
2412 | name = tracecmd_xml_node_type(child); | ||
2413 | if (strcmp(name, "FilterType") != 0) | ||
2414 | return -1; | ||
2415 | |||
2416 | value = tracecmd_xml_node_value(handle, child); | ||
2417 | /* Do nothing with all events enabled */ | ||
2418 | if (strcmp(value, "all events") == 0) | ||
2419 | return 0; | ||
2420 | |||
2421 | node = tracecmd_xml_node_next(child); | ||
2422 | if (!node) | ||
2423 | return -1; | ||
2424 | |||
2425 | pevent_filter_clear_trivial(event_filter, FILTER_TRIVIAL_BOTH); | ||
2426 | ginfo->all_events = FALSE; | ||
2427 | |||
2428 | trace_filter_load_events(event_filter, handle, node); | ||
2429 | |||
2430 | return 0; | ||
2431 | } | ||
2432 | |||
2433 | int trace_graph_load_filters(struct graph_info *ginfo, | ||
2434 | struct tracecmd_xml_handle *handle) | ||
2435 | { | ||
2436 | struct tracecmd_xml_system *system; | ||
2437 | struct tracecmd_xml_system_node *syschild; | ||
2438 | const char *name; | ||
2439 | |||
2440 | system = tracecmd_xml_find_system(handle, "TraceGraph"); | ||
2441 | if (!system) | ||
2442 | return -1; | ||
2443 | |||
2444 | syschild = tracecmd_xml_system_node(system); | ||
2445 | if (!syschild) | ||
2446 | goto out_free_sys; | ||
2447 | |||
2448 | do { | ||
2449 | name = tracecmd_xml_node_type(syschild); | ||
2450 | |||
2451 | if (strcmp(name, "EventFilter") == 0) | ||
2452 | load_event_filter(ginfo, handle, syschild); | ||
2453 | |||
2454 | else if (strcmp(name, "TaskFilter") == 0) | ||
2455 | trace_filter_load_task_filter(ginfo->task_filter, handle, syschild); | ||
2456 | |||
2457 | else if (strcmp(name, "HideTasks") == 0) | ||
2458 | trace_filter_load_task_filter(ginfo->hide_tasks, handle, syschild); | ||
2459 | |||
2460 | syschild = tracecmd_xml_node_next(syschild); | ||
2461 | } while (syschild); | ||
2462 | |||
2463 | if (filter_task_count(ginfo->task_filter) || | ||
2464 | filter_task_count(ginfo->hide_tasks)) | ||
2465 | ginfo->filter_available = 1; | ||
2466 | else | ||
2467 | ginfo->filter_available = 0; | ||
2468 | |||
2469 | tracecmd_xml_free_system(system); | ||
2470 | |||
2471 | trace_graph_refresh(ginfo); | ||
2472 | |||
2473 | return 0; | ||
2474 | |||
2475 | out_free_sys: | ||
2476 | tracecmd_xml_free_system(system); | ||
2477 | return -1; | ||
2478 | } | ||
2479 | |||
2480 | int trace_graph_save_filters(struct graph_info *ginfo, | ||
2481 | struct tracecmd_xml_handle *handle) | ||
2482 | { | ||
2483 | struct event_filter *event_filter; | ||
2484 | |||
2485 | tracecmd_xml_start_system(handle, "TraceGraph", VERSION_STRING); | ||
2486 | |||
2487 | event_filter = ginfo->event_filter; | ||
2488 | |||
2489 | tracecmd_xml_start_sub_system(handle, "EventFilter"); | ||
2490 | |||
2491 | if (ginfo->all_events || !event_filter) | ||
2492 | tracecmd_xml_write_element(handle, "FilterType", "all events"); | ||
2493 | else { | ||
2494 | tracecmd_xml_write_element(handle, "FilterType", "filter"); | ||
2495 | trace_filter_save_events(handle, event_filter); | ||
2496 | } | ||
2497 | |||
2498 | tracecmd_xml_end_sub_system(handle); | ||
2499 | |||
2500 | if (ginfo->task_filter && filter_task_count(ginfo->task_filter)) { | ||
2501 | tracecmd_xml_start_sub_system(handle, "TaskFilter"); | ||
2502 | trace_filter_save_tasks(handle, ginfo->task_filter); | ||
2503 | tracecmd_xml_end_sub_system(handle); | ||
2504 | } | ||
2505 | |||
2506 | if (ginfo->hide_tasks && filter_task_count(ginfo->hide_tasks)) { | ||
2507 | tracecmd_xml_start_sub_system(handle, "HideTasks"); | ||
2508 | trace_filter_save_tasks(handle, ginfo->hide_tasks); | ||
2509 | tracecmd_xml_end_sub_system(handle); | ||
2510 | } | ||
2511 | |||
2512 | tracecmd_xml_end_system(handle); | ||
2513 | |||
2514 | return 0; | ||
2515 | } | ||
2516 | |||
2398 | struct graph_info * | 2517 | struct graph_info * |
2399 | trace_graph_create_with_callbacks(struct tracecmd_input *handle, | 2518 | trace_graph_create_with_callbacks(struct tracecmd_input *handle, |
2400 | struct graph_callbacks *cbs) | 2519 | struct graph_callbacks *cbs) |
diff --git a/trace-graph.h b/trace-graph.h index 91ae161..916ad50 100644 --- a/trace-graph.h +++ b/trace-graph.h | |||
@@ -24,6 +24,7 @@ | |||
24 | #include <gtk/gtk.h> | 24 | #include <gtk/gtk.h> |
25 | #include "trace-cmd.h" | 25 | #include "trace-cmd.h" |
26 | #include "trace-hash.h" | 26 | #include "trace-hash.h" |
27 | #include "trace-xml.h" | ||
27 | 28 | ||
28 | struct graph_info; | 29 | struct graph_info; |
29 | 30 | ||
@@ -306,6 +307,11 @@ void trace_graph_copy_filter(struct graph_info *ginfo, | |||
306 | struct event_filter *event_filter); | 307 | struct event_filter *event_filter); |
307 | gint *trace_graph_task_list(struct graph_info *ginfo); | 308 | gint *trace_graph_task_list(struct graph_info *ginfo); |
308 | 309 | ||
310 | int trace_graph_load_filters(struct graph_info *ginfo, | ||
311 | struct tracecmd_xml_handle *handle); | ||
312 | int trace_graph_save_filters(struct graph_info *ginfo, | ||
313 | struct tracecmd_xml_handle *handle); | ||
314 | |||
309 | /* plots */ | 315 | /* plots */ |
310 | void trace_graph_plot_free(struct graph_info *ginfo); | 316 | void trace_graph_plot_free(struct graph_info *ginfo); |
311 | void trace_graph_plot_init(struct graph_info *ginfo); | 317 | void trace_graph_plot_init(struct graph_info *ginfo); |