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