| 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 | |
| 23 | #include "event_processing_lttng_common.h" |
| 24 | |
| 25 | |
| 26 | #ifndef g_info |
| 27 | #define g_info(format...) g_log (G_LOG_DOMAIN, G_LOG_LEVEL_INFO, format) |
| 28 | #endif |
| 29 | |
| 30 | |
| 31 | /* |
| 32 | * Initialize the GQuarks needed to register the event hooks for |
| 33 | * synchronization |
| 34 | */ |
| 35 | void createQuarks() |
| 36 | { |
| 37 | LTT_CHANNEL_NET= g_quark_from_static_string("net"); |
| 38 | LTT_CHANNEL_NETIF_STATE= g_quark_from_static_string("netif_state"); |
| 39 | |
| 40 | LTT_EVENT_DEV_XMIT_EXTENDED= g_quark_from_static_string("dev_xmit_extended"); |
| 41 | LTT_EVENT_DEV_RECEIVE= g_quark_from_static_string("dev_receive"); |
| 42 | LTT_EVENT_TCPV4_RCV_EXTENDED= g_quark_from_static_string("tcpv4_rcv_extended"); |
| 43 | LTT_EVENT_NETWORK_IPV4_INTERFACE= |
| 44 | g_quark_from_static_string("network_ipv4_interface"); |
| 45 | |
| 46 | LTT_FIELD_SKB= g_quark_from_static_string("skb"); |
| 47 | LTT_FIELD_PROTOCOL= g_quark_from_static_string("protocol"); |
| 48 | LTT_FIELD_NETWORK_PROTOCOL= |
| 49 | g_quark_from_static_string("network_protocol"); |
| 50 | LTT_FIELD_TRANSPORT_PROTOCOL= |
| 51 | g_quark_from_static_string("transport_protocol"); |
| 52 | LTT_FIELD_SADDR= g_quark_from_static_string("saddr"); |
| 53 | LTT_FIELD_DADDR= g_quark_from_static_string("daddr"); |
| 54 | LTT_FIELD_TOT_LEN= g_quark_from_static_string("tot_len"); |
| 55 | LTT_FIELD_IHL= g_quark_from_static_string("ihl"); |
| 56 | LTT_FIELD_SOURCE= g_quark_from_static_string("source"); |
| 57 | LTT_FIELD_DEST= g_quark_from_static_string("dest"); |
| 58 | LTT_FIELD_SEQ= g_quark_from_static_string("seq"); |
| 59 | LTT_FIELD_ACK_SEQ= g_quark_from_static_string("ack_seq"); |
| 60 | LTT_FIELD_DOFF= g_quark_from_static_string("doff"); |
| 61 | LTT_FIELD_ACK= g_quark_from_static_string("ack"); |
| 62 | LTT_FIELD_RST= g_quark_from_static_string("rst"); |
| 63 | LTT_FIELD_SYN= g_quark_from_static_string("syn"); |
| 64 | LTT_FIELD_FIN= g_quark_from_static_string("fin"); |
| 65 | LTT_FIELD_NAME= g_quark_from_static_string("name"); |
| 66 | LTT_FIELD_ADDRESS= g_quark_from_static_string("address"); |
| 67 | LTT_FIELD_UP= g_quark_from_static_string("up"); |
| 68 | } |
| 69 | |
| 70 | |
| 71 | /* Fill hookListList and add event hooks |
| 72 | * |
| 73 | * Note: possibilité de remettre le code avec lttv_trace_find_marker_ids (voir |
| 74 | * r328) |
| 75 | * |
| 76 | * Args: |
| 77 | * hookListList: LttvTraceHook hookListList[traceNum][hookNum] |
| 78 | * traceSetContext: LTTV traceset |
| 79 | * hookFunction: call back function when event is encountered |
| 80 | * hookData: data that will be made accessible to hookFunction in |
| 81 | * arg0->hook_data |
| 82 | */ |
| 83 | void registerHooks(GArray* hookListList, LttvTracesetContext* const |
| 84 | traceSetContext, LttvHook hookFunction, gpointer hookData) |
| 85 | { |
| 86 | unsigned int i, j, k; |
| 87 | unsigned int traceNb= lttv_traceset_number(traceSetContext->ts); |
| 88 | struct { |
| 89 | GQuark channelName; |
| 90 | GQuark eventName; |
| 91 | GQuark* fields; |
| 92 | } eventHookInfoList[] = { |
| 93 | { |
| 94 | .channelName= LTT_CHANNEL_NET, |
| 95 | .eventName= LTT_EVENT_DEV_XMIT_EXTENDED, |
| 96 | .fields= FIELD_ARRAY(LTT_FIELD_SKB, LTT_FIELD_NETWORK_PROTOCOL, |
| 97 | LTT_FIELD_TRANSPORT_PROTOCOL, LTT_FIELD_SADDR, |
| 98 | LTT_FIELD_DADDR, LTT_FIELD_TOT_LEN, LTT_FIELD_IHL, |
| 99 | LTT_FIELD_SOURCE, LTT_FIELD_DEST, LTT_FIELD_SEQ, |
| 100 | LTT_FIELD_ACK_SEQ, LTT_FIELD_DOFF, LTT_FIELD_ACK, |
| 101 | LTT_FIELD_RST, LTT_FIELD_SYN, LTT_FIELD_FIN), |
| 102 | }, { |
| 103 | .channelName= LTT_CHANNEL_NET, |
| 104 | .eventName= LTT_EVENT_DEV_RECEIVE, |
| 105 | .fields= FIELD_ARRAY(LTT_FIELD_SKB, LTT_FIELD_PROTOCOL), |
| 106 | }, { |
| 107 | .channelName= LTT_CHANNEL_NET, |
| 108 | .eventName= LTT_EVENT_TCPV4_RCV_EXTENDED, |
| 109 | .fields= FIELD_ARRAY(LTT_FIELD_SKB, LTT_FIELD_SADDR, |
| 110 | LTT_FIELD_DADDR, LTT_FIELD_TOT_LEN, LTT_FIELD_IHL, |
| 111 | LTT_FIELD_SOURCE, LTT_FIELD_DEST, LTT_FIELD_SEQ, |
| 112 | LTT_FIELD_ACK_SEQ, LTT_FIELD_DOFF, LTT_FIELD_ACK, |
| 113 | LTT_FIELD_RST, LTT_FIELD_SYN, LTT_FIELD_FIN), |
| 114 | }, { |
| 115 | .channelName= LTT_CHANNEL_NETIF_STATE, |
| 116 | .eventName= LTT_EVENT_NETWORK_IPV4_INTERFACE, |
| 117 | .fields= FIELD_ARRAY(LTT_FIELD_NAME, LTT_FIELD_ADDRESS, |
| 118 | LTT_FIELD_UP), |
| 119 | } |
| 120 | }; // This is called a compound literal |
| 121 | unsigned int hookNb= sizeof(eventHookInfoList) / sizeof(*eventHookInfoList); |
| 122 | |
| 123 | for(i= 0; i < traceNb; i++) |
| 124 | { |
| 125 | LttvTraceContext* tc; |
| 126 | GArray* hookList; |
| 127 | int retval; |
| 128 | |
| 129 | tc= traceSetContext->traces[i]; |
| 130 | hookList= g_array_new(FALSE, FALSE, sizeof(LttvTraceHook)); |
| 131 | g_array_append_val(hookListList, hookList); |
| 132 | |
| 133 | // Find the hooks |
| 134 | for (j= 0; j < hookNb; j++) |
| 135 | { |
| 136 | guint old_len; |
| 137 | |
| 138 | old_len= hookList->len; |
| 139 | retval= lttv_trace_find_hook(tc->t, |
| 140 | eventHookInfoList[j].channelName, |
| 141 | eventHookInfoList[j].eventName, eventHookInfoList[j].fields, |
| 142 | hookFunction, hookData, &hookList); |
| 143 | if (retval != 0) |
| 144 | { |
| 145 | g_warning("Trace %d contains no %s.%s marker\n", i, |
| 146 | g_quark_to_string(eventHookInfoList[j].channelName), |
| 147 | g_quark_to_string(eventHookInfoList[j].eventName)); |
| 148 | } |
| 149 | else |
| 150 | { |
| 151 | g_assert(hookList->len - old_len == 1); |
| 152 | } |
| 153 | } |
| 154 | |
| 155 | // Add the hooks to each tracefile's event_by_id hook list |
| 156 | for(j= 0; j < tc->tracefiles->len; j++) |
| 157 | { |
| 158 | LttvTracefileContext* tfc; |
| 159 | |
| 160 | tfc= g_array_index(tc->tracefiles, LttvTracefileContext*, j); |
| 161 | |
| 162 | for(k= 0; k < hookList->len; k++) |
| 163 | { |
| 164 | LttvTraceHook* traceHook; |
| 165 | |
| 166 | traceHook= &g_array_index(hookList, LttvTraceHook, k); |
| 167 | if (traceHook->hook_data != hookData) |
| 168 | { |
| 169 | g_assert_not_reached(); |
| 170 | } |
| 171 | if (traceHook->mdata == tfc->tf->mdata) |
| 172 | { |
| 173 | lttv_hooks_add(lttv_hooks_by_id_find(tfc->event_by_id, |
| 174 | traceHook->id), traceHook->h, traceHook, |
| 175 | LTTV_PRIO_DEFAULT); |
| 176 | } |
| 177 | } |
| 178 | } |
| 179 | } |
| 180 | } |
| 181 | |
| 182 | |
| 183 | /* Remove event hooks and free hookListList |
| 184 | * |
| 185 | * Args: |
| 186 | * hookListList: LttvTraceHook hookListList[traceNum][hookNum] |
| 187 | * traceSetContext: LTTV traceset |
| 188 | */ |
| 189 | void unregisterHooks(GArray* hookListList, LttvTracesetContext* const |
| 190 | traceSetContext) |
| 191 | { |
| 192 | unsigned int i, j, k; |
| 193 | unsigned int traceNb= lttv_traceset_number(traceSetContext->ts); |
| 194 | |
| 195 | for(i= 0; i < traceNb; i++) |
| 196 | { |
| 197 | LttvTraceContext* tc; |
| 198 | GArray* hookList; |
| 199 | |
| 200 | tc= traceSetContext->traces[i]; |
| 201 | hookList= g_array_index(hookListList, GArray*, i); |
| 202 | |
| 203 | // Remove the hooks from each tracefile's event_by_id hook list |
| 204 | for(j= 0; j < tc->tracefiles->len; j++) |
| 205 | { |
| 206 | LttvTracefileContext* tfc; |
| 207 | |
| 208 | tfc= g_array_index(tc->tracefiles, LttvTracefileContext*, j); |
| 209 | |
| 210 | for(k= 0; k < hookList->len; k++) |
| 211 | { |
| 212 | LttvTraceHook* traceHook; |
| 213 | |
| 214 | traceHook= &g_array_index(hookList, LttvTraceHook, k); |
| 215 | if (traceHook->mdata == tfc->tf->mdata) |
| 216 | { |
| 217 | lttv_hooks_remove_data(lttv_hooks_by_id_find(tfc->event_by_id, |
| 218 | traceHook->id), traceHook->h, traceHook); |
| 219 | } |
| 220 | } |
| 221 | } |
| 222 | |
| 223 | g_array_free(hookList, TRUE); |
| 224 | } |
| 225 | g_array_free(hookListList, TRUE); |
| 226 | } |