dc877563 |
1 | |
2 | #include <lttv/state.h> |
ba576a78 |
3 | #include <ltt/facility.h> |
4 | #include <ltt/trace.h> |
dc877563 |
5 | |
ffd54a90 |
6 | LttvInterruptType |
7 | LTTV_STATE_USER_MODE, |
8 | LTTV_STATE_SYSCALL, |
9 | LTTV_STATE_TRAP, |
10 | LTTV_STATE_IRQ; |
11 | |
12 | |
13 | LttvProcessStatus |
14 | LTTV_STATE_UNNAMED, |
15 | LTTV_STATE_WAIT_FORK, |
16 | LTTV_STATE_WAIT_CPU, |
17 | LTTV_STATE_EXIT, |
18 | LTTV_STATE_WAIT, |
19 | LTTV_STATE_RUN; |
20 | |
ba576a78 |
21 | static GQuark |
22 | LTTV_STATE_HOOKS; |
23 | |
24 | void remove_all_processes(GHashTable *processes); |
25 | |
dc877563 |
26 | |
27 | static void |
28 | init(LttvTracesetState *self, LttvTraceset *ts) |
29 | { |
30 | guint i, j, nb_trace, nb_tracefile; |
31 | |
ffd54a90 |
32 | LttvTraceContext *tc; |
dc877563 |
33 | |
ffd54a90 |
34 | LttvTraceState *tcs; |
35 | |
36 | LttvTracefileContext *tfc; |
dc877563 |
37 | |
ffd54a90 |
38 | LttvTracefileState *tfcs; |
39 | |
40 | LTTV_TRACESET_CONTEXT_CLASS(g_type_class_peek_parent(LTTV_TRACESET_STATE_GET_CLASS(self)))->init((LttvTracesetContext *)self, ts); |
dc877563 |
41 | |
42 | nb_trace = lttv_traceset_number(ts); |
43 | for(i = 0 ; i < nb_trace ; i++) { |
ffd54a90 |
44 | tcs = (LttvTraceState *)tc = (LTTV_TRACESET_CONTEXT(self)->traces[i]); |
45 | tcs->processes = g_hash_table_new(g_direct_hash, g_direct_equal); |
dc877563 |
46 | |
47 | nb_tracefile = ltt_trace_control_tracefile_number(tc->t); |
48 | for(j = 0 ; j < nb_tracefile ; j++) { |
ffd54a90 |
49 | tfcs = (LttvTracefileState *)tfc = tc->control_tracefiles[j]; |
50 | tfcs->process = NULL; |
dc877563 |
51 | } |
52 | |
53 | nb_tracefile = ltt_trace_per_cpu_tracefile_number(tc->t); |
54 | for(j = 0 ; j < nb_tracefile ; j++) { |
ffd54a90 |
55 | tfcs = (LttvTracefileState *)tfc = tc->per_cpu_tracefiles[j]; |
56 | tfcs->process = NULL; |
dc877563 |
57 | } |
58 | } |
59 | } |
60 | |
61 | |
62 | static void |
63 | fini(LttvTracesetState *self) |
64 | { |
65 | guint i, j, nb_trace, nb_tracefile; |
66 | |
ffd54a90 |
67 | LttvTraceState *tcs; |
dc877563 |
68 | |
ffd54a90 |
69 | LttvTracefileState *tfcs; |
dc877563 |
70 | |
ffd54a90 |
71 | nb_trace = lttv_traceset_number(LTTV_TRACESET_CONTEXT(self)->ts); |
dc877563 |
72 | for(i = 0 ; i < nb_trace ; i++) { |
ffd54a90 |
73 | tcs = (LttvTraceState *)(LTTV_TRACESET_CONTEXT(self)->traces[i]); |
74 | remove_all_processes(tcs->processes); |
75 | g_hash_table_destroy(tcs->processes); |
dc877563 |
76 | } |
ffd54a90 |
77 | LTTV_TRACESET_CONTEXT_CLASS(g_type_class_peek_parent(LTTV_TRACESET_STATE_GET_CLASS(self)))->fini((LttvTracesetContext *)self); |
dc877563 |
78 | } |
79 | |
80 | |
c432246e |
81 | static LttvTracesetContext * |
dc877563 |
82 | new_traceset_context(LttvTracesetContext *self) |
83 | { |
ffd54a90 |
84 | return LTTV_TRACESET_CONTEXT(g_object_new(LTTV_TRACESET_STATE_TYPE, NULL)); |
dc877563 |
85 | } |
86 | |
87 | |
c432246e |
88 | static LttvTraceContext * |
dc877563 |
89 | new_trace_context(LttvTracesetContext *self) |
90 | { |
ffd54a90 |
91 | return LTTV_TRACE_CONTEXT(g_object_new(LTTV_TRACE_STATE_TYPE, NULL)); |
dc877563 |
92 | } |
93 | |
94 | |
c432246e |
95 | static LttvTracefileContext * |
dc877563 |
96 | new_tracefile_context(LttvTracesetContext *self) |
97 | { |
ffd54a90 |
98 | return LTTV_TRACEFILE_CONTEXT(g_object_new(LTTV_TRACEFILE_STATE_TYPE, NULL)); |
99 | } |
100 | |
101 | |
102 | static void |
103 | traceset_state_instance_init (GTypeInstance *instance, gpointer g_class) |
104 | { |
105 | } |
106 | |
107 | |
108 | static void |
c6bc9cb9 |
109 | traceset_state_finalize (LttvTracesetState *self) |
ffd54a90 |
110 | { |
c6bc9cb9 |
111 | G_OBJECT_CLASS(g_type_class_peek_parent(g_type_class_peek_parent(LTTV_TRACESET_STATE_GET_CLASS(self))))->finalize(G_OBJECT(self)); |
ffd54a90 |
112 | } |
113 | |
114 | |
115 | static void |
116 | traceset_state_class_init (LttvTracesetContextClass *klass) |
117 | { |
118 | GObjectClass *gobject_class = G_OBJECT_CLASS(klass); |
119 | |
120 | gobject_class->finalize = (void (*)(GObject *self)) traceset_state_finalize; |
121 | klass->init = (void (*)(LttvTracesetContext *self, LttvTraceset *ts))init; |
122 | klass->fini = (void (*)(LttvTracesetContext *self))fini; |
123 | klass->new_traceset_context = new_traceset_context; |
124 | klass->new_trace_context = new_trace_context; |
125 | klass->new_tracefile_context = new_tracefile_context; |
dc877563 |
126 | } |
127 | |
128 | |
129 | GType |
130 | lttv_traceset_state_get_type(void) |
131 | { |
132 | static GType type = 0; |
133 | if (type == 0) { |
134 | static const GTypeInfo info = { |
135 | sizeof (LttvTracesetStateClass), |
136 | NULL, /* base_init */ |
137 | NULL, /* base_finalize */ |
ffd54a90 |
138 | (GClassInitFunc) traceset_state_class_init, /* class_init */ |
dc877563 |
139 | NULL, /* class_finalize */ |
140 | NULL, /* class_data */ |
141 | sizeof (LttvTracesetContext), |
142 | 0, /* n_preallocs */ |
ffd54a90 |
143 | (GInstanceInitFunc) traceset_state_instance_init /* instance_init */ |
dc877563 |
144 | }; |
145 | |
146 | type = g_type_register_static (LTTV_TRACESET_CONTEXT_TYPE, "LttvTracesetStateType", |
147 | &info, 0); |
148 | } |
149 | return type; |
150 | } |
151 | |
152 | |
153 | static void |
ffd54a90 |
154 | trace_state_instance_init (GTypeInstance *instance, gpointer g_class) |
dc877563 |
155 | { |
156 | } |
157 | |
158 | |
159 | static void |
c6bc9cb9 |
160 | trace_state_finalize (LttvTraceState *self) |
dc877563 |
161 | { |
c6bc9cb9 |
162 | G_OBJECT_CLASS(g_type_class_peek_parent(g_type_class_peek_parent(LTTV_TRACE_STATE_GET_CLASS(self))))->finalize(G_OBJECT(self)); |
dc877563 |
163 | } |
164 | |
165 | |
166 | static void |
ffd54a90 |
167 | trace_state_class_init (LttvTraceContextClass *klass) |
dc877563 |
168 | { |
169 | GObjectClass *gobject_class = G_OBJECT_CLASS(klass); |
170 | |
ffd54a90 |
171 | gobject_class->finalize = (void (*)(GObject *self)) trace_state_finalize; |
dc877563 |
172 | } |
173 | |
174 | |
175 | GType |
176 | lttv_trace_state_get_type(void) |
177 | { |
178 | static GType type = 0; |
179 | if (type == 0) { |
180 | static const GTypeInfo info = { |
181 | sizeof (LttvTraceStateClass), |
182 | NULL, /* base_init */ |
183 | NULL, /* base_finalize */ |
ffd54a90 |
184 | (GClassInitFunc) trace_state_class_init, /* class_init */ |
dc877563 |
185 | NULL, /* class_finalize */ |
186 | NULL, /* class_data */ |
c6bc9cb9 |
187 | sizeof (LttvTraceState), |
dc877563 |
188 | 0, /* n_preallocs */ |
ffd54a90 |
189 | (GInstanceInitFunc) trace_state_instance_init /* instance_init */ |
dc877563 |
190 | }; |
191 | |
192 | type = g_type_register_static (LTTV_TRACE_CONTEXT_TYPE, |
193 | "LttvTraceStateType", &info, 0); |
194 | } |
195 | return type; |
196 | } |
197 | |
198 | |
199 | static void |
ffd54a90 |
200 | tracefile_state_instance_init (GTypeInstance *instance, gpointer g_class) |
dc877563 |
201 | { |
202 | } |
203 | |
204 | |
205 | static void |
ffd54a90 |
206 | tracefile_state_finalize (LttvTracefileState *self) |
dc877563 |
207 | { |
c6bc9cb9 |
208 | G_OBJECT_CLASS(g_type_class_peek_parent(g_type_class_peek_parent(LTTV_TRACEFILE_STATE_GET_CLASS(self))))->finalize(G_OBJECT(self)); |
dc877563 |
209 | } |
210 | |
211 | |
212 | static void |
ffd54a90 |
213 | tracefile_state_class_init (LttvTracefileStateClass *klass) |
dc877563 |
214 | { |
215 | GObjectClass *gobject_class = G_OBJECT_CLASS(klass); |
216 | |
ffd54a90 |
217 | gobject_class->finalize = (void (*)(GObject *self)) tracefile_state_finalize; |
dc877563 |
218 | } |
219 | |
220 | |
221 | GType |
222 | lttv_tracefile_state_get_type(void) |
223 | { |
224 | static GType type = 0; |
225 | if (type == 0) { |
226 | static const GTypeInfo info = { |
227 | sizeof (LttvTracefileStateClass), |
228 | NULL, /* base_init */ |
229 | NULL, /* base_finalize */ |
ffd54a90 |
230 | (GClassInitFunc) tracefile_state_class_init, /* class_init */ |
dc877563 |
231 | NULL, /* class_finalize */ |
232 | NULL, /* class_data */ |
233 | sizeof (LttvTracefileState), |
234 | 0, /* n_preallocs */ |
ffd54a90 |
235 | (GInstanceInitFunc) tracefile_state_instance_init /* instance_init */ |
dc877563 |
236 | }; |
237 | |
238 | type = g_type_register_static (LTTV_TRACEFILE_CONTEXT_TYPE, |
239 | "LttvTracefileStateType", &info, 0); |
240 | } |
241 | return type; |
242 | } |
243 | |
244 | |
dc877563 |
245 | struct HookData { |
246 | LttField *f1; |
247 | LttField *f2; |
248 | LttField *f3; |
ffd54a90 |
249 | }; |
dc877563 |
250 | |
251 | |
252 | struct HookId { |
253 | LttvHook h; |
254 | guint id; |
255 | void *hook_data; |
256 | gboolean free_hook_data; |
ffd54a90 |
257 | }; |
dc877563 |
258 | |
259 | |
ffd54a90 |
260 | static void push_state(LttvTracefileState *tfs, LttvInterruptType t, |
261 | guint state_id) |
dc877563 |
262 | { |
ffd54a90 |
263 | LttvInterruptState *intr; |
dc877563 |
264 | |
265 | LttvProcessState *process = tfs->process; |
266 | |
267 | guint depth = process->interrupt_stack->len; |
268 | |
269 | g_array_set_size(process->interrupt_stack, depth + 1); |
270 | intr = &g_array_index(process->interrupt_stack, LttvInterruptState, depth); |
271 | intr->t = t; |
272 | intr->n = state_id; |
ffd54a90 |
273 | intr->entry = intr->last_change = LTTV_TRACEFILE_CONTEXT(tfs)->timestamp; |
dc877563 |
274 | intr->s = process->state->s; |
c432246e |
275 | process->state = intr; |
dc877563 |
276 | } |
277 | |
278 | |
ffd54a90 |
279 | static void pop_state(LttvTracefileState *tfs, LttvInterruptType t) |
dc877563 |
280 | { |
281 | LttvProcessState *process = tfs->process; |
282 | |
283 | guint depth = process->interrupt_stack->len - 1; |
284 | |
285 | g_assert(process->state->t == t); |
286 | g_array_remove_index(process->interrupt_stack, depth); |
287 | depth--; |
288 | process->state = &g_array_index(process->interrupt_stack, LttvInterruptState, |
289 | depth); |
290 | } |
291 | |
292 | |
ffd54a90 |
293 | LttvProcessState *create_process(LttvTracefileState *tfs, |
294 | LttvProcessState *parent, guint pid) |
dc877563 |
295 | { |
296 | LttvProcessState *process = g_new(LttvProcessState, 1); |
297 | |
298 | LttvInterruptState *intr; |
299 | |
ffd54a90 |
300 | LttvTraceContext *tc; |
301 | |
ba576a78 |
302 | LttvTraceState *tcs; |
303 | |
304 | LttvTracefileContext *tfc = LTTV_TRACEFILE_CONTEXT(tfs); |
ffd54a90 |
305 | |
ba576a78 |
306 | tcs = (LttvTraceState *)tc = tfc->t_context; |
ffd54a90 |
307 | |
308 | g_hash_table_insert(tcs->processes, GUINT_TO_POINTER(pid), process); |
dc877563 |
309 | process->pid = pid; |
ba576a78 |
310 | process->birth = tfc->timestamp; |
dc877563 |
311 | process->name = LTTV_STATE_UNNAMED; |
312 | process->interrupt_stack = g_array_new(FALSE, FALSE, |
313 | sizeof(LttvInterruptState)); |
314 | g_array_set_size(process->interrupt_stack, 1); |
ffd54a90 |
315 | intr = process->state = &g_array_index(process->interrupt_stack, |
316 | LttvInterruptState, 0); |
ba576a78 |
317 | intr->t = LTTV_STATE_USER_MODE; |
dc877563 |
318 | intr->n = 0; |
ba576a78 |
319 | intr->entry = tfc->timestamp; |
320 | intr->last_change = tfc->timestamp; |
dc877563 |
321 | intr->s = LTTV_STATE_WAIT_FORK; |
cbe7c836 |
322 | |
323 | return process; |
dc877563 |
324 | } |
325 | |
326 | |
ba576a78 |
327 | LttvProcessState *find_process(LttvTracefileState *tfs, guint pid) |
dc877563 |
328 | { |
ba576a78 |
329 | LttvTraceState *ts =(LttvTraceState *)LTTV_TRACEFILE_CONTEXT(tfs)->t_context; |
330 | LttvProcessState *process = g_hash_table_lookup(ts->processes, |
331 | GUINT_TO_POINTER(pid)); |
dc877563 |
332 | if(process == NULL) process = create_process(tfs, NULL, pid); |
333 | return process; |
334 | } |
335 | |
336 | |
ba576a78 |
337 | void exit_process(LttvTracefileState *tfs, LttvProcessState *process) |
dc877563 |
338 | { |
ba576a78 |
339 | LttvTraceState *ts = LTTV_TRACE_STATE(tfs->parent.t_context); |
340 | |
341 | g_hash_table_remove(ts->processes, GUINT_TO_POINTER(process->pid)); |
dc877563 |
342 | g_array_free(process->interrupt_stack, TRUE); |
343 | g_free(process); |
344 | } |
345 | |
346 | |
347 | void free_process_state(gpointer key, gpointer value, gpointer user_data) |
348 | { |
349 | g_array_free(((LttvProcessState *)value)->interrupt_stack, TRUE); |
350 | g_free(value); |
351 | } |
352 | |
353 | |
354 | void remove_all_processes(GHashTable *processes) |
355 | { |
356 | g_hash_table_foreach(processes, free_process_state, NULL); |
357 | } |
358 | |
359 | |
360 | gboolean syscall_entry(void *hook_data, void *call_data) |
361 | { |
362 | LttField *f = (LttField *)hook_data; |
363 | |
ba576a78 |
364 | LttvTracefileState *s = (LttvTracefileState *)call_data; |
dc877563 |
365 | |
ba576a78 |
366 | push_state(s, LTTV_STATE_SYSCALL, ltt_event_get_unsigned( |
367 | LTTV_TRACEFILE_CONTEXT(s)->e, f)); |
dc877563 |
368 | return FALSE; |
369 | } |
370 | |
371 | |
372 | gboolean syscall_exit(void *hook_data, void *call_data) |
373 | { |
ba576a78 |
374 | LttvTracefileState *s = (LttvTracefileState *)call_data; |
dc877563 |
375 | |
ffd54a90 |
376 | pop_state(s, LTTV_STATE_SYSCALL); |
dc877563 |
377 | return FALSE; |
378 | } |
379 | |
380 | |
381 | gboolean trap_entry(void *hook_data, void *call_data) |
382 | { |
383 | LttField *f = (LttField *)hook_data; |
384 | |
ba576a78 |
385 | LttvTracefileState *s = (LttvTracefileState *)call_data; |
dc877563 |
386 | |
ba576a78 |
387 | push_state(s, LTTV_STATE_TRAP, ltt_event_get_unsigned(s->parent.e, f)); |
dc877563 |
388 | return FALSE; |
389 | } |
390 | |
391 | |
392 | gboolean trap_exit(void *hook_data, void *call_data) |
393 | { |
ba576a78 |
394 | LttvTracefileState *s = (LttvTracefileState *)call_data; |
dc877563 |
395 | |
ffd54a90 |
396 | pop_state(s, LTTV_STATE_TRAP); |
dc877563 |
397 | return FALSE; |
398 | } |
399 | |
400 | |
401 | gboolean irq_entry(void *hook_data, void *call_data) |
402 | { |
403 | LttField *f = (LttField *)hook_data; |
404 | |
ba576a78 |
405 | LttvTracefileState *s = (LttvTracefileState *)call_data; |
dc877563 |
406 | |
407 | /* Do something with the info about being in user or system mode when int? */ |
ba576a78 |
408 | push_state(s, LTTV_STATE_IRQ, ltt_event_get_unsigned(s->parent.e, f)); |
dc877563 |
409 | return FALSE; |
410 | } |
411 | |
412 | |
413 | gboolean irq_exit(void *hook_data, void *call_data) |
414 | { |
ba576a78 |
415 | LttvTracefileState *s = (LttvTracefileState *)call_data; |
dc877563 |
416 | |
ffd54a90 |
417 | pop_state(s, LTTV_STATE_IRQ); |
dc877563 |
418 | return FALSE; |
419 | } |
420 | |
421 | |
422 | gboolean schedchange(void *hook_data, void *call_data) |
423 | { |
424 | struct HookData *h = (struct HookData *)hook_data; |
425 | |
ba576a78 |
426 | LttvTracefileState *s = (LttvTracefileState *)call_data; |
dc877563 |
427 | |
428 | guint pid_in, pid_out, state_out; |
429 | |
ba576a78 |
430 | pid_in = ltt_event_get_int(s->parent.e, h->f1); |
431 | pid_out = ltt_event_get_int(s->parent.e, h->f2); |
432 | state_out = ltt_event_get_int(s->parent.e, h->f3); |
dc877563 |
433 | if(s->process != NULL) { |
ffd54a90 |
434 | if(state_out == 0) s->process->state->s = LTTV_STATE_WAIT_CPU; |
435 | else if(s->process->state->s == LTTV_STATE_EXIT) |
ba576a78 |
436 | exit_process(s, s->process); |
ffd54a90 |
437 | else s->process->state->s = LTTV_STATE_WAIT; |
dc877563 |
438 | } |
ba576a78 |
439 | s->process = find_process(s, pid_in); |
ffd54a90 |
440 | s->process->state->s = LTTV_STATE_RUN; |
dc877563 |
441 | return FALSE; |
442 | } |
443 | |
444 | |
445 | gboolean process_fork(void *hook_data, void *call_data) |
446 | { |
447 | LttField *f = (LttField *)hook_data; |
448 | |
ba576a78 |
449 | LttvTracefileState *s = (LttvTracefileState *)call_data; |
dc877563 |
450 | |
451 | guint child_pid; |
452 | |
ba576a78 |
453 | child_pid = ltt_event_get_int(s->parent.e, f); |
454 | create_process(s, s->process, child_pid); |
dc877563 |
455 | return FALSE; |
456 | } |
457 | |
458 | |
459 | gboolean process_exit(void *hook_data, void *call_data) |
460 | { |
ba576a78 |
461 | LttvTracefileState *s = (LttvTracefileState *)call_data; |
dc877563 |
462 | |
463 | if(s->process != NULL) { |
ffd54a90 |
464 | s->process->state->s = LTTV_STATE_EXIT; |
dc877563 |
465 | } |
466 | return FALSE; |
467 | } |
468 | |
469 | |
470 | static LttField * |
471 | find_field(LttEventType *et, const char *field) |
472 | { |
473 | LttType *t; |
474 | |
475 | LttField *f; |
476 | |
477 | guint i, nb; |
478 | |
479 | char *name; |
480 | |
481 | if(field == NULL) return NULL; |
482 | |
483 | f = ltt_eventtype_field(et); |
484 | t = ltt_eventtype_type(et); |
485 | g_assert(ltt_type_class(t) == LTT_STRUCT); |
486 | nb = ltt_type_member_number(t); |
487 | for(i = 0 ; i < nb ; i++) { |
488 | ltt_type_member_type(t, i, &name); |
489 | if(strcmp(name, field) == 0) break; |
490 | } |
491 | g_assert(i < nb); |
492 | return ltt_field_member(f, i); |
493 | } |
494 | |
495 | |
ba576a78 |
496 | static struct HookId |
497 | find_hook(LttTrace *t, char *facility, char *event, |
498 | char *field1, char *field2, char *field3, LttvHook h) |
dc877563 |
499 | { |
500 | LttFacility *f; |
501 | |
502 | LttEventType *et; |
503 | |
504 | guint nb, pos, i; |
505 | |
506 | struct HookId hook_id; |
507 | |
508 | struct HookData hook_data, *phook_data; |
509 | |
510 | char *name; |
511 | |
512 | nb = ltt_trace_facility_find(t, facility, &pos); |
513 | if(nb < 1) g_error("No %s facility", facility); |
ba576a78 |
514 | f = ltt_trace_facility_get(t, pos); |
515 | et = ltt_facility_eventtype_get_by_name(f, event); |
dc877563 |
516 | if(et == NULL) g_error("Event %s does not exist", event); |
517 | |
c432246e |
518 | hook_id.id = ltt_eventtype_id(et); |
dc877563 |
519 | hook_id.h = h; |
520 | hook_id.free_hook_data = FALSE; |
521 | hook_data.f1 = find_field(et, field1); |
522 | hook_data.f2 = find_field(et, field2); |
523 | hook_data.f3 = find_field(et, field3); |
ba576a78 |
524 | if(hook_data.f1 == NULL) hook_id.hook_data = NULL; |
525 | else if(hook_data.f2 == NULL) hook_id.hook_data = hook_data.f1; |
dc877563 |
526 | else { |
527 | phook_data = g_new(struct HookData, 1); |
528 | *phook_data = hook_data; |
529 | hook_id.hook_data = phook_data; |
530 | hook_id.free_hook_data = TRUE; |
531 | } |
532 | return hook_id; |
533 | } |
534 | |
535 | |
536 | lttv_state_add_event_hooks(LttvTracesetState *self) |
537 | { |
ba576a78 |
538 | LttvTraceset *traceset = self->parent.ts; |
dc877563 |
539 | |
ba576a78 |
540 | guint i, j, k, nb_trace, nb_control, nb_per_cpu, nb_tracefile; |
dc877563 |
541 | |
542 | LttFacility *f; |
543 | |
544 | LttEventType *et; |
545 | |
ba576a78 |
546 | LttvTraceState *ts; |
dc877563 |
547 | |
ba576a78 |
548 | LttvTracefileState *tfs; |
dc877563 |
549 | |
550 | void *hook_data; |
551 | |
552 | GArray *hooks; |
553 | |
554 | struct HookId hook_id; |
555 | |
556 | LttvAttributeValue val; |
557 | |
ba576a78 |
558 | nb_trace = lttv_traceset_number(traceset); |
dc877563 |
559 | for(i = 0 ; i < nb_trace ; i++) { |
ba576a78 |
560 | ts = (LttvTraceState *)self->parent.traces[i]; |
dc877563 |
561 | |
562 | /* Find the eventtype id for the following events and register the |
563 | associated by id hooks. */ |
564 | |
ba576a78 |
565 | hooks = g_array_new(FALSE, FALSE, sizeof(struct HookId)); |
cbe7c836 |
566 | hook_id = find_hook(ts->parent.t, "core","syscall_entry","syscall_id", |
567 | NULL, NULL, syscall_entry); |
568 | g_array_append_val(hooks, hook_id); |
569 | |
570 | hook_id = find_hook(ts->parent.t, "core", "syscall_exit", |
571 | NULL, NULL, NULL, syscall_exit); |
572 | g_array_append_val(hooks, hook_id); |
573 | |
574 | hook_id = find_hook(ts->parent.t, "core", "trap_entry", "trap_id", |
575 | NULL, NULL, trap_entry); |
576 | g_array_append_val(hooks, hook_id); |
577 | |
578 | hook_id = find_hook(ts->parent.t, "core", "trap_exit", NULL, NULL, |
579 | NULL, trap_exit); |
580 | g_array_append_val(hooks, hook_id); |
581 | |
582 | hook_id = find_hook(ts->parent.t, "core", "irq_entry", "irq_id", |
583 | NULL, NULL, irq_entry); |
584 | g_array_append_val(hooks, hook_id); |
585 | |
586 | hook_id = find_hook(ts->parent.t, "core", "irq_exit", NULL, NULL, |
587 | NULL, irq_exit); |
588 | g_array_append_val(hooks, hook_id); |
589 | |
590 | hook_id = find_hook(ts->parent.t, "core", "schedchange", |
591 | "in", "out", "out_state", schedchange); |
592 | g_array_append_val(hooks, hook_id); |
593 | |
d83f6739 |
594 | /* for now, in core facility there is no process_fork and process_exit event |
cbe7c836 |
595 | hook_id = find_hook(ts->parent.t, "core", "process_fork", |
596 | "child_pid", NULL, NULL, process_fork); |
597 | g_array_append_val(hooks, hook_id); |
598 | |
599 | hook_id = find_hook(ts->parent.t, "core", "process_exit", |
600 | NULL, NULL, NULL, process_exit); |
601 | g_array_append_val(hooks, hook_id); |
d83f6739 |
602 | */ |
dc877563 |
603 | |
604 | /* Add these hooks to each before_event_by_id hooks list */ |
605 | |
ba576a78 |
606 | nb_control = ltt_trace_control_tracefile_number(ts->parent.t); |
cbe7c836 |
607 | nb_per_cpu = ltt_trace_per_cpu_tracefile_number(ts->parent.t); |
dc877563 |
608 | nb_tracefile = nb_control + nb_per_cpu; |
609 | for(j = 0 ; j < nb_tracefile ; j++) { |
610 | if(j < nb_control) { |
ba576a78 |
611 | tfs = LTTV_TRACEFILE_STATE(ts->parent.control_tracefiles[j]); |
dc877563 |
612 | } |
613 | else { |
cbe7c836 |
614 | tfs = LTTV_TRACEFILE_STATE(ts->parent.per_cpu_tracefiles[j-nb_control]); |
dc877563 |
615 | } |
616 | |
617 | for(k = 0 ; k < hooks->len ; k++) { |
618 | hook_id = g_array_index(hooks, struct HookId, k); |
ba576a78 |
619 | lttv_hooks_add(lttv_hooks_by_id_find(tfs->parent.before_event_by_id, |
620 | hook_id.id), hook_id.h, hook_id.hook_data); |
ffd54a90 |
621 | } |
dc877563 |
622 | } |
ba576a78 |
623 | lttv_attribute_find(self->parent.a, LTTV_STATE_HOOKS, LTTV_POINTER, &val); |
624 | *(val.v_pointer) = hooks; |
dc877563 |
625 | } |
626 | } |
627 | |
628 | |
629 | lttv_state_remove_event_hooks(LttvTracesetState *self) |
630 | { |
ba576a78 |
631 | LttvTraceset *traceset = self->parent.ts; |
dc877563 |
632 | |
ba576a78 |
633 | guint i, j, k, nb_trace, nb_control, nb_per_cpu, nb_tracefile; |
dc877563 |
634 | |
ba576a78 |
635 | LttvTraceState *ts; |
dc877563 |
636 | |
ba576a78 |
637 | LttvTracefileState *tfs; |
dc877563 |
638 | |
639 | void *hook_data; |
640 | |
641 | GArray *hooks; |
642 | |
643 | struct HookId hook_id; |
644 | |
645 | LttvAttributeValue val; |
646 | |
ba576a78 |
647 | nb_trace = lttv_traceset_number(traceset); |
dc877563 |
648 | for(i = 0 ; i < nb_trace ; i++) { |
ba576a78 |
649 | ts = LTTV_TRACE_STATE(self->parent.traces[i]); |
650 | lttv_attribute_find(self->parent.a, LTTV_STATE_HOOKS, LTTV_POINTER, &val); |
651 | hooks = *(val.v_pointer); |
dc877563 |
652 | |
653 | /* Add these hooks to each before_event_by_id hooks list */ |
654 | |
ba576a78 |
655 | nb_control = ltt_trace_control_tracefile_number(ts->parent.t); |
cbe7c836 |
656 | nb_per_cpu = ltt_trace_per_cpu_tracefile_number(ts->parent.t); |
dc877563 |
657 | nb_tracefile = nb_control + nb_per_cpu; |
658 | for(j = 0 ; j < nb_tracefile ; j++) { |
659 | if(j < nb_control) { |
ba576a78 |
660 | tfs = LTTV_TRACEFILE_STATE(ts->parent.control_tracefiles[j]); |
dc877563 |
661 | } |
662 | else { |
cbe7c836 |
663 | tfs = LTTV_TRACEFILE_STATE(ts->parent.per_cpu_tracefiles[j-nb_control]); |
dc877563 |
664 | } |
665 | |
666 | for(k = 0 ; k < hooks->len ; k++) { |
667 | hook_id = g_array_index(hooks, struct HookId, k); |
ba576a78 |
668 | lttv_hooks_remove_data( |
669 | lttv_hooks_by_id_find(tfs->parent.before_event_by_id, |
670 | hook_id.id), hook_id.h, hook_id.hook_data); |
ba576a78 |
671 | if(hook_id.free_hook_data) g_free(hook_id.hook_data); |
ffd54a90 |
672 | } |
cbe7c836 |
673 | // for(k = 0 ; k < hooks->len ; k++) { |
674 | // hook_id = g_array_index(hooks, struct HookId, k); |
675 | // if(hook_id.free_hook_data) g_free(hook_id.hook_data); |
676 | // } |
dc877563 |
677 | } |
678 | g_array_free(hooks, TRUE); |
679 | } |
680 | } |
681 | |
682 | |
ffd54a90 |
683 | void lttv_state_init(int argc, char **argv) |
684 | { |
685 | LTTV_STATE_UNNAMED = g_quark_from_string("unnamed"); |
686 | LTTV_STATE_USER_MODE = g_quark_from_string("user mode"); |
687 | LTTV_STATE_WAIT_FORK = g_quark_from_string("wait fork"); |
688 | LTTV_STATE_SYSCALL = g_quark_from_string("system call"); |
689 | LTTV_STATE_TRAP = g_quark_from_string("trap"); |
690 | LTTV_STATE_IRQ = g_quark_from_string("irq"); |
691 | LTTV_STATE_WAIT_CPU = g_quark_from_string("wait for cpu"); |
692 | LTTV_STATE_EXIT = g_quark_from_string("exiting"); |
693 | LTTV_STATE_WAIT = g_quark_from_string("wait for I/O"); |
694 | LTTV_STATE_RUN = g_quark_from_string("running"); |
695 | LTTV_STATE_HOOKS = g_quark_from_string("saved state hooks"); |
696 | } |
dc877563 |
697 | |
ffd54a90 |
698 | void lttv_state_destroy() |
699 | { |
700 | } |
dc877563 |
701 | |
702 | |
703 | |
704 | |