1 /* This module inserts a hook in the program main loop. This hook processes
2 all the events in the main tracefile. */
6 #include <lttv/attribute.h>
8 #include <lttv/module.h>
9 #include <lttv/processTrace.h>
10 #include <lttv/state.h>
12 static LttvTraceset
*traceset
;
28 void lttv_trace_option(void *hook_data
)
32 trace
= ltt_trace_open(a_trace
);
33 if(trace
== NULL
) g_critical("cannot open trace %s", a_trace
);
34 lttv_traceset_add(traceset
, trace
);
38 static void process_traceset(void *hook_data
, void *call_data
)
40 LttvTracesetState
*tc
;
44 tc
= g_object_new(LTTV_TRACESET_STATE
);
45 lttv_context_init(LTTV_TRACESET_CONTEXT(tc
), traceset
);
47 lttv_traceset_context_add_hooks(LTTV_TRACESET_CONTEXT(tc
),
48 before_traceset
, after_traceset
, before_trace
, after_trace
,
49 before_tracefile
, after_tracefile
, before_event
, after_event
);
50 lttv_state_add_event_hooks(tc
);
54 end
.tv_sec
= G_MAXULONG
;
55 end
.tv_nsec
= G_MAXULONG
;
57 lttv_process_trace(start
, end
, traceset
, tc
);
58 lttv_traceset_context_remove_hooks(LTTV_TRACESET_CONTEXT(tc
),
59 before_traceset
, after_traceset
, before_trace
, after_trace
,
60 before_tracefile
, after_tracefile
, before_event
, after_event
);
62 lttv_state_remove_event_hooks(tc
);
63 lttv_context_fini(LTTV_TRACESET_CONTEXT(tc
));
68 void init(LttvModule
*self
, int argc
, char **argv
)
70 LttvAttribute_value
*value
;
72 LttvIAttributes
*attributes
= LTTV_IATTRIBUTES(lttv_global_attributes());
74 lttv_option_add("trace", 't',
75 "add a trace to the trace set to analyse",
76 "pathname of the directory containing the trace",
77 LTTV_OPT_STRING
, &aTrace
, lttv_trace_option
, NULL
);
79 traceset
= lttv_traceset_new();
81 before_traceset
= lttv_hooks_new();
82 after_traceset
= lttv_hooks_new();
83 before_trace
= lttv_hooks_new();
84 after_trace
= lttv_hooks_new();
85 before_tracefile
= lttv_hooks_new();
86 after_tracefile
= lttv_hooks_new();
87 before_event
= lttv_hooks_new();
88 after_event
= lttv_hooks_new();
90 g_assert(lttv_iattribute_find_by_path(attributes
, "hooks/traceset/before",
91 LTTV_POINTER
, &value
));
92 *(value
->v_pointer
) = before_traceset
;
93 g_assert(lttv_iattribute_find_by_path(attributes
, "hooks/traceset/after",
94 LTTV_POINTER
, &value
));
95 *(value
->v_pointer
) = after_traceset
;
96 g_assert(lttv_iattribute_find_by_path(attributes
, "hooks/trace/before",
97 LTTV_POINTER
, &value
));
98 *(value
->v_pointer
) = before_trace
;
99 g_assert(lttv_iattribute_find_by_path(attributes
, "hooks/trace/after",
100 LTTV_POINTER
, &value
));
101 *(value
->v_pointer
) = after_trace
;
102 g_assert(lttv_iattribute_find_by_path(attributes
, "hooks/tracefile/before",
103 LTTV_POINTER
, &value
));
104 *(value
->v_pointer
) = before_tracefile
;
105 g_assert(lttv_iattribute_find_by_path(attributes
, "hooks/tracefile/after",
106 LTTV_POINTER
, &value
));
107 *(value
->v_pointer
) = after_tracefile
;
108 g_assert(lttv_iattribute_find_by_path(attributes
, "hooks/event/before",
109 LTTV_POINTER
, &value
));
110 *(value
->v_pointer
) = before_event
;
111 g_assert(lttv_iattribute_find_by_path(attributes
, "hooks/event/after",
112 LTTV_POINTER
, &value
));
113 *(value
->v_pointer
) = after_event
;
115 g_assert(lttv_iattribute_find_by_path(attributes
, "hooks/main/before",
116 LTTV_POINTER
, &value
));
117 g_assert((main_hooks
= *(value
->v_pointer
)) != NULL
);
118 lttv_hooks_add(main_hooks
, process_traceset
, NULL
);
126 lttv_hooks_remove(main_hooks
, process_traceset
, NULL
);
128 lttv_option_remove("trace");
130 lttv_hooks_destroy(before_traceset
);
131 lttv_hooks_destroy(after_traceset
);
132 lttv_hooks_destroy(before_trace
);
133 lttv_hooks_destroy(after_trace
);
134 lttv_hooks_destroy(before_tracefile
);
135 lttv_hooks_destroy(after_tracefile
);
136 lttv_hooks_destroy(before_event
);
137 lttv_hooks_destroy(after_event
);
139 nb
= lttv_traceset_number(traceset
);
140 for(i
= 0 ; i
< nb
, i
++) {
141 ltt_trace_close(lttv_traceset_get(traceset
);
This page took 0.033214 seconds and 5 git commands to generate.