aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--trace-filter.c75
-rw-r--r--trace-filter.h14
-rw-r--r--trace-view-main.c46
-rw-r--r--trace-view.c116
-rw-r--r--trace-view.h2
-rw-r--r--trace-xml.c104
-rw-r--r--trace-xml.h19
7 files changed, 366 insertions, 10 deletions
diff --git a/trace-filter.c b/trace-filter.c
index 904c9cb..efdb5fa 100644
--- a/trace-filter.c
+++ b/trace-filter.c
@@ -2209,3 +2209,78 @@ int trace_filter_save_tasks(struct tracecmd_xml_handle *handle,
2209{ 2209{
2210 return 0; 2210 return 0;
2211} 2211}
2212
2213int trace_filter_load_events(struct event_filter *event_filter,
2214 struct tracecmd_xml_handle *handle,
2215 struct tracecmd_xml_system_node *node)
2216{
2217 struct tracecmd_xml_system_node *child;
2218 const char *name;
2219 const char *system;
2220 const char *event;
2221 const char *value;
2222 char *buffer;
2223
2224 while (node) {
2225 name = tracecmd_xml_node_type(node);
2226
2227 if (strcmp(name, "System") == 0) {
2228 system = tracecmd_xml_node_value(handle, node);
2229 pevent_filter_add_filter_str(event_filter,
2230 system, NULL);
2231 } else if (strcmp(name, "Event") == 0) {
2232 system = NULL;
2233 event = NULL;
2234 value = NULL;
2235 child = tracecmd_xml_node_child(node);
2236 if (!child)
2237 return -1;
2238 do {
2239 name = tracecmd_xml_node_type(child);
2240 if (strcmp(name, "System") == 0)
2241 system = tracecmd_xml_node_value(handle, child);
2242 else if (strcmp(name, "Name") == 0)
2243 event = tracecmd_xml_node_value(handle, child);
2244 else if (strcmp(name, "Advanced") == 0)
2245 value = tracecmd_xml_node_value(handle, child);
2246 child = tracecmd_xml_node_next(child);
2247 } while (child);
2248
2249 if (event || system) {
2250 if (event && system) {
2251 if (value) {
2252 buffer = malloc_or_die(strlen(event) +
2253 strlen(system) +
2254 strlen(value) + 3);
2255 sprintf(buffer, "%s/%s:%s",
2256 system, event, value);
2257 } else {
2258 buffer = malloc_or_die(strlen(event) +
2259 strlen(system) + 2);
2260 sprintf(buffer, "%s/%s",
2261 system, event);
2262 }
2263 } else {
2264 if (!event)
2265 event = system;
2266 if (value) {
2267 buffer = malloc_or_die(strlen(event) +
2268 strlen(value) + 2);
2269 sprintf(buffer, "%s:%s",
2270 event, value);
2271 } else {
2272 buffer = malloc_or_die(strlen(event) + 1);
2273 sprintf(buffer, "%s", event);
2274 }
2275 }
2276 pevent_filter_add_filter_str(event_filter,
2277 buffer, NULL);
2278 free(buffer);
2279 }
2280 }
2281
2282 node = tracecmd_xml_node_next(node);
2283 }
2284
2285 return 0;
2286}
diff --git a/trace-filter.h b/trace-filter.h
index 7575244..915b174 100644
--- a/trace-filter.h
+++ b/trace-filter.h
@@ -135,16 +135,20 @@ typedef void (*trace_filter_cpu_cb_func)(gboolean accept,
135void trace_filter_cpu_dialog(gboolean all_cpus, guint64 *cpu_mask_selected, gint cpus, 135void trace_filter_cpu_dialog(gboolean all_cpus, guint64 *cpu_mask_selected, gint cpus,
136 trace_filter_cpu_cb_func func, gpointer data); 136 trace_filter_cpu_cb_func func, gpointer data);
137 137
138/* put here because there's no other place */
139
140int str_cmp(const void *a, const void *b);
141int id_cmp(const void *a, const void *b);
142
143void trace_array_add(gint **array, gint *count, gint val); 138void trace_array_add(gint **array, gint *count, gint val);
144 139
140/* save and load filters */
145int trace_filter_save_events(struct tracecmd_xml_handle *handle, 141int trace_filter_save_events(struct tracecmd_xml_handle *handle,
146 struct event_filter *filter); 142 struct event_filter *filter);
147int trace_filter_save_tasks(struct tracecmd_xml_handle *handle, 143int trace_filter_save_tasks(struct tracecmd_xml_handle *handle,
148 struct filter_task *filter); 144 struct filter_task *filter);
145int trace_filter_load_events(struct event_filter *event_filter,
146 struct tracecmd_xml_handle *handle,
147 struct tracecmd_xml_system_node *node);
148
149/* put here because there's no other place */
150
151int str_cmp(const void *a, const void *b);
152int id_cmp(const void *a, const void *b);
149 153
150#endif /* _TRACE_FILTER_H */ 154#endif /* _TRACE_FILTER_H */
diff --git a/trace-view-main.c b/trace-view-main.c
index 52fb4f8..22b9e32 100644
--- a/trace-view-main.c
+++ b/trace-view-main.c
@@ -72,7 +72,30 @@ load_clicked (gpointer data)
72 g_free(filename); 72 g_free(filename);
73} 73}
74 74
75/* Callback for the clicked signal of the Save State button */ 75/* Callback for the clicked signal of the Load Filters button */
76static void
77load_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("Load Filters");
85 if (!filename)
86 return;
87
88 handle = tracecmd_xml_open(filename);
89 if (!handle)
90 warning("Could not open %s", filename);
91 g_free(filename);
92
93 trace_view_load_filters(handle, trace_tree);
94
95 tracecmd_xml_close(handle);
96}
97
98/* Callback for the clicked signal of the Save Filters button */
76static void 99static void
77save_filters_clicked (gpointer data) 100save_filters_clicked (gpointer data)
78{ 101{
@@ -81,13 +104,13 @@ save_filters_clicked (gpointer data)
81 struct tracecmd_xml_handle *handle; 104 struct tracecmd_xml_handle *handle;
82 gchar *filename; 105 gchar *filename;
83 106
84 filename = trace_get_file_dialog("Save State"); 107 filename = trace_get_file_dialog("Save Filters");
85 if (!filename) 108 if (!filename)
86 return; 109 return;
87 110
88 handle = tracecmd_xml_create(filename); 111 handle = tracecmd_xml_create(filename);
89 if (!handle) 112 if (!handle)
90 warning("Could not create save state %s", filename); 113 warning("Could not create %s", filename);
91 g_free(filename); 114 g_free(filename);
92 115
93 trace_view_save_filters(handle, trace_tree); 116 trace_view_save_filters(handle, trace_tree);
@@ -286,7 +309,22 @@ void trace_view(int argc, char **argv)
286 gtk_widget_show(sub_item); 309 gtk_widget_show(sub_item);
287 310
288 311
289 /* --- File - Save State Option --- */ 312 /* --- File - Load Filter Option --- */
313
314 sub_item = gtk_menu_item_new_with_label("Load filters");
315
316 /* Add them to the menu */
317 gtk_menu_shell_append(GTK_MENU_SHELL (menu), sub_item);
318
319 g_signal_connect_swapped (G_OBJECT (sub_item), "activate",
320 G_CALLBACK (load_filters_clicked),
321 (gpointer) &tree_info);
322
323 /* We do need to show menu items */
324 gtk_widget_show(sub_item);
325
326
327 /* --- File - Save Filter Option --- */
290 328
291 sub_item = gtk_menu_item_new_with_label("Save filters"); 329 sub_item = gtk_menu_item_new_with_label("Save filters");
292 330
diff --git a/trace-view.c b/trace-view.c
index c183b19..094f226 100644
--- a/trace-view.c
+++ b/trace-view.c
@@ -918,3 +918,119 @@ int trace_view_save_filters(struct tracecmd_xml_handle *handle,
918 918
919 return 0; 919 return 0;
920} 920}
921
922static int load_event_filter(TraceViewStore *store,
923 struct tracecmd_xml_handle *handle,
924 struct tracecmd_xml_system_node *node)
925{
926 struct tracecmd_xml_system_node *child;
927 struct event_filter *event_filter;
928 const char *name;
929 const char *value;
930
931 event_filter = trace_view_store_get_event_filter(store);
932
933 child = tracecmd_xml_node_child(node);
934 name = tracecmd_xml_node_type(child);
935 if (strcmp(name, "FilterType") != 0)
936 return -1;
937
938 value = tracecmd_xml_node_value(handle, child);
939 /* Do nothing with all events enabled */
940 if (strcmp(value, "all events") == 0)
941 return 0;
942
943 node = tracecmd_xml_node_next(child);
944 if (!node)
945 return -1;
946
947 trace_view_store_clear_all_events_enabled(store);
948
949 trace_filter_load_events(event_filter, handle, node);
950
951 return 0;
952}
953
954static int load_task_filter(TraceViewStore *store,
955 struct tracecmd_xml_handle *handle,
956 struct tracecmd_xml_system_node *node)
957{
958 struct tracecmd_xml_system_node *child;
959 const char *name;
960 const char *value;
961
962 child = tracecmd_xml_node_child(node);
963 name = tracecmd_xml_node_type(child);
964 if (strcmp(name, "FilterType") == 0) {
965 value = tracecmd_xml_node_value(handle, child);
966 printf("value = %s\n", value);
967 }
968
969 return 0;
970}
971
972static int load_hide_tasks(TraceViewStore *store,
973 struct tracecmd_xml_handle *handle,
974 struct tracecmd_xml_system_node *node)
975{
976 struct tracecmd_xml_system_node *child;
977 const char *name;
978 const char *value;
979
980 child = tracecmd_xml_node_child(node);
981 name = tracecmd_xml_node_type(child);
982 if (strcmp(name, "FilterType") == 0) {
983 value = tracecmd_xml_node_value(handle, child);
984 printf("value = %s\n", value);
985 }
986
987 return 0;
988}
989
990int trace_view_load_filters(struct tracecmd_xml_handle *handle,
991 GtkTreeView *trace_tree)
992{
993 struct tracecmd_xml_system *system;
994 struct tracecmd_xml_system_node *syschild;
995 GtkTreeModel *model;
996 TraceViewStore *store;
997 const char *name;
998
999 model = gtk_tree_view_get_model(trace_tree);
1000 if (!model)
1001 return -1;
1002
1003 store = TRACE_VIEW_STORE(model);
1004
1005 system = tracecmd_xml_find_system(handle, "TraceView");
1006 if (!system)
1007 return -1;
1008
1009 syschild = tracecmd_xml_system_node(system);
1010 if (!syschild)
1011 goto out_free_sys;
1012
1013 do {
1014 name = tracecmd_xml_node_type(syschild);
1015
1016 if (strcmp(name, "EventFilter") == 0)
1017 load_event_filter(store, handle, syschild);
1018
1019 else if (strcmp(name, "TaskFilter") == 0)
1020 load_task_filter(store, handle, syschild);
1021
1022 else if (strcmp(name, "HideTasks") == 0)
1023 load_hide_tasks(store, handle, syschild);
1024
1025 syschild = tracecmd_xml_node_next(syschild);
1026 } while (syschild);
1027
1028 tracecmd_xml_free_system(system);
1029
1030 update_rows(trace_tree, store);
1031 return 0;
1032
1033 out_free_sys:
1034 tracecmd_xml_free_system(system);
1035 return -1;
1036}
diff --git a/trace-view.h b/trace-view.h
index 5ad33bf..81dac6f 100644
--- a/trace-view.h
+++ b/trace-view.h
@@ -68,5 +68,7 @@ gint trace_view_get_selected_row(GtkWidget *treeview);
68 68
69int trace_view_save_filters(struct tracecmd_xml_handle *handle, 69int trace_view_save_filters(struct tracecmd_xml_handle *handle,
70 GtkTreeView *treeview); 70 GtkTreeView *treeview);
71int trace_view_load_filters(struct tracecmd_xml_handle *handle,
72 GtkTreeView *treeview);
71 73
72#endif /* _TRACE_VIEW_H */ 74#endif /* _TRACE_VIEW_H */
diff --git a/trace-xml.c b/trace-xml.c
index 0bc130c..47cb3c9 100644
--- a/trace-xml.c
+++ b/trace-xml.c
@@ -25,13 +25,20 @@
25 25
26#include <libxml/xmlwriter.h> 26#include <libxml/xmlwriter.h>
27#include <libxml/parser.h> 27#include <libxml/parser.h>
28#include <libxml/encoding.h> 28#include <libxml/xpath.h>
29 29
30#include "trace-cmd.h" 30#include "trace-cmd.h"
31#include "trace-xml.h" 31#include "trace-xml.h"
32 32
33struct tracecmd_xml_handle { 33struct tracecmd_xml_handle {
34 xmlTextWriterPtr writer; 34 xmlTextWriterPtr writer;
35 xmlDocPtr doc;
36};
37
38struct tracecmd_xml_system {
39 struct tracecmd_xml_handle *handle;
40 xmlXPathObjectPtr result;
41 xmlNodePtr cur;
35}; 42};
36 43
37#define TRACE_ENCODING "UTF-8" 44#define TRACE_ENCODING "UTF-8"
@@ -122,6 +129,101 @@ void tracecmd_xml_close(struct tracecmd_xml_handle *handle)
122 xmlTextWriterEndDocument(handle->writer); 129 xmlTextWriterEndDocument(handle->writer);
123 xmlFreeTextWriter(handle->writer); 130 xmlFreeTextWriter(handle->writer);
124 } 131 }
132 if (handle->doc) {
133 xmlFreeDoc(handle->doc);
134 }
135 free(handle);
136}
137
138/***********************************************************/
139/*** Reading XML files ***/
140/***********************************************************/
141
142
143struct tracecmd_xml_handle *tracecmd_xml_open(const char *file)
144{
145 struct tracecmd_xml_handle *handle;
125 146
147 handle = malloc_or_die(sizeof(*handle));
148 memset(handle, 0, sizeof(*handle));
149
150 handle->doc = xmlParseFile(file);
151 if (!handle->doc)
152 goto fail_free;
153
154 return handle;
155
156 fail_free:
126 free(handle); 157 free(handle);
158 return NULL;
159}
160
161struct tracecmd_xml_system *
162tracecmd_xml_find_system(struct tracecmd_xml_handle *handle,
163 const char *system)
164{
165 struct tracecmd_xml_system *sys;
166 xmlXPathContextPtr context;
167 xmlXPathObjectPtr result;
168 xmlChar *xpath;
169 char *path;
170
171 path = malloc_or_die(strlen(system) + 3);
172 sprintf(path, "//%s", system);
173 xpath = BAD_CAST path;
174
175 context = xmlXPathNewContext(handle->doc);
176 result = xmlXPathEvalExpression(xpath, context);
177 free(path);
178
179 if (xmlXPathNodeSetIsEmpty(result->nodesetval)) {
180 xmlXPathFreeObject(result);
181 return NULL;
182 }
183
184 sys = malloc_or_die(sizeof(*sys));
185 sys->handle = handle;
186 sys->result = result;
187 sys->cur = result->nodesetval->nodeTab[0]->xmlChildrenNode;
188
189 return sys;
190}
191
192struct tracecmd_xml_system_node *
193tracecmd_xml_system_node(struct tracecmd_xml_system *system)
194{
195 return (struct tracecmd_xml_system_node *)system->cur;
196}
197
198const char *tracecmd_xml_node_type(struct tracecmd_xml_system_node *tnode)
199{
200 xmlNodePtr node = (xmlNodePtr)tnode;
201 return (const char *)node->name;
202}
203
204struct tracecmd_xml_system_node *
205tracecmd_xml_node_child(struct tracecmd_xml_system_node *tnode)
206{
207 xmlNodePtr node = (xmlNodePtr)tnode;
208 return (struct tracecmd_xml_system_node *)node->xmlChildrenNode;
209}
210
211struct tracecmd_xml_system_node *
212tracecmd_xml_node_next(struct tracecmd_xml_system_node *tnode)
213{
214 xmlNodePtr node = (xmlNodePtr)tnode;
215 return (struct tracecmd_xml_system_node *)node->next;
216}
217
218const char *tracecmd_xml_node_value(struct tracecmd_xml_handle *handle,
219 struct tracecmd_xml_system_node *tnode)
220{
221 xmlNodePtr node = (xmlNodePtr)tnode;
222 return (const char *)xmlNodeListGetString(handle->doc, node->xmlChildrenNode, 1);
223}
224
225void tracecmd_xml_free_system(struct tracecmd_xml_system *system)
226{
227 xmlXPathFreeObject(system->result);
228 free(system);
127} 229}
diff --git a/trace-xml.h b/trace-xml.h
index 41f6193..4006538 100644
--- a/trace-xml.h
+++ b/trace-xml.h
@@ -22,8 +22,11 @@
22#define __TRACE_XML_H 22#define __TRACE_XML_H
23 23
24struct tracecmd_xml_handle; 24struct tracecmd_xml_handle;
25struct tacecmd_xml_system;
26struct tacecmd_xml_system_node;
25 27
26struct tracecmd_xml_handle *tracecmd_xml_create(const char *name); 28struct tracecmd_xml_handle *tracecmd_xml_create(const char *name);
29struct tracecmd_xml_handle *tracecmd_xml_open(const char *name);
27void tracecmd_xml_close(struct tracecmd_xml_handle *handle); 30void tracecmd_xml_close(struct tracecmd_xml_handle *handle);
28 31
29int tracecmd_xml_start_system(struct tracecmd_xml_handle *handle, 32int tracecmd_xml_start_system(struct tracecmd_xml_handle *handle,
@@ -38,4 +41,20 @@ int tracecmd_xml_write_element(struct tracecmd_xml_handle *handle,
38 const char *obj, 41 const char *obj,
39 const char *fmt, ...); 42 const char *fmt, ...);
40 43
44struct tracecmd_xml_handle *tracecmd_xml_open(const char *file);
45
46struct tracecmd_xml_system *
47tracecmd_xml_find_system(struct tracecmd_xml_handle *handle,
48 const char *system);
49void tracecmd_xml_free_system(struct tracecmd_xml_system *system);
50struct tracecmd_xml_system_node *
51tracecmd_xml_system_node(struct tracecmd_xml_system *system);
52const char *tracecmd_xml_node_type(struct tracecmd_xml_system_node *tnode);
53struct tracecmd_xml_system_node *
54tracecmd_xml_node_child(struct tracecmd_xml_system_node *tnode);
55struct tracecmd_xml_system_node *
56tracecmd_xml_node_next(struct tracecmd_xml_system_node *tnode);
57const char *tracecmd_xml_node_value(struct tracecmd_xml_handle *handle,
58 struct tracecmd_xml_system_node *tnode);
59
41#endif /* __TRACE_XML_H */ 60#endif /* __TRACE_XML_H */