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