git-svn-id: http://ltt.polymtl.ca/svn@179 04897980-b3bd-0310-b5e0-8ef037075253
[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
13 static LttvTraceset *traceset;
14
15 static LttvHooks
16 *before_traceset,
17 *after_traceset,
18 *before_trace,
19 *after_trace,
20 *before_tracefile,
21 *after_tracefile,
22 *before_event,
23 *after_event,
24 *main_hooks;
25
26 static char *a_trace;
27
28
29 void lttv_trace_option(void *hook_data)
30 {
31 LttTrace *trace;
32
33 trace = ltt_trace_open(a_trace);
34 if(trace == NULL) g_critical("cannot open trace %s", a_trace);
35 lttv_traceset_add(traceset, trace);
36 }
37
38
39 static gboolean process_traceset(void *hook_data, void *call_data)
40 {
41 LttvTracesetState *tc;
42
43 LttTime start, end;
44
45 tc = g_object_new(LTTV_TRACESET_STATE_TYPE, NULL);
46 lttv_context_init(LTTV_TRACESET_CONTEXT(tc), traceset);
47
48 lttv_traceset_context_add_hooks(LTTV_TRACESET_CONTEXT(tc),
49 before_traceset, after_traceset, NULL, before_trace, after_trace,
50 NULL, before_tracefile, after_tracefile, NULL, before_event, after_event);
51 lttv_state_add_event_hooks(tc);
52
53 start.tv_sec = 0;
54 start.tv_nsec = 0;
55 end.tv_sec = G_MAXULONG;
56 end.tv_nsec = G_MAXULONG;
57
58 lttv_process_trace(start, end, traceset, LTTV_TRACESET_CONTEXT(tc));
59 lttv_traceset_context_remove_hooks(LTTV_TRACESET_CONTEXT(tc),
60 before_traceset, after_traceset, NULL, before_trace, after_trace,
61 NULL, before_tracefile, after_tracefile, NULL, before_event, after_event);
62
63 lttv_state_remove_event_hooks(tc);
64 lttv_context_fini(LTTV_TRACESET_CONTEXT(tc));
65 g_object_unref(tc);
66 }
67
68
69 G_MODULE_EXPORT void init(LttvModule *self, int argc, char **argv)
70 {
71 LttvAttributeValue value;
72
73 LttvIAttribute *attributes = LTTV_IATTRIBUTE(lttv_global_attributes());
74
75 lttv_option_add("trace", 't',
76 "add a trace to the trace set to analyse",
77 "pathname of the directory containing the trace",
78 LTTV_OPT_STRING, &a_trace, lttv_trace_option, NULL);
79
80 traceset = lttv_traceset_new();
81
82 before_traceset = lttv_hooks_new();
83 after_traceset = lttv_hooks_new();
84 before_trace = lttv_hooks_new();
85 after_trace = lttv_hooks_new();
86 before_tracefile = lttv_hooks_new();
87 after_tracefile = lttv_hooks_new();
88 before_event = lttv_hooks_new();
89 after_event = lttv_hooks_new();
90
91 g_assert(lttv_iattribute_find_by_path(attributes, "hooks/traceset/before",
92 LTTV_POINTER, &value));
93 *(value.v_pointer) = before_traceset;
94 g_assert(lttv_iattribute_find_by_path(attributes, "hooks/traceset/after",
95 LTTV_POINTER, &value));
96 *(value.v_pointer) = after_traceset;
97 g_assert(lttv_iattribute_find_by_path(attributes, "hooks/trace/before",
98 LTTV_POINTER, &value));
99 *(value.v_pointer) = before_trace;
100 g_assert(lttv_iattribute_find_by_path(attributes, "hooks/trace/after",
101 LTTV_POINTER, &value));
102 *(value.v_pointer) = after_trace;
103 g_assert(lttv_iattribute_find_by_path(attributes, "hooks/tracefile/before",
104 LTTV_POINTER, &value));
105 *(value.v_pointer) = before_tracefile;
106 g_assert(lttv_iattribute_find_by_path(attributes, "hooks/tracefile/after",
107 LTTV_POINTER, &value));
108 *(value.v_pointer) = after_tracefile;
109 g_assert(lttv_iattribute_find_by_path(attributes, "hooks/event/before",
110 LTTV_POINTER, &value));
111 *(value.v_pointer) = before_event;
112 g_assert(lttv_iattribute_find_by_path(attributes, "hooks/event/after",
113 LTTV_POINTER, &value));
114 *(value.v_pointer) = after_event;
115
116 g_assert(lttv_iattribute_find_by_path(attributes, "hooks/main/before",
117 LTTV_POINTER, &value));
118 g_assert((main_hooks = *(value.v_pointer)) != NULL);
119 lttv_hooks_add(main_hooks, process_traceset, NULL);
120 }
121
122
123 G_MODULE_EXPORT void destroy()
124 {
125 guint i, nb;
126
127 lttv_hooks_remove_data(main_hooks, process_traceset, NULL);
128
129 lttv_option_remove("trace");
130
131 lttv_hooks_destroy(before_traceset);
132 lttv_hooks_destroy(after_traceset);
133 lttv_hooks_destroy(before_trace);
134 lttv_hooks_destroy(after_trace);
135 lttv_hooks_destroy(before_tracefile);
136 lttv_hooks_destroy(after_tracefile);
137 lttv_hooks_destroy(before_event);
138 lttv_hooks_destroy(after_event);
139
140 nb = lttv_traceset_number(traceset);
141 for(i = 0 ; i < nb ; i++) {
142 ltt_trace_close(lttv_traceset_get(traceset, i));
143 }
144
145 lttv_traceset_destroy(traceset);
146 }
147
This page took 0.031596 seconds and 4 git commands to generate.