| 1 | /* This module inserts a hook in the program main loop. This hook processes |
| 2 | all the events in the main tracefile. */ |
| 3 | |
| 4 | |
| 5 | #include <lttv/lttv.h> |
| 6 | #include <lttv/attribute.h> |
| 7 | #include <lttv/hook.h> |
| 8 | #include <lttv/module.h> |
| 9 | #include <lttv/processTrace.h> |
| 10 | #include <lttv/state.h> |
| 11 | |
| 12 | static LttvTraceset *traceset; |
| 13 | |
| 14 | static LttvHooks |
| 15 | *before_traceset, |
| 16 | *after_traceset, |
| 17 | *before_trace, |
| 18 | *after_trace, |
| 19 | *before_tracefile, |
| 20 | *after_tracefile, |
| 21 | *before_event, |
| 22 | *after_event, |
| 23 | *main_hooks; |
| 24 | |
| 25 | static char *a_trace; |
| 26 | |
| 27 | |
| 28 | void lttv_trace_option(void *hook_data) |
| 29 | { |
| 30 | LttTrace *trace; |
| 31 | |
| 32 | trace = ltt_trace_open(a_trace); |
| 33 | if(trace == NULL) g_critical("cannot open trace %s", a_trace); |
| 34 | lttv_traceset_add(traceset, trace); |
| 35 | } |
| 36 | |
| 37 | |
| 38 | static void process_traceset(void *hook_data, void *call_data) |
| 39 | { |
| 40 | LttvTracesetState *tc; |
| 41 | |
| 42 | LttTime start, end; |
| 43 | |
| 44 | tc = g_object_new(LTTV_TRACESET_STATE); |
| 45 | lttv_context_init(LTTV_TRACESET_CONTEXT(tc), traceset); |
| 46 | |
| 47 | lttv_traceset_context_add_hooks(LTTV_TRACESET_CONTEXT(tc), |
| 48 | before_traceset, after_traceset, before_trace, after_trace, |
| 49 | before_tracefile, after_tracefile, before_event, after_event); |
| 50 | lttv_state_add_event_hooks(tc); |
| 51 | |
| 52 | start.tv_sec = 0; |
| 53 | start.tv_nsec = 0; |
| 54 | end.tv_sec = G_MAXULONG; |
| 55 | end.tv_nsec = G_MAXULONG; |
| 56 | |
| 57 | lttv_process_trace(start, end, traceset, tc); |
| 58 | lttv_traceset_context_remove_hooks(LTTV_TRACESET_CONTEXT(tc), |
| 59 | before_traceset, after_traceset, before_trace, after_trace, |
| 60 | before_tracefile, after_tracefile, before_event, after_event); |
| 61 | |
| 62 | lttv_state_remove_event_hooks(tc); |
| 63 | lttv_context_fini(LTTV_TRACESET_CONTEXT(tc)); |
| 64 | g_object_unref(tc); |
| 65 | } |
| 66 | |
| 67 | |
| 68 | void init(LttvModule *self, int argc, char **argv) |
| 69 | { |
| 70 | LttvAttribute_value *value; |
| 71 | |
| 72 | LttvIAttributes *attributes = LTTV_IATTRIBUTES(lttv_global_attributes()); |
| 73 | |
| 74 | lttv_option_add("trace", 't', |
| 75 | "add a trace to the trace set to analyse", |
| 76 | "pathname of the directory containing the trace", |
| 77 | LTTV_OPT_STRING, &aTrace, lttv_trace_option, NULL); |
| 78 | |
| 79 | traceset = lttv_traceset_new(); |
| 80 | |
| 81 | before_traceset = lttv_hooks_new(); |
| 82 | after_traceset = lttv_hooks_new(); |
| 83 | before_trace = lttv_hooks_new(); |
| 84 | after_trace = lttv_hooks_new(); |
| 85 | before_tracefile = lttv_hooks_new(); |
| 86 | after_tracefile = lttv_hooks_new(); |
| 87 | before_event = lttv_hooks_new(); |
| 88 | after_event = lttv_hooks_new(); |
| 89 | |
| 90 | g_assert(lttv_iattribute_find_by_path(attributes, "hooks/traceset/before", |
| 91 | LTTV_POINTER, &value)); |
| 92 | *(value->v_pointer) = before_traceset; |
| 93 | g_assert(lttv_iattribute_find_by_path(attributes, "hooks/traceset/after", |
| 94 | LTTV_POINTER, &value)); |
| 95 | *(value->v_pointer) = after_traceset; |
| 96 | g_assert(lttv_iattribute_find_by_path(attributes, "hooks/trace/before", |
| 97 | LTTV_POINTER, &value)); |
| 98 | *(value->v_pointer) = before_trace; |
| 99 | g_assert(lttv_iattribute_find_by_path(attributes, "hooks/trace/after", |
| 100 | LTTV_POINTER, &value)); |
| 101 | *(value->v_pointer) = after_trace; |
| 102 | g_assert(lttv_iattribute_find_by_path(attributes, "hooks/tracefile/before", |
| 103 | LTTV_POINTER, &value)); |
| 104 | *(value->v_pointer) = before_tracefile; |
| 105 | g_assert(lttv_iattribute_find_by_path(attributes, "hooks/tracefile/after", |
| 106 | LTTV_POINTER, &value)); |
| 107 | *(value->v_pointer) = after_tracefile; |
| 108 | g_assert(lttv_iattribute_find_by_path(attributes, "hooks/event/before", |
| 109 | LTTV_POINTER, &value)); |
| 110 | *(value->v_pointer) = before_event; |
| 111 | g_assert(lttv_iattribute_find_by_path(attributes, "hooks/event/after", |
| 112 | LTTV_POINTER, &value)); |
| 113 | *(value->v_pointer) = after_event; |
| 114 | |
| 115 | g_assert(lttv_iattribute_find_by_path(attributes, "hooks/main/before", |
| 116 | LTTV_POINTER, &value)); |
| 117 | g_assert((main_hooks = *(value->v_pointer)) != NULL); |
| 118 | lttv_hooks_add(main_hooks, process_traceset, NULL); |
| 119 | } |
| 120 | |
| 121 | |
| 122 | void destroy() |
| 123 | { |
| 124 | guint i, nb; |
| 125 | |
| 126 | lttv_hooks_remove(main_hooks, process_traceset, NULL); |
| 127 | |
| 128 | lttv_option_remove("trace"); |
| 129 | |
| 130 | lttv_hooks_destroy(before_traceset); |
| 131 | lttv_hooks_destroy(after_traceset); |
| 132 | lttv_hooks_destroy(before_trace); |
| 133 | lttv_hooks_destroy(after_trace); |
| 134 | lttv_hooks_destroy(before_tracefile); |
| 135 | lttv_hooks_destroy(after_tracefile); |
| 136 | lttv_hooks_destroy(before_event); |
| 137 | lttv_hooks_destroy(after_event); |
| 138 | |
| 139 | nb = lttv_traceset_number(traceset); |
| 140 | for(i = 0 ; i < nb, i++) { |
| 141 | ltt_trace_close(lttv_traceset_get(traceset); |
| 142 | } |
| 143 | } |
| 144 | |