Skip to content

Commit

Permalink
kernelshark/parse-events: Add tests if event filters are same
Browse files Browse the repository at this point in the history
On load of event filters, if the list and graph filters are the same,
then make them synced.

On syncing of event filters, if they are already the same, do not ask
which way to sync, just sync them and keep them synced.

Signed-off-by: Steven Rostedt <[email protected]>
  • Loading branch information
Steven Rostedt authored and rostedt committed Jun 10, 2010
1 parent f501cf4 commit b09e5f4
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 5 deletions.
29 changes: 24 additions & 5 deletions kernel-shark.c
Original file line number Diff line number Diff line change
Expand Up @@ -311,9 +311,12 @@ load_filters_clicked (gpointer data)
struct shark_info *info = data;
struct graph_info *ginfo = info->ginfo;
GtkTreeView *trace_tree = GTK_TREE_VIEW(info->treeview);
GtkTreeModel *model;
TraceViewStore *store;
struct tracecmd_xml_handle *handle;
struct filter_task *task_filter;
struct filter_task *hide_tasks;
struct event_filter *event_filter;
gchar *filename;
int ret;

Expand Down Expand Up @@ -349,7 +352,6 @@ load_filters_clicked (gpointer data)
ret = tracecmd_xml_system_exists(handle,
"ListTaskFilter");
if (ret) {

task_filter = info->list_task_filter;
hide_tasks = info->list_hide_tasks;
filter_task_clear(task_filter);
Expand Down Expand Up @@ -377,6 +379,16 @@ load_filters_clicked (gpointer data)
info->list_hide_tasks))
sync_task_filters(info);

model = gtk_tree_view_get_model(trace_tree);
if (!model)
goto out;

store = TRACE_VIEW_STORE(model);
event_filter = trace_view_store_get_event_filter(store);

if (pevent_filter_compare(event_filter, ginfo->event_filter))
sync_event_filters(info);

out:
g_free(filename);

Expand Down Expand Up @@ -563,10 +575,15 @@ sync_events_filter_clicked (GtkWidget *subitem, gpointer data)
return;

store = TRACE_VIEW_STORE(model);
event_filter = trace_view_store_get_event_filter(store);

/* Ask user which way to sync */
result = trace_sync_select_menu("Sync Event Filters",
selections, &keep);
/* If they are already equal, then just perminently sync them */
if (pevent_filter_compare(event_filter, ginfo->event_filter))
result = 2;
else
/* Ask user which way to sync */
result = trace_sync_select_menu("Sync Event Filters",
selections, &keep);

switch (result) {
case 0:
Expand All @@ -579,11 +596,13 @@ sync_events_filter_clicked (GtkWidget *subitem, gpointer data)
case 1:
/* Sync Graph Filter with List Filter */
all_events = trace_view_store_get_all_events_enabled(store);
event_filter = trace_view_store_get_event_filter(store);

trace_graph_copy_filter(info->ginfo, all_events,
event_filter);
break;
case 2:
keep = 1;
break;
default:
keep = 0;
}
Expand Down
2 changes: 2 additions & 0 deletions parse-events.h
Original file line number Diff line number Diff line change
Expand Up @@ -701,4 +701,6 @@ int pevent_filter_copy(struct event_filter *dest, struct event_filter *source);
int pevent_update_trivial(struct event_filter *dest, struct event_filter *source,
enum filter_trivial_type type);

int pevent_filter_compare(struct event_filter *filter1, struct event_filter *filter2);

#endif /* _PARSE_EVENTS_H */
57 changes: 57 additions & 0 deletions parse-filter.c
Original file line number Diff line number Diff line change
Expand Up @@ -2026,3 +2026,60 @@ pevent_filter_make_string(struct event_filter *filter, int event_id)
return arg_to_str(filter, filter_type->filter);
}

/**
* pevent_filter_compare - compare two filters and return if they are the same
* @filter1: Filter to compare with @filter2
* @filter2: Filter to compare with @filter1
*
* Returns:
* 1 if the two filters hold the same content.
* 0 if they do not.
*/
int pevent_filter_compare(struct event_filter *filter1, struct event_filter *filter2)
{
struct filter_type *filter_type1;
struct filter_type *filter_type2;
char *str1, *str2;
int result;
int i;

/* Do the easy checks first */
if (filter1->filters != filter2->filters)
return 0;
if (!filter1->filters && !filter2->filters)
return 1;

/*
* Now take a look at each of the events to see if they have the same
* filters to them.
*/
for (i = 0; i < filter1->filters; i++) {
filter_type1 = &filter1->event_filters[i];
filter_type2 = find_filter_type(filter2, filter_type1->event_id);
if (!filter_type2)
break;
if (filter_type1->filter->type != filter_type2->filter->type)
break;
switch (filter_type1->filter->type) {
case FILTER_TRIVIAL_FALSE:
case FILTER_TRIVIAL_TRUE:
/* trivial types just need the type compared */
continue;
default:
break;
}
/* The best way to compare complex filters is with strings */
str1 = arg_to_str(filter1, filter_type1->filter);
str2 = arg_to_str(filter2, filter_type2->filter);
result = strcmp(str1, str2) != 0;
free(str1);
free(str2);
if (result)
break;
}

if (i < filter1->filters)
return 0;
return 1;
}

0 comments on commit b09e5f4

Please sign in to comment.