diff options
author | Steven Rostedt <srostedt@redhat.com> | 2010-02-10 17:14:28 -0500 |
---|---|---|
committer | Steven Rostedt <rostedt@goodmis.org> | 2010-02-10 17:14:28 -0500 |
commit | bdd0561e19389a10901240dc907a969d9f97c898 (patch) | |
tree | d35822214d1fffdddbd461953e987fce2616f61a | |
parent | 6386dc2ff83f321883f5eecb40f0b6ab414f9e46 (diff) |
trace-graph: Add hash to lookup pids and cpus
Add a hash in the graph info to quickly look up to see if plots
have been registered to a pid or cpus. This is currently not used
but will be in the following patches.
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
-rw-r--r-- | trace-graph.c | 3 | ||||
-rw-r--r-- | trace-graph.h | 42 | ||||
-rw-r--r-- | trace-plot-cpu.c | 5 | ||||
-rw-r--r-- | trace-plot-task.c | 7 | ||||
-rw-r--r-- | trace-plot.c | 133 |
5 files changed, 171 insertions, 19 deletions
diff --git a/trace-graph.c b/trace-graph.c index 85009cf..f1f0a2c 100644 --- a/trace-graph.c +++ b/trace-graph.c | |||
@@ -1626,7 +1626,6 @@ static void draw_info(struct graph_info *ginfo, | |||
1626 | 1626 | ||
1627 | draw_timeline(ginfo, new_width); | 1627 | draw_timeline(ginfo, new_width); |
1628 | 1628 | ||
1629 | |||
1630 | for (i = 0; i < ginfo->plots; i++) | 1629 | for (i = 0; i < ginfo->plots; i++) |
1631 | draw_plot(ginfo, i, new_width, ginfo->read_comms); | 1630 | draw_plot(ginfo, i, new_width, ginfo->read_comms); |
1632 | 1631 | ||
@@ -2087,7 +2086,7 @@ trace_graph_create_with_callbacks(struct tracecmd_input *handle, | |||
2087 | 2086 | ||
2088 | ginfo->task_filter = filter_task_hash_alloc(); | 2087 | ginfo->task_filter = filter_task_hash_alloc(); |
2089 | ginfo->hide_tasks = filter_task_hash_alloc(); | 2088 | ginfo->hide_tasks = filter_task_hash_alloc(); |
2090 | 2089 | ||
2091 | ginfo->widget = gtk_hbox_new(FALSE, 0); | 2090 | ginfo->widget = gtk_hbox_new(FALSE, 0); |
2092 | gtk_widget_show(ginfo->widget); | 2091 | gtk_widget_show(ginfo->widget); |
2093 | 2092 | ||
diff --git a/trace-graph.h b/trace-graph.h index 8e75dbb..f7bc117 100644 --- a/trace-graph.h +++ b/trace-graph.h | |||
@@ -81,6 +81,7 @@ struct plot_callbacks { | |||
81 | }; | 81 | }; |
82 | 82 | ||
83 | struct graph_plot { | 83 | struct graph_plot { |
84 | struct graph_plot *next; /* for hash */ | ||
84 | int pos; | 85 | int pos; |
85 | char *label; | 86 | char *label; |
86 | const struct plot_callbacks *cb; | 87 | const struct plot_callbacks *cb; |
@@ -92,6 +93,14 @@ struct graph_callbacks { | |||
92 | graph_filter_cb *filter; | 93 | graph_filter_cb *filter; |
93 | }; | 94 | }; |
94 | 95 | ||
96 | struct plot_hash { | ||
97 | struct plot_hash *next; | ||
98 | struct graph_plot *plots; | ||
99 | gint val; | ||
100 | }; | ||
101 | |||
102 | #define PLOT_HASH_SIZE 1024 | ||
103 | |||
95 | struct graph_info { | 104 | struct graph_info { |
96 | struct tracecmd_input *handle; | 105 | struct tracecmd_input *handle; |
97 | struct pevent *pevent; | 106 | struct pevent *pevent; |
@@ -101,6 +110,9 @@ struct graph_info { | |||
101 | struct graph_plot **plot_array; /* all plots */ | 110 | struct graph_plot **plot_array; /* all plots */ |
102 | struct graph_plot *plot_clicked; /* plot that was clicked on */ | 111 | struct graph_plot *plot_clicked; /* plot that was clicked on */ |
103 | 112 | ||
113 | gint nr_task_hash; | ||
114 | struct plot_hash *task_hash[PLOT_HASH_SIZE]; | ||
115 | struct plot_hash *cpu_hash[PLOT_HASH_SIZE]; | ||
104 | 116 | ||
105 | GtkWidget *widget; /* Box to hold graph */ | 117 | GtkWidget *widget; /* Box to hold graph */ |
106 | GtkWidget *scrollwin; /* graph scroll window */ | 118 | GtkWidget *scrollwin; /* graph scroll window */ |
@@ -226,15 +238,29 @@ gboolean trace_graph_filter_on_event(struct graph_info *ginfo, struct record *re | |||
226 | /* plots */ | 238 | /* plots */ |
227 | void trace_graph_plot_free(struct graph_info *ginfo); | 239 | void trace_graph_plot_free(struct graph_info *ginfo); |
228 | void trace_graph_plot_init(struct graph_info *ginfo); | 240 | void trace_graph_plot_init(struct graph_info *ginfo); |
229 | void trace_graph_plot_append(struct graph_info *ginfo, | 241 | struct graph_plot *trace_graph_plot_append(struct graph_info *ginfo, |
230 | const char *label, const struct plot_callbacks *cb, | 242 | const char *label, |
231 | void *data); | 243 | const struct plot_callbacks *cb, |
232 | void trace_graph_plot_insert(struct graph_info *ginfo, | 244 | void *data); |
233 | int pos, | 245 | struct graph_plot *trace_graph_plot_insert(struct graph_info *ginfo, |
234 | const char *label, const struct plot_callbacks *cb, | 246 | int pos, |
235 | void *data); | 247 | const char *label, |
248 | const struct plot_callbacks *cb, | ||
249 | void *data); | ||
236 | void trace_graph_plot_remove(struct graph_info *ginfo, struct graph_plot *plot); | 250 | void trace_graph_plot_remove(struct graph_info *ginfo, struct graph_plot *plot); |
237 | 251 | struct plot_hash *trace_graph_plot_find_task(struct graph_info *ginfo, gint task); | |
252 | void trace_graph_plot_add_task(struct graph_info *ginfo, struct graph_plot *plot, | ||
253 | gint task); | ||
254 | void trace_graph_plot_remove_task(struct graph_info *ginfo, | ||
255 | struct graph_plot *plot, | ||
256 | gint task); | ||
257 | struct plot_hash *trace_graph_plot_find_cpu(struct graph_info *ginfo, gint cpu); | ||
258 | void trace_graph_plot_add_cpu(struct graph_info *ginfo, struct graph_plot *plot, | ||
259 | gint cpu); | ||
260 | void trace_graph_plot_remove_cpu(struct graph_info *ginfo, struct graph_plot *plot, | ||
261 | gint cpu); | ||
262 | |||
263 | /* plot callbacks */ | ||
238 | int trace_graph_plot_match_time(struct graph_info *ginfo, | 264 | int trace_graph_plot_match_time(struct graph_info *ginfo, |
239 | struct graph_plot *plot, | 265 | struct graph_plot *plot, |
240 | unsigned long long time); | 266 | unsigned long long time); |
diff --git a/trace-plot-cpu.c b/trace-plot-cpu.c index 7fd9ecc..2690155 100644 --- a/trace-plot-cpu.c +++ b/trace-plot-cpu.c | |||
@@ -398,6 +398,7 @@ void cpu_plot_destroy(struct graph_info *ginfo, struct graph_plot *plot) | |||
398 | { | 398 | { |
399 | struct cpu_plot_info *cpu_info = plot->private; | 399 | struct cpu_plot_info *cpu_info = plot->private; |
400 | 400 | ||
401 | trace_graph_plot_remove_cpu(ginfo, plot, cpu_info->cpu); | ||
401 | free(cpu_info); | 402 | free(cpu_info); |
402 | } | 403 | } |
403 | 404 | ||
@@ -414,6 +415,7 @@ static const struct plot_callbacks cpu_plot_cb = { | |||
414 | void graph_plot_init_cpus(struct graph_info *ginfo, int cpus) | 415 | void graph_plot_init_cpus(struct graph_info *ginfo, int cpus) |
415 | { | 416 | { |
416 | struct cpu_plot_info *cpu_info; | 417 | struct cpu_plot_info *cpu_info; |
418 | struct graph_plot *plot; | ||
417 | char label[100]; | 419 | char label[100]; |
418 | long cpu; | 420 | long cpu; |
419 | 421 | ||
@@ -423,6 +425,7 @@ void graph_plot_init_cpus(struct graph_info *ginfo, int cpus) | |||
423 | 425 | ||
424 | snprintf(label, 100, "CPU %ld", cpu); | 426 | snprintf(label, 100, "CPU %ld", cpu); |
425 | 427 | ||
426 | trace_graph_plot_append(ginfo, label, &cpu_plot_cb, cpu_info); | 428 | plot = trace_graph_plot_append(ginfo, label, &cpu_plot_cb, cpu_info); |
429 | trace_graph_plot_add_cpu(ginfo, plot, cpu); | ||
427 | } | 430 | } |
428 | } | 431 | } |
diff --git a/trace-plot-task.c b/trace-plot-task.c index abe4025..6b35586 100644 --- a/trace-plot-task.c +++ b/trace-plot-task.c | |||
@@ -536,6 +536,8 @@ void task_plot_destroy(struct graph_info *ginfo, struct graph_plot *plot) | |||
536 | { | 536 | { |
537 | struct task_plot_info *task_info = plot->private; | 537 | struct task_plot_info *task_info = plot->private; |
538 | 538 | ||
539 | trace_graph_plot_remove_task(ginfo, plot, task_info->pid); | ||
540 | |||
539 | free(task_info); | 541 | free(task_info); |
540 | } | 542 | } |
541 | 543 | ||
@@ -576,11 +578,14 @@ void graph_plot_init_tasks(struct graph_info *ginfo) | |||
576 | void graph_plot_task(struct graph_info *ginfo, int pid) | 578 | void graph_plot_task(struct graph_info *ginfo, int pid) |
577 | { | 579 | { |
578 | struct task_plot_info *task_info; | 580 | struct task_plot_info *task_info; |
581 | struct graph_plot *plot; | ||
579 | char label[100]; | 582 | char label[100]; |
580 | 583 | ||
581 | task_info = malloc_or_die(sizeof(*task_info)); | 584 | task_info = malloc_or_die(sizeof(*task_info)); |
582 | task_info->pid = pid; | 585 | task_info->pid = pid; |
583 | 586 | ||
584 | snprintf(label, 100, "TASK %d", pid); | 587 | snprintf(label, 100, "TASK %d", pid); |
585 | trace_graph_plot_append(ginfo, label, &task_plot_cb, task_info); | 588 | plot = trace_graph_plot_append(ginfo, label, &task_plot_cb, task_info); |
589 | |||
590 | trace_graph_plot_add_task(ginfo, plot, pid); | ||
586 | } | 591 | } |
diff --git a/trace-plot.c b/trace-plot.c index c6f7e7a..5f0ab75 100644 --- a/trace-plot.c +++ b/trace-plot.c | |||
@@ -44,9 +44,10 @@ allocate_plot(struct graph_info *ginfo, | |||
44 | return plot; | 44 | return plot; |
45 | } | 45 | } |
46 | 46 | ||
47 | void trace_graph_plot_append(struct graph_info *ginfo, | 47 | struct graph_plot * |
48 | const char *label, const struct plot_callbacks *cb, | 48 | trace_graph_plot_append(struct graph_info *ginfo, |
49 | void *data) | 49 | const char *label, const struct plot_callbacks *cb, |
50 | void *data) | ||
50 | { | 51 | { |
51 | struct graph_plot *plot; | 52 | struct graph_plot *plot; |
52 | 53 | ||
@@ -69,12 +70,15 @@ void trace_graph_plot_append(struct graph_info *ginfo, | |||
69 | } | 70 | } |
70 | 71 | ||
71 | ginfo->plots++; | 72 | ginfo->plots++; |
73 | |||
74 | return plot; | ||
72 | } | 75 | } |
73 | 76 | ||
74 | void trace_graph_plot_insert(struct graph_info *ginfo, | 77 | struct graph_plot * |
75 | int pos, | 78 | trace_graph_plot_insert(struct graph_info *ginfo, |
76 | const char *label, const struct plot_callbacks *cb, | 79 | int pos, |
77 | void *data) | 80 | const char *label, const struct plot_callbacks *cb, |
81 | void *data) | ||
78 | { | 82 | { |
79 | struct graph_plot *plot; | 83 | struct graph_plot *plot; |
80 | int i; | 84 | int i; |
@@ -104,6 +108,8 @@ void trace_graph_plot_insert(struct graph_info *ginfo, | |||
104 | /* Update the new positions */ | 108 | /* Update the new positions */ |
105 | for (i = pos + 1; i < ginfo->plots; i++) | 109 | for (i = pos + 1; i < ginfo->plots; i++) |
106 | ginfo->plot_array[i]->pos = i; | 110 | ginfo->plot_array[i]->pos = i; |
111 | |||
112 | return plot; | ||
107 | } | 113 | } |
108 | 114 | ||
109 | void trace_graph_plot_remove(struct graph_info *ginfo, struct graph_plot *plot) | 115 | void trace_graph_plot_remove(struct graph_info *ginfo, struct graph_plot *plot) |
@@ -131,6 +137,119 @@ void trace_graph_plot_remove(struct graph_info *ginfo, struct graph_plot *plot) | |||
131 | } | 137 | } |
132 | } | 138 | } |
133 | 139 | ||
140 | static struct plot_hash *find_hash(struct plot_hash **array, gint val) | ||
141 | { | ||
142 | struct plot_hash *hash; | ||
143 | gint key; | ||
144 | |||
145 | key = trace_hash(val) % PLOT_HASH_SIZE; | ||
146 | |||
147 | for (hash = array[key]; hash; hash = hash->next) { | ||
148 | if (hash->val == val) | ||
149 | return hash; | ||
150 | } | ||
151 | |||
152 | return NULL; | ||
153 | } | ||
154 | |||
155 | static void add_hash(struct plot_hash **array, struct graph_plot *plot, gint val) | ||
156 | { | ||
157 | struct plot_hash *hash; | ||
158 | gint key; | ||
159 | |||
160 | hash = find_hash(array, val); | ||
161 | if (!hash) { | ||
162 | hash = g_new0(typeof(*hash), 1); | ||
163 | g_assert(hash); | ||
164 | key = trace_hash(val) % PLOT_HASH_SIZE; | ||
165 | hash->next = array[key]; | ||
166 | hash->val = val; | ||
167 | array[key] = hash; | ||
168 | } | ||
169 | |||
170 | plot->next = hash->plots; | ||
171 | hash->plots = plot; | ||
172 | } | ||
173 | |||
174 | static void remove_hash(struct plot_hash **array, struct graph_plot *plot, gint val) | ||
175 | { | ||
176 | struct plot_hash *hash, **phash; | ||
177 | struct graph_plot **pplot; | ||
178 | gint key; | ||
179 | |||
180 | hash = find_hash(array, val); | ||
181 | pplot = &hash->plots; | ||
182 | |||
183 | while (*pplot) { | ||
184 | if (*pplot == plot) { | ||
185 | *pplot = plot->next; | ||
186 | break; | ||
187 | } | ||
188 | pplot = &(*pplot)->next; | ||
189 | } | ||
190 | |||
191 | if (hash->plots) | ||
192 | return; | ||
193 | |||
194 | /* remove this hash item */ | ||
195 | key = trace_hash(val) % PLOT_HASH_SIZE; | ||
196 | phash = &array[key]; | ||
197 | while (*phash) { | ||
198 | if (*phash == hash) { | ||
199 | *phash = hash->next; | ||
200 | break; | ||
201 | } | ||
202 | phash = &(*phash)->next; | ||
203 | } | ||
204 | |||
205 | g_free(hash); | ||
206 | } | ||
207 | |||
208 | struct plot_hash * | ||
209 | trace_graph_plot_find_task(struct graph_info *ginfo, gint task) | ||
210 | { | ||
211 | return find_hash(ginfo->task_hash, task); | ||
212 | } | ||
213 | |||
214 | void trace_graph_plot_add_task(struct graph_info *ginfo, | ||
215 | struct graph_plot *plot, | ||
216 | gint task) | ||
217 | { | ||
218 | add_hash(ginfo->task_hash, plot, task); | ||
219 | ginfo->nr_task_hash++; | ||
220 | } | ||
221 | |||
222 | void trace_graph_plot_remove_task(struct graph_info *ginfo, | ||
223 | struct graph_plot *plot, | ||
224 | gint task) | ||
225 | { | ||
226 | remove_hash(ginfo->task_hash, plot, task); | ||
227 | ginfo->nr_task_hash--; | ||
228 | } | ||
229 | |||
230 | struct plot_hash * | ||
231 | trace_graph_plot_find_cpu(struct graph_info *ginfo, gint cpu) | ||
232 | { | ||
233 | return find_hash(ginfo->cpu_hash, cpu); | ||
234 | } | ||
235 | |||
236 | void trace_graph_plot_add_cpu(struct graph_info *ginfo, | ||
237 | struct graph_plot *plot, | ||
238 | gint cpu) | ||
239 | { | ||
240 | add_hash(ginfo->cpu_hash, plot, cpu); | ||
241 | } | ||
242 | |||
243 | void trace_graph_plot_remove_cpu(struct graph_info *ginfo, | ||
244 | struct graph_plot *plot, | ||
245 | gint cpu) | ||
246 | { | ||
247 | remove_hash(ginfo->cpu_hash, plot, cpu); | ||
248 | } | ||
249 | |||
250 | |||
251 | /* Plot callback helpers */ | ||
252 | |||
134 | int trace_graph_plot_match_time(struct graph_info *ginfo, | 253 | int trace_graph_plot_match_time(struct graph_info *ginfo, |
135 | struct graph_plot *plot, | 254 | struct graph_plot *plot, |
136 | unsigned long long time) | 255 | unsigned long long time) |