Commit | Line | Data |
---|---|---|
70407e86 BP |
1 | /* This file is part of the Linux Trace Toolkit viewer |
2 | * Copyright (C) 2009 Benjamin Poirier <benjamin.poirier@polymtl.ca> | |
3 | * | |
4 | * This program is free software; you can redistribute it and/or modify | |
5 | * it under the terms of the GNU General Public License Version 2 as | |
6 | * published by the Free Software Foundation; | |
7 | * | |
8 | * This program is distributed in the hope that it will be useful, | |
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
11 | * GNU General Public License for more details. | |
12 | * | |
13 | * You should have received a copy of the GNU General Public License | |
14 | * along with this program; if not, write to the Free Software | |
15 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, | |
16 | * MA 02111-1307, USA. | |
17 | */ | |
18 | ||
19 | #ifdef HAVE_CONFIG_H | |
20 | #include <config.h> | |
21 | #endif | |
22 | ||
f6691532 | 23 | #include "data_structures.h" |
10341d26 | 24 | #include "event_processing_lttng_common.h" |
70407e86 BP |
25 | |
26 | ||
70407e86 BP |
27 | #ifndef g_info |
28 | #define g_info(format...) g_log (G_LOG_DOMAIN, G_LOG_LEVEL_INFO, format) | |
29 | #endif | |
30 | ||
31 | ||
70407e86 BP |
32 | /* |
33 | * Initialize the GQuarks needed to register the event hooks for | |
34 | * synchronization | |
35 | */ | |
36 | void createQuarks() | |
37 | { | |
38 | LTT_CHANNEL_NET= g_quark_from_static_string("net"); | |
70407e86 | 39 | |
fea7219b | 40 | LTT_EVENT_DEV_XMIT_EXTENDED= g_quark_from_static_string("dev_xmit_extended"); |
70407e86 | 41 | LTT_EVENT_DEV_RECEIVE= g_quark_from_static_string("dev_receive"); |
fea7219b | 42 | LTT_EVENT_TCPV4_RCV_EXTENDED= g_quark_from_static_string("tcpv4_rcv_extended"); |
f6691532 | 43 | LTT_EVENT_UDPV4_RCV_EXTENDED= g_quark_from_static_string("udpv4_rcv_extended"); |
70407e86 BP |
44 | |
45 | LTT_FIELD_SKB= g_quark_from_static_string("skb"); | |
46 | LTT_FIELD_PROTOCOL= g_quark_from_static_string("protocol"); | |
47 | LTT_FIELD_NETWORK_PROTOCOL= | |
48 | g_quark_from_static_string("network_protocol"); | |
49 | LTT_FIELD_TRANSPORT_PROTOCOL= | |
50 | g_quark_from_static_string("transport_protocol"); | |
51 | LTT_FIELD_SADDR= g_quark_from_static_string("saddr"); | |
52 | LTT_FIELD_DADDR= g_quark_from_static_string("daddr"); | |
53 | LTT_FIELD_TOT_LEN= g_quark_from_static_string("tot_len"); | |
54 | LTT_FIELD_IHL= g_quark_from_static_string("ihl"); | |
55 | LTT_FIELD_SOURCE= g_quark_from_static_string("source"); | |
56 | LTT_FIELD_DEST= g_quark_from_static_string("dest"); | |
57 | LTT_FIELD_SEQ= g_quark_from_static_string("seq"); | |
58 | LTT_FIELD_ACK_SEQ= g_quark_from_static_string("ack_seq"); | |
59 | LTT_FIELD_DOFF= g_quark_from_static_string("doff"); | |
60 | LTT_FIELD_ACK= g_quark_from_static_string("ack"); | |
61 | LTT_FIELD_RST= g_quark_from_static_string("rst"); | |
62 | LTT_FIELD_SYN= g_quark_from_static_string("syn"); | |
63 | LTT_FIELD_FIN= g_quark_from_static_string("fin"); | |
f6691532 BP |
64 | LTT_FIELD_UNICAST= g_quark_from_static_string("unicast"); |
65 | LTT_FIELD_ULEN= g_quark_from_static_string("ulen"); | |
66 | LTT_FIELD_DATA_START= g_quark_from_static_string("data_start"); | |
70407e86 BP |
67 | } |
68 | ||
69 | ||
70 | /* Fill hookListList and add event hooks | |
71 | * | |
72 | * Note: possibilité de remettre le code avec lttv_trace_find_marker_ids (voir | |
73 | * r328) | |
74 | * | |
75 | * Args: | |
08365995 BP |
76 | * hookListList: LttvTraceHook hookListList[traceNum][hookNum] |
77 | * traceSetContext: LTTV traceset | |
78 | * hookFunction: call back function when event is encountered | |
79 | * hookData: data that will be made accessible to hookFunction in | |
80 | * arg0->hook_data | |
f6691532 | 81 | * eventTypes: types of events for which to register hooks |
70407e86 BP |
82 | */ |
83 | void registerHooks(GArray* hookListList, LttvTracesetContext* const | |
f6691532 BP |
84 | traceSetContext, LttvHook hookFunction, gpointer hookData, const bool |
85 | const* eventTypes) | |
70407e86 BP |
86 | { |
87 | unsigned int i, j, k; | |
08365995 BP |
88 | unsigned int traceNb= lttv_traceset_number(traceSetContext->ts); |
89 | struct { | |
90 | GQuark channelName; | |
91 | GQuark eventName; | |
92 | GQuark* fields; | |
f6691532 | 93 | bool eventTypes[TYPE_COUNT]; |
08365995 BP |
94 | } eventHookInfoList[] = { |
95 | { | |
96 | .channelName= LTT_CHANNEL_NET, | |
fea7219b | 97 | .eventName= LTT_EVENT_DEV_XMIT_EXTENDED, |
08365995 BP |
98 | .fields= FIELD_ARRAY(LTT_FIELD_SKB, LTT_FIELD_NETWORK_PROTOCOL, |
99 | LTT_FIELD_TRANSPORT_PROTOCOL, LTT_FIELD_SADDR, | |
100 | LTT_FIELD_DADDR, LTT_FIELD_TOT_LEN, LTT_FIELD_IHL, | |
101 | LTT_FIELD_SOURCE, LTT_FIELD_DEST, LTT_FIELD_SEQ, | |
102 | LTT_FIELD_ACK_SEQ, LTT_FIELD_DOFF, LTT_FIELD_ACK, | |
103 | LTT_FIELD_RST, LTT_FIELD_SYN, LTT_FIELD_FIN), | |
f6691532 BP |
104 | .eventTypes[TCP]= true, |
105 | .eventTypes[UDP]= true, | |
08365995 BP |
106 | }, { |
107 | .channelName= LTT_CHANNEL_NET, | |
108 | .eventName= LTT_EVENT_DEV_RECEIVE, | |
109 | .fields= FIELD_ARRAY(LTT_FIELD_SKB, LTT_FIELD_PROTOCOL), | |
f6691532 BP |
110 | .eventTypes[TCP]= true, |
111 | .eventTypes[UDP]= true, | |
08365995 BP |
112 | }, { |
113 | .channelName= LTT_CHANNEL_NET, | |
fea7219b | 114 | .eventName= LTT_EVENT_TCPV4_RCV_EXTENDED, |
08365995 BP |
115 | .fields= FIELD_ARRAY(LTT_FIELD_SKB, LTT_FIELD_SADDR, |
116 | LTT_FIELD_DADDR, LTT_FIELD_TOT_LEN, LTT_FIELD_IHL, | |
117 | LTT_FIELD_SOURCE, LTT_FIELD_DEST, LTT_FIELD_SEQ, | |
118 | LTT_FIELD_ACK_SEQ, LTT_FIELD_DOFF, LTT_FIELD_ACK, | |
119 | LTT_FIELD_RST, LTT_FIELD_SYN, LTT_FIELD_FIN), | |
f6691532 BP |
120 | .eventTypes[TCP]= true, |
121 | .eventTypes[UDP]= false, | |
08365995 | 122 | }, { |
f6691532 BP |
123 | .channelName= LTT_CHANNEL_NET, |
124 | .eventName= LTT_EVENT_UDPV4_RCV_EXTENDED, | |
125 | .fields= FIELD_ARRAY(LTT_FIELD_SKB, LTT_FIELD_SADDR, | |
126 | LTT_FIELD_DADDR, LTT_FIELD_UNICAST, LTT_FIELD_ULEN, | |
127 | LTT_FIELD_DATA_START), | |
128 | .eventTypes[TCP]= false, | |
129 | .eventTypes[UDP]= true, | |
08365995 BP |
130 | } |
131 | }; // This is called a compound literal | |
132 | unsigned int hookNb= sizeof(eventHookInfoList) / sizeof(*eventHookInfoList); | |
70407e86 BP |
133 | |
134 | for(i= 0; i < traceNb; i++) | |
135 | { | |
136 | LttvTraceContext* tc; | |
137 | GArray* hookList; | |
138 | int retval; | |
139 | ||
140 | tc= traceSetContext->traces[i]; | |
141 | hookList= g_array_new(FALSE, FALSE, sizeof(LttvTraceHook)); | |
142 | g_array_append_val(hookListList, hookList); | |
143 | ||
144 | // Find the hooks | |
145 | for (j= 0; j < hookNb; j++) | |
146 | { | |
147 | guint old_len; | |
f6691532 BP |
148 | bool registerHook; |
149 | ||
d4721e1a | 150 | registerHook= false; |
f6691532 BP |
151 | for (k= 0; k < TYPE_COUNT; k++) |
152 | { | |
d4721e1a | 153 | if (eventTypes[k] && eventHookInfoList[j].eventTypes[k]) |
f6691532 | 154 | { |
d4721e1a | 155 | registerHook= true; |
f6691532 BP |
156 | break; |
157 | } | |
158 | } | |
159 | if (!registerHook) | |
160 | { | |
161 | continue; | |
162 | } | |
70407e86 BP |
163 | |
164 | old_len= hookList->len; | |
165 | retval= lttv_trace_find_hook(tc->t, | |
166 | eventHookInfoList[j].channelName, | |
167 | eventHookInfoList[j].eventName, eventHookInfoList[j].fields, | |
168 | hookFunction, hookData, &hookList); | |
169 | if (retval != 0) | |
170 | { | |
171 | g_warning("Trace %d contains no %s.%s marker\n", i, | |
172 | g_quark_to_string(eventHookInfoList[j].channelName), | |
173 | g_quark_to_string(eventHookInfoList[j].eventName)); | |
174 | } | |
175 | else | |
176 | { | |
177 | g_assert(hookList->len - old_len == 1); | |
178 | } | |
179 | } | |
180 | ||
181 | // Add the hooks to each tracefile's event_by_id hook list | |
182 | for(j= 0; j < tc->tracefiles->len; j++) | |
183 | { | |
184 | LttvTracefileContext* tfc; | |
185 | ||
186 | tfc= g_array_index(tc->tracefiles, LttvTracefileContext*, j); | |
187 | ||
188 | for(k= 0; k < hookList->len; k++) | |
189 | { | |
190 | LttvTraceHook* traceHook; | |
191 | ||
192 | traceHook= &g_array_index(hookList, LttvTraceHook, k); | |
193 | if (traceHook->hook_data != hookData) | |
194 | { | |
195 | g_assert_not_reached(); | |
196 | } | |
197 | if (traceHook->mdata == tfc->tf->mdata) | |
198 | { | |
08365995 | 199 | lttv_hooks_add(lttv_hooks_by_id_find(tfc->event_by_id, |
70407e86 BP |
200 | traceHook->id), traceHook->h, traceHook, |
201 | LTTV_PRIO_DEFAULT); | |
202 | } | |
203 | } | |
204 | } | |
205 | } | |
206 | } | |
207 | ||
208 | ||
209 | /* Remove event hooks and free hookListList | |
210 | * | |
211 | * Args: | |
212 | * hookListList: LttvTraceHook hookListList[traceNum][hookNum] | |
213 | * traceSetContext: LTTV traceset | |
70407e86 BP |
214 | */ |
215 | void unregisterHooks(GArray* hookListList, LttvTracesetContext* const | |
08365995 | 216 | traceSetContext) |
70407e86 BP |
217 | { |
218 | unsigned int i, j, k; | |
08365995 | 219 | unsigned int traceNb= lttv_traceset_number(traceSetContext->ts); |
70407e86 BP |
220 | |
221 | for(i= 0; i < traceNb; i++) | |
222 | { | |
223 | LttvTraceContext* tc; | |
224 | GArray* hookList; | |
225 | ||
226 | tc= traceSetContext->traces[i]; | |
227 | hookList= g_array_index(hookListList, GArray*, i); | |
228 | ||
229 | // Remove the hooks from each tracefile's event_by_id hook list | |
230 | for(j= 0; j < tc->tracefiles->len; j++) | |
231 | { | |
232 | LttvTracefileContext* tfc; | |
233 | ||
234 | tfc= g_array_index(tc->tracefiles, LttvTracefileContext*, j); | |
235 | ||
236 | for(k= 0; k < hookList->len; k++) | |
237 | { | |
238 | LttvTraceHook* traceHook; | |
239 | ||
240 | traceHook= &g_array_index(hookList, LttvTraceHook, k); | |
241 | if (traceHook->mdata == tfc->tf->mdata) | |
242 | { | |
243 | lttv_hooks_remove_data(lttv_hooks_by_id_find(tfc->event_by_id, | |
244 | traceHook->id), traceHook->h, traceHook); | |
245 | } | |
246 | } | |
247 | } | |
248 | ||
249 | g_array_free(hookList, TRUE); | |
250 | } | |
251 | g_array_free(hookListList, TRUE); | |
252 | } |