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>
12 #include <lttv/stats.h>
13 #include <ltt/trace.h>
15 static LttvTraceset
*traceset
;
30 static gboolean a_stats
;
32 void lttv_trace_option(void *hook_data
)
36 trace
= ltt_trace_open(a_trace
);
37 if(trace
== NULL
) g_critical("cannot open trace %s", a_trace
);
38 lttv_traceset_add(traceset
, lttv_trace_new(trace
));
42 static gboolean
process_traceset(void *hook_data
, void *call_data
)
44 LttvTracesetStats
*tscs
;
46 LttvTracesetContext
*tc
;
50 g_info("BatchAnalysis begin process traceset");
52 tscs
= g_object_new(LTTV_TRACESET_STATS_TYPE
, NULL
);
53 tc
= &tscs
->parent
.parent
;
55 g_info("BatchAnalysis initialize context");
57 lttv_context_init(tc
, traceset
);
58 lttv_state_add_event_hooks(&tscs
->parent
);
59 if(a_stats
) lttv_stats_add_event_hooks(tscs
);
61 lttv_traceset_context_add_hooks(tc
,
62 before_traceset
, after_traceset
, NULL
, before_trace
, after_trace
,
63 NULL
, before_tracefile
, after_tracefile
, NULL
, before_event
, after_event
);
67 end
.tv_sec
= G_MAXULONG
;
68 end
.tv_nsec
= G_MAXULONG
;
70 g_info("BatchAnalysis process traceset");
72 lttv_process_traceset_seek_time(tc
, start
);
73 lttv_process_traceset(tc
, end
, G_MAXULONG
);
75 g_info("BatchAnalysis destroy context");
77 lttv_traceset_context_remove_hooks(tc
,
78 before_traceset
, after_traceset
, NULL
, before_trace
, after_trace
,
79 NULL
, before_tracefile
, after_tracefile
, NULL
, before_event
, after_event
);
80 lttv_state_remove_event_hooks(&tscs
->parent
);
81 if(a_stats
) lttv_stats_remove_event_hooks(tscs
);
82 lttv_context_fini(tc
);
85 g_info("BatchAnalysis end process traceset");
89 G_MODULE_EXPORT
void init(LttvModule
*self
, int argc
, char **argv
)
91 LttvAttributeValue value
;
93 LttvIAttribute
*attributes
= LTTV_IATTRIBUTE(lttv_global_attributes());
95 g_info("Init batchAnalysis.c");
97 lttv_option_add("trace", 't',
98 "add a trace to the trace set to analyse",
99 "pathname of the directory containing the trace",
100 LTTV_OPT_STRING
, &a_trace
, lttv_trace_option
, NULL
);
103 lttv_option_add("stats", 's',
104 "write the traceset and trace statistics",
106 LTTV_OPT_NONE
, &a_stats
, NULL
, NULL
);
109 traceset
= lttv_traceset_new();
111 before_traceset
= lttv_hooks_new();
112 after_traceset
= lttv_hooks_new();
113 before_trace
= lttv_hooks_new();
114 after_trace
= lttv_hooks_new();
115 before_tracefile
= lttv_hooks_new();
116 after_tracefile
= lttv_hooks_new();
117 before_event
= lttv_hooks_new();
118 after_event
= lttv_hooks_new();
120 g_assert(lttv_iattribute_find_by_path(attributes
, "hooks/traceset/before",
121 LTTV_POINTER
, &value
));
122 *(value
.v_pointer
) = before_traceset
;
123 g_assert(lttv_iattribute_find_by_path(attributes
, "hooks/traceset/after",
124 LTTV_POINTER
, &value
));
125 *(value
.v_pointer
) = after_traceset
;
126 g_assert(lttv_iattribute_find_by_path(attributes
, "hooks/trace/before",
127 LTTV_POINTER
, &value
));
128 *(value
.v_pointer
) = before_trace
;
129 g_assert(lttv_iattribute_find_by_path(attributes
, "hooks/trace/after",
130 LTTV_POINTER
, &value
));
131 *(value
.v_pointer
) = after_trace
;
132 g_assert(lttv_iattribute_find_by_path(attributes
, "hooks/tracefile/before",
133 LTTV_POINTER
, &value
));
134 *(value
.v_pointer
) = before_tracefile
;
135 g_assert(lttv_iattribute_find_by_path(attributes
, "hooks/tracefile/after",
136 LTTV_POINTER
, &value
));
137 *(value
.v_pointer
) = after_tracefile
;
138 g_assert(lttv_iattribute_find_by_path(attributes
, "hooks/event/before",
139 LTTV_POINTER
, &value
));
140 *(value
.v_pointer
) = before_event
;
141 g_assert(lttv_iattribute_find_by_path(attributes
, "hooks/event/after",
142 LTTV_POINTER
, &value
));
143 *(value
.v_pointer
) = after_event
;
145 g_assert(lttv_iattribute_find_by_path(attributes
, "hooks/main/before",
146 LTTV_POINTER
, &value
));
147 g_assert((main_hooks
= *(value
.v_pointer
)) != NULL
);
148 lttv_hooks_add(main_hooks
, process_traceset
, NULL
);
152 G_MODULE_EXPORT
void destroy()
158 g_info("Destroy batchAnalysis.c");
160 lttv_option_remove("trace");
161 lttv_option_remove("stats");
163 lttv_hooks_destroy(before_traceset
);
164 lttv_hooks_destroy(after_traceset
);
165 lttv_hooks_destroy(before_trace
);
166 lttv_hooks_destroy(after_trace
);
167 lttv_hooks_destroy(before_tracefile
);
168 lttv_hooks_destroy(after_tracefile
);
169 lttv_hooks_destroy(before_event
);
170 lttv_hooks_destroy(after_event
);
171 lttv_hooks_remove_data(main_hooks
, process_traceset
, NULL
);
173 nb
= lttv_traceset_number(traceset
);
174 for(i
= 0 ; i
< nb
; i
++) {
175 trace
= lttv_traceset_get(traceset
, i
);
176 ltt_trace_close(lttv_trace(trace
));
177 lttv_trace_destroy(trace
);
180 lttv_traceset_destroy(traceset
);
This page took 0.032148 seconds and 4 git commands to generate.