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