aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSteven Rostedt <srostedt@redhat.com>2010-02-19 15:00:20 -0500
committerSteven Rostedt <rostedt@goodmis.org>2010-02-19 20:36:08 -0500
commit805794bb3e0fda067a57de592083770110a9d43c (patch)
treec11fc9cbc8f3981be167ba64341c4fab2e3472dd
parent6cbbc27cb3bc55731928713d06b7ae03574444d5 (diff)
trace-graph: Change drag from zoom to time difference
Make the drag show the time difference between two points and change zoom to be shift+drag. Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
-rw-r--r--trace-graph.c193
-rw-r--r--trace-graph.h2
2 files changed, 133 insertions, 62 deletions
diff --git a/trace-graph.c b/trace-graph.c
index 7f982bd..bf67da9 100644
--- a/trace-graph.c
+++ b/trace-graph.c
@@ -360,6 +360,12 @@ static void clear_last_line(GtkWidget *widget, struct graph_info *ginfo)
360 update_with_backend(ginfo, x, 0, x+2, widget->allocation.height); 360 update_with_backend(ginfo, x, 0, x+2, widget->allocation.height);
361} 361}
362 362
363static void clear_info_box(struct graph_info *ginfo)
364{
365 update_with_backend(ginfo, ginfo->plot_data_x, ginfo->plot_data_y,
366 ginfo->plot_data_w, ginfo->plot_data_h);
367}
368
363static void redraw_graph(struct graph_info *ginfo) 369static void redraw_graph(struct graph_info *ginfo)
364{ 370{
365 gdouble height; 371 gdouble height;
@@ -712,17 +718,47 @@ button_press_event(GtkWidget *widget, GdkEventButton *event, gpointer data)
712 return TRUE; 718 return TRUE;
713 } 719 }
714 720
715
716 ginfo->press_x = event->x; 721 ginfo->press_x = event->x;
717 ginfo->last_x = 0; 722 ginfo->last_x = 0;
718 723
719 draw_line(widget, event->x, ginfo); 724 draw_line(widget, event->x, ginfo);
720 725
721 ginfo->line_active = TRUE; 726 ginfo->line_active = TRUE;
727 ginfo->line_time = convert_x_to_time(ginfo, event->x);
728
729 if (!(event->state & GDK_SHIFT_MASK))
730 ginfo->zoom = TRUE;
722 731
723 return TRUE; 732 return TRUE;
724} 733}
725 734
735static void draw_latency(struct graph_info *ginfo, gint x, gint y);
736static void draw_plot_info(struct graph_info *ginfo, struct graph_plot *plot,
737 gint x, gint y);
738
739static void motion_plot(struct graph_info *ginfo, gint x, gint y)
740{
741 struct graph_plot *plot;
742
743 if (!ginfo->curr_pixmap)
744 return;
745
746 if (ginfo->line_active) {
747 if (ginfo->last_x)
748 clear_last_line(ginfo->draw, ginfo);
749 ginfo->last_x = x;
750 draw_line(ginfo->draw, ginfo->press_x, ginfo);
751 draw_line(ginfo->draw, x, ginfo);
752 if (!ginfo->zoom)
753 draw_latency(ginfo, x, y);
754 return;
755 }
756
757 plot = find_plot_by_y(ginfo, y);
758 if (plot)
759 draw_plot_info(ginfo, plot, x, y);
760}
761
726static gboolean 762static gboolean
727info_button_press_event(GtkWidget *widget, GdkEventButton *event, gpointer data) 763info_button_press_event(GtkWidget *widget, GdkEventButton *event, gpointer data)
728{ 764{
@@ -744,6 +780,10 @@ info_button_press_event(GtkWidget *widget, GdkEventButton *event, gpointer data)
744 draw_line(ginfo->draw, 0, ginfo); 780 draw_line(ginfo->draw, 0, ginfo);
745 781
746 ginfo->line_active = TRUE; 782 ginfo->line_active = TRUE;
783 ginfo->line_time = convert_x_to_time(ginfo, gtk_adjustment_get_value(ginfo->hadj));;
784
785 if (!(event->state & GDK_SHIFT_MASK))
786 ginfo->zoom = TRUE;
747 787
748 return FALSE; 788 return FALSE;
749} 789}
@@ -764,8 +804,8 @@ info_motion_notify_event(GtkWidget *widget, GdkEventMotion *event, gpointer data
764 if (!ginfo->curr_pixmap) 804 if (!ginfo->curr_pixmap)
765 return FALSE; 805 return FALSE;
766 806
767 update_with_backend(ginfo, ginfo->plot_data_x, ginfo->plot_data_y, 807 clear_info_box(ginfo);
768 ginfo->plot_data_w, ginfo->plot_data_h); 808
769 if (event->is_hint) 809 if (event->is_hint)
770 gdk_window_get_pointer(event->window, &x, &y, &state); 810 gdk_window_get_pointer(event->window, &x, &y, &state);
771 else { 811 else {
@@ -779,16 +819,14 @@ info_motion_notify_event(GtkWidget *widget, GdkEventMotion *event, gpointer data
779 if (x < 0) 819 if (x < 0)
780 return FALSE; 820 return FALSE;
781 821
782 if (ginfo->last_x) 822 x += gtk_adjustment_get_value(ginfo->hadj);
783 clear_last_line(ginfo->draw, ginfo); 823
784 ginfo->last_x = x; 824 motion_plot(ginfo, x, y);
785 draw_line(ginfo->draw, ginfo->press_x, ginfo);
786 draw_line(ginfo->draw, x, ginfo);
787 825
788 return FALSE; 826 return FALSE;
789} 827}
790 828
791static void activate_zoom(struct graph_info *ginfo, gint x); 829static void button_release(struct graph_info *ginfo, gint x);
792 830
793static gboolean 831static gboolean
794info_button_release_event(GtkWidget *widget, GdkEventMotion *event, gpointer data) 832info_button_release_event(GtkWidget *widget, GdkEventMotion *event, gpointer data)
@@ -801,7 +839,7 @@ info_button_release_event(GtkWidget *widget, GdkEventMotion *event, gpointer dat
801 839
802 x = event->x - ginfo->scrollwin->allocation.x - ginfo->info_scrollwin->allocation.x; 840 x = event->x - ginfo->scrollwin->allocation.x - ginfo->info_scrollwin->allocation.x;
803 841
804 activate_zoom(ginfo, x); 842 button_release(ginfo, x);
805 843
806 return FALSE; 844 return FALSE;
807} 845}
@@ -940,15 +978,11 @@ int trace_graph_check_sched_switch(struct graph_info *ginfo,
940 return ret; 978 return ret;
941} 979}
942 980
943static void draw_plot_info(struct graph_info *ginfo, struct graph_plot *plot, 981static void draw_info_box(struct graph_info *ginfo, const gchar *buffer,
944 gint x, gint y) 982 gint x, gint y)
945{ 983{
946 PangoLayout *layout; 984 PangoLayout *layout;
947 GtkAdjustment *vadj; 985 GtkAdjustment *vadj;
948 struct pevent *pevent;
949 guint64 time;
950 unsigned long sec, usec;
951 struct trace_seq s;
952 gint width, height; 986 gint width, height;
953 GdkPixmap *pix; 987 GdkPixmap *pix;
954 static GdkGC *pix_bg; 988 static GdkGC *pix_bg;
@@ -966,25 +1000,7 @@ static void draw_plot_info(struct graph_info *ginfo, struct graph_plot *plot,
966 gdk_gc_set_foreground(pix_bg, &color); 1000 gdk_gc_set_foreground(pix_bg, &color);
967 } 1001 }
968 1002
969 time = convert_x_to_time(ginfo, x); 1003 layout = gtk_widget_create_pango_layout(ginfo->draw, buffer);
970 convert_nano(time, &sec, &usec);
971
972 pevent = ginfo->pevent;
973
974 trace_seq_init(&s);
975
976 dprintf(3, "start=%llu end=%llu time=%llu\n",
977 (u64)ginfo->start_time, (u64)ginfo->end_time, (u64)time);
978
979 if (!trace_graph_plot_display_info(ginfo, plot, &s, time)) {
980 /* Just display the current time */
981 trace_seq_init(&s);
982 trace_seq_printf(&s, "%lu.%06lu", sec, usec);
983 }
984
985 trace_seq_putc(&s, 0);
986
987 layout = gtk_widget_create_pango_layout(ginfo->draw, s.buffer);
988 pango_layout_get_pixel_size(layout, &width, &height); 1004 pango_layout_get_pixel_size(layout, &width, &height);
989 1005
990 width += PLOT_BOARDER * 2; 1006 width += PLOT_BOARDER * 2;
@@ -1032,19 +1048,74 @@ static void draw_plot_info(struct graph_info *ginfo, struct graph_plot *plot,
1032 g_object_unref(pix); 1048 g_object_unref(pix);
1033} 1049}
1034 1050
1051static void draw_plot_info(struct graph_info *ginfo, struct graph_plot *plot,
1052 gint x, gint y)
1053{
1054 struct pevent *pevent;
1055 guint64 time;
1056 unsigned long sec, usec;
1057 struct trace_seq s;
1058
1059 time = convert_x_to_time(ginfo, x);
1060 convert_nano(time, &sec, &usec);
1061
1062 pevent = ginfo->pevent;
1063
1064 trace_seq_init(&s);
1065
1066 dprintf(3, "start=%llu end=%llu time=%llu\n",
1067 (u64)ginfo->start_time, (u64)ginfo->end_time, (u64)time);
1068
1069 if (!trace_graph_plot_display_info(ginfo, plot, &s, time)) {
1070 /* Just display the current time */
1071 trace_seq_init(&s);
1072 trace_seq_printf(&s, "%lu.%06lu", sec, usec);
1073 }
1074
1075 trace_seq_putc(&s, 0);
1076
1077 draw_info_box(ginfo, s.buffer, x, y);
1078}
1079
1080static void draw_latency(struct graph_info *ginfo, gint x, gint y)
1081{
1082 struct pevent *pevent;
1083 unsigned long sec, usec;
1084 struct trace_seq s;
1085 gboolean neg;
1086 gint64 time;
1087
1088 time = convert_x_to_time(ginfo, x);
1089 time -= ginfo->line_time;
1090
1091 if (time < 0) {
1092 neg = TRUE;
1093 time *= -1;
1094 } else
1095 neg = FALSE;
1096
1097 convert_nano(time, &sec, &usec);
1098
1099 pevent = ginfo->pevent;
1100
1101 trace_seq_init(&s);
1102 trace_seq_printf(&s, "Diff: %s%ld.%06lu secs", neg ? "-":"", sec, usec);
1103
1104 draw_info_box(ginfo, s.buffer, x, y);
1105}
1106
1035static gboolean 1107static gboolean
1036motion_notify_event(GtkWidget *widget, GdkEventMotion *event, gpointer data) 1108motion_notify_event(GtkWidget *widget, GdkEventMotion *event, gpointer data)
1037{ 1109{
1038 struct graph_info *ginfo = data; 1110 struct graph_info *ginfo = data;
1039 GdkModifierType state; 1111 GdkModifierType state;
1040 gint x, y; 1112 gint x, y;
1041 struct graph_plot *plot;
1042 1113
1043 if (!ginfo->handle) 1114 if (!ginfo->handle)
1044 return FALSE; 1115 return FALSE;
1045 1116
1046 update_with_backend(ginfo, ginfo->plot_data_x, ginfo->plot_data_y, 1117 clear_info_box(ginfo);
1047 ginfo->plot_data_w, ginfo->plot_data_h); 1118
1048 if (event->is_hint) 1119 if (event->is_hint)
1049 gdk_window_get_pointer(event->window, &x, &y, &state); 1120 gdk_window_get_pointer(event->window, &x, &y, &state);
1050 else { 1121 else {
@@ -1053,21 +1124,7 @@ motion_notify_event(GtkWidget *widget, GdkEventMotion *event, gpointer data)
1053 state = event->state; 1124 state = event->state;
1054 } 1125 }
1055 1126
1056 if (!ginfo->curr_pixmap) 1127 motion_plot(ginfo, x, y);
1057 return TRUE;
1058
1059 if (ginfo->line_active) {
1060 if (ginfo->last_x)
1061 clear_last_line(widget, ginfo);
1062 ginfo->last_x = x;
1063 draw_line(widget, ginfo->press_x, ginfo);
1064 draw_line(widget, x, ginfo);
1065 return TRUE;
1066 }
1067
1068 plot = find_plot_by_y(ginfo, y);
1069 if (plot)
1070 draw_plot_info(ginfo, plot, x, y);
1071 1128
1072 return TRUE; 1129 return TRUE;
1073} 1130}
@@ -1320,16 +1377,13 @@ static void zoom_out_window(struct graph_info *ginfo, gint start, gint end)
1320 1377
1321 ginfo->hadj_value = start_x; 1378 ginfo->hadj_value = start_x;
1322} 1379}
1380
1323static void activate_zoom(struct graph_info *ginfo, gint x) 1381static void activate_zoom(struct graph_info *ginfo, gint x)
1324{ 1382{
1325 1383 if (!ginfo->zoom)
1326 if (!ginfo->line_active)
1327 return; 1384 return;
1328 1385
1329 ginfo->line_active = FALSE; 1386 ginfo->zoom = FALSE;
1330 clear_last_line(ginfo->draw, ginfo);
1331 ginfo->last_x = ginfo->press_x;
1332 clear_last_line(ginfo->draw, ginfo);
1333 1387
1334 if (x > ginfo->press_x) { 1388 if (x > ginfo->press_x) {
1335 /* make a decent zoom */ 1389 /* make a decent zoom */
@@ -1340,6 +1394,22 @@ static void activate_zoom(struct graph_info *ginfo, gint x)
1340 zoom_out_window(ginfo, ginfo->press_x, x); 1394 zoom_out_window(ginfo, ginfo->press_x, x);
1341} 1395}
1342 1396
1397static void button_release(struct graph_info *ginfo, gint x)
1398{
1399
1400 if (!ginfo->line_active)
1401 return;
1402
1403 clear_last_line(ginfo->draw, ginfo);
1404 ginfo->last_x = ginfo->press_x;
1405 clear_last_line(ginfo->draw, ginfo);
1406 ginfo->line_active = FALSE;
1407
1408 clear_info_box(ginfo);
1409
1410 activate_zoom(ginfo, x);
1411}
1412
1343static gboolean 1413static gboolean
1344button_release_event(GtkWidget *widget, GdkEventMotion *event, gpointer data) 1414button_release_event(GtkWidget *widget, GdkEventMotion *event, gpointer data)
1345{ 1415{
@@ -1348,7 +1418,7 @@ button_release_event(GtkWidget *widget, GdkEventMotion *event, gpointer data)
1348 if (!ginfo->handle) 1418 if (!ginfo->handle)
1349 return FALSE; 1419 return FALSE;
1350 1420
1351 activate_zoom(ginfo, event->x); 1421 button_release(ginfo, event->x);
1352 1422
1353 return TRUE; 1423 return TRUE;
1354} 1424}
@@ -1361,8 +1431,7 @@ leave_notify_event(GtkWidget *widget, GdkEventCrossing *event, gpointer data)
1361 if (!ginfo->handle) 1431 if (!ginfo->handle)
1362 return FALSE; 1432 return FALSE;
1363 1433
1364 update_with_backend(ginfo, ginfo->plot_data_x, ginfo->plot_data_y, 1434 clear_info_box(ginfo);
1365 ginfo->plot_data_w, ginfo->plot_data_h);
1366 1435
1367 return FALSE; 1436 return FALSE;
1368} 1437}
diff --git a/trace-graph.h b/trace-graph.h
index c501353..8cb51d4 100644
--- a/trace-graph.h
+++ b/trace-graph.h
@@ -184,6 +184,8 @@ struct graph_info {
184 gint press_x; /* x where button is pressed */ 184 gint press_x; /* x where button is pressed */
185 gint last_x; /* last x seen while moving mouse */ 185 gint last_x; /* last x seen while moving mouse */
186 gboolean line_active; /* set when button is pressed */ 186 gboolean line_active; /* set when button is pressed */
187 guint64 line_time; /* time line of where line_active is set */
188 gboolean zoom; /* set when shift button is pressed */
187 189
188 gdouble hadj_value; /* value to set hadj width */ 190 gdouble hadj_value; /* value to set hadj width */
189 gdouble hadj_page_size; /* visible size to set hadj */ 191 gdouble hadj_page_size; /* visible size to set hadj */