diff options
author | Steven Rostedt <rostedt@goodmis.org> | 2009-12-22 15:44:27 -0500 |
---|---|---|
committer | Steven Rostedt <rostedt@goodmis.org> | 2009-12-22 15:44:27 -0500 |
commit | 5e54d490c9ef2faf6cda0c7b91ccb670038d733a (patch) | |
tree | f5f2335fcf40208d15eea8252ac04d607aece8c4 | |
parent | 50cc61439893bc8d60f8ec310a50b53a5178c5dc (diff) |
kernel-shark: Add callbacks from trace-graph for selection
Add a way for events in the trace graph to call back into the
kernel shark code. Implement the select first.
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
-rw-r--r-- | kernel-shark.c | 32 | ||||
-rw-r--r-- | kernel-shark.h | 1 | ||||
-rw-r--r-- | trace-graph.c | 13 | ||||
-rw-r--r-- | trace-graph.h | 18 |
4 files changed, 62 insertions, 2 deletions
diff --git a/kernel-shark.c b/kernel-shark.c index 8fd16c9..ce4df11 100644 --- a/kernel-shark.c +++ b/kernel-shark.c | |||
@@ -36,6 +36,33 @@ | |||
36 | 36 | ||
37 | #define input_file "trace.dat" | 37 | #define input_file "trace.dat" |
38 | 38 | ||
39 | /* graph callbacks */ | ||
40 | |||
41 | /* convert_nano() and print_time() are copied from trace-graph.c for debugging | ||
42 | purposes, and should be deleted when this is complete (or merged with | ||
43 | trace-graph.c */ | ||
44 | |||
45 | static void convert_nano(unsigned long long time, unsigned long *sec, | ||
46 | unsigned long *usec) | ||
47 | { | ||
48 | *sec = time / 1000000000ULL; | ||
49 | *usec = (time / 1000) % 1000000; | ||
50 | } | ||
51 | |||
52 | static void print_time(unsigned long long time) | ||
53 | { | ||
54 | unsigned long sec, usec; | ||
55 | |||
56 | convert_nano(time, &sec, &usec); | ||
57 | printf("%lu.%06lu", sec, usec); | ||
58 | } | ||
59 | |||
60 | static void ks_graph_select(struct graph_info *ginfo, guint64 cursor) | ||
61 | { | ||
62 | printf("Cursor: "); | ||
63 | print_time(cursor); | ||
64 | printf(" selected\n"); | ||
65 | } | ||
39 | 66 | ||
40 | /* Callback for the clicked signal of the Exit button */ | 67 | /* Callback for the clicked signal of the Exit button */ |
41 | static void | 68 | static void |
@@ -211,7 +238,10 @@ void kernel_shark(int argc, char **argv) | |||
211 | 238 | ||
212 | /* --- Set up Drawing --- */ | 239 | /* --- Set up Drawing --- */ |
213 | 240 | ||
214 | info->ginfo = trace_graph_create(handle, GTK_SCROLLED_WINDOW(scrollwin)); | 241 | info->graph_cbs.select = ks_graph_select; |
242 | |||
243 | info->ginfo = trace_graph_create_with_callbacks(handle, GTK_SCROLLED_WINDOW(scrollwin), | ||
244 | &info->graph_cbs); | ||
215 | draw = trace_graph_get_draw(info->ginfo); | 245 | draw = trace_graph_get_draw(info->ginfo); |
216 | 246 | ||
217 | gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(scrollwin), | 247 | gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(scrollwin), |
diff --git a/kernel-shark.h b/kernel-shark.h index 58761b0..1e6302f 100644 --- a/kernel-shark.h +++ b/kernel-shark.h | |||
@@ -7,6 +7,7 @@ | |||
7 | struct shark_info { | 7 | struct shark_info { |
8 | struct graph_info *ginfo; | 8 | struct graph_info *ginfo; |
9 | GtkWidget *treeview; | 9 | GtkWidget *treeview; |
10 | struct graph_callbacks graph_cbs; | ||
10 | }; | 11 | }; |
11 | 12 | ||
12 | #endif /* _KERNEL_SHARK_H */ | 13 | #endif /* _KERNEL_SHARK_H */ |
diff --git a/trace-graph.c b/trace-graph.c index d97c4d1..15dfbd7 100644 --- a/trace-graph.c +++ b/trace-graph.c | |||
@@ -221,6 +221,8 @@ button_press_event(GtkWidget *widget, GdkEventButton *event, gpointer data) | |||
221 | ginfo->cursor = event->x / ginfo->resolution + | 221 | ginfo->cursor = event->x / ginfo->resolution + |
222 | ginfo->view_start_time; | 222 | ginfo->view_start_time; |
223 | draw_cursor(ginfo); | 223 | draw_cursor(ginfo); |
224 | if (ginfo->callbacks && ginfo->callbacks->select) | ||
225 | ginfo->callbacks->select(ginfo, ginfo->cursor); | ||
224 | return TRUE; | 226 | return TRUE; |
225 | } | 227 | } |
226 | 228 | ||
@@ -1150,7 +1152,8 @@ destroy_event(GtkWidget *widget, gpointer data) | |||
1150 | 1152 | ||
1151 | 1153 | ||
1152 | struct graph_info * | 1154 | struct graph_info * |
1153 | trace_graph_create(struct tracecmd_input *handle, GtkScrolledWindow *scrollwin) | 1155 | trace_graph_create_with_callbacks(struct tracecmd_input *handle, GtkScrolledWindow *scrollwin, |
1156 | struct graph_callbacks *cbs) | ||
1154 | { | 1157 | { |
1155 | struct graph_info *ginfo; | 1158 | struct graph_info *ginfo; |
1156 | unsigned long sec, usec; | 1159 | unsigned long sec, usec; |
@@ -1164,6 +1167,8 @@ trace_graph_create(struct tracecmd_input *handle, GtkScrolledWindow *scrollwin) | |||
1164 | ginfo->pevent = tracecmd_get_pevent(handle); | 1167 | ginfo->pevent = tracecmd_get_pevent(handle); |
1165 | ginfo->cpus = tracecmd_cpus(handle); | 1168 | ginfo->cpus = tracecmd_cpus(handle); |
1166 | 1169 | ||
1170 | ginfo->callbacks = cbs; | ||
1171 | |||
1167 | ginfo->start_time = -1ULL; | 1172 | ginfo->start_time = -1ULL; |
1168 | ginfo->end_time = 0; | 1173 | ginfo->end_time = 0; |
1169 | 1174 | ||
@@ -1223,3 +1228,9 @@ trace_graph_create(struct tracecmd_input *handle, GtkScrolledWindow *scrollwin) | |||
1223 | 1228 | ||
1224 | return ginfo; | 1229 | return ginfo; |
1225 | } | 1230 | } |
1231 | |||
1232 | struct graph_info * | ||
1233 | trace_graph_create(struct tracecmd_input *handle, GtkScrolledWindow *scrollwin) | ||
1234 | { | ||
1235 | return trace_graph_create_with_callbacks(handle, scrollwin, NULL); | ||
1236 | } | ||
diff --git a/trace-graph.h b/trace-graph.h index dd5f58b..3f6de2d 100644 --- a/trace-graph.h +++ b/trace-graph.h | |||
@@ -3,6 +3,14 @@ | |||
3 | 3 | ||
4 | #include "trace-cmd.h" | 4 | #include "trace-cmd.h" |
5 | 5 | ||
6 | struct graph_info; | ||
7 | |||
8 | typedef void (graph_select_cb)(struct graph_info *ginfo, guint64 time); | ||
9 | |||
10 | struct graph_callbacks { | ||
11 | graph_select_cb *select; | ||
12 | }; | ||
13 | |||
6 | struct graph_info { | 14 | struct graph_info { |
7 | struct tracecmd_input *handle; | 15 | struct tracecmd_input *handle; |
8 | struct pevent *pevent; | 16 | struct pevent *pevent; |
@@ -32,6 +40,8 @@ struct graph_info { | |||
32 | gint full_width; /* width of full trace in pixels */ | 40 | gint full_width; /* width of full trace in pixels */ |
33 | /* This includes non visible part of trace */ | 41 | /* This includes non visible part of trace */ |
34 | 42 | ||
43 | struct graph_callbacks *callbacks; /* call back hooks for changes to graph */ | ||
44 | |||
35 | /* Box info for CPU data info window */ | 45 | /* Box info for CPU data info window */ |
36 | gint cpu_data_x; | 46 | gint cpu_data_x; |
37 | gint cpu_data_y; | 47 | gint cpu_data_y; |
@@ -48,10 +58,18 @@ struct graph_info { | |||
48 | 58 | ||
49 | struct graph_info * | 59 | struct graph_info * |
50 | trace_graph_create(struct tracecmd_input *handle, GtkScrolledWindow *scrollwin); | 60 | trace_graph_create(struct tracecmd_input *handle, GtkScrolledWindow *scrollwin); |
61 | struct graph_info * | ||
62 | trace_graph_create_with_callbacks(struct tracecmd_input *handle, GtkScrolledWindow *scrollwin, | ||
63 | struct graph_callbacks *cbs); | ||
51 | 64 | ||
52 | static inline GtkWidget *trace_graph_get_draw(struct graph_info *ginfo) | 65 | static inline GtkWidget *trace_graph_get_draw(struct graph_info *ginfo) |
53 | { | 66 | { |
54 | return ginfo->draw; | 67 | return ginfo->draw; |
55 | } | 68 | } |
56 | 69 | ||
70 | static inline struct graph_callbacks *trace_graph_get_callbacks(struct graph_info *ginfo) | ||
71 | { | ||
72 | return ginfo->callbacks; | ||
73 | } | ||
74 | |||
57 | #endif /* _TRACE_GRAPH_H */ | 75 | #endif /* _TRACE_GRAPH_H */ |