48f6f3c2 |
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> |
ffd54a90 |
8 | #include <lttv/option.h> |
996acd92 |
9 | #include <lttv/module.h> |
dc877563 |
10 | #include <lttv/processTrace.h> |
11 | #include <lttv/state.h> |
b445142a |
12 | #include <lttv/stats.h> |
a5dcde2f |
13 | #include <ltt/trace.h> |
48f6f3c2 |
14 | |
dc877563 |
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 | |
b445142a |
30 | static gboolean a_stats; |
dc877563 |
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); |
308711e5 |
38 | lttv_traceset_add(traceset, lttv_trace_new(trace)); |
dc877563 |
39 | } |
40 | |
41 | |
ffd54a90 |
42 | static gboolean process_traceset(void *hook_data, void *call_data) |
48f6f3c2 |
43 | { |
b445142a |
44 | LttvTracesetStats *tscs; |
45 | |
46 | LttvTracesetContext *tc; |
48f6f3c2 |
47 | |
dc877563 |
48 | LttTime start, end; |
48f6f3c2 |
49 | |
b445142a |
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"); |
48f6f3c2 |
56 | |
b445142a |
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, |
ffd54a90 |
62 | before_traceset, after_traceset, NULL, before_trace, after_trace, |
63 | NULL, before_tracefile, after_tracefile, NULL, before_event, after_event); |
48f6f3c2 |
64 | |
dc877563 |
65 | start.tv_sec = 0; |
66 | start.tv_nsec = 0; |
67 | end.tv_sec = G_MAXULONG; |
68 | end.tv_nsec = G_MAXULONG; |
48f6f3c2 |
69 | |
b445142a |
70 | g_info("BatchAnalysis process traceset"); |
71 | |
308711e5 |
72 | lttv_process_traceset_seek_time(tc, start); |
73 | lttv_process_traceset(tc, end, G_MAXULONG); |
b445142a |
74 | |
75 | g_info("BatchAnalysis destroy context"); |
76 | |
77 | lttv_traceset_context_remove_hooks(tc, |
ffd54a90 |
78 | before_traceset, after_traceset, NULL, before_trace, after_trace, |
79 | NULL, before_tracefile, after_tracefile, NULL, before_event, after_event); |
b445142a |
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); |
48f6f3c2 |
84 | |
b445142a |
85 | g_info("BatchAnalysis end process traceset"); |
48f6f3c2 |
86 | } |
87 | |
88 | |
d83f6739 |
89 | G_MODULE_EXPORT void init(LttvModule *self, int argc, char **argv) |
48f6f3c2 |
90 | { |
ffd54a90 |
91 | LttvAttributeValue value; |
dc877563 |
92 | |
ffd54a90 |
93 | LttvIAttribute *attributes = LTTV_IATTRIBUTE(lttv_global_attributes()); |
dc877563 |
94 | |
b445142a |
95 | g_info("Init batchAnalysis.c"); |
96 | |
dc877563 |
97 | lttv_option_add("trace", 't', |
98 | "add a trace to the trace set to analyse", |
99 | "pathname of the directory containing the trace", |
ffd54a90 |
100 | LTTV_OPT_STRING, &a_trace, lttv_trace_option, NULL); |
dc877563 |
101 | |
b445142a |
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 | |
dc877563 |
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)); |
ffd54a90 |
122 | *(value.v_pointer) = before_traceset; |
dc877563 |
123 | g_assert(lttv_iattribute_find_by_path(attributes, "hooks/traceset/after", |
124 | LTTV_POINTER, &value)); |
ffd54a90 |
125 | *(value.v_pointer) = after_traceset; |
dc877563 |
126 | g_assert(lttv_iattribute_find_by_path(attributes, "hooks/trace/before", |
127 | LTTV_POINTER, &value)); |
ffd54a90 |
128 | *(value.v_pointer) = before_trace; |
dc877563 |
129 | g_assert(lttv_iattribute_find_by_path(attributes, "hooks/trace/after", |
130 | LTTV_POINTER, &value)); |
ffd54a90 |
131 | *(value.v_pointer) = after_trace; |
dc877563 |
132 | g_assert(lttv_iattribute_find_by_path(attributes, "hooks/tracefile/before", |
133 | LTTV_POINTER, &value)); |
ffd54a90 |
134 | *(value.v_pointer) = before_tracefile; |
dc877563 |
135 | g_assert(lttv_iattribute_find_by_path(attributes, "hooks/tracefile/after", |
136 | LTTV_POINTER, &value)); |
ffd54a90 |
137 | *(value.v_pointer) = after_tracefile; |
dc877563 |
138 | g_assert(lttv_iattribute_find_by_path(attributes, "hooks/event/before", |
139 | LTTV_POINTER, &value)); |
ffd54a90 |
140 | *(value.v_pointer) = before_event; |
dc877563 |
141 | g_assert(lttv_iattribute_find_by_path(attributes, "hooks/event/after", |
142 | LTTV_POINTER, &value)); |
ffd54a90 |
143 | *(value.v_pointer) = after_event; |
dc877563 |
144 | |
145 | g_assert(lttv_iattribute_find_by_path(attributes, "hooks/main/before", |
146 | LTTV_POINTER, &value)); |
ffd54a90 |
147 | g_assert((main_hooks = *(value.v_pointer)) != NULL); |
dc877563 |
148 | lttv_hooks_add(main_hooks, process_traceset, NULL); |
48f6f3c2 |
149 | } |
150 | |
151 | |
d83f6739 |
152 | G_MODULE_EXPORT void destroy() |
48f6f3c2 |
153 | { |
dc877563 |
154 | guint i, nb; |
48f6f3c2 |
155 | |
308711e5 |
156 | LttvTrace *trace; |
157 | |
b445142a |
158 | g_info("Destroy batchAnalysis.c"); |
159 | |
dc877563 |
160 | lttv_option_remove("trace"); |
b445142a |
161 | lttv_option_remove("stats"); |
48f6f3c2 |
162 | |
dc877563 |
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); |
311e7f46 |
171 | lttv_hooks_remove_data(main_hooks, process_traceset, NULL); |
48f6f3c2 |
172 | |
dc877563 |
173 | nb = lttv_traceset_number(traceset); |
ffd54a90 |
174 | for(i = 0 ; i < nb ; i++) { |
308711e5 |
175 | trace = lttv_traceset_get(traceset, i); |
176 | ltt_trace_close(lttv_trace(trace)); |
177 | lttv_trace_destroy(trace); |
dc877563 |
178 | } |
c6bc9cb9 |
179 | |
180 | lttv_traceset_destroy(traceset); |
dc877563 |
181 | } |
48f6f3c2 |
182 | |