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