Filter for selecting trace and tracefile
[lttv.git] / ltt / branches / poly / lttv / batchAnalysis.c
CommitLineData
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>
48f6f3c2 13
dc877563 14static LttvTraceset *traceset;
15
16static 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
27static char *a_trace;
28
b445142a 29static gboolean a_stats;
dc877563 30
31void 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);
308711e5 37 lttv_traceset_add(traceset, lttv_trace_new(trace));
dc877563 38}
39
40
ffd54a90 41static gboolean process_traceset(void *hook_data, void *call_data)
48f6f3c2 42{
b445142a 43 LttvTracesetStats *tscs;
44
45 LttvTracesetContext *tc;
48f6f3c2 46
dc877563 47 LttTime start, end;
48f6f3c2 48
b445142a 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");
48f6f3c2 55
b445142a 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,
ffd54a90 61 before_traceset, after_traceset, NULL, before_trace, after_trace,
62 NULL, before_tracefile, after_tracefile, NULL, before_event, after_event);
48f6f3c2 63
dc877563 64 start.tv_sec = 0;
65 start.tv_nsec = 0;
66 end.tv_sec = G_MAXULONG;
67 end.tv_nsec = G_MAXULONG;
48f6f3c2 68
b445142a 69 g_info("BatchAnalysis process traceset");
70
308711e5 71 lttv_process_traceset_seek_time(tc, start);
72 lttv_process_traceset(tc, end, G_MAXULONG);
b445142a 73
74 g_info("BatchAnalysis destroy context");
75
76 lttv_traceset_context_remove_hooks(tc,
ffd54a90 77 before_traceset, after_traceset, NULL, before_trace, after_trace,
78 NULL, before_tracefile, after_tracefile, NULL, before_event, after_event);
b445142a 79 lttv_state_remove_event_hooks(&tscs->parent);
80 if(a_stats) lttv_stats_remove_event_hooks(tscs);
81 lttv_context_fini(tc);
82 g_object_unref(tscs);
48f6f3c2 83
b445142a 84 g_info("BatchAnalysis end process traceset");
48f6f3c2 85}
86
87
d83f6739 88G_MODULE_EXPORT void init(LttvModule *self, int argc, char **argv)
48f6f3c2 89{
ffd54a90 90 LttvAttributeValue value;
dc877563 91
ffd54a90 92 LttvIAttribute *attributes = LTTV_IATTRIBUTE(lttv_global_attributes());
dc877563 93
b445142a 94 g_info("Init batchAnalysis.c");
95
dc877563 96 lttv_option_add("trace", 't',
97 "add a trace to the trace set to analyse",
98 "pathname of the directory containing the trace",
ffd54a90 99 LTTV_OPT_STRING, &a_trace, lttv_trace_option, NULL);
dc877563 100
b445142a 101 a_stats = FALSE;
102 lttv_option_add("stats", 's',
103 "write the traceset and trace statistics",
104 "",
105 LTTV_OPT_NONE, &a_stats, NULL, NULL);
106
107
dc877563 108 traceset = lttv_traceset_new();
109
110 before_traceset = lttv_hooks_new();
111 after_traceset = lttv_hooks_new();
112 before_trace = lttv_hooks_new();
113 after_trace = lttv_hooks_new();
114 before_tracefile = lttv_hooks_new();
115 after_tracefile = lttv_hooks_new();
116 before_event = lttv_hooks_new();
117 after_event = lttv_hooks_new();
118
119 g_assert(lttv_iattribute_find_by_path(attributes, "hooks/traceset/before",
120 LTTV_POINTER, &value));
ffd54a90 121 *(value.v_pointer) = before_traceset;
dc877563 122 g_assert(lttv_iattribute_find_by_path(attributes, "hooks/traceset/after",
123 LTTV_POINTER, &value));
ffd54a90 124 *(value.v_pointer) = after_traceset;
dc877563 125 g_assert(lttv_iattribute_find_by_path(attributes, "hooks/trace/before",
126 LTTV_POINTER, &value));
ffd54a90 127 *(value.v_pointer) = before_trace;
dc877563 128 g_assert(lttv_iattribute_find_by_path(attributes, "hooks/trace/after",
129 LTTV_POINTER, &value));
ffd54a90 130 *(value.v_pointer) = after_trace;
dc877563 131 g_assert(lttv_iattribute_find_by_path(attributes, "hooks/tracefile/before",
132 LTTV_POINTER, &value));
ffd54a90 133 *(value.v_pointer) = before_tracefile;
dc877563 134 g_assert(lttv_iattribute_find_by_path(attributes, "hooks/tracefile/after",
135 LTTV_POINTER, &value));
ffd54a90 136 *(value.v_pointer) = after_tracefile;
dc877563 137 g_assert(lttv_iattribute_find_by_path(attributes, "hooks/event/before",
138 LTTV_POINTER, &value));
ffd54a90 139 *(value.v_pointer) = before_event;
dc877563 140 g_assert(lttv_iattribute_find_by_path(attributes, "hooks/event/after",
141 LTTV_POINTER, &value));
ffd54a90 142 *(value.v_pointer) = after_event;
dc877563 143
144 g_assert(lttv_iattribute_find_by_path(attributes, "hooks/main/before",
145 LTTV_POINTER, &value));
ffd54a90 146 g_assert((main_hooks = *(value.v_pointer)) != NULL);
dc877563 147 lttv_hooks_add(main_hooks, process_traceset, NULL);
48f6f3c2 148}
149
150
d83f6739 151G_MODULE_EXPORT void destroy()
48f6f3c2 152{
dc877563 153 guint i, nb;
48f6f3c2 154
308711e5 155 LttvTrace *trace;
156
b445142a 157 g_info("Destroy batchAnalysis.c");
158
dc877563 159 lttv_option_remove("trace");
b445142a 160 lttv_option_remove("stats");
48f6f3c2 161
dc877563 162 lttv_hooks_destroy(before_traceset);
163 lttv_hooks_destroy(after_traceset);
164 lttv_hooks_destroy(before_trace);
165 lttv_hooks_destroy(after_trace);
166 lttv_hooks_destroy(before_tracefile);
167 lttv_hooks_destroy(after_tracefile);
168 lttv_hooks_destroy(before_event);
169 lttv_hooks_destroy(after_event);
311e7f46 170 lttv_hooks_remove_data(main_hooks, process_traceset, NULL);
48f6f3c2 171
dc877563 172 nb = lttv_traceset_number(traceset);
ffd54a90 173 for(i = 0 ; i < nb ; i++) {
308711e5 174 trace = lttv_traceset_get(traceset, i);
175 ltt_trace_close(lttv_trace(trace));
176 lttv_trace_destroy(trace);
dc877563 177 }
c6bc9cb9 178
179 lttv_traceset_destroy(traceset);
dc877563 180}
48f6f3c2 181
This page took 0.031738 seconds and 4 git commands to generate.