forked from smihir/trace-cmd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
trace-graph.c
2845 lines (2220 loc) · 68.3 KB
/
trace-graph.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 <unistd.h>
#include <gtk/gtk.h>
#include "trace-compat.h"
#include "trace-cmd.h"
#include "trace-local.h"
#include "trace-graph.h"
#include "trace-hash.h"
#include "trace-filter.h"
#include "trace-gui.h"
#include "event-utils.h"
#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 MAX_WIDTH 10000
#define PLOT_SIZE 10
#define PLOT_BOX_SIZE PLOT_SIZE
#define PLOT_GIVE 2
#define PLOT_BEGIN 80
#define PLOT_SEP 50
#define PLOT_LINE(plot) (PLOT_SEP * (plot) + PLOT_BEGIN + PLOT_SIZE)
#define PLOT_TOP(plot) (PLOT_LINE(plot) - PLOT_SIZE * 2)
#define PLOT_BOX_TOP(plot) (PLOT_LINE(plot) - PLOT_SIZE)
#define PLOT_BOTTOM(plot) (PLOT_LINE(plot)-1)
#define PLOT_BOX_BOTTOM(plot) (PLOT_LINE(plot))
#define PLOT_SPACE(plots) (PLOT_SEP * (plots) + PLOT_BEGIN)
#define PLOT_LABEL(plot) (PLOT_TOP(plot))
#define PLOT_X 5
static gint largest_plot_label;
static GdkGC *green;
static GdkGC *red;
static void redraw_pixmap_backend(struct graph_info *ginfo);
static void update_label_window(struct graph_info *ginfo);
struct task_list {
struct task_list *next;
gint pid;
};
static guint get_task_hash_key(gint pid)
{
return trace_hash(pid) % TASK_HASH_SIZE;
}
static struct task_list *find_task_hash(struct graph_info *ginfo,
gint key, gint pid)
{
struct task_list *list;
for (list = ginfo->tasks[key]; list; list = list->next) {
if (list->pid == pid)
return list;
}
return NULL;
}
static struct task_list *add_task_hash(struct graph_info *ginfo,
int pid)
{
struct task_list *list;
guint key = get_task_hash_key(pid);
list = find_task_hash(ginfo, key, pid);
if (list)
return list;
list = malloc_or_die(sizeof(*list));
list->pid = pid;
list->next = ginfo->tasks[key];
ginfo->tasks[key] = list;
return list;
}
static void free_task_hash(struct graph_info *ginfo)
{
struct task_list *list;
int i;
for (i = 0; i < TASK_HASH_SIZE; i++) {
while (ginfo->tasks[i]) {
list = ginfo->tasks[i];
ginfo->tasks[i] = list->next;
free(list);
}
}
}
/**
* trace_graph_task_list - return an allocated list of all found tasks
* @ginfo: The graph info structure
*
* Returns an allocated list of pids found in the graph, ending
* with a -1. This array must be freed with free().
*/
gint *trace_graph_task_list(struct graph_info *ginfo)
{
struct task_list *list;
gint *pids;
gint count = 0;
gint i;
for (i = 0; i < TASK_HASH_SIZE; i++) {
list = ginfo->tasks[i];
while (list) {
if (count)
pids = realloc(pids, sizeof(*pids) * (count + 2));
else
pids = malloc(sizeof(*pids) * 2);
pids[count++] = list->pid;
pids[count] = -1;
list = list->next;
}
}
return pids;
}
static void convert_nano(unsigned long long time, unsigned long *sec,
unsigned long *usec)
{
*sec = time / 1000000000ULL;
*usec = (time / 1000) % 1000000;
}
static int convert_time_to_x(struct graph_info *ginfo, guint64 time)
{
if (time < ginfo->view_start_time)
return 0;
return (time - ginfo->view_start_time) * ginfo->resolution;
}
static guint64 convert_x_to_time(struct graph_info *ginfo, gint x)
{
double d = x;
return (guint64)(d / ginfo->resolution) + ginfo->view_start_time;
}
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 init_event_cache(struct graph_info *ginfo)
{
ginfo->ftrace_sched_switch_id = -1;
ginfo->event_sched_switch_id = -1;
ginfo->event_wakeup_id = -1;
ginfo->event_wakeup_new_id = -1;
ginfo->event_pid_field = NULL;
ginfo->event_comm_field = NULL;
ginfo->ftrace_pid_field = NULL;
ginfo->ftrace_comm_field = NULL;
ginfo->wakeup_pid_field = NULL;
ginfo->wakeup_success_field = NULL;
ginfo->wakeup_new_pid_field = NULL;
ginfo->wakeup_new_success_field = NULL;
/*
* The first time reading the through the list
* test the sched_switch for comms that did not make
* it into the pevent command line list.
*/
ginfo->read_comms = TRUE;
}
struct filter_task_item *
trace_graph_filter_task_find_pid(struct graph_info *ginfo, gint pid)
{
return filter_task_find_pid(ginfo->task_filter, pid);
}
struct filter_task_item *
trace_graph_hide_task_find_pid(struct graph_info *ginfo, gint pid)
{
return filter_task_find_pid(ginfo->hide_tasks, pid);
}
static void graph_filter_task_add_pid(struct graph_info *ginfo, gint pid)
{
filter_task_add_pid(ginfo->task_filter, pid);
ginfo->filter_available = 1;
}
static void graph_filter_task_remove_pid(struct graph_info *ginfo, gint pid)
{
filter_task_remove_pid(ginfo->task_filter, pid);
if (!filter_task_count(ginfo->task_filter) &&
!filter_task_count(ginfo->hide_tasks)) {
ginfo->filter_available = 0;
ginfo->filter_enabled = 0;
}
}
static void graph_hide_task_add_pid(struct graph_info *ginfo, gint pid)
{
filter_task_add_pid(ginfo->hide_tasks, pid);
ginfo->filter_available = 1;
}
static void graph_hide_task_remove_pid(struct graph_info *ginfo, gint pid)
{
filter_task_remove_pid(ginfo->hide_tasks, pid);
if (!filter_task_count(ginfo->task_filter) &&
!filter_task_count(ginfo->hide_tasks)) {
ginfo->filter_available = 0;
ginfo->filter_enabled = 0;
}
}
static void graph_filter_task_clear(struct graph_info *ginfo)
{
filter_task_clear(ginfo->task_filter);
filter_task_clear(ginfo->hide_tasks);
ginfo->filter_available = 0;
ginfo->filter_enabled = 0;
}
gboolean trace_graph_filter_on_event(struct graph_info *ginfo, struct pevent_record *record)
{
int ret;
if (!record)
return TRUE;
if (ginfo->all_events)
return FALSE;
ret = pevent_filter_match(ginfo->event_filter, record);
return ret == FILTER_MATCH ? FALSE : TRUE;
}
gboolean trace_graph_filter_on_task(struct graph_info *ginfo, gint pid)
{
gboolean filter;
filter = FALSE;
if (ginfo->filter_enabled &&
((filter_task_count(ginfo->task_filter) &&
!trace_graph_filter_task_find_pid(ginfo, pid)) ||
(filter_task_count(ginfo->hide_tasks) &&
trace_graph_hide_task_find_pid(ginfo, pid))))
filter = TRUE;
return filter;
}
static void __update_with_backend(struct graph_info *ginfo,
gint x, gint y,
gint width, gint height)
{
gdk_draw_drawable(ginfo->draw->window,
ginfo->draw->style->fg_gc[GTK_WIDGET_STATE(ginfo->draw)],
ginfo->curr_pixmap,
x, y, x, y,
width, height);
}
static void update_label_time(GtkWidget *label, gint64 time)
{
unsigned long sec, usec;
struct trace_seq s;
char *min = "";
if (time < 0) {
time *= -1;
min = "-";
}
convert_nano(time, &sec, &usec);
trace_seq_init(&s);
trace_seq_printf(&s, "%s%lu.%06lu", min, sec, usec);
gtk_label_set_text(GTK_LABEL(label), s.buffer);
trace_seq_destroy(&s);
}
static void update_cursor(struct graph_info *ginfo)
{
update_label_time(ginfo->cursor_label, ginfo->cursor);
}
static void update_pointer(struct graph_info *ginfo, gint x)
{
guint64 time;
time = convert_x_to_time(ginfo, x);
update_label_time(ginfo->pointer_time, time);
}
static void update_marka(struct graph_info *ginfo, gint x)
{
guint64 timeA;
timeA = convert_x_to_time(ginfo, x);
ginfo->marka_time = timeA;
update_label_time(ginfo->marka_label, timeA);
}
static void update_markb(struct graph_info *ginfo, guint x)
{
gint64 timeA, timeB;
timeA = ginfo->marka_time;
timeB = convert_x_to_time(ginfo, x);
ginfo->markb_time = timeB;
update_label_time(ginfo->markb_label, timeB);
update_label_time(ginfo->delta_label, timeB - timeA);
}
static void draw_cursor(struct graph_info *ginfo)
{
gint x;
if (!ginfo->cursor)
return;
update_cursor(ginfo);
if (ginfo->cursor < ginfo->view_start_time ||
ginfo->cursor > ginfo->view_end_time)
return;
x = convert_time_to_x(ginfo, ginfo->cursor);
gdk_draw_line(ginfo->draw->window, ginfo->draw->style->mid_gc[3],
x, 0, x, ginfo->draw->allocation.height);
}
static void draw_marka(struct graph_info *ginfo)
{
gint x;
if (!ginfo->show_marka)
return;
x = convert_time_to_x(ginfo, ginfo->marka_time);
gdk_draw_line(ginfo->draw->window, green,
x, 0, x, ginfo->draw->allocation.height);
}
static void draw_markb(struct graph_info *ginfo)
{
gint x;
if (!ginfo->show_markb)
return;
x = convert_time_to_x(ginfo, ginfo->markb_time);
gdk_draw_line(ginfo->draw->window, red,
x, 0, x, ginfo->draw->allocation.height);
}
static void update_with_backend(struct graph_info *ginfo,
gint x, gint y,
gint width, gint height)
{
__update_with_backend(ginfo, x, y, width, height);
draw_cursor(ginfo);
draw_markb(ginfo);
draw_marka(ginfo);
}
static gboolean
expose_event(GtkWidget *widget, GdkEventExpose *event, gpointer data)
{
struct graph_info *ginfo = data;
update_with_backend(ginfo,
event->area.x, event->area.y,
event->area.width, event->area.height);
return FALSE;
}
static void
draw_line(GtkWidget *widget, gdouble x, struct graph_info *ginfo)
{
gdk_draw_line(widget->window, widget->style->black_gc,
x, 0, x, widget->allocation.height);
}
static void clear_line(struct graph_info *ginfo, gint x)
{
if (x)
x--;
update_with_backend(ginfo, x, 0, x+2, ginfo->draw->allocation.height);
}
static void clear_info_box(struct graph_info *ginfo)
{
update_with_backend(ginfo, ginfo->plot_data_x, ginfo->plot_data_y,
ginfo->plot_data_w, ginfo->plot_data_h);
}
static void redraw_graph(struct graph_info *ginfo)
{
gdouble height;
gdouble width;
redraw_pixmap_backend(ginfo);
width = ginfo->draw->allocation.width;
height = ginfo->draw->allocation.height;
update_with_backend(ginfo, 0, 0, width, height);
}
void trace_graph_filter_toggle(struct graph_info *ginfo)
{
ginfo->filter_enabled ^= 1;
redraw_graph(ginfo);
}
static void
filter_enable_clicked (gpointer data)
{
struct graph_info *ginfo = data;
trace_graph_filter_toggle(ginfo);
}
void trace_graph_filter_add_remove_task(struct graph_info *ginfo,
gint pid)
{
gint filter_enabled = ginfo->filter_enabled;
struct filter_task_item *task;
task = trace_graph_filter_task_find_pid(ginfo, pid);
if (task)
graph_filter_task_remove_pid(ginfo, task->pid);
else
graph_filter_task_add_pid(ginfo, pid);
if (ginfo->callbacks && ginfo->callbacks->filter)
ginfo->callbacks->filter(ginfo, ginfo->task_filter,
ginfo->hide_tasks);
if (filter_enabled)
redraw_graph(ginfo);
}
void trace_graph_filter_hide_show_task(struct graph_info *ginfo,
gint pid)
{
gint filter_enabled = ginfo->filter_enabled;
struct filter_task_item *task;
task = trace_graph_hide_task_find_pid(ginfo, pid);
if (task)
graph_hide_task_remove_pid(ginfo, task->pid);
else
graph_hide_task_add_pid(ginfo, pid);
if (ginfo->callbacks && ginfo->callbacks->filter)
ginfo->callbacks->filter(ginfo, ginfo->task_filter,
ginfo->hide_tasks);
if (filter_enabled)
redraw_graph(ginfo);
}
static void
filter_add_task_clicked (gpointer data)
{
struct graph_info *ginfo = data;
trace_graph_filter_add_remove_task(ginfo, ginfo->filter_task_selected);
}
static void
filter_hide_task_clicked (gpointer data)
{
struct graph_info *ginfo = data;
trace_graph_filter_hide_show_task(ginfo, ginfo->filter_task_selected);
}
void trace_graph_clear_tasks(struct graph_info *ginfo)
{
gint filter_enabled = ginfo->filter_enabled;
graph_filter_task_clear(ginfo);
if (ginfo->callbacks && ginfo->callbacks->filter)
ginfo->callbacks->filter(ginfo, ginfo->task_filter,
ginfo->hide_tasks);
if (filter_enabled)
redraw_graph(ginfo);
}
void trace_graph_update_filters(struct graph_info *ginfo,
struct filter_task *task_filter,
struct filter_task *hide_tasks)
{
/* Make sure the filter passed in is not the filter we use */
if (task_filter != ginfo->task_filter) {
filter_task_hash_free(ginfo->task_filter);
ginfo->task_filter = filter_task_hash_copy(task_filter);
}
if (hide_tasks != ginfo->hide_tasks) {
filter_task_hash_free(ginfo->hide_tasks);
ginfo->hide_tasks = filter_task_hash_copy(hide_tasks);
}
if (ginfo->callbacks && ginfo->callbacks->filter)
ginfo->callbacks->filter(ginfo, ginfo->task_filter,
ginfo->hide_tasks);
if (ginfo->filter_enabled)
redraw_graph(ginfo);
if (filter_task_count(ginfo->task_filter) ||
filter_task_count(ginfo->hide_tasks))
ginfo->filter_available = 1;
else {
ginfo->filter_enabled = 0;
ginfo->filter_available = 0;
}
}
void trace_graph_refresh_filters(struct graph_info *ginfo)
{
trace_graph_update_filters(ginfo, ginfo->task_filter,
ginfo->hide_tasks);
}
static void
filter_clear_tasks_clicked (gpointer data)
{
struct graph_info *ginfo = data;
trace_graph_clear_tasks(ginfo);
}
static void
plot_task_clicked (gpointer data)
{
struct graph_info *ginfo = data;
struct graph_plot *plot = ginfo->plot_clicked;
int pos;
if (plot)
pos = plot->pos + 1;
else
pos = ginfo->plots + 1;
graph_plot_task(ginfo, ginfo->filter_task_selected, pos);
ginfo->draw_height = PLOT_SPACE(ginfo->plots);
gtk_widget_set_size_request(ginfo->draw, ginfo->draw_width, ginfo->draw_height);
update_label_window(ginfo);
}
static void
remove_plot_clicked (gpointer data)
{
struct graph_info *ginfo = data;
struct graph_plot *plot = ginfo->plot_clicked;
if (!plot)
return;
trace_graph_plot_remove(ginfo, plot);
ginfo->draw_height = PLOT_SPACE(ginfo->plots);
gtk_widget_set_size_request(ginfo->draw, ginfo->draw_width, ginfo->draw_height);
update_label_window(ginfo);
}
static struct graph_plot *find_plot_by_y(struct graph_info *ginfo, gint y)
{
gint i;
for (i = 0; i < ginfo->plots; i++) {
if (y >= (PLOT_TOP(i) - PLOT_GIVE) &&
y <= (PLOT_BOTTOM(i) + PLOT_GIVE)) {
return ginfo->plot_array[i];
}
}
return NULL;
}
static gboolean
do_pop_up(GtkWidget *widget, GdkEventButton *event, gpointer data)
{
struct graph_info *ginfo = data;
static GtkWidget *menu;
static GtkWidget *menu_filter_enable;
static GtkWidget *menu_filter_add_task;
static GtkWidget *menu_filter_hide_task;
static GtkWidget *menu_filter_clear_tasks;
static GtkWidget *menu_plot_task;
static GtkWidget *menu_remove_plot;
struct pevent_record *record = NULL;
struct graph_plot *plot;
const char *comm;
guint64 time;
gchar *text;
gint pid;
gint len;
gint x, y;
x = event->x;
y = event->y;
if (!menu) {
menu = gtk_menu_new();
menu_filter_enable = gtk_menu_item_new_with_label("Enable Filter");
gtk_widget_show(menu_filter_enable);
gtk_menu_shell_append(GTK_MENU_SHELL (menu), menu_filter_enable);
g_signal_connect_swapped (G_OBJECT (menu_filter_enable), "activate",
G_CALLBACK (filter_enable_clicked),
data);
menu_filter_add_task = gtk_menu_item_new_with_label("Add Task");
gtk_widget_show(menu_filter_add_task);
gtk_menu_shell_append(GTK_MENU_SHELL (menu), menu_filter_add_task);
g_signal_connect_swapped (G_OBJECT (menu_filter_add_task), "activate",
G_CALLBACK (filter_add_task_clicked),
data);
menu_filter_hide_task = gtk_menu_item_new_with_label("Hide Task");
gtk_widget_show(menu_filter_hide_task);
gtk_menu_shell_append(GTK_MENU_SHELL (menu), menu_filter_hide_task);
g_signal_connect_swapped (G_OBJECT (menu_filter_hide_task), "activate",
G_CALLBACK (filter_hide_task_clicked),
data);
menu_filter_clear_tasks = gtk_menu_item_new_with_label("Clear Task Filter");
gtk_widget_show(menu_filter_clear_tasks);
gtk_menu_shell_append(GTK_MENU_SHELL (menu), menu_filter_clear_tasks);
g_signal_connect_swapped (G_OBJECT (menu_filter_clear_tasks), "activate",
G_CALLBACK (filter_clear_tasks_clicked),
data);
menu_plot_task = gtk_menu_item_new_with_label("Plot task");
gtk_menu_shell_append(GTK_MENU_SHELL (menu), menu_plot_task);
g_signal_connect_swapped (G_OBJECT (menu_plot_task), "activate",
G_CALLBACK (plot_task_clicked),
data);
menu_remove_plot = gtk_menu_item_new_with_label("Remove Plot");
gtk_menu_shell_append(GTK_MENU_SHELL (menu), menu_remove_plot);
gtk_widget_show(menu_remove_plot);
g_signal_connect_swapped (G_OBJECT (menu_remove_plot), "activate",
G_CALLBACK (remove_plot_clicked),
data);
}
if (ginfo->filter_enabled)
gtk_menu_item_set_label(GTK_MENU_ITEM(menu_filter_enable),
"Disable Filter");
else
gtk_menu_item_set_label(GTK_MENU_ITEM(menu_filter_enable),
"Enable Filter");
if (ginfo->filter_available)
gtk_widget_set_sensitive(menu_filter_enable, TRUE);
else
gtk_widget_set_sensitive(menu_filter_enable, FALSE);
if (filter_task_count(ginfo->task_filter) ||
filter_task_count(ginfo->hide_tasks))
gtk_widget_set_sensitive(menu_filter_clear_tasks, TRUE);
else
gtk_widget_set_sensitive(menu_filter_clear_tasks, FALSE);
time = convert_x_to_time(ginfo, x);
plot = find_plot_by_y(ginfo, y);
ginfo->plot_clicked = plot;
if (plot) {
record = trace_graph_plot_find_record(ginfo, plot, time);
gtk_widget_set_sensitive(menu_remove_plot, TRUE);
} else
gtk_widget_set_sensitive(menu_remove_plot, FALSE);
if (record) {
if (!trace_graph_check_sched_switch(ginfo, record, &pid, &comm)) {
pid = pevent_data_pid(ginfo->pevent, record);
comm = pevent_data_comm_from_pid(ginfo->pevent, pid);
}
len = strlen(comm) + 50;
text = g_malloc(len);
g_assert(text);
if (trace_graph_filter_task_find_pid(ginfo, pid))
snprintf(text, len, "Remove %s-%d from filter", comm, pid);
else
snprintf(text, len, "Add %s-%d to filter", comm, pid);
ginfo->filter_task_selected = pid;
gtk_menu_item_set_label(GTK_MENU_ITEM(menu_filter_add_task),
text);
if (trace_graph_hide_task_find_pid(ginfo, pid))
snprintf(text, len, "Show %s-%d", comm, pid);
else
snprintf(text, len, "Hide %s-%d", comm, pid);
gtk_menu_item_set_label(GTK_MENU_ITEM(menu_filter_hide_task),
text);
snprintf(text, len, "Plot %s-%d", comm, pid);
gtk_menu_item_set_label(GTK_MENU_ITEM(menu_plot_task),
text);
g_free(text);
gtk_widget_set_sensitive(menu_filter_add_task, TRUE);
gtk_widget_set_sensitive(menu_filter_hide_task, TRUE);
gtk_widget_show(menu_plot_task);
free_record(record);
} else {
gtk_menu_item_set_label(GTK_MENU_ITEM(menu_filter_add_task),
"Add task to filter");
gtk_widget_set_sensitive(menu_filter_add_task, FALSE);
gtk_menu_item_set_label(GTK_MENU_ITEM(menu_filter_hide_task),
"Hide task");
gtk_widget_set_sensitive(menu_filter_hide_task, FALSE);
gtk_widget_hide(menu_plot_task);
}
gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, 3,
gtk_get_current_event_time());
return TRUE;
}
static void draw_info_box(struct graph_info *ginfo, const gchar *buffer,
gint x, gint y);
static void stop_zoom_tip(struct graph_info *ginfo)
{
clear_info_box(ginfo);
}
static void show_zoom_tip(struct graph_info *ginfo, gint x, gint y)
{
clear_info_box(ginfo);
draw_info_box(ginfo,
"Click and hold left mouse and drag right to zoom in\n"
"Click and hold left mouse and drag left to zoom out",
x, y);
}
static void button_press(struct graph_info *ginfo, gint x, gint y, guint state)
{
ginfo->press_x = x;
ginfo->last_x = 0;
draw_line(ginfo->draw, x, ginfo);
ginfo->line_active = TRUE;
ginfo->line_time = convert_x_to_time(ginfo, x);
if (state & GDK_SHIFT_MASK) {
ginfo->show_markb = FALSE;
clear_line(ginfo, convert_time_to_x(ginfo, ginfo->markb_time));
/* We only update A if it hasn't been made yet */
if (!ginfo->marka_time) {
ginfo->show_marka = FALSE;
clear_line(ginfo, convert_time_to_x(ginfo, ginfo->marka_time));
update_marka(ginfo, x);
}
} else {
ginfo->zoom = TRUE;
show_zoom_tip(ginfo, x, y);
}
return;
}
static gboolean
button_press_event(GtkWidget *widget, GdkEventButton *event, gpointer data)
{
struct graph_info *ginfo = data;
if (!ginfo->handle)
return FALSE;
if (event->button == 3)
return do_pop_up(widget, event, data);
if (event->button != 1)
return TRUE;
/* check for double click */
if (event->type == GDK_2BUTTON_PRESS) {
stop_zoom_tip(ginfo);
if (ginfo->line_active) {
ginfo->line_active = FALSE;
clear_line(ginfo, ginfo->last_x);
clear_line(ginfo, ginfo->press_x);
}
if (ginfo->cursor >= ginfo->view_start_time &&
ginfo->cursor <= ginfo->view_end_time) {
ginfo->last_x = convert_time_to_x(ginfo, ginfo->cursor);
ginfo->cursor = 0;
clear_line(ginfo, ginfo->last_x);
}
ginfo->cursor = convert_x_to_time(ginfo, event->x);
draw_cursor(ginfo);
if (ginfo->callbacks && ginfo->callbacks->select)
ginfo->callbacks->select(ginfo, ginfo->cursor);
return TRUE;
}
button_press(ginfo, event->x, event->y, event->state);
return TRUE;
}
static void draw_latency(struct graph_info *ginfo, gint x, gint y);
static void draw_plot_info(struct graph_info *ginfo, struct graph_plot *plot,
gint x, gint y);
static void motion_plot(struct graph_info *ginfo, gint x, gint y)
{
struct graph_plot *plot;
if (ginfo->zoom)
stop_zoom_tip(ginfo);
if (!ginfo->curr_pixmap)
return;
if (ginfo->pointer_time)
update_pointer(ginfo, x);
if (ginfo->line_active) {
if (ginfo->last_x)
clear_line(ginfo, ginfo->last_x);
ginfo->last_x = x;
draw_line(ginfo->draw, ginfo->press_x, ginfo);
draw_line(ginfo->draw, x, ginfo);
if (!ginfo->zoom)
draw_latency(ginfo, x, y);
return;
}
plot = find_plot_by_y(ginfo, y);
if (plot)
draw_plot_info(ginfo, plot, x, y);
}
static gboolean
info_button_press_event(GtkWidget *widget, GdkEventButton *event, gpointer data)
{
struct graph_info *ginfo = data;
if (!ginfo->handle)
return FALSE;
if (event->button != 1)
return FALSE;
/* check for double click */
if (event->type == GDK_2BUTTON_PRESS)
return FALSE;
button_press(ginfo, gtk_adjustment_get_value(ginfo->hadj), event->y, event->state);
return FALSE;
}
static gboolean
info_motion_notify_event(GtkWidget *widget, GdkEventMotion *event, gpointer data)
{
struct graph_info *ginfo = data;
GdkModifierType state;
gint x, y;
if (!ginfo->handle)
return FALSE;
if (!ginfo->line_active)
return FALSE;
if (!ginfo->curr_pixmap)
return FALSE;
clear_info_box(ginfo);
if (event->is_hint)
gdk_window_get_pointer(event->window, &x, &y, &state);
else {
x = event->x;
y = event->y;
}
/* Position x relative to the location in the drawing area */
x -= ginfo->scrollwin->allocation.x - ginfo->info_scrollwin->allocation.x;
if (x < 0)
return FALSE;
x += gtk_adjustment_get_value(ginfo->hadj);
motion_plot(ginfo, x, y);
return FALSE;
}
static void button_release(struct graph_info *ginfo, gint x);
static gboolean
info_button_release_event(GtkWidget *widget, GdkEventMotion *event, gpointer data)
{
struct graph_info *ginfo = data;
gint x;
if (!ginfo->handle)
return FALSE;
x = event->x - ginfo->scrollwin->allocation.x - ginfo->info_scrollwin->allocation.x;
button_release(ginfo, x);
return FALSE;