forked from rostedt/trace-cmd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkernel-shark.c
2392 lines (1839 loc) · 59.4 KB
/
kernel-shark.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright (C) 2009, 2010 Red Hat Inc, Steven Rostedt <[email protected]>
*
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License (not later!)
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, see <http://www.gnu.org/licenses>
*
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*/
#include <stdio.h>
#include <string.h>
#include <stdarg.h>
#include <fcntl.h>
#include <dirent.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <gtk/gtk.h>
#include <errno.h>
#include <getopt.h>
#include <libgen.h>
#include "trace-compat.h"
#include "trace-capture.h"
#include "trace-cmd.h"
#include "trace-gui.h"
#include "kernel-shark.h"
#include "event-utils.h"
#include "version.h"
#define ___stringify(X) #X
#define __stringify(X) ___stringify(X)
#define DEBUG_LEVEL 0
#if DEBUG_LEVEL > 0
# define dprintf(l, x...) \
do { \
if (l <= DEBUG_LEVEL) \
printf(x); \
} while (0)
#else
# define dprintf(l, x...) do { if (0) printf(x); } while (0)
#endif
#define TRACE_WIDTH 800
#define TRACE_HEIGHT 600
#define default_input_file "trace.dat"
static char *input_file;
void usage(char *prog)
{
printf("Usage: %s\n", prog);
printf(" -h Display this help message\n");
printf(" -v Display version and exit\n");
printf(" -i input_file, default is %s\n", default_input_file);
}
static gboolean display_warnings;
/*
* trace_sync_select_menu - helper function to the syncing of list and graph filters
*
* Creates a pop up dialog with the selections given. The selections will be
* radio buttons to the user. The keep is a value that will be set to the check
* box (default on) if the user wants to keep the selection persistant.
*/
static int trace_sync_select_menu(const gchar *title,
gchar **selections, gboolean *keep)
{
GtkWidget *dialog;
GtkWidget *radio;
GtkWidget *check;
GSList *group;
int result;
int i;
dialog = gtk_dialog_new_with_buttons(title,
NULL,
GTK_DIALOG_MODAL,
"OK", GTK_RESPONSE_ACCEPT,
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
NULL);
radio = gtk_radio_button_new_with_label(NULL, selections[0]);
gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), radio, TRUE, TRUE, 0);
gtk_widget_show(radio);
group = gtk_radio_button_get_group(GTK_RADIO_BUTTON(radio));
for (i = 1; selections[i]; i++) {
radio = gtk_radio_button_new_with_label(group, selections[i]);
gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), radio, TRUE, TRUE, 0);
gtk_widget_show(radio);
}
check = gtk_check_button_new_with_label("Keep the filters in sync?");
gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), check, TRUE, TRUE, 0);
gtk_widget_show(check);
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(check), TRUE);
result = gtk_dialog_run(GTK_DIALOG(dialog));
switch (result) {
case GTK_RESPONSE_ACCEPT:
i = 0;
for (i = 0; group; i++, group = g_slist_next(group)) {
radio = group->data;
if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(radio)))
break;
}
result = i;
*keep = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(check));
break;
default:
result = -1;
}
gtk_widget_destroy(dialog);
return result;
}
static void update_tree_view_filters(struct shark_info *info,
struct filter_task *task_filter,
struct filter_task *hide_tasks)
{
if (info->list_filter_enabled)
trace_view_update_filters(info->treeview,
task_filter, hide_tasks);
if (filter_task_count(task_filter) ||
filter_task_count(hide_tasks))
info->list_filter_available = 1;
else {
info->list_filter_enabled = 0;
info->list_filter_available = 0;
}
}
/* graph callbacks */
/* convert_nano() and print_time() are copied from trace-graph.c for debugging
purposes, and should be deleted when this is complete (or merged with
trace-graph.c */
static void convert_nano(unsigned long long time, unsigned long *sec,
unsigned long *usec)
{
*sec = time / 1000000000ULL;
*usec = (time / 1000) % 1000000;
}
static void print_time(unsigned long long time)
{
unsigned long sec, usec;
if (!DEBUG_LEVEL)
return;
convert_nano(time, &sec, &usec);
printf("%lu.%06lu", sec, usec);
}
static void ks_graph_select(struct graph_info *ginfo, guint64 cursor)
{
struct graph_callbacks *cbs;
struct shark_info *info;
dprintf(1, "Cursor: ");
print_time(cursor);
dprintf(1, " selected\n");
cbs = trace_graph_get_callbacks(ginfo);
info = container_of(cbs, struct shark_info, graph_cbs);
trace_view_select(info->treeview, cursor);
}
static void ks_graph_filter(struct graph_info *ginfo,
struct filter_task *task_filter,
struct filter_task *hide_tasks)
{
struct graph_callbacks *cbs;
struct shark_info *info;
cbs = trace_graph_get_callbacks(ginfo);
info = container_of(cbs, struct shark_info, graph_cbs);
if (!info->sync_task_filters)
return;
update_tree_view_filters(info, task_filter, hide_tasks);
}
static void free_info(struct shark_info *info)
{
tracecmd_close(info->handle);
trace_graph_free_info(info->ginfo);
filter_task_hash_free(info->list_task_filter);
filter_task_hash_free(info->list_hide_tasks);
kernel_shark_clear_capture(info);
free(info->current_filter);
free(info->ginfo);
free(info);
}
static void update_title(GtkWidget *window, const gchar *file)
{
GString *gstr;
gchar *str;
gstr = g_string_new("kernelshark");
g_string_append_printf(gstr, "(%s)", basename(file));
str = g_string_free(gstr, FALSE);
gtk_window_set_title(GTK_WINDOW(window), str);
g_free(str);
}
static void unsync_task_filters(struct shark_info *info)
{
info->sync_task_filters = 0;
gtk_menu_item_set_label(GTK_MENU_ITEM(info->task_sync_menu),
"Sync Graph and List Task Filters");
gtk_menu_item_set_label(GTK_MENU_ITEM(info->graph_task_menu),
"graph tasks");
gtk_menu_item_set_label(GTK_MENU_ITEM(info->graph_hide_task_menu),
"graph hide tasks");
gtk_widget_show(info->list_task_menu);
gtk_widget_show(info->list_hide_task_menu);
/* The list now uses its own hash */
info->list_task_filter = filter_task_hash_copy(info->ginfo->task_filter);
info->list_hide_tasks = filter_task_hash_copy(info->ginfo->hide_tasks);
}
static void sync_task_filters(struct shark_info *info)
{
info->sync_task_filters = 1;
gtk_menu_item_set_label(GTK_MENU_ITEM(info->task_sync_menu),
"Unsync Graph and List Task Filters");
gtk_menu_item_set_label(GTK_MENU_ITEM(info->graph_task_menu),
"tasks");
gtk_menu_item_set_label(GTK_MENU_ITEM(info->graph_hide_task_menu),
"hide tasks");
gtk_widget_hide(info->list_task_menu);
gtk_widget_hide(info->list_hide_task_menu);
}
static void unsync_event_filters(struct shark_info *info)
{
info->sync_event_filters = 0;
gtk_menu_item_set_label(GTK_MENU_ITEM(info->events_sync_menu),
"Sync Graph and List Event Filters");
gtk_menu_item_set_label(GTK_MENU_ITEM(info->graph_events_menu),
"graph events");
gtk_menu_item_set_label(GTK_MENU_ITEM(info->graph_adv_events_menu),
"graph advanced events");
gtk_widget_show(info->list_events_menu);
gtk_widget_show(info->list_adv_events_menu);
}
static void sync_event_filters(struct shark_info *info)
{
info->sync_event_filters = 1;
gtk_menu_item_set_label(GTK_MENU_ITEM(info->events_sync_menu),
"Unsync Graph and List Event Filters");
gtk_menu_item_set_label(GTK_MENU_ITEM(info->graph_events_menu),
"events");
gtk_menu_item_set_label(GTK_MENU_ITEM(info->graph_adv_events_menu),
"advanced events");
gtk_widget_hide(info->list_events_menu);
gtk_widget_hide(info->list_adv_events_menu);
}
static void alt_warn(const char *fmt, va_list ap)
{
display_warnings = TRUE;
vpr_stat(fmt, ap);
}
/**
* kernelshark_load_file - load a new file into kernelshark
* @info: the kernelshark descriptor
* @file: the file to load
*
* Returns: 0 on success, -1 on error
*/
int kernelshark_load_file(struct shark_info *info, const char *file)
{
struct tracecmd_input *handle;
/*
* Have warnings go into the status bar. If we had any
* warnings, pop up a message at the end.
*/
display_warnings = 0;
pr_stat("\nLoading file %s", file);
trace_dialog_register_alt_warning(alt_warn);
handle = tracecmd_open(file);
trace_dialog_register_alt_warning(NULL);
if (display_warnings) {
errno = 0;
warning("Warnings occurred on loading.\n"
"See display status for details");
}
if (!handle)
return -1;
tracecmd_close(info->handle);
info->handle = handle;
trace_graph_load_handle(info->ginfo, handle);
trace_view_reload(info->treeview, handle, info->spin);
update_title(info->window, file);
return 0;
}
static void
/* Callback for the clicked signal of the Load button */
load_clicked (gpointer data)
{
struct shark_info *info = data;
gchar *filename;
filename = trace_get_file_dialog_filter("Load File", NULL,
TRACE_DIALOG_FILTER_DATA, FALSE);
if (!filename)
return;
kernelshark_load_file(info, filename);
g_free(filename);
}
static GString *get_home_filters_new(void)
{
char *path = getenv("HOME");
GString *str;
str = g_string_new(path);
g_string_append(str, "/.trace-cmd/filters/");
return str;
}
static int create_home_filters(void)
{
char *path = getenv("HOME");
GString *str;
struct stat st;
int ret;
str = g_string_new(path);
g_string_append(str, "/.trace-cmd");
ret = stat(str->str, &st);
if (ret < 0) {
ret = mkdir(str->str, 0755);
if (ret < 0) {
warning("Can not create %s", str->str);
goto out;
}
}
g_string_append(str, "/filters");
ret = stat(str->str, &st);
if (ret < 0) {
ret = mkdir(str->str, 0755);
if (ret < 0) {
warning("Can not create %s", str->str);
goto out;
}
}
ret = 0;
out:
g_string_free(str, TRUE);
return ret;
}
static void load_filter(struct shark_info *info, const char *filename)
{
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;
int ret;
handle = tracecmd_xml_open(filename);
if (!handle) {
warning("Could not open %s", filename);
return;
}
/* Unsync the list and graph filters */
if (info->sync_task_filters)
unsync_task_filters(info);
if (info->sync_event_filters)
unsync_event_filters(info);
ret = tracecmd_xml_system_exists(handle,
"GraphTaskFilter");
if (ret) {
filter_task_clear(ginfo->task_filter);
filter_task_clear(ginfo->hide_tasks);
trace_filter_load_filters(handle,
"GraphTaskFilter",
ginfo->task_filter,
ginfo->hide_tasks);
trace_graph_refresh_filters(ginfo);
}
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);
filter_task_clear(hide_tasks);
trace_filter_load_filters(handle,
"ListTaskFilter",
task_filter,
hide_tasks);
update_tree_view_filters(info, task_filter, hide_tasks);
}
trace_graph_load_filters(ginfo, handle);
ret = trace_view_load_filters(handle, trace_tree);
tracecmd_xml_close(handle);
/*
* If the events or tasks filters are the same for both
* the list and graph, then sync them back.
*/
if (filter_task_compare(ginfo->task_filter,
info->list_task_filter) &&
filter_task_compare(ginfo->hide_tasks,
info->list_hide_tasks))
sync_task_filters(info);
model = gtk_tree_view_get_model(trace_tree);
if (!model)
return;
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);
}
static void load_filter_clicked(GtkMenuItem *item, gpointer data)
{
struct shark_info *info = data;
const char *name;
GString *path;
name = gtk_menu_item_get_label(item);
path = get_home_filters_new();
g_string_append_printf(path, "/%s.ksf", name);
load_filter(info, path->str);
g_string_free(path, TRUE);
free(info->current_filter);
info->current_filter = strdup(name);
}
/* Callback for the clicked signal of the Load Filters button */
static void
import_filters_clicked (gpointer data)
{
struct shark_info *info = data;
gchar *filename;
filename = trace_get_file_dialog_filter("Load Filters", NULL,
TRACE_DIALOG_FILTER_FILTER, FALSE);
if (!filename)
return;
load_filter(info, filename);
}
static void save_filters(struct shark_info *info, const char *filename)
{
struct graph_info *ginfo = info->ginfo;
struct tracecmd_xml_handle *handle;
GtkTreeView *trace_tree = GTK_TREE_VIEW(info->treeview);
struct filter_task *task_filter;
struct filter_task *hide_tasks;
handle = tracecmd_xml_create(filename, VERSION_STRING);
if (!handle) {
warning("Could not create %s", filename);
return;
}
trace_view_save_filters(handle, trace_tree);
trace_graph_save_filters(ginfo, handle);
trace_filter_save_filters(handle,
"GraphTaskFilter",
ginfo->task_filter,
ginfo->hide_tasks);
if (info->sync_task_filters) {
task_filter = ginfo->task_filter;
hide_tasks = ginfo->hide_tasks;
} else {
task_filter = info->list_task_filter;
hide_tasks = info->list_hide_tasks;
}
trace_filter_save_filters(handle,
"ListTaskFilter",
task_filter, hide_tasks);
tracecmd_xml_close(handle);
}
/* Callback for the clicked signal of the Save Filters button */
static void
export_filters_clicked (gpointer data)
{
struct shark_info *info = data;
gchar *filename;
filename = trace_get_file_dialog_filter("Save Filters", "Save",
TRACE_DIALOG_FILTER_FILTER, TRUE);
if (!filename)
return;
save_filters(info, filename);
g_free(filename);
}
static void update_load_filter(struct shark_info *info)
{
struct dirent *dent;
struct stat st;
DIR *dir;
GtkWidget *menu;
GtkWidget *sub_item;
GString *path;
int ret;
path = get_home_filters_new();
menu = gtk_menu_new();
ret = stat(path->str, &st);
if (ret < 0 || !S_ISDIR(st.st_mode))
goto update_rest;
dir = opendir(path->str);
if (!dir)
goto update_rest;
while ((dent = readdir(dir))) {
const char *name = dent->d_name;
GString *file;
gchar *item;
if (strcmp(name, ".") == 0 ||
strcmp(name, "..") == 0)
continue;
if (strcmp(name + strlen(name) - 4, ".ksf") != 0)
continue;
file = g_string_new(path->str);
g_string_append_printf(file, "/%s", name);
/* Save the file name but remove the .kss extention */
item = g_strdup(name);
item[strlen(name) - 4] = 0;
sub_item = gtk_menu_item_new_with_label(item);
gtk_menu_shell_append(GTK_MENU_SHELL (menu), sub_item);
gtk_widget_show(sub_item);
g_signal_connect(G_OBJECT (sub_item), "activate",
G_CALLBACK (load_filter_clicked),
(gpointer) info);
g_free(item);
g_string_free(file, TRUE);
}
update_rest:
g_string_free(path, TRUE);
/* --- File - Load Filter - Filters --- */
sub_item = gtk_menu_item_new_with_label("Import Filter");
g_signal_connect_swapped (G_OBJECT (sub_item), "activate",
G_CALLBACK (import_filters_clicked),
(gpointer) info);
/* Add them to the menu */
gtk_menu_shell_append(GTK_MENU_SHELL (menu), sub_item);
/* We do need to show menu items */
gtk_widget_show(sub_item);
gtk_menu_item_set_submenu(GTK_MENU_ITEM (info->load_filter_menu), menu);
}
/* Callback for the clicked signal of the Save Filters button */
static void
save_filter_clicked (gpointer data)
{
struct shark_info *info = data;
struct stat st;
GtkWidget *dialog;
GtkWidget *hbox;
GtkWidget *label;
GtkWidget *entry;
GString *file;
const char *name;
gint result;
int ret;
dialog = gtk_dialog_new_with_buttons("Save Filter",
NULL,
GTK_DIALOG_MODAL,
GTK_STOCK_OK,
GTK_RESPONSE_ACCEPT,
GTK_STOCK_CANCEL,
GTK_RESPONSE_REJECT,
NULL);
hbox = gtk_hbox_new(FALSE, 0);
gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), hbox, FALSE, FALSE, 0);
gtk_widget_show(hbox);
label = gtk_label_new("Filter Name: ");
gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
gtk_widget_show(label);
entry = gtk_entry_new();
gtk_box_pack_start(GTK_BOX(hbox), entry, FALSE, FALSE, 0);
gtk_widget_show(entry);
if (info->current_filter)
gtk_entry_set_text(GTK_ENTRY(entry), info->current_filter);
again:
result = gtk_dialog_run(GTK_DIALOG(dialog));
switch (result) {
case GTK_RESPONSE_ACCEPT:
name = gtk_entry_get_text(GTK_ENTRY(entry));
if (!name || !has_text(name)) {
warning("Must enter a name");
goto again;
}
/* Make sure home settings exists */
if (create_home_filters() < 0)
break;
file = get_home_filters_new();
g_string_append_printf(file, "/%s.ksf", name);
ret = stat(file->str, &st);
if (ret >= 0) {
ret = trace_dialog(GTK_WINDOW(dialog), TRACE_GUI_ASK,
"The Filter '%s' already exists.\n"
"Are you sure you want to replace it",
name);
if (ret == GTK_RESPONSE_NO) {
g_string_free(file, TRUE);
goto again;
}
}
save_filters(info, file->str);
free(info->current_filter);
info->current_filter = strdup(name);
update_load_filter(info);
g_string_free(file, TRUE);
break;
case GTK_RESPONSE_REJECT:
break;
default:
break;
};
gtk_widget_destroy(dialog);
}
/* Callback for the clicked signal of the Exit button */
static void
exit_clicked (gpointer data)
{
struct shark_info *info = data;
gtk_widget_destroy (info->window); /* the user data points to the main window */
free_info(info);
gtk_main_quit ();
}
/* Callback for the delete_event signal of the main application window */
static gint
delete_event (GtkWidget *widget, GdkEvent *event, gpointer data)
{
struct shark_info *info = data;
gtk_widget_destroy (widget); /* destroy the main window */
free_info(info);
gtk_main_quit ();
return TRUE;
}
/* Callback for the clicked signal of the tasks sync filter button */
static void
sync_task_filter_clicked (GtkWidget *subitem, gpointer data)
{
struct shark_info *info = data;
struct filter_task *task_filter;
struct filter_task *hide_tasks;
GtkTreeView *trace_tree = GTK_TREE_VIEW(info->treeview);
GtkTreeModel *model;
TraceViewStore *store;
gboolean keep;
gchar *selections[] = { "Sync List Filter with Graph Filter",
"Sync Graph Filter with List Filter",
NULL };
int result;
if (info->sync_task_filters) {
/* Separate the List and Graph filters */
unsync_task_filters(info);
return;
}
model = gtk_tree_view_get_model(trace_tree);
if (!model)
return;
store = TRACE_VIEW_STORE(model);
/* If they are already equal, then just perminently sync them */
if (filter_task_compare(info->ginfo->task_filter,
info->list_task_filter) &&
filter_task_compare(info->ginfo->hide_tasks,
info->list_hide_tasks))
result = 2;
else
/* Ask user which way to sync */
result = trace_sync_select_menu("Sync Task Filters",
selections, &keep);
switch (result) {
case 0:
/* Sync List Filter with Graph Filter */
filter_task_hash_free(info->list_task_filter);
filter_task_hash_free(info->list_hide_tasks);
info->list_task_filter = NULL;
info->list_hide_tasks = NULL;
task_filter = info->ginfo->task_filter;
hide_tasks = info->ginfo->hide_tasks;
if (!keep) {
info->list_task_filter = filter_task_hash_copy(task_filter);
info->list_hide_tasks = filter_task_hash_copy(hide_tasks);
}
update_tree_view_filters(info, task_filter, hide_tasks);
break;
case 1:
/* Sync Graph Filter with List Filter */
trace_graph_update_filters(info->ginfo,
info->list_task_filter,
info->list_hide_tasks);
if (keep) {
filter_task_hash_free(info->list_task_filter);
filter_task_hash_free(info->list_hide_tasks);
info->list_task_filter = NULL;
info->list_hide_tasks = NULL;
}
break;
case 2:
keep = 1;
break;
default:
keep = 0;
}
if (keep)
sync_task_filters(info);
}
/* Callback for the clicked signal of the events sync filter button */
static void
sync_events_filter_clicked (GtkWidget *subitem, gpointer data)
{
struct shark_info *info = data;
struct graph_info *ginfo = info->ginfo;
struct event_filter *event_filter;
GtkTreeView *trace_tree = GTK_TREE_VIEW(info->treeview);
GtkTreeModel *model;
TraceViewStore *store;
gboolean keep;
gboolean all_events;
gchar *selections[] = { "Sync List Filter with Graph Filter",
"Sync Graph Filter with List Filter",
NULL };
int result;
if (info->sync_event_filters) {
/* Separate the List and Graph filters */
unsync_event_filters(info);
return;
}
model = gtk_tree_view_get_model(trace_tree);
if (!model)
return;
store = TRACE_VIEW_STORE(model);
event_filter = trace_view_store_get_event_filter(store);
/* 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:
/* Sync List Filter with Graph Filter */
all_events = ginfo->all_events;
trace_view_copy_filter(info->treeview, all_events,
ginfo->event_filter);
break;
case 1:
/* Sync Graph Filter with List Filter */
all_events = trace_view_store_get_all_events_enabled(store);
trace_graph_copy_filter(info->ginfo, all_events,
event_filter);
break;
case 2:
keep = 1;
break;
default:
keep = 0;
}
if (keep)
sync_event_filters(info);
}
static void filter_list_enable_clicked (gpointer data);
static void
__update_list_task_filter_callback(struct shark_info *info,
gboolean accept,
gint *selected,
struct filter_task *task_filter)
{
GtkTreeView *trace_tree = GTK_TREE_VIEW(info->treeview);
GtkTreeModel *model;
TraceViewStore *store;
int i;
if (!accept)
return;
model = gtk_tree_view_get_model(trace_tree);
if (!model)
return;
store = TRACE_VIEW_STORE(model);
filter_task_clear(task_filter);
if (selected) {
for (i = 0; selected[i] >= 0; i++)
filter_task_add_pid(task_filter, selected[i]);
}
update_tree_view_filters(info, info->list_task_filter, info->list_hide_tasks);
/*
* The menu filters always enable the filters.
*/
if (info->list_filter_available && !info->list_filter_enabled)
filter_list_enable_clicked(info);
}
static void
update_list_task_filter_callback(gboolean accept,
gint *selected,
gint *non_select,
gpointer data)
{
struct shark_info *info = data;
__update_list_task_filter_callback(info, accept, selected,
info->list_task_filter);
}
static void
update_list_hide_task_filter_callback(gboolean accept,
gint *selected,
gint *non_select,
gpointer data)
{
struct shark_info *info = data;
__update_list_task_filter_callback(info, accept, selected,
info->list_hide_tasks);
}
/* Callback for the clicked signal of the List Tasks filter button */
static void
__list_tasks_clicked (struct shark_info *info,
struct filter_task *task_filter,
trace_task_cb_func func)
{
GtkTreeView *trace_tree = GTK_TREE_VIEW(info->treeview);
struct graph_info *ginfo = info->ginfo;
GtkTreeModel *model;
TraceViewStore *store;
gint *selected;
gint *tasks;
if (!ginfo->handle)
return;
model = gtk_tree_view_get_model(trace_tree);
if (!model)
return;
store = TRACE_VIEW_STORE(model);
tasks = trace_graph_task_list(ginfo);
selected = filter_task_pids(task_filter);
trace_task_dialog(info->handle, tasks, selected, func, info);
free(tasks);
free(selected);
}
static void
list_tasks_clicked (gpointer data)
{
struct shark_info *info = data;
__list_tasks_clicked(info, info->list_task_filter,
update_list_task_filter_callback);
}
static void
list_hide_tasks_clicked (gpointer data)
{
struct shark_info *info = data;
__list_tasks_clicked(info, info->list_hide_tasks,
update_list_hide_task_filter_callback);
}
static void
__update_graph_task_filter_callback(struct shark_info *info,
gboolean accept,