diff options
author | Steven Rostedt <srostedt@redhat.com> | 2010-02-05 16:49:55 -0500 |
---|---|---|
committer | Steven Rostedt <rostedt@goodmis.org> | 2010-02-05 16:53:02 -0500 |
commit | a645eb66cba85e94d543c81d8f08c05609154a04 (patch) | |
tree | 07364fa32b7f6c0258c12d9ecd526b6cb36fbde5 | |
parent | e47280879899214015a85bdc96c4b7febeeedb3e (diff) |
trace-graph: Make helper functions to convert time and x
Add convert_x_to_time() and convert_time_to_x() instead of hard coding
it and having it error prone.
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
-rw-r--r-- | trace-graph.c | 42 |
1 files changed, 26 insertions, 16 deletions
diff --git a/trace-graph.c b/trace-graph.c index 8e59cfd..77a1153 100644 --- a/trace-graph.c +++ b/trace-graph.c | |||
@@ -71,6 +71,20 @@ static void convert_nano(unsigned long long time, unsigned long *sec, | |||
71 | *usec = (time / 1000) % 1000000; | 71 | *usec = (time / 1000) % 1000000; |
72 | } | 72 | } |
73 | 73 | ||
74 | static int convert_time_to_x(struct graph_info *ginfo, guint64 time) | ||
75 | { | ||
76 | if (time < ginfo->view_start_time) | ||
77 | return 0; | ||
78 | return (time - ginfo->view_start_time) * ginfo->resolution; | ||
79 | } | ||
80 | |||
81 | static guint64 convert_x_to_time(struct graph_info *ginfo, gint x) | ||
82 | { | ||
83 | double d = x; | ||
84 | |||
85 | return (guint64)(d / ginfo->resolution) + ginfo->view_start_time; | ||
86 | } | ||
87 | |||
74 | static void print_time(unsigned long long time) | 88 | static void print_time(unsigned long long time) |
75 | { | 89 | { |
76 | unsigned long sec, usec; | 90 | unsigned long sec, usec; |
@@ -256,8 +270,7 @@ static void draw_cursor(struct graph_info *ginfo) | |||
256 | ginfo->cursor > ginfo->view_end_time) | 270 | ginfo->cursor > ginfo->view_end_time) |
257 | return; | 271 | return; |
258 | 272 | ||
259 | x = (ginfo->cursor - ginfo->view_start_time) | 273 | x = convert_time_to_x(ginfo, ginfo->cursor); |
260 | * ginfo->resolution; | ||
261 | 274 | ||
262 | gdk_draw_line(ginfo->draw->window, ginfo->draw->style->mid_gc[3], | 275 | gdk_draw_line(ginfo->draw->window, ginfo->draw->style->mid_gc[3], |
263 | x, 0, x, ginfo->draw->allocation.width); | 276 | x, 0, x, ginfo->draw->allocation.width); |
@@ -511,7 +524,7 @@ do_pop_up(GtkWidget *widget, GdkEventButton *event, gpointer data) | |||
511 | else | 524 | else |
512 | gtk_widget_set_sensitive(menu_filter_clear_tasks, FALSE); | 525 | gtk_widget_set_sensitive(menu_filter_clear_tasks, FALSE); |
513 | 526 | ||
514 | time = (x / ginfo->resolution) + ginfo->view_start_time; | 527 | time = convert_x_to_time(ginfo, x); |
515 | 528 | ||
516 | for (cpu = 0; cpu < ginfo->cpus; cpu++) { | 529 | for (cpu = 0; cpu < ginfo->cpus; cpu++) { |
517 | if (y >= (CPU_TOP(cpu) - CPU_GIVE) && | 530 | if (y >= (CPU_TOP(cpu) - CPU_GIVE) && |
@@ -599,14 +612,12 @@ button_press_event(GtkWidget *widget, GdkEventButton *event, gpointer data) | |||
599 | } | 612 | } |
600 | if (ginfo->cursor >= ginfo->view_start_time && | 613 | if (ginfo->cursor >= ginfo->view_start_time && |
601 | ginfo->cursor <= ginfo->view_end_time) { | 614 | ginfo->cursor <= ginfo->view_end_time) { |
602 | ginfo->last_x = (ginfo->cursor - ginfo->view_start_time) | 615 | ginfo->last_x = convert_time_to_x(ginfo, ginfo->cursor); |
603 | * ginfo->resolution; | ||
604 | ginfo->cursor = 0; | 616 | ginfo->cursor = 0; |
605 | clear_last_line(widget, ginfo); | 617 | clear_last_line(widget, ginfo); |
606 | } | 618 | } |
607 | 619 | ||
608 | ginfo->cursor = event->x / ginfo->resolution + | 620 | ginfo->cursor = convert_x_to_time(ginfo, event->x); |
609 | ginfo->view_start_time; | ||
610 | draw_cursor(ginfo); | 621 | draw_cursor(ginfo); |
611 | if (ginfo->callbacks && ginfo->callbacks->select) | 622 | if (ginfo->callbacks && ginfo->callbacks->select) |
612 | ginfo->callbacks->select(ginfo, ginfo->cursor); | 623 | ginfo->callbacks->select(ginfo, ginfo->cursor); |
@@ -879,7 +890,7 @@ static void draw_cpu_info(struct graph_info *ginfo, gint cpu, gint x, gint y) | |||
879 | gdk_gc_set_foreground(pix_bg, &color); | 890 | gdk_gc_set_foreground(pix_bg, &color); |
880 | } | 891 | } |
881 | 892 | ||
882 | time = (x / ginfo->resolution) + ginfo->view_start_time; | 893 | time = convert_x_to_time(ginfo, x); |
883 | convert_nano(time, &sec, &usec); | 894 | convert_nano(time, &sec, &usec); |
884 | 895 | ||
885 | pevent = ginfo->pevent; | 896 | pevent = ginfo->pevent; |
@@ -1192,7 +1203,7 @@ static void zoom_in_window(struct graph_info *ginfo, gint start, gint end) | |||
1192 | update_graph_to_start_x(ginfo); | 1203 | update_graph_to_start_x(ginfo); |
1193 | 1204 | ||
1194 | ginfo->hadj_value = start; | 1205 | ginfo->hadj_value = start; |
1195 | ginfo->hadj_value = (start_time - ginfo->view_start_time) * ginfo->resolution; | 1206 | ginfo->hadj_value = convert_time_to_x(ginfo, start_time); |
1196 | 1207 | ||
1197 | if (ginfo->hadj_value > (ginfo->draw_width - view_width)) | 1208 | if (ginfo->hadj_value > (ginfo->draw_width - view_width)) |
1198 | ginfo->hadj_value = ginfo->draw_width - view_width; | 1209 | ginfo->hadj_value = ginfo->draw_width - view_width; |
@@ -1209,7 +1220,7 @@ static void zoom_in_window(struct graph_info *ginfo, gint start, gint end) | |||
1209 | 1220 | ||
1210 | 1221 | ||
1211 | dprintf(1, "*** ended with with "); | 1222 | dprintf(1, "*** ended with with "); |
1212 | print_time(ginfo->hadj_value / ginfo->resolution + ginfo->view_start_time); | 1223 | print_time(convert_x_to_time(ginfo, ginfo->hadj_value)); |
1213 | dprintf(1, "\n"); | 1224 | dprintf(1, "\n"); |
1214 | 1225 | ||
1215 | } | 1226 | } |
@@ -1244,7 +1255,7 @@ static void zoom_out_window(struct graph_info *ginfo, gint start, gint end) | |||
1244 | start_x = gtk_adjustment_get_value(ginfo->hadj); | 1255 | start_x = gtk_adjustment_get_value(ginfo->hadj); |
1245 | mid = start_x + view_width / 2; | 1256 | mid = start_x + view_width / 2; |
1246 | 1257 | ||
1247 | time = mid / ginfo->resolution + ginfo->view_start_time; | 1258 | time = convert_x_to_time(ginfo, mid); |
1248 | 1259 | ||
1249 | divider = start - end; | 1260 | divider = start - end; |
1250 | 1261 | ||
@@ -1291,7 +1302,7 @@ static void zoom_out_window(struct graph_info *ginfo, gint start, gint end) | |||
1291 | else | 1302 | else |
1292 | gtk_widget_set_size_request(ginfo->draw, ginfo->draw_width, ginfo->draw_height); | 1303 | gtk_widget_set_size_request(ginfo->draw, ginfo->draw_width, ginfo->draw_height); |
1293 | 1304 | ||
1294 | mid = (time - ginfo->view_start_time) * ginfo->resolution; | 1305 | mid = convert_time_to_x(ginfo, time); |
1295 | start_x = mid - view_width / 2; | 1306 | start_x = mid - view_width / 2; |
1296 | if (start_x < 0) | 1307 | if (start_x < 0) |
1297 | start_x = 0; | 1308 | start_x = 0; |
@@ -1668,7 +1679,7 @@ static void draw_timeline(struct graph_info *ginfo, gint width) | |||
1668 | 1679 | ||
1669 | for (mid = view_width / 2; mid < (width - view_width / 2 + 10); | 1680 | for (mid = view_width / 2; mid < (width - view_width / 2 + 10); |
1670 | mid += view_width / 2) { | 1681 | mid += view_width / 2) { |
1671 | time = mid / ginfo->resolution + ginfo->view_start_time; | 1682 | time = convert_x_to_time(ginfo, mid); |
1672 | 1683 | ||
1673 | convert_nano(time, &sec, &usec); | 1684 | convert_nano(time, &sec, &usec); |
1674 | trace_seq_init(&s); | 1685 | trace_seq_init(&s); |
@@ -1749,7 +1760,7 @@ void trace_graph_select_by_time(struct graph_info *ginfo, guint64 time) | |||
1749 | redraw_pixmap_backend(ginfo); | 1760 | redraw_pixmap_backend(ginfo); |
1750 | 1761 | ||
1751 | /* Adjust start to be the location for the hadj */ | 1762 | /* Adjust start to be the location for the hadj */ |
1752 | mid = (time - ginfo->view_start_time) * ginfo->resolution; | 1763 | mid = convert_time_to_x(ginfo, time); |
1753 | start = mid - view_width / 2; | 1764 | start = mid - view_width / 2; |
1754 | if (start < 0) | 1765 | if (start < 0) |
1755 | start = 0; | 1766 | start = 0; |
@@ -1758,8 +1769,7 @@ void trace_graph_select_by_time(struct graph_info *ginfo, guint64 time) | |||
1758 | start = width - view_width; | 1769 | start = width - view_width; |
1759 | gtk_adjustment_set_value(ginfo->hadj, start); | 1770 | gtk_adjustment_set_value(ginfo->hadj, start); |
1760 | 1771 | ||
1761 | ginfo->last_x = (ginfo->cursor - ginfo->view_start_time) | 1772 | ginfo->last_x = convert_time_to_x(ginfo, ginfo->cursor); |
1762 | * ginfo->resolution; | ||
1763 | ginfo->cursor = 0; | 1773 | ginfo->cursor = 0; |
1764 | clear_last_line(ginfo->draw, ginfo); | 1774 | clear_last_line(ginfo->draw, ginfo); |
1765 | ginfo->cursor = time; | 1775 | ginfo->cursor = time; |