diff options
author | Steven Rostedt <srostedt@redhat.com> | 2009-12-29 19:42:24 -0500 |
---|---|---|
committer | Steven Rostedt <rostedt@goodmis.org> | 2009-12-29 19:42:24 -0500 |
commit | aabc0ac51066e9abb995ed13878565b17ee36f45 (patch) | |
tree | 0b706485b24d1e6692d51951f9ac276427729600 | |
parent | d4c933761708232329bd255b51748a05a3222ec3 (diff) |
trace-graph: Add separate drawing area to hold CPU labels
This adds a separate drawing area to hald the CPU labels.
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
-rw-r--r-- | trace-graph.c | 190 | ||||
-rw-r--r-- | trace-graph.h | 2 |
2 files changed, 119 insertions, 73 deletions
diff --git a/trace-graph.c b/trace-graph.c index b003ab4..d9a26e4 100644 --- a/trace-graph.c +++ b/trace-graph.c | |||
@@ -41,7 +41,8 @@ | |||
41 | #define CPU_BOTTOM(cpu) (CPU_LINE(cpu)-1) | 41 | #define CPU_BOTTOM(cpu) (CPU_LINE(cpu)-1) |
42 | #define CPU_BOX_BOTTOM(cpu) (CPU_LINE(cpu)) | 42 | #define CPU_BOX_BOTTOM(cpu) (CPU_LINE(cpu)) |
43 | #define CPU_SPACE(cpus) (80 * (cpus) + 80) | 43 | #define CPU_SPACE(cpus) (80 * (cpus) + 80) |
44 | #define CPU_LABEL(cpu) (CPU_BOTTOM(cpu)) | 44 | #define CPU_LABEL(cpu) (CPU_TOP(cpu)) |
45 | #define CPU_X 5 | ||
45 | 46 | ||
46 | static gint ftrace_sched_switch_id = -1; | 47 | static gint ftrace_sched_switch_id = -1; |
47 | static gint event_sched_switch_id = -1; | 48 | static gint event_sched_switch_id = -1; |
@@ -76,65 +77,6 @@ static void __update_with_backend(struct graph_info *ginfo, | |||
76 | width, height); | 77 | width, height); |
77 | } | 78 | } |
78 | 79 | ||
79 | static void clear_old_cpu_label(struct graph_info *ginfo, gint cpu) | ||
80 | { | ||
81 | __update_with_backend(ginfo, | ||
82 | ginfo->cpu_x, CPU_LABEL(cpu), | ||
83 | largest_cpu_label+1, 20); | ||
84 | } | ||
85 | |||
86 | static void clear_old_cpu_labels(struct graph_info *ginfo) | ||
87 | { | ||
88 | gint cpu; | ||
89 | |||
90 | for (cpu = 0; cpu < ginfo->cpus; cpu++) | ||
91 | clear_old_cpu_label(ginfo, cpu); | ||
92 | } | ||
93 | |||
94 | static void __draw_cpu_label(struct graph_info *ginfo, gint cpu) | ||
95 | { | ||
96 | PangoLayout *layout; | ||
97 | gchar buf[BUFSIZ]; | ||
98 | gint width, height; | ||
99 | |||
100 | snprintf(buf, BUFSIZ, "CPU %d", cpu); | ||
101 | |||
102 | layout = gtk_widget_create_pango_layout(ginfo->draw, buf); | ||
103 | pango_layout_get_pixel_size(layout, &width, &height); | ||
104 | width += 4; | ||
105 | |||
106 | if (width > largest_cpu_label) | ||
107 | largest_cpu_label = width; | ||
108 | gdk_draw_rectangle(ginfo->draw->window, | ||
109 | ginfo->draw->style->white_gc, | ||
110 | TRUE, | ||
111 | ginfo->cpu_x, CPU_LABEL(cpu)+4, | ||
112 | width, height); | ||
113 | gdk_draw_layout(ginfo->draw->window, | ||
114 | ginfo->draw->style->black_gc, | ||
115 | ginfo->cpu_x + 2, CPU_LABEL(cpu) + 4, | ||
116 | layout); | ||
117 | g_object_unref(layout); | ||
118 | } | ||
119 | |||
120 | static void draw_cpu_label(struct graph_info *ginfo, gint cpu) | ||
121 | { | ||
122 | clear_old_cpu_label(ginfo, cpu); | ||
123 | __draw_cpu_label(ginfo, cpu); | ||
124 | } | ||
125 | |||
126 | |||
127 | static void draw_cpu_labels(struct graph_info *ginfo) | ||
128 | { | ||
129 | gint cpu; | ||
130 | |||
131 | clear_old_cpu_labels(ginfo); | ||
132 | ginfo->cpu_x = gtk_adjustment_get_value(ginfo->vadj) + 5; | ||
133 | |||
134 | for (cpu = 0; cpu < ginfo->cpus; cpu++) | ||
135 | __draw_cpu_label(ginfo, cpu); | ||
136 | } | ||
137 | |||
138 | static void draw_cursor(struct graph_info *ginfo) | 80 | static void draw_cursor(struct graph_info *ginfo) |
139 | { | 81 | { |
140 | gint x; | 82 | gint x; |
@@ -154,20 +96,10 @@ static void update_with_backend(struct graph_info *ginfo, | |||
154 | gint x, gint y, | 96 | gint x, gint y, |
155 | gint width, gint height) | 97 | gint width, gint height) |
156 | { | 98 | { |
157 | gint cpu; | ||
158 | |||
159 | __update_with_backend(ginfo, x, y, width, height); | 99 | __update_with_backend(ginfo, x, y, width, height); |
160 | 100 | ||
161 | if (ginfo->cursor) | 101 | if (ginfo->cursor) |
162 | draw_cursor(ginfo); | 102 | draw_cursor(ginfo); |
163 | |||
164 | for (cpu = 0; cpu < ginfo->cpus; cpu++ ) { | ||
165 | if (y <= CPU_BOTTOM(cpu) && | ||
166 | y + height > CPU_TOP(cpu) && | ||
167 | x + width > ginfo->cpu_x && | ||
168 | x <= ginfo->cpu_x + largest_cpu_label) | ||
169 | draw_cpu_label(ginfo, cpu); | ||
170 | } | ||
171 | } | 103 | } |
172 | 104 | ||
173 | static gboolean | 105 | static gboolean |
@@ -677,12 +609,13 @@ static void zoom_in_window(struct graph_info *ginfo, gint start, gint end) | |||
677 | static gboolean | 609 | static gboolean |
678 | value_changed(GtkWidget *widget, gpointer data) | 610 | value_changed(GtkWidget *widget, gpointer data) |
679 | { | 611 | { |
612 | #if 0 | ||
680 | struct graph_info *ginfo = data; | 613 | struct graph_info *ginfo = data; |
681 | GtkAdjustment *adj = GTK_ADJUSTMENT(widget); | 614 | GtkAdjustment *adj = GTK_ADJUSTMENT(widget); |
682 | 615 | ||
683 | draw_cpu_labels(ginfo); | ||
684 | printf("value = %f\n", | 616 | printf("value = %f\n", |
685 | gtk_adjustment_get_value(adj)); | 617 | gtk_adjustment_get_value(adj)); |
618 | #endif | ||
686 | 619 | ||
687 | return TRUE; | 620 | return TRUE; |
688 | 621 | ||
@@ -1096,8 +1029,6 @@ static void draw_info(struct graph_info *ginfo, | |||
1096 | draw_cpu(ginfo, cpu, new_width, read_comms); | 1029 | draw_cpu(ginfo, cpu, new_width, read_comms); |
1097 | 1030 | ||
1098 | read_comms = 0; | 1031 | read_comms = 0; |
1099 | |||
1100 | draw_cpu_labels(ginfo); | ||
1101 | } | 1032 | } |
1102 | 1033 | ||
1103 | void trace_graph_select_by_time(struct graph_info *ginfo, guint64 time) | 1034 | void trace_graph_select_by_time(struct graph_info *ginfo, guint64 time) |
@@ -1225,6 +1156,103 @@ destroy_event(GtkWidget *widget, gpointer data) | |||
1225 | return TRUE; | 1156 | return TRUE; |
1226 | } | 1157 | } |
1227 | 1158 | ||
1159 | static gboolean | ||
1160 | info_expose_event(GtkWidget *widget, GdkEventExpose *event, gpointer data) | ||
1161 | { | ||
1162 | struct graph_info *ginfo = data; | ||
1163 | |||
1164 | gdk_draw_drawable(ginfo->info->window, | ||
1165 | ginfo->info->style->fg_gc[GTK_WIDGET_STATE(ginfo->info)], | ||
1166 | ginfo->info_pixmap, | ||
1167 | event->area.x, event->area.y, | ||
1168 | event->area.x, event->area.y, | ||
1169 | event->area.width, event->area.height); | ||
1170 | |||
1171 | return FALSE; | ||
1172 | } | ||
1173 | |||
1174 | static void info_draw_cpu_label(struct graph_info *ginfo, gint cpu) | ||
1175 | { | ||
1176 | PangoLayout *layout; | ||
1177 | gchar buf[BUFSIZ]; | ||
1178 | gint width, height; | ||
1179 | |||
1180 | snprintf(buf, BUFSIZ, "CPU %d", cpu); | ||
1181 | |||
1182 | layout = gtk_widget_create_pango_layout(ginfo->info, buf); | ||
1183 | pango_layout_get_pixel_size(layout, &width, &height); | ||
1184 | width += 4; | ||
1185 | |||
1186 | if (width > largest_cpu_label) | ||
1187 | largest_cpu_label = width; | ||
1188 | gdk_draw_rectangle(ginfo->info_pixmap, | ||
1189 | ginfo->info->style->white_gc, | ||
1190 | TRUE, | ||
1191 | CPU_X, CPU_LABEL(cpu)+4, | ||
1192 | width, height); | ||
1193 | gdk_draw_layout(ginfo->info_pixmap, | ||
1194 | ginfo->info->style->black_gc, | ||
1195 | CPU_X+ 2, CPU_LABEL(cpu) + 4, | ||
1196 | layout); | ||
1197 | g_object_unref(layout); | ||
1198 | } | ||
1199 | |||
1200 | static void info_draw_cpu_labels(struct graph_info *ginfo) | ||
1201 | { | ||
1202 | gint cpu; | ||
1203 | #if 0 | ||
1204 | clear_old_cpu_labels(ginfo); | ||
1205 | ginfo->cpu_x = gtk_adjustment_get_value(ginfo->vadj) + 5; | ||
1206 | #endif | ||
1207 | |||
1208 | for (cpu = 0; cpu < ginfo->cpus; cpu++) | ||
1209 | info_draw_cpu_label(ginfo, cpu); | ||
1210 | } | ||
1211 | |||
1212 | static gboolean | ||
1213 | info_configure_event(GtkWidget *widget, GdkEventMotion *event, gpointer data) | ||
1214 | { | ||
1215 | struct graph_info *ginfo = data; | ||
1216 | |||
1217 | if (ginfo->info_pixmap) | ||
1218 | g_object_unref(ginfo->info_pixmap); | ||
1219 | |||
1220 | ginfo->info_pixmap = gdk_pixmap_new(ginfo->info->window, | ||
1221 | ginfo->info->allocation.width, | ||
1222 | ginfo->info->allocation.height, | ||
1223 | -1); | ||
1224 | |||
1225 | gdk_draw_rectangle(ginfo->info_pixmap, | ||
1226 | ginfo->info->style->white_gc, | ||
1227 | TRUE, | ||
1228 | 0, 0, | ||
1229 | ginfo->info->allocation.width, | ||
1230 | ginfo->info->allocation.height); | ||
1231 | |||
1232 | info_draw_cpu_labels(ginfo); | ||
1233 | |||
1234 | gtk_widget_set_size_request(ginfo->info, largest_cpu_label + 10, | ||
1235 | ginfo->draw_height); | ||
1236 | |||
1237 | return TRUE; | ||
1238 | } | ||
1239 | |||
1240 | static GtkWidget * | ||
1241 | create_graph_info(struct graph_info *ginfo) | ||
1242 | { | ||
1243 | GtkWidget *info; | ||
1244 | |||
1245 | info = gtk_drawing_area_new(); | ||
1246 | |||
1247 | gtk_signal_connect(GTK_OBJECT(info), "expose_event", | ||
1248 | (GtkSignalFunc) info_expose_event, ginfo); | ||
1249 | gtk_signal_connect(GTK_OBJECT(info), "configure_event", | ||
1250 | (GtkSignalFunc) info_configure_event, ginfo); | ||
1251 | |||
1252 | gtk_widget_set_events(info, GDK_EXPOSURE_MASK); | ||
1253 | |||
1254 | return info; | ||
1255 | } | ||
1228 | 1256 | ||
1229 | struct graph_info * | 1257 | struct graph_info * |
1230 | trace_graph_create_with_callbacks(struct tracecmd_input *handle, | 1258 | trace_graph_create_with_callbacks(struct tracecmd_input *handle, |
@@ -1256,6 +1284,22 @@ trace_graph_create_with_callbacks(struct tracecmd_input *handle, | |||
1256 | GTK_POLICY_AUTOMATIC); | 1284 | GTK_POLICY_AUTOMATIC); |
1257 | gtk_widget_show(ginfo->scrollwin); | 1285 | gtk_widget_show(ginfo->scrollwin); |
1258 | 1286 | ||
1287 | |||
1288 | ginfo->info_scrollwin = gtk_scrolled_window_new(NULL, | ||
1289 | gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(ginfo->scrollwin))); | ||
1290 | |||
1291 | gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(ginfo->info_scrollwin), | ||
1292 | GTK_POLICY_NEVER, | ||
1293 | GTK_POLICY_NEVER); | ||
1294 | gtk_widget_show(ginfo->info_scrollwin); | ||
1295 | gtk_box_pack_start(GTK_BOX(ginfo->widget), ginfo->info_scrollwin, FALSE, FALSE, 0); | ||
1296 | |||
1297 | ginfo->info = create_graph_info(ginfo); | ||
1298 | gtk_widget_show(ginfo->info); | ||
1299 | |||
1300 | gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(ginfo->info_scrollwin), | ||
1301 | ginfo->info); | ||
1302 | |||
1259 | gtk_box_pack_start(GTK_BOX (ginfo->widget), ginfo->scrollwin, TRUE, TRUE, 0); | 1303 | gtk_box_pack_start(GTK_BOX (ginfo->widget), ginfo->scrollwin, TRUE, TRUE, 0); |
1260 | 1304 | ||
1261 | ginfo->draw_height = CPU_SPACE(ginfo->cpus); | 1305 | ginfo->draw_height = CPU_SPACE(ginfo->cpus); |
diff --git a/trace-graph.h b/trace-graph.h index d1b6c6f..a9d7293 100644 --- a/trace-graph.h +++ b/trace-graph.h | |||
@@ -17,9 +17,11 @@ struct graph_info { | |||
17 | gint cpus; | 17 | gint cpus; |
18 | GtkWidget *widget; /* Box to hold graph */ | 18 | GtkWidget *widget; /* Box to hold graph */ |
19 | GtkWidget *scrollwin; /* graph scroll window */ | 19 | GtkWidget *scrollwin; /* graph scroll window */ |
20 | GtkWidget *info_scrollwin; /* graph scroll window (for info widget) */ | ||
20 | GtkWidget *info; /* info window */ | 21 | GtkWidget *info; /* info window */ |
21 | GtkWidget *draw; | 22 | GtkWidget *draw; |
22 | GdkPixmap *curr_pixmap; /* pixmap backstore */ | 23 | GdkPixmap *curr_pixmap; /* pixmap backstore */ |
24 | GdkPixmap *info_pixmap; /* pixmap backstore */ | ||
23 | GtkAdjustment *vadj; /* scrollwindow vert adjust */ | 25 | GtkAdjustment *vadj; /* scrollwindow vert adjust */ |
24 | guint64 start_time; /* True start time of trace */ | 26 | guint64 start_time; /* True start time of trace */ |
25 | guint64 end_time; /* True end time of trace */ | 27 | guint64 end_time; /* True end time of trace */ |