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/option.h>
9 #include <lttv/module.h>
10 #include <lttv/processTrace.h>
11 #include <lttv/state.h>
13 static LttvTraceset
*traceset
;
29 void lttv_trace_option(void *hook_data
)
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
);
39 static gboolean
process_traceset(void *hook_data
, void *call_data
)
41 LttvTracesetState
*tc
;
45 tc
= g_object_new(LTTV_TRACESET_STATE_TYPE
, NULL
);
46 lttv_context_init(LTTV_TRACESET_CONTEXT(tc
), traceset
);
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
);
55 end
.tv_sec
= G_MAXULONG
;
56 end
.tv_nsec
= G_MAXULONG
;
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
);
63 lttv_state_remove_event_hooks(tc
);
64 lttv_context_fini(LTTV_TRACESET_CONTEXT(tc
));
69 G_MODULE_EXPORT
void init(LttvModule
*self
, int argc
, char **argv
)
71 LttvAttributeValue value
;
73 LttvIAttribute
*attributes
= LTTV_IATTRIBUTE(lttv_global_attributes());
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
);
80 traceset
= lttv_traceset_new();
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();
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
;
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
);
123 G_MODULE_EXPORT
void destroy()
127 lttv_option_remove("trace");
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
);
137 lttv_hooks_remove_data(main_hooks
, process_traceset
, NULL
);
139 nb
= lttv_traceset_number(traceset
);
140 for(i
= 0 ; i
< nb
; i
++) {
141 ltt_trace_close(lttv_traceset_get(traceset
, i
));
144 lttv_traceset_destroy(traceset
);
This page took 0.047396 seconds and 4 git commands to generate.