git-svn-id: http://ltt.polymtl.ca/svn@289 04897980-b3bd-0310-b5e0-8ef037075253
[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>
48f6f3c2 12
dc877563 13static LttvTraceset *traceset;
14
15static LttvHooks
16 *before_traceset,
17 *after_traceset,
18 *before_trace,
19 *after_trace,
20 *before_tracefile,
21 *after_tracefile,
22 *before_event,
23 *after_event,
24 *main_hooks;
25
26static char *a_trace;
27
28
29void lttv_trace_option(void *hook_data)
30{
31 LttTrace *trace;
32
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);
36}
37
38
ffd54a90 39static gboolean process_traceset(void *hook_data, void *call_data)
48f6f3c2 40{
dc877563 41 LttvTracesetState *tc;
48f6f3c2 42
dc877563 43 LttTime start, end;
48f6f3c2 44
ffd54a90 45 tc = g_object_new(LTTV_TRACESET_STATE_TYPE, NULL);
dc877563 46 lttv_context_init(LTTV_TRACESET_CONTEXT(tc), traceset);
48f6f3c2 47
dc877563 48 lttv_traceset_context_add_hooks(LTTV_TRACESET_CONTEXT(tc),
ffd54a90 49 before_traceset, after_traceset, NULL, before_trace, after_trace,
50 NULL, before_tracefile, after_tracefile, NULL, before_event, after_event);
dc877563 51 lttv_state_add_event_hooks(tc);
48f6f3c2 52
dc877563 53 start.tv_sec = 0;
54 start.tv_nsec = 0;
55 end.tv_sec = G_MAXULONG;
56 end.tv_nsec = G_MAXULONG;
48f6f3c2 57
270e7cc5 58 lttv_process_trace(start, end, traceset, LTTV_TRACESET_CONTEXT(tc),G_MAXULONG);
dc877563 59 lttv_traceset_context_remove_hooks(LTTV_TRACESET_CONTEXT(tc),
ffd54a90 60 before_traceset, after_traceset, NULL, before_trace, after_trace,
61 NULL, before_tracefile, after_tracefile, NULL, before_event, after_event);
48f6f3c2 62
dc877563 63 lttv_state_remove_event_hooks(tc);
64 lttv_context_fini(LTTV_TRACESET_CONTEXT(tc));
65 g_object_unref(tc);
48f6f3c2 66}
67
68
d83f6739 69G_MODULE_EXPORT void init(LttvModule *self, int argc, char **argv)
48f6f3c2 70{
ffd54a90 71 LttvAttributeValue value;
dc877563 72
ffd54a90 73 LttvIAttribute *attributes = LTTV_IATTRIBUTE(lttv_global_attributes());
dc877563 74
75 lttv_option_add("trace", 't',
76 "add a trace to the trace set to analyse",
77 "pathname of the directory containing the trace",
ffd54a90 78 LTTV_OPT_STRING, &a_trace, lttv_trace_option, NULL);
dc877563 79
80 traceset = lttv_traceset_new();
81
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();
90
91 g_assert(lttv_iattribute_find_by_path(attributes, "hooks/traceset/before",
92 LTTV_POINTER, &value));
ffd54a90 93 *(value.v_pointer) = before_traceset;
dc877563 94 g_assert(lttv_iattribute_find_by_path(attributes, "hooks/traceset/after",
95 LTTV_POINTER, &value));
ffd54a90 96 *(value.v_pointer) = after_traceset;
dc877563 97 g_assert(lttv_iattribute_find_by_path(attributes, "hooks/trace/before",
98 LTTV_POINTER, &value));
ffd54a90 99 *(value.v_pointer) = before_trace;
dc877563 100 g_assert(lttv_iattribute_find_by_path(attributes, "hooks/trace/after",
101 LTTV_POINTER, &value));
ffd54a90 102 *(value.v_pointer) = after_trace;
dc877563 103 g_assert(lttv_iattribute_find_by_path(attributes, "hooks/tracefile/before",
104 LTTV_POINTER, &value));
ffd54a90 105 *(value.v_pointer) = before_tracefile;
dc877563 106 g_assert(lttv_iattribute_find_by_path(attributes, "hooks/tracefile/after",
107 LTTV_POINTER, &value));
ffd54a90 108 *(value.v_pointer) = after_tracefile;
dc877563 109 g_assert(lttv_iattribute_find_by_path(attributes, "hooks/event/before",
110 LTTV_POINTER, &value));
ffd54a90 111 *(value.v_pointer) = before_event;
dc877563 112 g_assert(lttv_iattribute_find_by_path(attributes, "hooks/event/after",
113 LTTV_POINTER, &value));
ffd54a90 114 *(value.v_pointer) = after_event;
dc877563 115
116 g_assert(lttv_iattribute_find_by_path(attributes, "hooks/main/before",
117 LTTV_POINTER, &value));
ffd54a90 118 g_assert((main_hooks = *(value.v_pointer)) != NULL);
dc877563 119 lttv_hooks_add(main_hooks, process_traceset, NULL);
48f6f3c2 120}
121
122
d83f6739 123G_MODULE_EXPORT void destroy()
48f6f3c2 124{
dc877563 125 guint i, nb;
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);
311e7f46 137 lttv_hooks_remove_data(main_hooks, process_traceset, NULL);
48f6f3c2 138
dc877563 139 nb = lttv_traceset_number(traceset);
ffd54a90 140 for(i = 0 ; i < nb ; i++) {
141 ltt_trace_close(lttv_traceset_get(traceset, i));
dc877563 142 }
c6bc9cb9 143
144 lttv_traceset_destroy(traceset);
dc877563 145}
48f6f3c2 146
This page took 0.029596 seconds and 4 git commands to generate.