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