| 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/option.h> |
| 9 | #include <lttv/module.h> |
| 10 | #include <lttv/processTrace.h> |
| 11 | #include <lttv/state.h> |
| 12 | #include <lttv/stats.h> |
| 13 | #include <ltt/trace.h> |
| 14 | |
| 15 | static LttvTraceset *traceset; |
| 16 | |
| 17 | static LttvHooks |
| 18 | *before_traceset, |
| 19 | *after_traceset, |
| 20 | *before_trace, |
| 21 | *after_trace, |
| 22 | *before_tracefile, |
| 23 | *after_tracefile, |
| 24 | *before_event, |
| 25 | *after_event, |
| 26 | *main_hooks; |
| 27 | |
| 28 | static char *a_trace; |
| 29 | |
| 30 | static gboolean a_stats; |
| 31 | |
| 32 | void lttv_trace_option(void *hook_data) |
| 33 | { |
| 34 | LttTrace *trace; |
| 35 | |
| 36 | trace = ltt_trace_open(a_trace); |
| 37 | if(trace == NULL) g_critical("cannot open trace %s", a_trace); |
| 38 | lttv_traceset_add(traceset, lttv_trace_new(trace)); |
| 39 | } |
| 40 | |
| 41 | |
| 42 | static gboolean process_traceset(void *hook_data, void *call_data) |
| 43 | { |
| 44 | LttvTracesetStats *tscs; |
| 45 | |
| 46 | LttvTracesetContext *tc; |
| 47 | |
| 48 | LttTime start, end; |
| 49 | |
| 50 | g_info("BatchAnalysis begin process traceset"); |
| 51 | |
| 52 | tscs = g_object_new(LTTV_TRACESET_STATS_TYPE, NULL); |
| 53 | tc = &tscs->parent.parent; |
| 54 | |
| 55 | g_info("BatchAnalysis initialize context"); |
| 56 | |
| 57 | lttv_context_init(tc, traceset); |
| 58 | lttv_state_add_event_hooks(&tscs->parent); |
| 59 | if(a_stats) lttv_stats_add_event_hooks(tscs); |
| 60 | |
| 61 | lttv_traceset_context_add_hooks(tc, |
| 62 | before_traceset, after_traceset, NULL, before_trace, after_trace, |
| 63 | NULL, before_tracefile, after_tracefile, NULL, before_event, after_event); |
| 64 | |
| 65 | start.tv_sec = 0; |
| 66 | start.tv_nsec = 0; |
| 67 | end.tv_sec = G_MAXULONG; |
| 68 | end.tv_nsec = G_MAXULONG; |
| 69 | |
| 70 | g_info("BatchAnalysis process traceset"); |
| 71 | |
| 72 | lttv_process_traceset_seek_time(tc, start); |
| 73 | lttv_process_traceset(tc, end, G_MAXULONG); |
| 74 | |
| 75 | g_info("BatchAnalysis destroy context"); |
| 76 | |
| 77 | lttv_traceset_context_remove_hooks(tc, |
| 78 | before_traceset, after_traceset, NULL, before_trace, after_trace, |
| 79 | NULL, before_tracefile, after_tracefile, NULL, before_event, after_event); |
| 80 | lttv_state_remove_event_hooks(&tscs->parent); |
| 81 | if(a_stats) lttv_stats_remove_event_hooks(tscs); |
| 82 | lttv_context_fini(tc); |
| 83 | g_object_unref(tscs); |
| 84 | |
| 85 | g_info("BatchAnalysis end process traceset"); |
| 86 | } |
| 87 | |
| 88 | |
| 89 | G_MODULE_EXPORT void init(LttvModule *self, int argc, char **argv) |
| 90 | { |
| 91 | LttvAttributeValue value; |
| 92 | |
| 93 | LttvIAttribute *attributes = LTTV_IATTRIBUTE(lttv_global_attributes()); |
| 94 | |
| 95 | g_info("Init batchAnalysis.c"); |
| 96 | |
| 97 | lttv_option_add("trace", 't', |
| 98 | "add a trace to the trace set to analyse", |
| 99 | "pathname of the directory containing the trace", |
| 100 | LTTV_OPT_STRING, &a_trace, lttv_trace_option, NULL); |
| 101 | |
| 102 | a_stats = FALSE; |
| 103 | lttv_option_add("stats", 's', |
| 104 | "write the traceset and trace statistics", |
| 105 | "", |
| 106 | LTTV_OPT_NONE, &a_stats, NULL, NULL); |
| 107 | |
| 108 | |
| 109 | traceset = lttv_traceset_new(); |
| 110 | |
| 111 | before_traceset = lttv_hooks_new(); |
| 112 | after_traceset = lttv_hooks_new(); |
| 113 | before_trace = lttv_hooks_new(); |
| 114 | after_trace = lttv_hooks_new(); |
| 115 | before_tracefile = lttv_hooks_new(); |
| 116 | after_tracefile = lttv_hooks_new(); |
| 117 | before_event = lttv_hooks_new(); |
| 118 | after_event = lttv_hooks_new(); |
| 119 | |
| 120 | g_assert(lttv_iattribute_find_by_path(attributes, "hooks/traceset/before", |
| 121 | LTTV_POINTER, &value)); |
| 122 | *(value.v_pointer) = before_traceset; |
| 123 | g_assert(lttv_iattribute_find_by_path(attributes, "hooks/traceset/after", |
| 124 | LTTV_POINTER, &value)); |
| 125 | *(value.v_pointer) = after_traceset; |
| 126 | g_assert(lttv_iattribute_find_by_path(attributes, "hooks/trace/before", |
| 127 | LTTV_POINTER, &value)); |
| 128 | *(value.v_pointer) = before_trace; |
| 129 | g_assert(lttv_iattribute_find_by_path(attributes, "hooks/trace/after", |
| 130 | LTTV_POINTER, &value)); |
| 131 | *(value.v_pointer) = after_trace; |
| 132 | g_assert(lttv_iattribute_find_by_path(attributes, "hooks/tracefile/before", |
| 133 | LTTV_POINTER, &value)); |
| 134 | *(value.v_pointer) = before_tracefile; |
| 135 | g_assert(lttv_iattribute_find_by_path(attributes, "hooks/tracefile/after", |
| 136 | LTTV_POINTER, &value)); |
| 137 | *(value.v_pointer) = after_tracefile; |
| 138 | g_assert(lttv_iattribute_find_by_path(attributes, "hooks/event/before", |
| 139 | LTTV_POINTER, &value)); |
| 140 | *(value.v_pointer) = before_event; |
| 141 | g_assert(lttv_iattribute_find_by_path(attributes, "hooks/event/after", |
| 142 | LTTV_POINTER, &value)); |
| 143 | *(value.v_pointer) = after_event; |
| 144 | |
| 145 | g_assert(lttv_iattribute_find_by_path(attributes, "hooks/main/before", |
| 146 | LTTV_POINTER, &value)); |
| 147 | g_assert((main_hooks = *(value.v_pointer)) != NULL); |
| 148 | lttv_hooks_add(main_hooks, process_traceset, NULL); |
| 149 | } |
| 150 | |
| 151 | |
| 152 | G_MODULE_EXPORT void destroy() |
| 153 | { |
| 154 | guint i, nb; |
| 155 | |
| 156 | LttvTrace *trace; |
| 157 | |
| 158 | g_info("Destroy batchAnalysis.c"); |
| 159 | |
| 160 | lttv_option_remove("trace"); |
| 161 | lttv_option_remove("stats"); |
| 162 | |
| 163 | lttv_hooks_destroy(before_traceset); |
| 164 | lttv_hooks_destroy(after_traceset); |
| 165 | lttv_hooks_destroy(before_trace); |
| 166 | lttv_hooks_destroy(after_trace); |
| 167 | lttv_hooks_destroy(before_tracefile); |
| 168 | lttv_hooks_destroy(after_tracefile); |
| 169 | lttv_hooks_destroy(before_event); |
| 170 | lttv_hooks_destroy(after_event); |
| 171 | lttv_hooks_remove_data(main_hooks, process_traceset, NULL); |
| 172 | |
| 173 | nb = lttv_traceset_number(traceset); |
| 174 | for(i = 0 ; i < nb ; i++) { |
| 175 | trace = lttv_traceset_get(traceset, i); |
| 176 | ltt_trace_close(lttv_trace(trace)); |
| 177 | lttv_trace_destroy(trace); |
| 178 | } |
| 179 | |
| 180 | lttv_traceset_destroy(traceset); |
| 181 | } |
| 182 | |