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