9c312311 |
1 | /* This file is part of the Linux Trace Toolkit viewer |
2 | * Copyright (C) 2003-2004 Michel Dagenais |
3 | * |
4 | * This program is free software; you can redistribute it and/or modify |
5 | * it under the terms of the GNU General Public License Version 2 as |
6 | * published by the Free Software Foundation; |
7 | * |
8 | * This program is distributed in the hope that it will be useful, |
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
11 | * GNU General Public License for more details. |
12 | * |
13 | * You should have received a copy of the GNU General Public License |
14 | * along with this program; if not, write to the Free Software |
15 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, |
16 | * MA 02111-1307, USA. |
17 | */ |
18 | |
dc877563 |
19 | |
20 | #include <lttv/state.h> |
ba576a78 |
21 | #include <ltt/facility.h> |
22 | #include <ltt/trace.h> |
308711e5 |
23 | #include <ltt/event.h> |
a5dcde2f |
24 | #include <ltt/type.h> |
dc877563 |
25 | |
b445142a |
26 | LttvExecutionMode |
27 | LTTV_STATE_MODE_UNKNOWN, |
ffd54a90 |
28 | LTTV_STATE_USER_MODE, |
29 | LTTV_STATE_SYSCALL, |
30 | LTTV_STATE_TRAP, |
31 | LTTV_STATE_IRQ; |
32 | |
b445142a |
33 | LttvExecutionSubmode |
34 | LTTV_STATE_SUBMODE_UNKNOWN, |
35 | LTTV_STATE_SUBMODE_NONE; |
ffd54a90 |
36 | |
37 | LttvProcessStatus |
38 | LTTV_STATE_UNNAMED, |
39 | LTTV_STATE_WAIT_FORK, |
40 | LTTV_STATE_WAIT_CPU, |
41 | LTTV_STATE_EXIT, |
42 | LTTV_STATE_WAIT, |
43 | LTTV_STATE_RUN; |
44 | |
ba576a78 |
45 | static GQuark |
308711e5 |
46 | LTTV_STATE_TRACEFILES, |
47 | LTTV_STATE_PROCESSES, |
48 | LTTV_STATE_PROCESS, |
49 | LTTV_STATE_EVENT, |
50 | LTTV_STATE_SAVED_STATES, |
51 | LTTV_STATE_TIME, |
ba576a78 |
52 | LTTV_STATE_HOOKS; |
53 | |
b445142a |
54 | |
55 | static void fill_name_tables(LttvTraceState *tcs); |
56 | |
57 | static void free_name_tables(LttvTraceState *tcs); |
58 | |
308711e5 |
59 | static void lttv_state_free_process_table(GHashTable *processes); |
ba576a78 |
60 | |
dc877563 |
61 | |
308711e5 |
62 | void lttv_state_save(LttvTraceState *self, LttvAttribute *container) |
63 | { |
64 | LTTV_TRACE_STATE_GET_CLASS(self)->state_save(self, container); |
65 | } |
66 | |
67 | |
68 | void lttv_state_restore(LttvTraceState *self, LttvAttribute *container) |
69 | { |
70 | LTTV_TRACE_STATE_GET_CLASS(self)->state_restore(self, container); |
71 | } |
72 | |
73 | |
74 | void lttv_state_saved_state_free(LttvTraceState *self, |
75 | LttvAttribute *container) |
76 | { |
77 | LTTV_TRACE_STATE_GET_CLASS(self)->state_restore(self, container); |
78 | } |
79 | |
80 | |
2a2fa4f0 |
81 | guint process_hash(gconstpointer key) |
82 | { |
83 | return ((LttvProcessState *)key)->pid; |
84 | } |
85 | |
86 | |
87 | gboolean process_equal(gconstpointer a, gconstpointer b) |
88 | { |
89 | LttvProcessState *process_a, *process_b; |
90 | |
91 | process_a = (LttvProcessState *)a; |
92 | process_b = (LttvProcessState *)b; |
93 | |
94 | if(process_a->pid != process_b->pid) return FALSE; |
95 | if(process_a->pid == 0 && |
96 | process_a->last_cpu != process_b->last_cpu) return FALSE; |
97 | return TRUE; |
98 | } |
99 | |
100 | |
308711e5 |
101 | static void |
102 | restore_init_state(LttvTraceState *self) |
103 | { |
104 | guint i, nb_control, nb_per_cpu, nb_tracefile; |
105 | |
106 | LttvTracefileState *tfcs; |
107 | |
108 | LttTime null_time = {0,0}; |
109 | |
110 | if(self->processes != NULL) lttv_state_free_process_table(self->processes); |
2a2fa4f0 |
111 | self->processes = g_hash_table_new(process_hash, process_equal); |
308711e5 |
112 | self->nb_event = 0; |
113 | |
114 | nb_control = ltt_trace_control_tracefile_number(self->parent.t); |
115 | nb_per_cpu = ltt_trace_per_cpu_tracefile_number(self->parent.t); |
116 | nb_tracefile = nb_control + nb_per_cpu; |
117 | for(i = 0 ; i < nb_tracefile ; i++) { |
118 | if(i < nb_control) { |
119 | tfcs = LTTV_TRACEFILE_STATE(self->parent.control_tracefiles[i]); |
120 | } |
121 | else { |
122 | tfcs = LTTV_TRACEFILE_STATE(self->parent.per_cpu_tracefiles[i - nb_control]); |
123 | } |
124 | |
125 | tfcs->parent.timestamp = null_time; |
126 | tfcs->saved_position = 0; |
2a2fa4f0 |
127 | tfcs->process = lttv_state_create_process(tfcs, NULL,0); |
128 | tfcs->process->state->s = LTTV_STATE_RUN; |
129 | tfcs->process->last_cpu = tfcs->cpu_name; |
308711e5 |
130 | } |
131 | } |
132 | |
2a2fa4f0 |
133 | static LttTime time_zero = {0,0}; |
308711e5 |
134 | |
dc877563 |
135 | static void |
136 | init(LttvTracesetState *self, LttvTraceset *ts) |
137 | { |
b445142a |
138 | guint i, j, nb_trace, nb_control, nb_per_cpu, nb_tracefile; |
dc877563 |
139 | |
ffd54a90 |
140 | LttvTraceContext *tc; |
dc877563 |
141 | |
ffd54a90 |
142 | LttvTraceState *tcs; |
143 | |
ffd54a90 |
144 | LttvTracefileState *tfcs; |
3d27549e |
145 | |
b445142a |
146 | LTTV_TRACESET_CONTEXT_CLASS(g_type_class_peek(LTTV_TRACESET_CONTEXT_TYPE))-> |
147 | init((LttvTracesetContext *)self, ts); |
dc877563 |
148 | |
149 | nb_trace = lttv_traceset_number(ts); |
150 | for(i = 0 ; i < nb_trace ; i++) { |
b445142a |
151 | tc = self->parent.traces[i]; |
152 | tcs = (LttvTraceState *)tc; |
308711e5 |
153 | tcs->save_interval = 100000; |
2a2fa4f0 |
154 | tcs->max_time_state_recomputed_in_seek = &time_zero; |
b445142a |
155 | fill_name_tables(tcs); |
dc877563 |
156 | |
b445142a |
157 | nb_control = ltt_trace_control_tracefile_number(tc->t); |
158 | nb_per_cpu = ltt_trace_per_cpu_tracefile_number(tc->t); |
159 | nb_tracefile = nb_control + nb_per_cpu; |
dc877563 |
160 | for(j = 0 ; j < nb_tracefile ; j++) { |
b445142a |
161 | if(j < nb_control) { |
162 | tfcs = LTTV_TRACEFILE_STATE(tc->control_tracefiles[j]); |
163 | } |
164 | else { |
165 | tfcs = LTTV_TRACEFILE_STATE(tc->per_cpu_tracefiles[j - nb_control]); |
166 | } |
b445142a |
167 | tfcs->cpu_name= g_quark_from_string(ltt_tracefile_name(tfcs->parent.tf)); |
dc877563 |
168 | } |
308711e5 |
169 | tcs->processes = NULL; |
170 | restore_init_state(tcs); |
dc877563 |
171 | } |
172 | } |
173 | |
174 | |
175 | static void |
176 | fini(LttvTracesetState *self) |
177 | { |
178 | guint i, j, nb_trace, nb_tracefile; |
179 | |
ffd54a90 |
180 | LttvTraceState *tcs; |
dc877563 |
181 | |
ffd54a90 |
182 | LttvTracefileState *tfcs; |
dc877563 |
183 | |
ffd54a90 |
184 | nb_trace = lttv_traceset_number(LTTV_TRACESET_CONTEXT(self)->ts); |
dc877563 |
185 | for(i = 0 ; i < nb_trace ; i++) { |
ffd54a90 |
186 | tcs = (LttvTraceState *)(LTTV_TRACESET_CONTEXT(self)->traces[i]); |
308711e5 |
187 | lttv_state_free_process_table(tcs->processes); |
188 | tcs->processes = NULL; |
b445142a |
189 | free_name_tables(tcs); |
dc877563 |
190 | } |
b445142a |
191 | LTTV_TRACESET_CONTEXT_CLASS(g_type_class_peek(LTTV_TRACESET_CONTEXT_TYPE))-> |
192 | fini((LttvTracesetContext *)self); |
dc877563 |
193 | } |
194 | |
195 | |
c432246e |
196 | static LttvTracesetContext * |
dc877563 |
197 | new_traceset_context(LttvTracesetContext *self) |
198 | { |
ffd54a90 |
199 | return LTTV_TRACESET_CONTEXT(g_object_new(LTTV_TRACESET_STATE_TYPE, NULL)); |
dc877563 |
200 | } |
201 | |
202 | |
c432246e |
203 | static LttvTraceContext * |
dc877563 |
204 | new_trace_context(LttvTracesetContext *self) |
205 | { |
ffd54a90 |
206 | return LTTV_TRACE_CONTEXT(g_object_new(LTTV_TRACE_STATE_TYPE, NULL)); |
dc877563 |
207 | } |
208 | |
209 | |
c432246e |
210 | static LttvTracefileContext * |
dc877563 |
211 | new_tracefile_context(LttvTracesetContext *self) |
212 | { |
ffd54a90 |
213 | return LTTV_TRACEFILE_CONTEXT(g_object_new(LTTV_TRACEFILE_STATE_TYPE, NULL)); |
214 | } |
215 | |
216 | |
308711e5 |
217 | static void copy_process_state(gpointer key, gpointer value,gpointer user_data) |
ffd54a90 |
218 | { |
308711e5 |
219 | LttvProcessState *process, *new_process; |
ffd54a90 |
220 | |
308711e5 |
221 | GHashTable *new_processes = (GHashTable *)user_data; |
ffd54a90 |
222 | |
308711e5 |
223 | guint i; |
224 | |
225 | process = (LttvProcessState *)value; |
226 | new_process = g_new(LttvProcessState, 1); |
227 | *new_process = *process; |
228 | new_process->execution_stack = g_array_new(FALSE, FALSE, |
229 | sizeof(LttvExecutionState)); |
230 | g_array_set_size(new_process->execution_stack,process->execution_stack->len); |
231 | for(i = 0 ; i < process->execution_stack->len; i++) { |
232 | g_array_index(new_process->execution_stack, LttvExecutionState, i) = |
233 | g_array_index(process->execution_stack, LttvExecutionState, i); |
234 | } |
235 | new_process->state = &g_array_index(new_process->execution_stack, |
236 | LttvExecutionState, new_process->execution_stack->len - 1); |
2a2fa4f0 |
237 | g_hash_table_insert(new_processes, new_process, new_process); |
ffd54a90 |
238 | } |
239 | |
240 | |
308711e5 |
241 | static GHashTable *lttv_state_copy_process_table(GHashTable *processes) |
ffd54a90 |
242 | { |
2a2fa4f0 |
243 | GHashTable *new_processes = g_hash_table_new(process_hash, process_equal); |
ffd54a90 |
244 | |
308711e5 |
245 | g_hash_table_foreach(processes, copy_process_state, new_processes); |
246 | return new_processes; |
dc877563 |
247 | } |
248 | |
249 | |
308711e5 |
250 | /* The saved state for each trace contains a member "processes", which |
251 | stores a copy of the process table, and a member "tracefiles" with |
252 | one entry per tracefile. Each tracefile has a "process" member pointing |
253 | to the current process and a "position" member storing the tracefile |
254 | position (needed to seek to the current "next" event. */ |
255 | |
256 | static void state_save(LttvTraceState *self, LttvAttribute *container) |
dc877563 |
257 | { |
308711e5 |
258 | guint i, nb_control, nb_per_cpu, nb_tracefile; |
dc877563 |
259 | |
308711e5 |
260 | LttvTracefileState *tfcs; |
261 | |
262 | LttvAttribute *tracefiles_tree, *tracefile_tree; |
263 | |
264 | LttvAttributeType type; |
265 | |
266 | LttvAttributeValue value; |
267 | |
268 | LttvAttributeName name; |
269 | |
270 | LttEventPosition *ep; |
271 | |
272 | tracefiles_tree = lttv_attribute_find_subdir(container, |
273 | LTTV_STATE_TRACEFILES); |
274 | |
275 | value = lttv_attribute_add(container, LTTV_STATE_PROCESSES, |
276 | LTTV_POINTER); |
277 | *(value.v_pointer) = lttv_state_copy_process_table(self->processes); |
278 | |
279 | nb_control = ltt_trace_control_tracefile_number(self->parent.t); |
280 | nb_per_cpu = ltt_trace_per_cpu_tracefile_number(self->parent.t); |
281 | nb_tracefile = nb_control + nb_per_cpu; |
282 | |
283 | for(i = 0 ; i < nb_tracefile ; i++) { |
284 | if(i < nb_control) |
285 | tfcs = (LttvTracefileState *)self->parent.control_tracefiles[i]; |
286 | else tfcs = (LttvTracefileState *) |
287 | self->parent.per_cpu_tracefiles[i - nb_control]; |
288 | |
289 | tracefile_tree = g_object_new(LTTV_ATTRIBUTE_TYPE, NULL); |
290 | value = lttv_attribute_add(tracefiles_tree, i, |
291 | LTTV_GOBJECT); |
292 | *(value.v_gobject) = (GObject *)tracefile_tree; |
293 | value = lttv_attribute_add(tracefile_tree, LTTV_STATE_PROCESS, |
294 | LTTV_UINT); |
295 | *(value.v_uint) = tfcs->process->pid; |
296 | value = lttv_attribute_add(tracefile_tree, LTTV_STATE_EVENT, |
297 | LTTV_POINTER); |
298 | if(tfcs->parent.e == NULL) *(value.v_pointer) = NULL; |
299 | else { |
a5dcde2f |
300 | ep = ltt_event_position_new(); |
308711e5 |
301 | ltt_event_position(tfcs->parent.e, ep); |
302 | *(value.v_pointer) = ep; |
303 | } |
dc877563 |
304 | } |
dc877563 |
305 | } |
306 | |
307 | |
308711e5 |
308 | static void state_restore(LttvTraceState *self, LttvAttribute *container) |
dc877563 |
309 | { |
2a2fa4f0 |
310 | guint i, nb_control, nb_per_cpu, nb_tracefile, pid; |
dc877563 |
311 | |
308711e5 |
312 | LttvTracefileState *tfcs; |
dc877563 |
313 | |
308711e5 |
314 | LttvAttribute *tracefiles_tree, *tracefile_tree; |
dc877563 |
315 | |
308711e5 |
316 | LttvAttributeType type; |
dc877563 |
317 | |
308711e5 |
318 | LttvAttributeValue value; |
dc877563 |
319 | |
308711e5 |
320 | LttvAttributeName name; |
dc877563 |
321 | |
308711e5 |
322 | LttEventPosition *ep; |
dc877563 |
323 | |
308711e5 |
324 | tracefiles_tree = lttv_attribute_find_subdir(container, |
325 | LTTV_STATE_TRACEFILES); |
dc877563 |
326 | |
308711e5 |
327 | type = lttv_attribute_get_by_name(container, LTTV_STATE_PROCESSES, |
328 | &value); |
329 | g_assert(type == LTTV_POINTER); |
330 | lttv_state_free_process_table(self->processes); |
331 | self->processes = lttv_state_copy_process_table(*(value.v_pointer)); |
332 | |
333 | nb_control = ltt_trace_control_tracefile_number(self->parent.t); |
334 | nb_per_cpu = ltt_trace_per_cpu_tracefile_number(self->parent.t); |
335 | nb_tracefile = nb_control + nb_per_cpu; |
336 | |
337 | for(i = 0 ; i < nb_tracefile ; i++) { |
338 | if(i < nb_control) tfcs = (LttvTracefileState *) |
339 | self->parent.control_tracefiles[i]; |
340 | else tfcs = (LttvTracefileState *) |
341 | self->parent.per_cpu_tracefiles[i - nb_control]; |
342 | |
343 | type = lttv_attribute_get(tracefiles_tree, i, &name, &value); |
344 | g_assert(type == LTTV_GOBJECT); |
345 | tracefile_tree = *((LttvAttribute **)(value.v_gobject)); |
346 | |
347 | type = lttv_attribute_get_by_name(tracefile_tree, LTTV_STATE_PROCESS, |
348 | &value); |
349 | g_assert(type == LTTV_UINT); |
2a2fa4f0 |
350 | pid = *(value.v_uint); |
351 | tfcs->process = lttv_state_find_process_or_create(tfcs, pid); |
352 | |
308711e5 |
353 | type = lttv_attribute_get_by_name(tracefile_tree, LTTV_STATE_EVENT, |
354 | &value); |
355 | g_assert(type == LTTV_POINTER); |
356 | if(*(value.v_pointer) == NULL) tfcs->parent.e = NULL; |
357 | else { |
358 | ep = *(value.v_pointer); |
359 | ltt_tracefile_seek_position(tfcs->parent.tf, ep); |
360 | tfcs->parent.e = ltt_tracefile_read(tfcs->parent.tf); |
361 | tfcs->parent.timestamp = ltt_event_time(tfcs->parent.e); |
362 | } |
dc877563 |
363 | } |
dc877563 |
364 | } |
365 | |
366 | |
308711e5 |
367 | static void state_saved_free(LttvTraceState *self, LttvAttribute *container) |
dc877563 |
368 | { |
308711e5 |
369 | guint i, nb_control, nb_per_cpu, nb_tracefile; |
dc877563 |
370 | |
308711e5 |
371 | LttvTracefileState *tfcs; |
dc877563 |
372 | |
308711e5 |
373 | LttvAttribute *tracefiles_tree, *tracefile_tree; |
dc877563 |
374 | |
308711e5 |
375 | LttvAttributeType type; |
dc877563 |
376 | |
308711e5 |
377 | LttvAttributeValue value; |
dc877563 |
378 | |
308711e5 |
379 | LttvAttributeName name; |
dc877563 |
380 | |
308711e5 |
381 | LttEventPosition *ep; |
dc877563 |
382 | |
308711e5 |
383 | tracefiles_tree = lttv_attribute_find_subdir(container, |
384 | LTTV_STATE_TRACEFILES); |
385 | lttv_attribute_remove_by_name(container, LTTV_STATE_TRACEFILES); |
dc877563 |
386 | |
308711e5 |
387 | type = lttv_attribute_get_by_name(container, LTTV_STATE_PROCESSES, |
388 | &value); |
389 | g_assert(type == LTTV_POINTER); |
390 | lttv_state_free_process_table(*(value.v_pointer)); |
391 | *(value.v_pointer) = NULL; |
392 | lttv_attribute_remove_by_name(container, LTTV_STATE_PROCESSES); |
393 | |
394 | nb_control = ltt_trace_control_tracefile_number(self->parent.t); |
395 | nb_per_cpu = ltt_trace_per_cpu_tracefile_number(self->parent.t); |
396 | nb_tracefile = nb_control + nb_per_cpu; |
397 | |
398 | for(i = 0 ; i < nb_tracefile ; i++) { |
399 | if(i < nb_control) tfcs = (LttvTracefileState *) |
400 | self->parent.control_tracefiles[i]; |
401 | else tfcs = (LttvTracefileState *) |
402 | self->parent.per_cpu_tracefiles[i - nb_control]; |
403 | |
404 | type = lttv_attribute_get(tracefiles_tree, i, &name, &value); |
405 | g_assert(type == LTTV_GOBJECT); |
406 | tracefile_tree = *((LttvAttribute **)(value.v_gobject)); |
407 | |
408 | type = lttv_attribute_get_by_name(tracefile_tree, LTTV_STATE_EVENT, |
409 | &value); |
410 | g_assert(type == LTTV_POINTER); |
411 | if(*(value.v_pointer) != NULL) g_free(*(value.v_pointer)); |
dc877563 |
412 | } |
308711e5 |
413 | lttv_attribute_recursive_free(tracefiles_tree); |
dc877563 |
414 | } |
415 | |
416 | |
b445142a |
417 | static void |
418 | fill_name_tables(LttvTraceState *tcs) |
419 | { |
420 | int i, nb; |
dc877563 |
421 | |
b445142a |
422 | char *f_name, *e_name; |
dc877563 |
423 | |
b445142a |
424 | LttvTraceHook h; |
425 | |
426 | LttEventType *et; |
427 | |
428 | LttType *t; |
429 | |
430 | GString *fe_name = g_string_new(""); |
431 | |
432 | nb = ltt_trace_eventtype_number(tcs->parent.t); |
433 | tcs->eventtype_names = g_new(GQuark, nb); |
434 | for(i = 0 ; i < nb ; i++) { |
435 | et = ltt_trace_eventtype_get(tcs->parent.t, i); |
436 | e_name = ltt_eventtype_name(et); |
437 | f_name = ltt_facility_name(ltt_eventtype_facility(et)); |
438 | g_string_printf(fe_name, "%s.%s", f_name, e_name); |
439 | tcs->eventtype_names[i] = g_quark_from_string(fe_name->str); |
440 | } |
dc877563 |
441 | |
b445142a |
442 | lttv_trace_find_hook(tcs->parent.t, "core", "syscall_entry", |
443 | "syscall_id", NULL, NULL, NULL, &h); |
444 | t = ltt_field_type(h.f1); |
445 | nb = ltt_type_element_number(t); |
446 | |
447 | /* CHECK syscalls should be an emun but currently are not! |
448 | tcs->syscall_names = g_new(GQuark, nb); |
449 | |
450 | for(i = 0 ; i < nb ; i++) { |
451 | tcs->syscall_names[i] = g_quark_from_string(ltt_enum_string_get(t, i)); |
452 | } |
453 | */ |
454 | |
455 | tcs->syscall_names = g_new(GQuark, 256); |
456 | for(i = 0 ; i < 256 ; i++) { |
457 | g_string_printf(fe_name, "syscall %d", i); |
458 | tcs->syscall_names[i] = g_quark_from_string(fe_name->str); |
459 | } |
460 | |
461 | lttv_trace_find_hook(tcs->parent.t, "core", "trap_entry", |
462 | "trap_id", NULL, NULL, NULL, &h); |
463 | t = ltt_field_type(h.f1); |
464 | nb = ltt_type_element_number(t); |
465 | |
466 | /* |
467 | tcs->trap_names = g_new(GQuark, nb); |
468 | for(i = 0 ; i < nb ; i++) { |
469 | tcs->trap_names[i] = g_quark_from_string(ltt_enum_string_get(t, i)); |
470 | } |
471 | */ |
472 | |
473 | tcs->trap_names = g_new(GQuark, 256); |
474 | for(i = 0 ; i < 256 ; i++) { |
475 | g_string_printf(fe_name, "trap %d", i); |
476 | tcs->trap_names[i] = g_quark_from_string(fe_name->str); |
477 | } |
478 | |
479 | lttv_trace_find_hook(tcs->parent.t, "core", "irq_entry", |
480 | "irq_id", NULL, NULL, NULL, &h); |
481 | t = ltt_field_type(h.f1); |
482 | nb = ltt_type_element_number(t); |
483 | |
484 | /* |
485 | tcs->irq_names = g_new(GQuark, nb); |
486 | for(i = 0 ; i < nb ; i++) { |
487 | tcs->irq_names[i] = g_quark_from_string(ltt_enum_string_get(t, i)); |
488 | } |
489 | */ |
490 | |
491 | tcs->irq_names = g_new(GQuark, 256); |
492 | for(i = 0 ; i < 256 ; i++) { |
493 | g_string_printf(fe_name, "irq %d", i); |
494 | tcs->irq_names[i] = g_quark_from_string(fe_name->str); |
495 | } |
496 | |
497 | g_string_free(fe_name, TRUE); |
498 | } |
499 | |
500 | |
501 | static void |
502 | free_name_tables(LttvTraceState *tcs) |
503 | { |
504 | g_free(tcs->eventtype_names); |
505 | g_free(tcs->syscall_names); |
506 | g_free(tcs->trap_names); |
507 | g_free(tcs->irq_names); |
508 | } |
dc877563 |
509 | |
b445142a |
510 | |
511 | static void push_state(LttvTracefileState *tfs, LttvExecutionMode t, |
ffd54a90 |
512 | guint state_id) |
dc877563 |
513 | { |
b445142a |
514 | LttvExecutionState *es; |
dc877563 |
515 | |
516 | LttvProcessState *process = tfs->process; |
517 | |
b445142a |
518 | guint depth = process->execution_stack->len; |
dc877563 |
519 | |
b445142a |
520 | g_array_set_size(process->execution_stack, depth + 1); |
521 | es = &g_array_index(process->execution_stack, LttvExecutionState, depth); |
522 | es->t = t; |
523 | es->n = state_id; |
524 | es->entry = es->change = tfs->parent.timestamp; |
525 | es->s = process->state->s; |
526 | process->state = es; |
dc877563 |
527 | } |
528 | |
529 | |
b445142a |
530 | static void pop_state(LttvTracefileState *tfs, LttvExecutionMode t) |
dc877563 |
531 | { |
532 | LttvProcessState *process = tfs->process; |
533 | |
b445142a |
534 | guint depth = process->execution_stack->len - 1; |
dc877563 |
535 | |
3d27549e |
536 | if(process->state->t != t){ |
b445142a |
537 | g_warning("Different execution mode type (%d.%09d): ignore it\n", |
538 | tfs->parent.timestamp.tv_sec, tfs->parent.timestamp.tv_nsec); |
8e8e6b64 |
539 | g_warning("process state has %s when pop_int is %s\n", |
540 | g_quark_to_string(process->state->t), |
541 | g_quark_to_string(t)); |
542 | g_warning("{ %u, %u, %s, %s }\n", |
543 | process->pid, |
544 | process->ppid, |
545 | g_quark_to_string(process->name), |
546 | g_quark_to_string(process->state->s)); |
3d27549e |
547 | return; |
548 | } |
b445142a |
549 | |
550 | if(depth == 0){ |
551 | g_warning("Trying to pop last state on stack (%d.%09d): ignore it\n", |
552 | tfs->parent.timestamp.tv_sec, tfs->parent.timestamp.tv_nsec); |
553 | return; |
554 | } |
555 | |
556 | g_array_remove_index(process->execution_stack, depth); |
dc877563 |
557 | depth--; |
b445142a |
558 | process->state = &g_array_index(process->execution_stack, LttvExecutionState, |
dc877563 |
559 | depth); |
b445142a |
560 | process->state->change = tfs->parent.timestamp; |
dc877563 |
561 | } |
562 | |
563 | |
2a2fa4f0 |
564 | LttvProcessState * |
565 | lttv_state_create_process(LttvTracefileState *tfs, LttvProcessState *parent, |
566 | guint pid) |
dc877563 |
567 | { |
568 | LttvProcessState *process = g_new(LttvProcessState, 1); |
569 | |
b445142a |
570 | LttvExecutionState *es; |
dc877563 |
571 | |
ffd54a90 |
572 | LttvTraceContext *tc; |
573 | |
ba576a78 |
574 | LttvTraceState *tcs; |
575 | |
b445142a |
576 | char buffer[128]; |
ffd54a90 |
577 | |
b445142a |
578 | tcs = (LttvTraceState *)tc = tfs->parent.t_context; |
60b53e4f |
579 | |
dc877563 |
580 | process->pid = pid; |
2a2fa4f0 |
581 | process->last_cpu = tfs->cpu_name; |
582 | g_hash_table_insert(tcs->processes, process, process); |
b445142a |
583 | |
584 | if(parent) { |
585 | process->ppid = parent->pid; |
586 | process->name = parent->name; |
2a2fa4f0 |
587 | process->creation_time = tfs->parent.timestamp; |
b445142a |
588 | } |
2a2fa4f0 |
589 | |
590 | /* No parent. This process exists but we are missing all information about |
591 | its creation. The birth time is set to zero but we remember the time of |
592 | insertion */ |
593 | |
b445142a |
594 | else { |
595 | process->ppid = 0; |
596 | process->name = LTTV_STATE_UNNAMED; |
2a2fa4f0 |
597 | process->creation_time = ltt_time_zero; |
b445142a |
598 | } |
599 | |
2a2fa4f0 |
600 | process->insertion_time = tfs->parent.timestamp; |
b445142a |
601 | sprintf(buffer,"%d-%lu.%lu",pid, process->creation_time.tv_sec, |
602 | process->creation_time.tv_nsec); |
603 | process->pid_time = g_quark_from_string(buffer); |
2a2fa4f0 |
604 | process->last_cpu = tfs->cpu_name; |
b445142a |
605 | process->execution_stack = g_array_new(FALSE, FALSE, |
606 | sizeof(LttvExecutionState)); |
607 | g_array_set_size(process->execution_stack, 1); |
608 | es = process->state = &g_array_index(process->execution_stack, |
609 | LttvExecutionState, 0); |
610 | es->t = LTTV_STATE_USER_MODE; |
611 | es->n = LTTV_STATE_SUBMODE_NONE; |
612 | es->entry = tfs->parent.timestamp; |
613 | es->change = tfs->parent.timestamp; |
614 | es->s = LTTV_STATE_WAIT_FORK; |
cbe7c836 |
615 | |
616 | return process; |
dc877563 |
617 | } |
618 | |
2a2fa4f0 |
619 | |
620 | LttvProcessState * |
621 | lttv_state_find_process_from_trace(LttvTraceState *ts, GQuark cpu, guint pid) |
dc877563 |
622 | { |
2a2fa4f0 |
623 | LttvProcessState key; |
624 | LttvProcessState *process; |
625 | |
626 | key.pid = pid; |
627 | key.last_cpu = cpu; |
628 | process = g_hash_table_lookup(ts->processes, &key); |
dc877563 |
629 | return process; |
630 | } |
631 | |
2a2fa4f0 |
632 | |
633 | LttvProcessState *lttv_state_find_process(LttvTracefileState *tfs, |
d0cd7f09 |
634 | guint pid) |
635 | { |
2a2fa4f0 |
636 | LttvTraceState *ts =(LttvTraceState *)tfs->parent.t_context; |
637 | return lttv_state_find_process_from_trace(ts, tfs->cpu_name, pid); |
d0cd7f09 |
638 | } |
639 | |
640 | |
2a2fa4f0 |
641 | LttvProcessState * |
642 | lttv_state_find_process_or_create(LttvTracefileState *tfs, guint pid) |
643 | { |
644 | LttvProcessState *process = lttv_state_find_process(tfs, pid); |
645 | |
646 | if(process == NULL) process = lttv_state_create_process(tfs, NULL, pid); |
647 | return process; |
648 | } |
649 | |
dc877563 |
650 | |
b445142a |
651 | static void exit_process(LttvTracefileState *tfs, LttvProcessState *process) |
dc877563 |
652 | { |
ba576a78 |
653 | LttvTraceState *ts = LTTV_TRACE_STATE(tfs->parent.t_context); |
2a2fa4f0 |
654 | LttvProcessState key; |
ba576a78 |
655 | |
2a2fa4f0 |
656 | key.pid = process->pid; |
657 | key.last_cpu = process->last_cpu; |
658 | g_hash_table_remove(ts->processes, &key); |
b445142a |
659 | g_array_free(process->execution_stack, TRUE); |
dc877563 |
660 | g_free(process); |
661 | } |
662 | |
663 | |
b445142a |
664 | static void free_process_state(gpointer key, gpointer value,gpointer user_data) |
dc877563 |
665 | { |
b445142a |
666 | g_array_free(((LttvProcessState *)value)->execution_stack, TRUE); |
dc877563 |
667 | g_free(value); |
668 | } |
669 | |
670 | |
308711e5 |
671 | static void lttv_state_free_process_table(GHashTable *processes) |
dc877563 |
672 | { |
673 | g_hash_table_foreach(processes, free_process_state, NULL); |
308711e5 |
674 | g_hash_table_destroy(processes); |
dc877563 |
675 | } |
676 | |
677 | |
b445142a |
678 | static gboolean syscall_entry(void *hook_data, void *call_data) |
dc877563 |
679 | { |
b445142a |
680 | LttField *f = ((LttvTraceHook *)hook_data)->f1; |
dc877563 |
681 | |
ba576a78 |
682 | LttvTracefileState *s = (LttvTracefileState *)call_data; |
dc877563 |
683 | |
b445142a |
684 | LttvExecutionSubmode submode; |
685 | |
686 | submode = ((LttvTraceState *)(s->parent.t_context))->syscall_names[ |
687 | ltt_event_get_unsigned(s->parent.e, f)]; |
688 | push_state(s, LTTV_STATE_SYSCALL, submode); |
dc877563 |
689 | return FALSE; |
690 | } |
691 | |
692 | |
b445142a |
693 | static gboolean syscall_exit(void *hook_data, void *call_data) |
dc877563 |
694 | { |
ba576a78 |
695 | LttvTracefileState *s = (LttvTracefileState *)call_data; |
dc877563 |
696 | |
ffd54a90 |
697 | pop_state(s, LTTV_STATE_SYSCALL); |
dc877563 |
698 | return FALSE; |
699 | } |
700 | |
701 | |
b445142a |
702 | static gboolean trap_entry(void *hook_data, void *call_data) |
dc877563 |
703 | { |
b445142a |
704 | LttField *f = ((LttvTraceHook *)hook_data)->f1; |
dc877563 |
705 | |
ba576a78 |
706 | LttvTracefileState *s = (LttvTracefileState *)call_data; |
dc877563 |
707 | |
b445142a |
708 | LttvExecutionSubmode submode; |
709 | |
710 | submode = ((LttvTraceState *)(s->parent.t_context))->trap_names[ |
711 | ltt_event_get_unsigned(s->parent.e, f)]; |
712 | push_state(s, LTTV_STATE_TRAP, submode); |
dc877563 |
713 | return FALSE; |
714 | } |
715 | |
716 | |
b445142a |
717 | static gboolean trap_exit(void *hook_data, void *call_data) |
dc877563 |
718 | { |
ba576a78 |
719 | LttvTracefileState *s = (LttvTracefileState *)call_data; |
dc877563 |
720 | |
ffd54a90 |
721 | pop_state(s, LTTV_STATE_TRAP); |
dc877563 |
722 | return FALSE; |
723 | } |
724 | |
725 | |
b445142a |
726 | static gboolean irq_entry(void *hook_data, void *call_data) |
dc877563 |
727 | { |
b445142a |
728 | LttField *f = ((LttvTraceHook *)hook_data)->f1; |
dc877563 |
729 | |
ba576a78 |
730 | LttvTracefileState *s = (LttvTracefileState *)call_data; |
dc877563 |
731 | |
b445142a |
732 | LttvExecutionSubmode submode; |
733 | |
734 | submode = ((LttvTraceState *)(s->parent.t_context))->irq_names[ |
735 | ltt_event_get_unsigned(s->parent.e, f)]; |
736 | |
dc877563 |
737 | /* Do something with the info about being in user or system mode when int? */ |
b445142a |
738 | push_state(s, LTTV_STATE_IRQ, submode); |
dc877563 |
739 | return FALSE; |
740 | } |
741 | |
742 | |
b445142a |
743 | static gboolean irq_exit(void *hook_data, void *call_data) |
dc877563 |
744 | { |
ba576a78 |
745 | LttvTracefileState *s = (LttvTracefileState *)call_data; |
dc877563 |
746 | |
ffd54a90 |
747 | pop_state(s, LTTV_STATE_IRQ); |
dc877563 |
748 | return FALSE; |
749 | } |
750 | |
751 | |
b445142a |
752 | static gboolean schedchange(void *hook_data, void *call_data) |
dc877563 |
753 | { |
b445142a |
754 | LttvTraceHook *h = (LttvTraceHook *)hook_data; |
dc877563 |
755 | |
ba576a78 |
756 | LttvTracefileState *s = (LttvTracefileState *)call_data; |
dc877563 |
757 | |
758 | guint pid_in, pid_out, state_out; |
759 | |
3d27549e |
760 | pid_in = ltt_event_get_unsigned(s->parent.e, h->f1); |
761 | pid_out = ltt_event_get_unsigned(s->parent.e, h->f2); |
762 | state_out = ltt_event_get_unsigned(s->parent.e, h->f3); |
b445142a |
763 | |
dc877563 |
764 | if(s->process != NULL) { |
b445142a |
765 | |
ffd54a90 |
766 | if(state_out == 0) s->process->state->s = LTTV_STATE_WAIT_CPU; |
767 | else if(s->process->state->s == LTTV_STATE_EXIT) |
ba576a78 |
768 | exit_process(s, s->process); |
ffd54a90 |
769 | else s->process->state->s = LTTV_STATE_WAIT; |
3d27549e |
770 | |
771 | if(s->process->pid == 0) |
90ffd2ad |
772 | s->process->pid = pid_out; |
b445142a |
773 | |
774 | s->process->state->change = s->parent.timestamp; |
dc877563 |
775 | } |
2a2fa4f0 |
776 | s->process = lttv_state_find_process_or_create(s, pid_in); |
ffd54a90 |
777 | s->process->state->s = LTTV_STATE_RUN; |
2a2fa4f0 |
778 | s->process->last_cpu = s->cpu_name; |
b445142a |
779 | s->process->state->change = s->parent.timestamp; |
dc877563 |
780 | return FALSE; |
781 | } |
782 | |
783 | |
b445142a |
784 | static gboolean process_fork(void *hook_data, void *call_data) |
dc877563 |
785 | { |
b445142a |
786 | LttField *f = ((LttvTraceHook *)hook_data)->f1; |
dc877563 |
787 | |
ba576a78 |
788 | LttvTracefileState *s = (LttvTracefileState *)call_data; |
dc877563 |
789 | |
790 | guint child_pid; |
791 | |
3d27549e |
792 | child_pid = ltt_event_get_unsigned(s->parent.e, f); |
2a2fa4f0 |
793 | lttv_state_create_process(s, s->process, child_pid); |
dc877563 |
794 | return FALSE; |
795 | } |
796 | |
797 | |
b445142a |
798 | static gboolean process_exit(void *hook_data, void *call_data) |
dc877563 |
799 | { |
ba576a78 |
800 | LttvTracefileState *s = (LttvTracefileState *)call_data; |
dc877563 |
801 | |
802 | if(s->process != NULL) { |
ffd54a90 |
803 | s->process->state->s = LTTV_STATE_EXIT; |
dc877563 |
804 | } |
805 | return FALSE; |
806 | } |
807 | |
808 | |
308711e5 |
809 | void lttv_state_add_event_hooks(LttvTracesetState *self) |
dc877563 |
810 | { |
ba576a78 |
811 | LttvTraceset *traceset = self->parent.ts; |
dc877563 |
812 | |
ba576a78 |
813 | guint i, j, k, nb_trace, nb_control, nb_per_cpu, nb_tracefile; |
dc877563 |
814 | |
ba576a78 |
815 | LttvTraceState *ts; |
dc877563 |
816 | |
ba576a78 |
817 | LttvTracefileState *tfs; |
dc877563 |
818 | |
dc877563 |
819 | GArray *hooks; |
820 | |
b445142a |
821 | LttvTraceHook hook; |
dc877563 |
822 | |
823 | LttvAttributeValue val; |
824 | |
ba576a78 |
825 | nb_trace = lttv_traceset_number(traceset); |
dc877563 |
826 | for(i = 0 ; i < nb_trace ; i++) { |
ba576a78 |
827 | ts = (LttvTraceState *)self->parent.traces[i]; |
dc877563 |
828 | |
829 | /* Find the eventtype id for the following events and register the |
830 | associated by id hooks. */ |
831 | |
b445142a |
832 | hooks = g_array_new(FALSE, FALSE, sizeof(LttvTraceHook)); |
833 | g_array_set_size(hooks, 9); |
834 | |
835 | lttv_trace_find_hook(ts->parent.t, "core","syscall_entry","syscall_id", |
836 | NULL, NULL, syscall_entry, &g_array_index(hooks, LttvTraceHook, 0)); |
cbe7c836 |
837 | |
b445142a |
838 | lttv_trace_find_hook(ts->parent.t, "core", "syscall_exit", NULL, NULL, |
839 | NULL, syscall_exit, &g_array_index(hooks, LttvTraceHook, 1)); |
cbe7c836 |
840 | |
b445142a |
841 | lttv_trace_find_hook(ts->parent.t, "core", "trap_entry", "trap_id", |
842 | NULL, NULL, trap_entry, &g_array_index(hooks, LttvTraceHook, 2)); |
cbe7c836 |
843 | |
b445142a |
844 | lttv_trace_find_hook(ts->parent.t, "core", "trap_exit", NULL, NULL, NULL, |
845 | trap_exit, &g_array_index(hooks, LttvTraceHook, 3)); |
cbe7c836 |
846 | |
b445142a |
847 | lttv_trace_find_hook(ts->parent.t, "core", "irq_entry", "irq_id", NULL, |
848 | NULL, irq_entry, &g_array_index(hooks, LttvTraceHook, 4)); |
cbe7c836 |
849 | |
b445142a |
850 | lttv_trace_find_hook(ts->parent.t, "core", "irq_exit", NULL, NULL, NULL, |
851 | irq_exit, &g_array_index(hooks, LttvTraceHook, 5)); |
cbe7c836 |
852 | |
b445142a |
853 | lttv_trace_find_hook(ts->parent.t, "core", "schedchange", "in", "out", |
854 | "out_state", schedchange, &g_array_index(hooks, LttvTraceHook, 6)); |
cbe7c836 |
855 | |
b445142a |
856 | lttv_trace_find_hook(ts->parent.t, "core", "process_fork", "child_pid", |
857 | NULL, NULL, process_fork, &g_array_index(hooks, LttvTraceHook, 7)); |
cbe7c836 |
858 | |
b445142a |
859 | lttv_trace_find_hook(ts->parent.t, "core", "process_exit", NULL, NULL, |
860 | NULL, process_exit, &g_array_index(hooks, LttvTraceHook, 8)); |
dc877563 |
861 | |
862 | /* Add these hooks to each before_event_by_id hooks list */ |
863 | |
ba576a78 |
864 | nb_control = ltt_trace_control_tracefile_number(ts->parent.t); |
cbe7c836 |
865 | nb_per_cpu = ltt_trace_per_cpu_tracefile_number(ts->parent.t); |
dc877563 |
866 | nb_tracefile = nb_control + nb_per_cpu; |
867 | for(j = 0 ; j < nb_tracefile ; j++) { |
868 | if(j < nb_control) { |
ba576a78 |
869 | tfs = LTTV_TRACEFILE_STATE(ts->parent.control_tracefiles[j]); |
dc877563 |
870 | } |
871 | else { |
cbe7c836 |
872 | tfs = LTTV_TRACEFILE_STATE(ts->parent.per_cpu_tracefiles[j-nb_control]); |
dc877563 |
873 | } |
874 | |
875 | for(k = 0 ; k < hooks->len ; k++) { |
b445142a |
876 | hook = g_array_index(hooks, LttvTraceHook, k); |
877 | lttv_hooks_add(lttv_hooks_by_id_find(tfs->parent.after_event_by_id, |
878 | hook.id), hook.h, &g_array_index(hooks, LttvTraceHook, k)); |
ffd54a90 |
879 | } |
dc877563 |
880 | } |
ba576a78 |
881 | lttv_attribute_find(self->parent.a, LTTV_STATE_HOOKS, LTTV_POINTER, &val); |
882 | *(val.v_pointer) = hooks; |
dc877563 |
883 | } |
884 | } |
885 | |
886 | |
308711e5 |
887 | void lttv_state_remove_event_hooks(LttvTracesetState *self) |
dc877563 |
888 | { |
ba576a78 |
889 | LttvTraceset *traceset = self->parent.ts; |
dc877563 |
890 | |
ba576a78 |
891 | guint i, j, k, nb_trace, nb_control, nb_per_cpu, nb_tracefile; |
dc877563 |
892 | |
ba576a78 |
893 | LttvTraceState *ts; |
dc877563 |
894 | |
ba576a78 |
895 | LttvTracefileState *tfs; |
dc877563 |
896 | |
dc877563 |
897 | GArray *hooks; |
898 | |
b445142a |
899 | LttvTraceHook hook; |
dc877563 |
900 | |
901 | LttvAttributeValue val; |
902 | |
ba576a78 |
903 | nb_trace = lttv_traceset_number(traceset); |
dc877563 |
904 | for(i = 0 ; i < nb_trace ; i++) { |
ba576a78 |
905 | ts = LTTV_TRACE_STATE(self->parent.traces[i]); |
906 | lttv_attribute_find(self->parent.a, LTTV_STATE_HOOKS, LTTV_POINTER, &val); |
907 | hooks = *(val.v_pointer); |
dc877563 |
908 | |
909 | /* Add these hooks to each before_event_by_id hooks list */ |
910 | |
ba576a78 |
911 | nb_control = ltt_trace_control_tracefile_number(ts->parent.t); |
cbe7c836 |
912 | nb_per_cpu = ltt_trace_per_cpu_tracefile_number(ts->parent.t); |
dc877563 |
913 | nb_tracefile = nb_control + nb_per_cpu; |
914 | for(j = 0 ; j < nb_tracefile ; j++) { |
915 | if(j < nb_control) { |
ba576a78 |
916 | tfs = LTTV_TRACEFILE_STATE(ts->parent.control_tracefiles[j]); |
dc877563 |
917 | } |
918 | else { |
cbe7c836 |
919 | tfs = LTTV_TRACEFILE_STATE(ts->parent.per_cpu_tracefiles[j-nb_control]); |
dc877563 |
920 | } |
921 | |
922 | for(k = 0 ; k < hooks->len ; k++) { |
b445142a |
923 | hook = g_array_index(hooks, LttvTraceHook, k); |
ba576a78 |
924 | lttv_hooks_remove_data( |
b445142a |
925 | lttv_hooks_by_id_find(tfs->parent.after_event_by_id, |
926 | hook.id), hook.h, &g_array_index(hooks, LttvTraceHook, k)); |
ffd54a90 |
927 | } |
dc877563 |
928 | } |
929 | g_array_free(hooks, TRUE); |
930 | } |
931 | } |
932 | |
933 | |
308711e5 |
934 | static gboolean block_end(void *hook_data, void *call_data) |
935 | { |
936 | LttvTracefileState *tfcs = (LttvTracefileState *)call_data; |
937 | |
938 | LttvTraceState *tcs = (LttvTraceState *)(tfcs->parent.t_context); |
939 | |
a5dcde2f |
940 | LttEventPosition *ep = ltt_event_position_new(); |
308711e5 |
941 | |
942 | guint nb_block, nb_event; |
943 | |
944 | LttTracefile *tf; |
945 | |
946 | LttvAttribute *saved_states_tree, *saved_state_tree; |
947 | |
948 | LttvAttributeValue value; |
949 | |
a5dcde2f |
950 | ltt_event_position(tfcs->parent.e, ep); |
308711e5 |
951 | |
a5dcde2f |
952 | ltt_event_position_get(ep, &nb_block, &nb_event, &tf); |
308711e5 |
953 | tcs->nb_event += nb_event - tfcs->saved_position; |
954 | tfcs->saved_position = 0; |
955 | if(tcs->nb_event >= tcs->save_interval) { |
956 | saved_states_tree = lttv_attribute_find_subdir(tcs->parent.t_a, |
957 | LTTV_STATE_SAVED_STATES); |
958 | saved_state_tree = g_object_new(LTTV_ATTRIBUTE_TYPE, NULL); |
959 | value = lttv_attribute_add(saved_states_tree, |
960 | lttv_attribute_get_number(saved_states_tree), LTTV_GOBJECT); |
961 | *(value.v_gobject) = (GObject *)saved_state_tree; |
962 | value = lttv_attribute_add(saved_state_tree, LTTV_STATE_TIME, LTTV_TIME); |
963 | *(value.v_time) = tfcs->parent.timestamp; |
964 | lttv_state_save(tcs, saved_state_tree); |
965 | tcs->nb_event = 0; |
966 | } |
967 | return FALSE; |
968 | } |
969 | |
970 | |
971 | void lttv_state_save_add_event_hooks(LttvTracesetState *self) |
972 | { |
973 | LttvTraceset *traceset = self->parent.ts; |
974 | |
975 | guint i, j, k, nb_trace, nb_control, nb_per_cpu, nb_tracefile; |
976 | |
977 | LttvTraceState *ts; |
978 | |
979 | LttvTracefileState *tfs; |
980 | |
981 | LttvTraceHook hook; |
982 | |
983 | nb_trace = lttv_traceset_number(traceset); |
984 | for(i = 0 ; i < nb_trace ; i++) { |
985 | ts = (LttvTraceState *)self->parent.traces[i]; |
986 | lttv_trace_find_hook(ts->parent.t, "core","block_end",NULL, |
987 | NULL, NULL, block_end, &hook); |
988 | |
989 | nb_control = ltt_trace_control_tracefile_number(ts->parent.t); |
990 | nb_per_cpu = ltt_trace_per_cpu_tracefile_number(ts->parent.t); |
991 | nb_tracefile = nb_control + nb_per_cpu; |
992 | for(j = 0 ; j < nb_tracefile ; j++) { |
993 | if(j < nb_control) { |
994 | tfs = LTTV_TRACEFILE_STATE(ts->parent.control_tracefiles[j]); |
995 | } |
996 | else { |
997 | tfs =LTTV_TRACEFILE_STATE(ts->parent.per_cpu_tracefiles[j-nb_control]); |
998 | } |
999 | |
1000 | lttv_hooks_add(lttv_hooks_by_id_find(tfs->parent.after_event_by_id, |
1001 | hook.id), hook.h, NULL); |
1002 | } |
1003 | } |
1004 | } |
1005 | |
1006 | |
1007 | void lttv_state_save_remove_event_hooks(LttvTracesetState *self) |
1008 | { |
1009 | LttvTraceset *traceset = self->parent.ts; |
1010 | |
1011 | guint i, j, k, nb_trace, nb_control, nb_per_cpu, nb_tracefile; |
1012 | |
1013 | LttvTraceState *ts; |
1014 | |
1015 | LttvTracefileState *tfs; |
1016 | |
1017 | LttvTraceHook hook; |
1018 | |
1019 | nb_trace = lttv_traceset_number(traceset); |
1020 | for(i = 0 ; i < nb_trace ; i++) { |
1021 | ts = LTTV_TRACE_STATE(self->parent.traces[i]); |
1022 | lttv_trace_find_hook(ts->parent.t, "core","block_end",NULL, |
1023 | NULL, NULL, block_end, &hook); |
1024 | |
1025 | nb_control = ltt_trace_control_tracefile_number(ts->parent.t); |
1026 | nb_per_cpu = ltt_trace_per_cpu_tracefile_number(ts->parent.t); |
1027 | nb_tracefile = nb_control + nb_per_cpu; |
1028 | for(j = 0 ; j < nb_tracefile ; j++) { |
1029 | if(j < nb_control) { |
1030 | tfs = LTTV_TRACEFILE_STATE(ts->parent.control_tracefiles[j]); |
1031 | } |
1032 | else { |
1033 | tfs =LTTV_TRACEFILE_STATE(ts->parent.per_cpu_tracefiles[j-nb_control]); |
1034 | } |
1035 | |
1036 | lttv_hooks_remove_data(lttv_hooks_by_id_find( |
1037 | tfs->parent.after_event_by_id, hook.id), hook.h, NULL); |
1038 | } |
1039 | } |
1040 | } |
1041 | |
1042 | |
dd025f91 |
1043 | void lttv_state_traceset_seek_time_closest(LttvTracesetState *self, LttTime t) |
308711e5 |
1044 | { |
1045 | LttvTraceset *traceset = self->parent.ts; |
1046 | |
1047 | guint i, j, nb_trace, nb_saved_state; |
1048 | |
1049 | int min_pos, mid_pos, max_pos; |
1050 | |
1051 | LttvTraceState *tcs; |
1052 | |
1053 | LttvAttributeValue value; |
1054 | |
1055 | LttvAttributeType type; |
1056 | |
1057 | LttvAttributeName name; |
1058 | |
1059 | LttvAttribute *saved_states_tree, *saved_state_tree, *closest_tree; |
1060 | |
1061 | nb_trace = lttv_traceset_number(traceset); |
1062 | for(i = 0 ; i < nb_trace ; i++) { |
1063 | tcs = (LttvTraceState *)self->parent.traces[i]; |
1064 | |
2a2fa4f0 |
1065 | if(ltt_time_compare(t, *(tcs->max_time_state_recomputed_in_seek)) < 0) { |
1066 | saved_states_tree = lttv_attribute_find_subdir(tcs->parent.t_a, |
1067 | LTTV_STATE_SAVED_STATES); |
1068 | min_pos = -1; |
1069 | |
1070 | if(saved_states_tree) { |
dd025f91 |
1071 | max_pos = lttv_attribute_get_number(saved_states_tree) - 1; |
1072 | mid_pos = max_pos / 2; |
1073 | while(min_pos < max_pos) { |
1074 | type = lttv_attribute_get(saved_states_tree, mid_pos, &name, &value); |
1075 | g_assert(type == LTTV_GOBJECT); |
1076 | saved_state_tree = *((LttvAttribute **)(value.v_gobject)); |
1077 | type = lttv_attribute_get_by_name(saved_state_tree, LTTV_STATE_TIME, |
1078 | &value); |
1079 | g_assert(type == LTTV_TIME); |
1080 | if(ltt_time_compare(*(value.v_time), t) < 0) { |
1081 | min_pos = mid_pos; |
1082 | closest_tree = saved_state_tree; |
1083 | } |
1084 | else max_pos = mid_pos - 1; |
1085 | |
1086 | mid_pos = (min_pos + max_pos + 1) / 2; |
1087 | } |
2a2fa4f0 |
1088 | } |
dd025f91 |
1089 | |
2a2fa4f0 |
1090 | /* restore the closest earlier saved state */ |
1091 | if(min_pos != -1) lttv_state_restore(tcs, closest_tree); |
dd025f91 |
1092 | |
2a2fa4f0 |
1093 | /* There is no saved state, yet we want to have it. Restart at T0 */ |
dd025f91 |
1094 | else { |
1095 | restore_init_state(tcs); |
1096 | lttv_process_trace_seek_time(&(tcs->parent), ltt_time_zero); |
308711e5 |
1097 | } |
9444deae |
1098 | } |
dd025f91 |
1099 | /* We want to seek quickly without restoring/updating the state */ |
1100 | else { |
308711e5 |
1101 | restore_init_state(tcs); |
dd025f91 |
1102 | lttv_process_trace_seek_time(&(tcs->parent), t); |
308711e5 |
1103 | } |
308711e5 |
1104 | } |
1105 | } |
1106 | |
1107 | |
1108 | static void |
1109 | traceset_state_instance_init (GTypeInstance *instance, gpointer g_class) |
1110 | { |
1111 | } |
1112 | |
1113 | |
1114 | static void |
1115 | traceset_state_finalize (LttvTracesetState *self) |
1116 | { |
1117 | G_OBJECT_CLASS(g_type_class_peek(LTTV_TRACESET_CONTEXT_TYPE))-> |
1118 | finalize(G_OBJECT(self)); |
1119 | } |
1120 | |
1121 | |
1122 | static void |
1123 | traceset_state_class_init (LttvTracesetContextClass *klass) |
1124 | { |
1125 | GObjectClass *gobject_class = G_OBJECT_CLASS(klass); |
1126 | |
1127 | gobject_class->finalize = (void (*)(GObject *self)) traceset_state_finalize; |
1128 | klass->init = (void (*)(LttvTracesetContext *self, LttvTraceset *ts))init; |
1129 | klass->fini = (void (*)(LttvTracesetContext *self))fini; |
1130 | klass->new_traceset_context = new_traceset_context; |
1131 | klass->new_trace_context = new_trace_context; |
1132 | klass->new_tracefile_context = new_tracefile_context; |
1133 | } |
1134 | |
1135 | |
1136 | GType |
1137 | lttv_traceset_state_get_type(void) |
1138 | { |
1139 | static GType type = 0; |
1140 | if (type == 0) { |
1141 | static const GTypeInfo info = { |
1142 | sizeof (LttvTracesetStateClass), |
1143 | NULL, /* base_init */ |
1144 | NULL, /* base_finalize */ |
1145 | (GClassInitFunc) traceset_state_class_init, /* class_init */ |
1146 | NULL, /* class_finalize */ |
1147 | NULL, /* class_data */ |
1148 | sizeof (LttvTracesetContext), |
1149 | 0, /* n_preallocs */ |
1150 | (GInstanceInitFunc) traceset_state_instance_init /* instance_init */ |
1151 | }; |
1152 | |
1153 | type = g_type_register_static (LTTV_TRACESET_CONTEXT_TYPE, "LttvTracesetStateType", |
1154 | &info, 0); |
1155 | } |
1156 | return type; |
1157 | } |
1158 | |
1159 | |
1160 | static void |
1161 | trace_state_instance_init (GTypeInstance *instance, gpointer g_class) |
1162 | { |
1163 | } |
1164 | |
1165 | |
1166 | static void |
1167 | trace_state_finalize (LttvTraceState *self) |
1168 | { |
1169 | G_OBJECT_CLASS(g_type_class_peek(LTTV_TRACE_CONTEXT_TYPE))-> |
1170 | finalize(G_OBJECT(self)); |
1171 | } |
1172 | |
1173 | |
1174 | static void |
1175 | trace_state_class_init (LttvTraceStateClass *klass) |
1176 | { |
1177 | GObjectClass *gobject_class = G_OBJECT_CLASS(klass); |
1178 | |
1179 | gobject_class->finalize = (void (*)(GObject *self)) trace_state_finalize; |
1180 | klass->state_save = state_save; |
1181 | klass->state_restore = state_restore; |
1182 | klass->state_saved_free = state_saved_free; |
1183 | } |
1184 | |
1185 | |
1186 | GType |
1187 | lttv_trace_state_get_type(void) |
1188 | { |
1189 | static GType type = 0; |
1190 | if (type == 0) { |
1191 | static const GTypeInfo info = { |
1192 | sizeof (LttvTraceStateClass), |
1193 | NULL, /* base_init */ |
1194 | NULL, /* base_finalize */ |
1195 | (GClassInitFunc) trace_state_class_init, /* class_init */ |
1196 | NULL, /* class_finalize */ |
1197 | NULL, /* class_data */ |
1198 | sizeof (LttvTraceState), |
1199 | 0, /* n_preallocs */ |
1200 | (GInstanceInitFunc) trace_state_instance_init /* instance_init */ |
1201 | }; |
1202 | |
1203 | type = g_type_register_static (LTTV_TRACE_CONTEXT_TYPE, |
1204 | "LttvTraceStateType", &info, 0); |
1205 | } |
1206 | return type; |
1207 | } |
1208 | |
1209 | |
1210 | static void |
1211 | tracefile_state_instance_init (GTypeInstance *instance, gpointer g_class) |
1212 | { |
1213 | } |
1214 | |
1215 | |
1216 | static void |
1217 | tracefile_state_finalize (LttvTracefileState *self) |
1218 | { |
1219 | G_OBJECT_CLASS(g_type_class_peek(LTTV_TRACEFILE_CONTEXT_TYPE))-> |
1220 | finalize(G_OBJECT(self)); |
1221 | } |
1222 | |
1223 | |
1224 | static void |
1225 | tracefile_state_class_init (LttvTracefileStateClass *klass) |
1226 | { |
1227 | GObjectClass *gobject_class = G_OBJECT_CLASS(klass); |
1228 | |
1229 | gobject_class->finalize = (void (*)(GObject *self)) tracefile_state_finalize; |
1230 | } |
1231 | |
1232 | |
1233 | GType |
1234 | lttv_tracefile_state_get_type(void) |
1235 | { |
1236 | static GType type = 0; |
1237 | if (type == 0) { |
1238 | static const GTypeInfo info = { |
1239 | sizeof (LttvTracefileStateClass), |
1240 | NULL, /* base_init */ |
1241 | NULL, /* base_finalize */ |
1242 | (GClassInitFunc) tracefile_state_class_init, /* class_init */ |
1243 | NULL, /* class_finalize */ |
1244 | NULL, /* class_data */ |
1245 | sizeof (LttvTracefileState), |
1246 | 0, /* n_preallocs */ |
1247 | (GInstanceInitFunc) tracefile_state_instance_init /* instance_init */ |
1248 | }; |
1249 | |
1250 | type = g_type_register_static (LTTV_TRACEFILE_CONTEXT_TYPE, |
1251 | "LttvTracefileStateType", &info, 0); |
1252 | } |
1253 | return type; |
1254 | } |
1255 | |
1256 | |
ffd54a90 |
1257 | void lttv_state_init(int argc, char **argv) |
1258 | { |
1259 | LTTV_STATE_UNNAMED = g_quark_from_string("unnamed"); |
b445142a |
1260 | LTTV_STATE_MODE_UNKNOWN = g_quark_from_string("unknown execution mode"); |
ffd54a90 |
1261 | LTTV_STATE_USER_MODE = g_quark_from_string("user mode"); |
1262 | LTTV_STATE_WAIT_FORK = g_quark_from_string("wait fork"); |
1263 | LTTV_STATE_SYSCALL = g_quark_from_string("system call"); |
1264 | LTTV_STATE_TRAP = g_quark_from_string("trap"); |
1265 | LTTV_STATE_IRQ = g_quark_from_string("irq"); |
b445142a |
1266 | LTTV_STATE_SUBMODE_UNKNOWN = g_quark_from_string("unknown submode"); |
1267 | LTTV_STATE_SUBMODE_NONE = g_quark_from_string("(no submode)"); |
ffd54a90 |
1268 | LTTV_STATE_WAIT_CPU = g_quark_from_string("wait for cpu"); |
1269 | LTTV_STATE_EXIT = g_quark_from_string("exiting"); |
1270 | LTTV_STATE_WAIT = g_quark_from_string("wait for I/O"); |
1271 | LTTV_STATE_RUN = g_quark_from_string("running"); |
308711e5 |
1272 | LTTV_STATE_TRACEFILES = g_quark_from_string("tracefiles"); |
1273 | LTTV_STATE_PROCESSES = g_quark_from_string("processes"); |
1274 | LTTV_STATE_PROCESS = g_quark_from_string("process"); |
1275 | LTTV_STATE_EVENT = g_quark_from_string("event"); |
1276 | LTTV_STATE_SAVED_STATES = g_quark_from_string("saved states"); |
1277 | LTTV_STATE_TIME = g_quark_from_string("time"); |
ffd54a90 |
1278 | LTTV_STATE_HOOKS = g_quark_from_string("saved state hooks"); |
1279 | } |
dc877563 |
1280 | |
ffd54a90 |
1281 | void lttv_state_destroy() |
1282 | { |
1283 | } |
dc877563 |
1284 | |
1285 | |
1286 | |
1287 | |